jquery.verySimpleImageViewer.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /**
  2. * jquery.verySimpleImageViewer.js
  3. * Ver. : 1.0.0
  4. * last update: 28/04/2018
  5. * Author: meshesha , https://github.com/meshesha
  6. * LICENSE: MIT
  7. * url:https://meshesha.github.io/verySimpleImageViewer
  8. */
  9. (function ($) {
  10. $.fn.verySimpleImageViewer = function( options ) {
  11. var settings = $.extend(true,{},{
  12. // These are the defaults.
  13. imageSource: "",
  14. frame: ['720px','480px',false],
  15. maxZoom: '300%',
  16. zoomFactor: '10%',
  17. mouse: true,
  18. keyboard: true,
  19. toolbar: true,
  20. rotateToolbar: true
  21. }, options );
  22. var imageSource = settings.imageSource;
  23. var frame = settings.frame;
  24. var maxZoom = settings.maxZoom;
  25. var zoomFactor = settings.zoomFactor;
  26. var isMouse = settings.mouse;
  27. var isKeyboard = settings.keyboard;
  28. var isToolbar = settings.toolbar;
  29. var rotateToolbar = settings.rotateToolbar;
  30. var self = this;
  31. //var $result = $(this);
  32. var parent = $(this)[0];
  33. var image = null;
  34. var rotateAngle = 0;
  35. self.frameElement = null;
  36. var orignalW,orignalH, zoomLevel = 0;
  37. var lastMousePosition = null, speed = 5;
  38. var mouseWheelObject = null;
  39. console.log(settings)
  40. /*Methods*/
  41. self.getFrameDimension = function() {
  42. return [self.frameElement.clientWidth,self.frameElement.clientHeight];
  43. }
  44. self.setDimension = function(width,height) { //width and height of image
  45. image.width=Math.round(width);
  46. image.height=Math.round(height);
  47. }
  48. self.getDimension = function() {
  49. return [image.width,image.height];
  50. }
  51. self.setPosition = function(x,y) { //x and y coordinate of image
  52. image.style.left=(Math.round(x)+'px');
  53. image.style.top=(Math.round(y)+'px');
  54. }
  55. self.getPosition = function() {
  56. return [retInt(image.style.left,'px'),retInt(image.style.top,'px')];
  57. }
  58. self.setMouseCursor = function() {
  59. var dimension = self.getDimension();
  60. var frameDimension = self.getFrameDimension();
  61. var cursor='crosshair';
  62. if(dimension[0]>frameDimension[0] && dimension[1]>frameDimension[1])
  63. cursor='move';
  64. else if(dimension[0]>frameDimension[0])
  65. cursor='e-resize';
  66. else if(dimension[1]>frameDimension[1])
  67. cursor='n-resize';
  68. image.style.cursor=cursor;
  69. }
  70. self.maxZoomCheck = function(width,height) {
  71. if(typeof width=='undefined' || typeof height=='undefined') {
  72. var temp = self.getDimension();
  73. width=temp[0], height=temp[1];
  74. }
  75. if(typeof maxZoom=='number') {
  76. return ((width/orignalW)>maxZoom || (height/orignalH)>maxZoom);
  77. }
  78. else if(typeof maxZoom=='object') {
  79. return (width>maxZoom[0] || height>maxZoom[1]);
  80. }
  81. }
  82. self.fitToFrame = function(width, height) { //width and height of image
  83. if(typeof width=='undefined' || typeof height=='undefined') {
  84. width = orignalW, height = orignalH;
  85. }
  86. var frameDimension = self.getFrameDimension(), newWidth,newHeight;
  87. newWidth = frameDimension[0];
  88. newHeight = Math.round((newWidth*height)/width);
  89. if(newHeight>(frameDimension[1])) {
  90. newHeight = frameDimension[1];
  91. newWidth = Math.round((newHeight*width)/height);
  92. }
  93. return [newWidth,newHeight];
  94. }
  95. self.getZoomLevel = function() {
  96. return zoomLevel;
  97. }
  98. self.zoomTo = function(newZoomLevel, x, y) {
  99. var frameDimension = self.getFrameDimension();
  100. //check if x and y coordinate is within the self.frameElement
  101. if(newZoomLevel<0 || x<0 || y<0 || x>=frameDimension[0] || y>=frameDimension[1])
  102. return false;
  103. var dimension = self.fitToFrame(orignalW,orignalH);
  104. for(var i=newZoomLevel; i>0;i--)
  105. dimension[0] *= zoomFactor, dimension[1] *= zoomFactor;
  106. //Calculate percentage increase/decrease and fix the image over given x,y coordinate
  107. var curWidth=image.width, curHeight=image.height;
  108. var position = self.getPosition();
  109. position[0]-=((x-position[0])*((dimension[0]/curWidth)-1)), position[1]-=((y-position[1])*((dimension[1]/curHeight)-1)); //Applying the above formula
  110. //Center image
  111. position = self.centerImage(dimension[0],dimension[1], position[0],position[1]);
  112. //Set dimension and position
  113. if(!self.maxZoomCheck(dimension[0],dimension[1])) {
  114. zoomLevel = newZoomLevel;
  115. self.setDimension(dimension[0],dimension[1]);
  116. self.setPosition(position[0],position[1]);
  117. self.setMouseCursor();
  118. }
  119. else
  120. return false;
  121. return true;
  122. }
  123. self.centerImage = function(width,height, x,y) { //width and height of image and (x,y) is the (left,top) of the image
  124. if(typeof width=='undefined' || typeof height=='undefined') {
  125. var temp = self.getDimension();
  126. width=temp[0], height=temp[1];
  127. }
  128. if(typeof x=='undefined' || typeof y=='undefined') {
  129. var temp = self.getPosition();
  130. x=temp[0], y=temp[1];
  131. }
  132. var frameDimension = self.getFrameDimension();
  133. if(width<=frameDimension[0])
  134. x = Math.round((frameDimension[0] - width)/2);
  135. if(height<=frameDimension[1])
  136. y = Math.round((frameDimension[1] - height)/2);
  137. if(width>frameDimension[0]) {
  138. if(x>0)
  139. x=0;
  140. else
  141. if((x+width)<frameDimension[0])
  142. x=frameDimension[0]-width;
  143. }
  144. if(height>frameDimension[1]) {
  145. if(y>0)
  146. y=0;
  147. else
  148. if((y+height)<frameDimension[1])
  149. y=frameDimension[1]-height;
  150. }
  151. return [x,y];
  152. }
  153. self.rotate = function(direction,reset){
  154. if(direction == "1"){
  155. rotateAngle += 90;
  156. }else{
  157. rotateAngle -= 90;
  158. }
  159. //console.log(self.frameElement)
  160. if(reset){
  161. $("." + self.frameElement.className +" .jqvsiv_main_image_content").css('transform','rotate(0deg)');
  162. }else{
  163. $("." + self.frameElement.className +" .jqvsiv_main_image_content").css('transform','rotate(' + rotateAngle + 'deg)');
  164. //need to reset mous position and direction - TODO
  165. }
  166. }
  167. self.reset = function() {
  168. var dimension = self.fitToFrame(orignalW,orignalH);
  169. var position = self.centerImage(dimension[0],dimension[1], 0,0);
  170. self.setDimension(dimension[0],dimension[1]);
  171. self.setPosition(position[0],position[1]);
  172. zoomLevel = 0;
  173. self.rotate("1",true);
  174. }
  175. /*Event handlers*/
  176. self.onmousewheel = function(event,object,direction) {
  177. self.frameElement.focus();
  178. if (!event){ //For IE
  179. event = window.event, event.returnValue = false;
  180. }else if (event.preventDefault){
  181. event.preventDefault();
  182. }
  183. if((zoomLevel+direction)>=0) {
  184. var mousePos = getMouseXY(event);
  185. var framePos = getObjectXY(self.frameElement);
  186. self.zoomTo(zoomLevel+direction, mousePos[0]-framePos[0], mousePos[1]-framePos[1]);
  187. }
  188. }
  189. self.onmousemove = function(event) {
  190. if (!event){ //For IE
  191. event = window.event, event.returnValue = false;
  192. }else if (event.preventDefault){
  193. event.preventDefault();
  194. }
  195. var mousePosition = getMouseXY(event);
  196. var position = self.getPosition();
  197. position[0] += (mousePosition[0]-lastMousePosition[0]), position[1]+=(mousePosition[1]-lastMousePosition[1]);
  198. lastMousePosition = mousePosition;
  199. position = self.centerImage(image.width,image.height, position[0],position[1]);
  200. self.setPosition(position[0],position[1]);
  201. }
  202. self.onmouseup_or_out = function(event) {
  203. if (!event){ //For IE
  204. event = window.event, event.returnValue = false;
  205. }else if (event.preventDefault){
  206. event.preventDefault();
  207. }
  208. image.onmousemove = image.onmouseup=image.onmouseout=null;
  209. image.onmousedown = self.onmousedown;
  210. }
  211. self.onmousedown = function(event) {
  212. self.frameElement.focus();
  213. if (!event){ //For IE
  214. event = window.event, event.returnValue = false;
  215. }else if (event.preventDefault){
  216. event.preventDefault();
  217. }
  218. lastMousePosition = getMouseXY(event);
  219. image.onmousemove = self.onmousemove;
  220. image.onmouseup = image.onmouseout=self.onmouseup_or_out;
  221. }
  222. self.onkeypress = function(event) {
  223. var keyCode;
  224. if(window.event){ // IE
  225. event = window.event, keyCode = event.keyCode, event.returnValue = false;
  226. }else if(event.which){
  227. keyCode = event.which, event.preventDefault();
  228. }
  229. keyCode = String.fromCharCode(keyCode);
  230. var position = self.getPosition();
  231. var LEFT='a',UP='w',RIGHT='d',DOWN='s', CENTER_IMAGE='c', ZOOMIN='=', ZOOMOUT='-'; ///Keys a,w,d,s
  232. if(keyCode == LEFT){
  233. position[0]+=speed;
  234. }else if(keyCode == UP){
  235. position[1] += speed;
  236. }else if(keyCode == RIGHT){
  237. position[0] -= speed;
  238. }else if(keyCode==DOWN){
  239. position[1] -= speed;
  240. }else if(keyCode == CENTER_IMAGE || keyCode == 'C'){
  241. self.reset();
  242. }else if(keyCode == ZOOMIN || keyCode == '+' || keyCode == 'x' || keyCode == 'X'){
  243. self.zoomTo(zoomLevel+1, self.frameElement.clientWidth/2, self.frameElement.clientHeight/2);
  244. }else if( (keyCode == ZOOMOUT || keyCode == 'z' || keyCode == 'Z') && zoomLevel > 0){
  245. self.zoomTo(zoomLevel-1, self.frameElement.clientWidth/2, self.frameElement.clientHeight/2);
  246. }
  247. if(keyCode == LEFT || keyCode == UP || keyCode == RIGHT || keyCode == DOWN) {
  248. position = self.centerImage(image.width,image.height, position[0],position[1]);
  249. self.setPosition(position[0],position[1]);
  250. speed += 2;
  251. }
  252. }
  253. self.onkeyup = function(event) {
  254. speed = 5;
  255. }
  256. /*Initializaion*/
  257. self.setZoomProp = function(newZoomFactor,newMaxZoom) {
  258. if(newZoomFactor == null){
  259. zoomFactor = 10;
  260. }
  261. zoomFactor = 1 + retInt(newZoomFactor,'%')/100;
  262. if(typeof newMaxZoom == 'string'){
  263. maxZoom = retInt(newMaxZoom,'%')/100;
  264. }else if(typeof newMaxZoom == 'object' && newMaxZoom != null) {
  265. maxZoom[0] = retInt(newMaxZoom[0],'px');
  266. maxZoom[1] = retInt(newMaxZoom[1],'px');
  267. }else{
  268. maxZoom = '300%';
  269. }
  270. }
  271. self.initImage = function() {
  272. image.style.maxWidth=image.style.width=image.style.maxHeight=image.style.height=null;
  273. orignalW=image.width;
  274. orignalH=image.height;
  275. var dimension = self.fitToFrame(orignalW, orignalH);
  276. self.setDimension(dimension[0],dimension[1]);
  277. if(frame[2] == true)
  278. self.frameElement.style.width = (Math.round(dimension[0])+ 'px');
  279. if(frame[3] == true)
  280. self.frameElement.style.height = (Math.round(dimension[1]) + 'px');
  281. var pos = self.centerImage(dimension[0],dimension[1], 0,0);
  282. self.setPosition(pos[0],pos[1]);
  283. self.setMouseCursor();
  284. //Set mouse handlers
  285. if(isMouse){
  286. mouseWheelObject = new mouseWheel();
  287. mouseWheelObject.init(image, self.onmousewheel);
  288. image.onmousedown = self.onmousedown;
  289. }
  290. //Set keyboard handlers
  291. if(isKeyboard){
  292. self.frameElement.onkeypress = self.onkeypress;
  293. self.frameElement.onkeyup = self.onkeyup;
  294. }
  295. //Set toolbar handlers
  296. if(isToolbar){
  297. self.loadToolbar(self);
  298. }
  299. }
  300. /*Set a base*/
  301. self.setZoomProp(zoomFactor,maxZoom);
  302. //Create self.frameElement - One time initialization
  303. self.frameElement = document.createElement('div');
  304. self.frameElement.className = 'image_viewer_inner_container';
  305. self.frameElement.style.width = frame[0];
  306. self.frameElement.style.height = frame[1];
  307. self.frameElement.style.border="0px solid #000";
  308. self.frameElement.style.margin="0px";
  309. self.frameElement.style.padding="0px";
  310. self.frameElement.style.overflow="hidden";
  311. self.frameElement.style.position="relative";
  312. self.frameElement.style.zIndex=2;
  313. self.frameElement.tabIndex=1;
  314. if(image!=null) {
  315. if (parent != null) {
  316. image.parentNode.removeChild(image);
  317. parent.appendChild(self.frameElement);
  318. }else{
  319. image.parentNode.replaceChild(self.frameElement,image);
  320. }
  321. image.style.margin=image.style.padding="0";
  322. image.style.borderWidth="0px";
  323. image.style.position='absolute';
  324. image.style.zIndex=3;
  325. self.frameElement.appendChild(image);
  326. //if(imageSource!=null)
  327. // self.preInitImage();
  328. //else
  329. // self.initImage();
  330. }else {
  331. if(parent!=null)
  332. parent.appendChild(self.frameElement);
  333. var div_imge_container = document.createElement('div');
  334. div_imge_container.className = 'jqvsiv_main_image_content';
  335. image = document.createElement('img');
  336. image.className = 'image_container';
  337. image.style.position='absolute';
  338. image.style.zIndex=3;
  339. div_imge_container.appendChild(image);
  340. self.frameElement.appendChild(div_imge_container);
  341. image.onload = self.initImage;
  342. image.src = imageSource;
  343. }
  344. //Toolbar
  345. self.loadToolbar = function(self) {
  346. //var toolbarImages="./images/toolbar";
  347. var toolbar = document.createElement('div');
  348. toolbar.className='jqvsiv_toolbar';
  349. var isEnterKey = function(event) {
  350. var keyCode;
  351. if(event.keyCode){ // IE
  352. keyCode = event.keyCode, event.returnValue = false;
  353. }else if(event.which){
  354. keyCode = event.which, event.preventDefault();
  355. }
  356. return keyCode == 13;
  357. }
  358. var zoomIn = document.createElement('img');
  359. zoomIn.className='jqvsiv_toolbarButton';
  360. zoomIn.title='Zoom in';
  361. zoomIn.tabIndex="1";
  362. zoomIn.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABN0lEQVRIic3WMW6DMBQGYN+EqhGJJYZMvUMHpByAKceIKpYuGUqmLjFESIm6pQORgpSJwNYoYsiQsSfB9utSUBKZYgcs1dI/4s+8Z2NQf54MMUnzAUk5Jil0kd+58v48GSJM0ryriQXJUZcrF70J0rh6wCSF/wVYfgaWn+kBRusjUMaBMg72at89MN6eoBxOGIPpRXqBhxdfCmkFyCC1wGh9hPH2VOXt67sCprsDOGFcxV4maoDlZ0AZB9lRUAZ4ttEL9NxAWK7aEtmr/VUZprtDbYme3z9re/Jnk00vqh50wljYZFEukcZdVCIqwCUitU1NL1IGSkT6HNjLBArKoKDsquZNUfuazjbQcwPpydWBm8ZrAVSRu69MGcSYBLzVpd+EGO7ijNr+togQYxJww12cH18/nn4Aw1rF5Pti/U4AAAAASUVORK5CYII=";//toolbarImages+'/in.png';
  363. zoomIn.onclick = zoomIn.onkeypress = function(event) {
  364. event=event?event:window.event;
  365. if (event.type == 'keypress')
  366. if(!isEnterKey(event))
  367. return;
  368. var frameDimension = self.getFrameDimension();
  369. self.zoomTo(self.getZoomLevel()+1, frameDimension[0]/2,frameDimension[1]/2);
  370. }
  371. var zoomOut = document.createElement('img');
  372. zoomOut.className='jqvsiv_toolbarButton';
  373. zoomOut.title='Zoom out';
  374. zoomOut.tabIndex="1";
  375. zoomOut.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAA3klEQVRIiWNQm7FPX2PmgbPqMw/805h54D81MNSss2oz9ukzaMw8cJZaBmPBZxmo6XJsPmGgoev/a8w88H/UglELaGiB/+rT/xO3XCQK+68+TZoF2rMO/v/z999/YsHvP3//a/Rtoq0FyrWz/6v2biQ+iHwWHfgfPW8rUdhj8pr/CtWz/itUz8KwBG8kq/ZsgGskBSNbQjAVUWoJUcmUEkuIzgfkWkJSRiPHEpJzMqmWkFVUkGIJ2VUmMZbIV87+R1GlT8gS+do5VxkobbZgs0S+cvY/+do5V5WalpgCAJUZolx/yaTFAAAAAElFTkSuQmCC";//toolbarImages+'/out.png';
  376. zoomOut.onclick = zoomOut.onkeypress = function(event) {
  377. event=event?event:window.event;
  378. if (event.type == 'keypress')
  379. if(!isEnterKey(event))
  380. return;
  381. var frameDimension = self.getFrameDimension();
  382. self.zoomTo(self.getZoomLevel()-1, frameDimension[0]/2,frameDimension[1]/2);
  383. }
  384. var center = document.createElement('img');
  385. center.className='jqvsiv_toolbarButton';
  386. center.title='Center image';
  387. center.tabIndex="1";
  388. center.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABmklEQVRIic3WvWrCUBQH8LyJomiCQwO+Q7u0bl0FX0MsqCA6CEIXa+LXJqhQQUEc2pBqEWkJlXQrzSA6VKEfLkUo5t+hNURNNNEUeuGMOb+bc8/hXsKd4WiK4QWS4WWK4WFF/OYS3BmOJiiGF6xKrBECYeXOtf6E+MPdg2J4/H+AzrURaPStBU4q9/AWOqBzbXSGr5jLMvzVrnVAU5rg4eUD3dEbAODmaQgynIcrVd8f8LA8prMvLNbt8whkOA97iIU9xK4hpoHTSwHqJQzG8ESLCrCKmAaSPUlJ/v45Q0OUcHheXQLUiGkgci0i3urBl67BcZZdS7yKbAU87E9Zkj0JEe4R1AUHZ6y0MbE6dIHjyh2a0mTpQOOtHpyxkilEF/AWOuiPp0sH6kvXYA+xphBdgM61lT5fHKi65kYRTWAxoYs+FwZjNERp7WMjiCYQaPQxl2VlQj3RIo40WtEIolsif7W7NKGbYhOysU1dqbrhdtRDts7BvoihK3NXxBbMyoYv/V0QR6IsEmaeLUYRWzArOxJlkUxfHXwDNFegvBR/iaAAAAAASUVORK5CYII=";//toolbarImages+'/center.png';
  389. center.onclick = center.onkeypress = function(event) {
  390. event=event?event:window.event;
  391. if (event.type == 'keypress')
  392. if(!isEnterKey(event))
  393. return;
  394. self.reset();
  395. }
  396. //self.rotate = function(direction)
  397. if(rotateToolbar){
  398. var rotateRight = document.createElement('img');
  399. rotateRight.className='jqvsiv_toolbarButton';
  400. rotateRight.title='Center image';
  401. rotateRight.tabIndex="1";
  402. rotateRight.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAB1ElEQVRIieXWwUvbYBjH8fwndRW7CoID3Wn3nYSdxIviQQa7bHdp62GIXvTiEBpTqUyZssKglk4UtJlawUmKshUtgtV6kMEs2m2lmpjvLrbM2TdrY3Yy8FwS+H3e503e943kCa60emVVeyirpldWcaKuszRPcKVV8sqq5lRwldIkJ0derRPpP44er6xyj4BXS2mKuoGcOuLR5KqzwJO3G6znTjEB48rk16XOSDLjDPBi4Quiq2k0ejegL75TCTvOFzCBC8Pg8PScrlCM2a1deiMb9oGD/E8A3iRSdIfjZL+f44+u4fYr9E4tVHCPRSdC4FlkC4CzYonGgEKDb+JGuf0KZ8USAB3jH4TTJQReLn0FYDN7ciu8XJvZEwCezyzS4JuoigiBnvltAHL5ghDI5QsAPB2LVO79jQiBFuUTPy50ALrD8VvhPeGPAJR0gwf+m8/+RCxf8nByH66//YFYkvbhadqGphmIJbkyTQB80bWq3ZURS6BZVpn6nBGug/daRjh9ZeTfKzmYoG9OZXnviOKlTkk3SOW+0anMW4aXq7a9KJigcfBdTYH2gDsg9W3XNpD6j8w6EFe/Yto79GtEXIFQWrL922KBuPoV0xUIpd2vZx7/Bh7Ty4bjzETnAAAAAElFTkSuQmCC";
  403. rotateRight.onclick = rotateRight.onkeypress = function(event) {
  404. event=event?event:window.event;
  405. if (event.type == 'keypress')
  406. if(!isEnterKey(event))
  407. return;
  408. //var frameDimension = self.getFrameDimension();
  409. self.rotate("1");
  410. }
  411. var rotateLeft = document.createElement('img');
  412. rotateLeft.className='jqvsiv_toolbarButton';
  413. rotateLeft.title='Center image';
  414. rotateLeft.tabIndex="1";
  415. rotateLeft.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAACQklEQVRIie3W3U9SYRwH8POfcEDj0Mtcq7XVP9BVra2tyy5aba1/wQOI2dxq3rQSeQ4qIdiLthZtNcSXc0wj8zgQCSEqmHOYLwnMCBU559uFwxREXoK7nu13+/38nme/59lDMcaRJjXhvYxJkDREQC2KMQmSmvBexjjSRKkJ761VcH6pCe+latn5YTuh6hWeq/9AbYBbb+cwubi+ubG9s5PYykhDkVVcfzP7b8BxIuDSgAjiXQAABJZ+Sh3DIh7xHoRX4llJlmFyzy9UDVwZFAEAsY10+pkYRKO+G+fv9+NMex9UWjN63X7IMnB74H2gKuCO04/cevc5Aprl8NLzBR3DImiWg0prxtfVBJyBKBru2T9WDOgmwsup7Qx6Pvhx4UF/AUCzHCxuP+K/N0GzXFGkKHCKjKcbW3vDuTCa5fB0Oojp6A+cbbeBZjn0TQX2AJrl0NBmK0COnCLGOBpX6syLuYATrRY8nwnhKnFA3dKDWOIXnIEo9jeRj5QcU+axK3bTNpRSac17Icf03XgxE0JWknHx4eABYBf5e1wlgRuvxVhWkhBaXgc34YN1KoDIWhKZrAStY7IgPB8p66Jds7jmHL5v+L6WxFIyhaH5KC53vioavh8pC2CIICvb7J9KBR5WZb9FjGlcUhmsYt2AXWQsSxusnroBGiJAY+IzSoN1tmyAIYJcKcJ0jW0pW574S4UrWCJRDBF8Fe+CCGC6+LRCbwkeCTRzQepkp+t01d8W02hKqTv4nOQ6VzRzQdVd+7k/U9So5+j1RlYAAAAASUVORK5CYII=";
  416. rotateLeft.onclick = rotateLeft.onkeypress = function(event) {
  417. event=event?event:window.event;
  418. if (event.type == 'keypress')
  419. if(!isEnterKey(event))
  420. return;
  421. //var frameDimension = self.getFrameDimension();
  422. self.rotate("-1");
  423. }
  424. }
  425. toolbar.appendChild(zoomIn);
  426. toolbar.appendChild(zoomOut);
  427. if(rotateToolbar){
  428. toolbar.appendChild(rotateRight);
  429. toolbar.appendChild(rotateLeft);
  430. }
  431. toolbar.appendChild(center);
  432. self.frameElement.appendChild(toolbar);
  433. }
  434. }
  435. function getObjectXY(object) {
  436. var left,top;
  437. objectCopy=object;
  438. if (object.offsetParent) {
  439. left=top=0;
  440. do {
  441. left += object.offsetLeft;
  442. if(object.style.borderLeftWidth!='')
  443. left+=parseInt(object.style.borderLeftWidth);
  444. else
  445. object.style.borderLeftWidth='0px';
  446. top += object.offsetTop;
  447. if(object.style.borderTopWidth!='')
  448. top+=parseInt(object.style.borderTopWidth);
  449. else
  450. object.style.borderTopWidth='0px';
  451. }
  452. while (object = object.offsetParent);
  453. }
  454. return [left-parseInt(objectCopy.style.borderLeftWidth),top-parseInt(objectCopy.style.borderLeftWidth)];
  455. }
  456. function retInt(str, suffix) {
  457. if(typeof str=='number')
  458. return str;
  459. var result=str.indexOf(suffix);
  460. return parseInt(str.substring(0,(result!=-1)?result:str.length))
  461. }
  462. /*Mouse related functions*/
  463. //Used to retrieve the mouse cursor position on screen (but event is needed as argument)
  464. function getMouseXY(event) {
  465. var posx = 0, posy = 0;
  466. if (!event) event = window.event; //firefox
  467. if (event.pageX || event.pageY) {
  468. posx = event.pageX;
  469. posy = event.pageY;
  470. }
  471. else if (event.clientX || event.clientY) { //IE
  472. posx = event.clientX + document.body.scrollLeft
  473. + document.documentElement.scrollLeft;
  474. posy = event.clientY + document.body.scrollTop
  475. + document.documentElement.scrollTop;
  476. }
  477. return [posx,posy];
  478. }
  479. function mouseWheel() {
  480. var self=this;
  481. /*Event handlers*/
  482. /*Mouse wheel functions*/
  483. //Default mouse wheel callback function
  484. //Variable local to 'this'
  485. var wheelCallback = function(event,object,delta){
  486. /*Override this function and write your code there*/
  487. /*
  488. delta=-1 when mouse wheel is rolled backwards (towards yourself)
  489. delta=1 when mouse wheel is rolled forward (away from one's self)
  490. Note: Here is where you can call the getMouseXY function using the 'event' argument
  491. */
  492. }
  493. //Mouse wheel event handler
  494. self.wheelHandler = function (event){
  495. var delta = 0;
  496. if (!event) //For IE
  497. event = window.event;
  498. if (event.wheelDelta) //IE
  499. {
  500. delta = event.wheelDelta/120;
  501. //if (window.opera) delta = -delta; //for Opera...hmm I read somewhere opera 9 need the delta sign inverted...tried in opera 10 and it doesnt require this!?
  502. }
  503. else if (event.detail) //firefox
  504. delta = -event.detail/3;
  505. if (event.preventDefault)
  506. event.preventDefault();
  507. event.returnValue = false;
  508. if (delta)
  509. wheelCallback(event,this,delta); //callback function
  510. }
  511. //Mouse wheel initialization
  512. self.init = function(object,callback) {
  513. if (object.addEventListener) //For firefox
  514. object.addEventListener('DOMMouseScroll', this.wheelHandler, false); //Mouse wheel initialization
  515. //For IE
  516. object.onmousewheel = this.wheelHandler; //Mouse wheel initialization
  517. wheelCallback=callback;
  518. }
  519. this.setCallback = function(callback){
  520. wheelCallback=callback;
  521. }
  522. }
  523. }(jQuery));