jquery.ez-plus.js 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. // jscs:disable
  2. /* jshint -W071, -W074 */
  3. // jscs:enable
  4. /* globals jQuery */
  5. /*
  6. * jQuery ezPlus 1.1.21
  7. * Demo's and documentation:
  8. * http://igorlino.github.io/elevatezoom-plus/
  9. *
  10. * licensed under MIT license.
  11. * http://en.wikipedia.org/wiki/MIT_License
  12. *
  13. */
  14. if (typeof Object.create !== 'function') {
  15. Object.create = function (obj) {
  16. function F() {
  17. }
  18. F.prototype = obj;
  19. return new F();
  20. };
  21. }
  22. (function ($, window, document, undefined) {
  23. var EZP = {
  24. init: function (options, elem) {
  25. var self = this;
  26. self.elem = elem;
  27. self.$elem = $(elem);
  28. self.options = $.extend({}, $.fn.ezPlus.options, self.responsiveConfig(options || {}));
  29. self.imageSrc = self.$elem.data(self.options.attrImageZoomSrc) ? self.$elem.data(self.options.attrImageZoomSrc) : self.$elem.attr('src');
  30. if (!self.options.enabled) {
  31. return;
  32. }
  33. //TINT OVERRIDE SETTINGS
  34. if (self.options.tint) {
  35. self.options.lensColour = 'transparent'; //colour of the lens background
  36. self.options.lensOpacity = '1'; //opacity of the lens
  37. }
  38. //INNER OVERRIDE SETTINGS
  39. if (self.options.zoomType === 'inner') {
  40. self.options.showLens = false;
  41. }
  42. // LENS OVERRIDE SETTINGS
  43. if (self.options.zoomType === 'lens') {
  44. self.options.zoomWindowWidth = 0;
  45. }
  46. //UUID WHEN MISSING IDENTIFIER
  47. if (self.options.zoomId === -1) {
  48. self.options.zoomId = generateUUID();
  49. }
  50. //Remove alt on hover
  51. self.$elem.parent().removeAttr('title').removeAttr('alt');
  52. self.zoomImage = self.imageSrc;
  53. self.refresh(1);
  54. //Create the image swap from the gallery
  55. var galleryEvent = self.options.galleryEvent + '.ezpspace';
  56. galleryEvent += self.options.touchEnabled ? ' touchend.ezpspace' : '';
  57. self.$galleries = $(self.options.gallery ? ('#' + self.options.gallery) : self.options.gallerySelector);
  58. self.$galleries.on(galleryEvent, self.options.galleryItem, function (e) {
  59. //Set a class on the currently active gallery image
  60. if (self.options.galleryActiveClass) {
  61. $(self.options.galleryItem, self.$galleries).removeClass(self.options.galleryActiveClass);
  62. $(this).addClass(self.options.galleryActiveClass);
  63. }
  64. //stop any link on the a tag from working
  65. if (this.tagName === 'A') {
  66. e.preventDefault();
  67. }
  68. //call the swap image function
  69. if ($(this).data(self.options.attrImageZoomSrc)) {
  70. self.zoomImagePre = $(this).data(self.options.attrImageZoomSrc);
  71. }
  72. else {
  73. self.zoomImagePre = $(this).data('image');
  74. }
  75. self.swaptheimage($(this).data('image'), self.zoomImagePre);
  76. if (this.tagName === 'A') {
  77. return false;
  78. }
  79. });
  80. function generateUUID() {
  81. var d = new Date().getTime();
  82. var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  83. var r = (d + Math.random() * 16) % 16 | 0; // jshint ignore:line
  84. d = Math.floor(d / 16); // jshint ignore:line
  85. return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); // jshint ignore:line
  86. });
  87. return uuid;
  88. }
  89. },
  90. refresh: function (length) {
  91. var self = this;
  92. setTimeout(function () {
  93. self.fetch(self.imageSrc, self.$elem, self.options.minZoomLevel);
  94. }, length || self.options.refresh);
  95. },
  96. fetch: function (imgsrc, element, minZoom) {
  97. //get the image
  98. var self = this;
  99. var newImg = new Image();
  100. newImg.onload = function () {
  101. //set the large image dimensions - used to calculte ratio's
  102. if (newImg.width / element.width() <= minZoom) {
  103. self.largeWidth = element.width() * minZoom;
  104. } else {
  105. self.largeWidth = newImg.width;
  106. }
  107. if (newImg.height / element.height() <= minZoom) {
  108. self.largeHeight = element.height() * minZoom;
  109. } else {
  110. self.largeHeight = newImg.height;
  111. }
  112. //once image is loaded start the calls
  113. self.startZoom();
  114. self.currentImage = self.imageSrc;
  115. //let caller know image has been loaded
  116. self.options.onZoomedImageLoaded(self.$elem);
  117. };
  118. self.setImageSource(newImg, imgsrc); // this must be done AFTER setting onload
  119. return;
  120. },
  121. setImageSource: function (image, src) {
  122. //sets an image's source.
  123. image.src = src;
  124. },
  125. startZoom: function () {
  126. var self = this;
  127. //get dimensions of the non zoomed image
  128. self.nzWidth = self.$elem.width();
  129. self.nzHeight = self.$elem.height();
  130. //activated elements
  131. self.isWindowActive = false;
  132. self.isLensActive = false;
  133. self.isTintActive = false;
  134. self.overWindow = false;
  135. //CrossFade Wrapper
  136. if (self.options.imageCrossfade) {
  137. var elementZoomWrapper = $('<div class="zoomWrapper"/>')
  138. .css({
  139. height: self.nzHeight,
  140. width: self.nzWidth
  141. });
  142. self.zoomWrap = self.$elem.wrap(elementZoomWrapper);
  143. self.$elem.css({
  144. position: 'absolute'
  145. });
  146. }
  147. self.zoomLock = 1;
  148. self.scrollingLock = false;
  149. self.changeBgSize = false;
  150. self.currentZoomLevel = self.options.zoomLevel;
  151. //get offset of the non zoomed image
  152. self.updateOffset(self);
  153. //calculate the width ratio of the large/small image
  154. self.widthRatio = (self.largeWidth / self.currentZoomLevel) / self.nzWidth;
  155. self.heightRatio = (self.largeHeight / self.currentZoomLevel) / self.nzHeight;
  156. function getWindowZoomStyle() {
  157. return {
  158. display: 'none',
  159. position: 'absolute',
  160. height: self.options.zoomWindowHeight,
  161. width: self.options.zoomWindowWidth,
  162. border: '' + self.options.borderSize + 'px solid ' + self.options.borderColour,
  163. backgroundSize: '' + (self.largeWidth / self.currentZoomLevel) + 'px ' + (self.largeHeight / self.currentZoomLevel) + 'px',
  164. backgroundPosition: '0px 0px',
  165. backgroundRepeat: 'no-repeat',
  166. backgroundColor: '' + self.options.zoomWindowBgColour,
  167. overflow: 'hidden',
  168. zIndex: 100
  169. };
  170. }
  171. //if window zoom
  172. if (self.options.zoomType === 'window') {
  173. self.zoomWindowStyle = getWindowZoomStyle();
  174. }
  175. function getInnerZoomStyle() {
  176. //has a border been put on the image? Lets cater for this
  177. var borderWidth = self.$elem.css('border-left-width');
  178. return {
  179. display: 'none',
  180. position: 'absolute',
  181. height: self.nzHeight,
  182. width: self.nzWidth,
  183. marginTop: borderWidth,
  184. marginLeft: borderWidth,
  185. border: '' + self.options.borderSize + 'px solid ' + self.options.borderColour,
  186. backgroundPosition: '0px 0px',
  187. backgroundRepeat: 'no-repeat',
  188. cursor: self.options.cursor,
  189. overflow: 'hidden',
  190. zIndex: self.options.zIndex
  191. };
  192. }
  193. //if inner zoom
  194. if (self.options.zoomType === 'inner') {
  195. self.zoomWindowStyle = getInnerZoomStyle();
  196. }
  197. function getWindowLensStyle() {
  198. // adjust images less than the window height
  199. if (self.nzHeight < self.options.zoomWindowHeight / self.heightRatio) {
  200. self.lensHeight = self.nzHeight;
  201. }
  202. else {
  203. self.lensHeight = self.options.zoomWindowHeight / self.heightRatio;
  204. }
  205. if (self.largeWidth < self.options.zoomWindowWidth) {
  206. self.lensWidth = self.nzWidth;
  207. }
  208. else {
  209. self.lensWidth = self.options.zoomWindowWidth / self.widthRatio;
  210. }
  211. return {
  212. display: 'none',
  213. position: 'absolute',
  214. height: self.lensHeight,
  215. width: self.lensWidth,
  216. border: '' + self.options.lensBorderSize + 'px' + ' solid ' + self.options.lensBorderColour,
  217. backgroundPosition: '0px 0px',
  218. backgroundRepeat: 'no-repeat',
  219. backgroundColor: self.options.lensColour,
  220. opacity: self.options.lensOpacity,
  221. cursor: self.options.cursor,
  222. zIndex: 999,
  223. overflow: 'hidden'
  224. };
  225. }
  226. //lens style for window zoom
  227. if (self.options.zoomType === 'window') {
  228. self.lensStyle = getWindowLensStyle();
  229. }
  230. //tint style
  231. self.tintStyle = {
  232. display: 'block',
  233. position: 'absolute',
  234. height: self.nzHeight,
  235. width: self.nzWidth,
  236. backgroundColor: self.options.tintColour,
  237. opacity: 0
  238. };
  239. //lens style for lens zoom with optional round for modern browsers
  240. self.lensRound = {};
  241. if (self.options.zoomType === 'lens') {
  242. self.lensStyle = {
  243. display: 'none',
  244. position: 'absolute',
  245. float: 'left',
  246. height: self.options.lensSize,
  247. width: self.options.lensSize,
  248. border: '' + self.options.borderSize + 'px solid ' + self.options.borderColour,
  249. backgroundPosition: '0px 0px',
  250. backgroundRepeat: 'no-repeat',
  251. backgroundColor: self.options.lensColour,
  252. cursor: self.options.cursor
  253. };
  254. }
  255. //does not round in all browsers
  256. if (self.options.lensShape === 'round') {
  257. self.lensRound = {
  258. borderRadius: self.options.lensSize / 2 + self.options.borderSize
  259. };
  260. }
  261. //create the div's + ""
  262. //self.zoomContainer = $('<div/>').addClass('zoomContainer').css({"position":"relative", "height":self.nzHeight, "width":self.nzWidth});
  263. self.zoomContainer = $('<div class="zoomContainer" ' + 'uuid="' + self.options.zoomId + '"/>');
  264. self.zoomContainer.css({
  265. position: 'absolute',
  266. top: self.nzOffset.top,
  267. left: self.nzOffset.left,
  268. height: self.nzHeight,
  269. width: self.nzWidth,
  270. zIndex: self.options.zIndex
  271. });
  272. if (self.$elem.attr('id')) {
  273. self.zoomContainer.attr('id', self.$elem.attr('id') + '-zoomContainer');
  274. }
  275. $(self.options.zoomContainerAppendTo).append(self.zoomContainer);
  276. //this will add overflow hidden and contrain the lens on lens mode
  277. if (self.options.containLensZoom && self.options.zoomType === 'lens') {
  278. self.zoomContainer.css('overflow', 'hidden');
  279. }
  280. if (self.options.zoomType !== 'inner') {
  281. self.zoomLens = $('<div class="zoomLens"/>')
  282. .css($.extend({}, self.lensStyle, self.lensRound))
  283. .appendTo(self.zoomContainer)
  284. .click(function () {
  285. self.$elem.trigger('click');
  286. });
  287. if (self.options.tint) {
  288. self.tintContainer = $('<div class="tintContainer"/>');
  289. self.zoomTint = $('<div class="zoomTint"/>').css(self.tintStyle);
  290. self.zoomLens.wrap(self.tintContainer);
  291. self.zoomTintcss = self.zoomLens.after(self.zoomTint);
  292. //if tint enabled - set an image to show over the tint
  293. self.zoomTintImage = $('<img src="' + self.$elem.attr('src') + '">')
  294. .css({
  295. position: 'absolute',
  296. top: 0,
  297. left: 0,
  298. height: self.nzHeight,
  299. width: self.nzWidth,
  300. maxWidth: 'none'
  301. })
  302. .appendTo(self.zoomLens)
  303. .click(function () {
  304. self.$elem.trigger('click');
  305. });
  306. }
  307. }
  308. //create zoom window
  309. var targetZoomContainer = isNaN(self.options.zoomWindowPosition) ? 'body' : self.zoomContainer;
  310. self.zoomWindow = $('<div class="zoomWindow"/>')
  311. .css($.extend({
  312. zIndex: 999,
  313. top: self.windowOffsetTop,
  314. left: self.windowOffsetLeft,
  315. }, self.zoomWindowStyle))
  316. .appendTo(targetZoomContainer).click(function () {
  317. self.$elem.trigger('click');
  318. });
  319. self.zoomWindowContainer = $('<div class="zoomWindowContainer" />')
  320. .css({
  321. width: self.options.zoomWindowWidth
  322. });
  323. self.zoomWindow.wrap(self.zoomWindowContainer);
  324. if (self.options.zoomType === 'lens') {
  325. self.zoomLens.css({
  326. backgroundImage: 'url("' + self.imageSrc + '")'
  327. });
  328. }
  329. if (self.options.zoomType === 'window') {
  330. self.zoomWindow.css({
  331. backgroundImage: 'url("' + self.imageSrc + '")'
  332. });
  333. }
  334. if (self.options.zoomType === 'inner') {
  335. self.zoomWindow.css({
  336. backgroundImage: 'url("' + self.imageSrc + '")'
  337. });
  338. }
  339. /*-------------------END THE ZOOM WINDOW AND LENS----------------------------------*/
  340. if (self.options.touchEnabled) {
  341. //touch events
  342. self.$elem.on('touchmove.ezpspace', function (e) {
  343. e.preventDefault();
  344. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  345. self.setPosition(touch);
  346. });
  347. self.zoomContainer.on('touchmove.ezpspace', function (e) {
  348. self.setElements('show');
  349. e.preventDefault();
  350. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  351. self.setPosition(touch);
  352. });
  353. self.zoomContainer.on('touchend.ezpspace', function (e) {
  354. self.showHideWindow('hide');
  355. if (self.options.showLens) {
  356. self.showHideLens('hide');
  357. }
  358. if (self.options.tint && self.options.zoomType !== 'inner') {
  359. self.showHideTint('hide');
  360. }
  361. });
  362. self.$elem.on('touchend.ezpspace', function (e) {
  363. self.showHideWindow('hide');
  364. if (self.options.showLens) {
  365. self.showHideLens('hide');
  366. }
  367. if (self.options.tint && self.options.zoomType !== 'inner') {
  368. self.showHideTint('hide');
  369. }
  370. });
  371. if (self.options.showLens) {
  372. self.zoomLens.on('touchmove.ezpspace', function (e) {
  373. e.preventDefault();
  374. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  375. self.setPosition(touch);
  376. });
  377. self.zoomLens.on('touchend.ezpspace', function (e) {
  378. self.showHideWindow('hide');
  379. if (self.options.showLens) {
  380. self.showHideLens('hide');
  381. }
  382. if (self.options.tint && self.options.zoomType !== 'inner') {
  383. self.showHideTint('hide');
  384. }
  385. });
  386. }
  387. }
  388. //Needed to work in IE
  389. self.$elem.on('mousemove.ezpspace', function (e) {
  390. if (self.overWindow === false) {
  391. self.setElements('show');
  392. }
  393. //make sure on orientation change the setposition is not fired
  394. if (self.lastX !== e.clientX || self.lastY !== e.clientY) {
  395. self.setPosition(e);
  396. self.currentLoc = e;
  397. }
  398. self.lastX = e.clientX;
  399. self.lastY = e.clientY;
  400. });
  401. self.zoomContainer.on('click.ezpspace touchstart.ezpspace', self.options.onImageClick);
  402. self.zoomContainer.on('mousemove.ezpspace', function (e) {
  403. if (self.overWindow === false) {
  404. self.setElements('show');
  405. }
  406. mouseMoveZoomHandler(e);
  407. });
  408. function mouseMoveZoomHandler(e) {
  409. //self.overWindow = true;
  410. //make sure on orientation change the setposition is not fired
  411. if (self.lastX !== e.clientX || self.lastY !== e.clientY) {
  412. self.setPosition(e);
  413. self.currentLoc = e;
  414. }
  415. self.lastX = e.clientX;
  416. self.lastY = e.clientY;
  417. }
  418. var elementToTrack = null;
  419. if (self.options.zoomType !== 'inner') {
  420. elementToTrack = self.zoomLens;
  421. }
  422. if (self.options.tint && self.options.zoomType !== 'inner') {
  423. elementToTrack = self.zoomTint;
  424. }
  425. if (self.options.zoomType === 'inner') {
  426. elementToTrack = self.zoomWindow;
  427. }
  428. //register the mouse tracking
  429. if (elementToTrack) {
  430. elementToTrack.on('mousemove.ezpspace', mouseMoveZoomHandler);
  431. }
  432. // lensFadeOut: 500, zoomTintFadeIn
  433. self.zoomContainer.add(self.$elem).mouseenter(function () {
  434. if (self.overWindow === false) {
  435. self.setElements('show');
  436. }
  437. }).mouseleave(function () {
  438. if (!self.scrollLock) {
  439. self.setElements('hide');
  440. self.options.onDestroy(self.$elem);
  441. }
  442. });
  443. //end ove image
  444. if (self.options.zoomType !== 'inner') {
  445. self.zoomWindow.mouseenter(function () {
  446. self.overWindow = true;
  447. self.setElements('hide');
  448. }).mouseleave(function () {
  449. self.overWindow = false;
  450. });
  451. }
  452. //end ove image
  453. // var delta = parseInt(e.originalEvent.wheelDelta || -e.originalEvent.detail);
  454. // $(this).empty();
  455. // return false;
  456. //fix for initial zoom setting
  457. //if (self.options.zoomLevel !== 1) {
  458. // self.changeZoomLevel(self.currentZoomLevel);
  459. //}
  460. //set the min zoomlevel
  461. if (self.options.minZoomLevel) {
  462. self.minZoomLevel = self.options.minZoomLevel;
  463. }
  464. else {
  465. self.minZoomLevel = self.options.scrollZoomIncrement * 10;
  466. }
  467. if (self.options.scrollZoom) {
  468. //see compatibility of mouse events at https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel
  469. self.zoomContainer.add(self.$elem).on('wheel DOMMouseScroll MozMousePixelScroll', function (e) {
  470. // in IE there is issue with firing of mouseleave - So check whether still scrolling
  471. // and on mouseleave check if scrolllock
  472. self.scrollLock = true;
  473. clearTimeout($.data(this, 'timer'));
  474. $.data(this, 'timer', setTimeout(function () {
  475. self.scrollLock = false;
  476. //do something
  477. }, 250));
  478. var theEvent = e.originalEvent.deltaY || e.originalEvent.detail * -1;
  479. //this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
  480. // e.preventDefault();
  481. e.stopImmediatePropagation();
  482. e.stopPropagation();
  483. e.preventDefault();
  484. if (theEvent === 0) {
  485. // fixes last event inversion bug
  486. return false;
  487. }
  488. var nextZoomLevel;
  489. if (theEvent / 120 > 0) {
  490. nextZoomLevel = parseFloat(self.currentZoomLevel) - self.options.scrollZoomIncrement;
  491. //scrolling up
  492. if (nextZoomLevel >= parseFloat(self.minZoomLevel)) {
  493. self.changeZoomLevel(nextZoomLevel);
  494. }
  495. }
  496. else {
  497. //scrolling down
  498. //Check if it has to maintain original zoom window aspect ratio or not
  499. if ((!self.fullheight && !self.fullwidth) || !self.options.mantainZoomAspectRatio) {
  500. nextZoomLevel = parseFloat(self.currentZoomLevel) + self.options.scrollZoomIncrement;
  501. if (self.options.maxZoomLevel) {
  502. if (nextZoomLevel <= self.options.maxZoomLevel) {
  503. self.changeZoomLevel(nextZoomLevel);
  504. }
  505. }
  506. else {
  507. //andy
  508. self.changeZoomLevel(nextZoomLevel);
  509. }
  510. }
  511. }
  512. return false;
  513. });
  514. }
  515. },
  516. destroy: function () {
  517. var self = this;
  518. self.$elem.off('.ezpspace');
  519. self.$galleries.off('.ezpspace');
  520. $(self.zoomContainer).remove();
  521. if (self.options.loadingIcon && !!self.spinner && !!self.spinner.length) {
  522. self.spinner.remove();
  523. delete self.spinner;
  524. }
  525. },
  526. getIdentifier: function () {
  527. var self = this;
  528. return self.options.zoomId;
  529. },
  530. setElements: function (type) {
  531. var self = this;
  532. if (!self.options.zoomEnabled) {
  533. return false;
  534. }
  535. if (type === 'show') {
  536. if (self.isWindowSet) {
  537. if (self.options.zoomType === 'inner') {
  538. self.showHideWindow('show');
  539. }
  540. if (self.options.zoomType === 'window') {
  541. self.showHideWindow('show');
  542. }
  543. if (self.options.showLens) {
  544. self.showHideLens('show');
  545. }
  546. if (self.options.tint && self.options.zoomType !== 'inner') {
  547. self.showHideTint('show');
  548. }
  549. }
  550. }
  551. if (type === 'hide') {
  552. if (self.options.zoomType === 'window') {
  553. self.showHideWindow('hide');
  554. }
  555. if (!self.options.tint) {
  556. self.showHideWindow('hide');
  557. }
  558. if (self.options.showLens) {
  559. self.showHideLens('hide');
  560. }
  561. if (self.options.tint) {
  562. self.showHideTint('hide');
  563. }
  564. }
  565. },
  566. setPosition: function (e) {
  567. var self = this;
  568. if (!self.options.zoomEnabled) {
  569. return false;
  570. }
  571. //recaclc offset each time in case the image moves
  572. //this can be caused by other on page elements
  573. self.nzHeight = self.$elem.height();
  574. self.nzWidth = self.$elem.width();
  575. self.updateOffset(self);
  576. if (self.options.tint && self.options.zoomType !== 'inner') {
  577. self.zoomTint.css({
  578. top: 0,
  579. left: 0
  580. });
  581. }
  582. //set responsive
  583. //will checking if the image needs changing before running this code work faster?
  584. if (self.options.responsive && !self.options.scrollZoom) {
  585. if (self.options.showLens) {
  586. var lensHeight, lensWidth;
  587. if (self.nzHeight < self.options.zoomWindowWidth / self.widthRatio) {
  588. self.lensHeight = self.nzHeight;
  589. }
  590. else {
  591. self.lensHeight = self.options.zoomWindowHeight / self.heightRatio;
  592. }
  593. if (self.largeWidth < self.options.zoomWindowWidth) {
  594. self.lensWidth = self.nzWidth;
  595. }
  596. else {
  597. self.lensWidth = (self.options.zoomWindowWidth / self.widthRatio);
  598. }
  599. self.widthRatio = self.largeWidth / self.nzWidth;
  600. self.heightRatio = self.largeHeight / self.nzHeight;
  601. if (self.options.zoomType !== 'lens') {
  602. //possibly dont need to keep recalcalculating
  603. //if the lens is heigher than the image, then set lens size to image size
  604. if (self.nzHeight < self.options.zoomWindowWidth / self.widthRatio) {
  605. self.lensHeight = self.nzHeight;
  606. }
  607. else {
  608. self.lensHeight = self.options.zoomWindowHeight / self.heightRatio;
  609. }
  610. if (self.nzWidth < self.options.zoomWindowHeight / self.heightRatio) {
  611. self.lensWidth = self.nzWidth;
  612. }
  613. else {
  614. self.lensWidth = self.options.zoomWindowWidth / self.widthRatio;
  615. }
  616. self.zoomLens.css({
  617. width: self.lensWidth,
  618. height: self.lensHeight
  619. });
  620. if (self.options.tint) {
  621. self.zoomTintImage.css({
  622. width: self.nzWidth,
  623. height: self.nzHeight
  624. });
  625. }
  626. }
  627. if (self.options.zoomType === 'lens') {
  628. self.zoomLens.css({
  629. width: self.options.lensSize,
  630. height: self.options.lensSize
  631. });
  632. }
  633. //end responsive image change
  634. }
  635. }
  636. //container fix
  637. self.zoomContainer.css({
  638. top: self.nzOffset.top,
  639. left: self.nzOffset.left,
  640. width: self.nzWidth, // new code
  641. height: self.nzHeight // new code
  642. });
  643. self.mouseLeft = parseInt(e.pageX - self.nzOffset.left);
  644. self.mouseTop = parseInt(e.pageY - self.nzOffset.top);
  645. //calculate the Location of the Lens
  646. //calculate the bound regions - but only if zoom window
  647. if (self.options.zoomType === 'window') {
  648. var zoomLensHeight = self.zoomLens.height() / 2;
  649. var zoomLensWidth = self.zoomLens.width() / 2;
  650. self.Etoppos = (self.mouseTop < 0 + zoomLensHeight);
  651. self.Eboppos = (self.mouseTop > self.nzHeight - zoomLensHeight - (self.options.lensBorderSize * 2));
  652. self.Eloppos = (self.mouseLeft < 0 + zoomLensWidth);
  653. self.Eroppos = (self.mouseLeft > (self.nzWidth - zoomLensWidth - (self.options.lensBorderSize * 2)));
  654. }
  655. //calculate the bound regions - but only for inner zoom
  656. if (self.options.zoomType === 'inner') {
  657. self.Etoppos = (self.mouseTop < ((self.nzHeight / 2) / self.heightRatio));
  658. self.Eboppos = (self.mouseTop > (self.nzHeight - ((self.nzHeight / 2) / self.heightRatio)));
  659. self.Eloppos = (self.mouseLeft < 0 + (((self.nzWidth / 2) / self.widthRatio)));
  660. self.Eroppos = (self.mouseLeft > (self.nzWidth - (self.nzWidth / 2) / self.widthRatio - (self.options.lensBorderSize * 2)));
  661. }
  662. // if the mouse position of the slider is one of the outerbounds, then hide window and lens
  663. if (self.mouseLeft < 0 || self.mouseTop < 0 || self.mouseLeft > self.nzWidth || self.mouseTop > self.nzHeight) {
  664. self.setElements('hide');
  665. return;
  666. }
  667. //else continue with operations
  668. else {
  669. //lens options
  670. if (self.options.showLens) {
  671. // self.showHideLens('show');
  672. //set background position of lens
  673. self.lensLeftPos = Math.floor(self.mouseLeft - self.zoomLens.width() / 2);
  674. self.lensTopPos = Math.floor(self.mouseTop - self.zoomLens.height() / 2);
  675. }
  676. //adjust the background position if the mouse is in one of the outer regions
  677. //Top region
  678. if (self.Etoppos) {
  679. self.lensTopPos = 0;
  680. }
  681. //Left Region
  682. if (self.Eloppos) {
  683. self.windowLeftPos = 0;
  684. self.lensLeftPos = 0;
  685. self.tintpos = 0;
  686. }
  687. //Set bottom and right region for window mode
  688. if (self.options.zoomType === 'window') {
  689. if (self.Eboppos) {
  690. self.lensTopPos = Math.max((self.nzHeight) - self.zoomLens.height() - (self.options.lensBorderSize * 2), 0);
  691. }
  692. if (self.Eroppos) {
  693. self.lensLeftPos = (self.nzWidth - (self.zoomLens.width()) - (self.options.lensBorderSize * 2));
  694. }
  695. }
  696. //Set bottom and right region for inner mode
  697. if (self.options.zoomType === 'inner') {
  698. if (self.Eboppos) {
  699. self.lensTopPos = Math.max(((self.nzHeight) - (self.options.lensBorderSize * 2)), 0);
  700. }
  701. if (self.Eroppos) {
  702. self.lensLeftPos = (self.nzWidth - (self.nzWidth) - (self.options.lensBorderSize * 2));
  703. }
  704. }
  705. //if lens zoom
  706. if (self.options.zoomType === 'lens') {
  707. self.windowLeftPos = ((e.pageX - self.nzOffset.left) * self.widthRatio - self.zoomLens.width() / 2) * -1;
  708. self.windowTopPos = ((e.pageY - self.nzOffset.top) * self.heightRatio - self.zoomLens.height() / 2) * -1;
  709. self.zoomLens.css({
  710. backgroundPosition: '' + self.windowLeftPos + 'px ' + self.windowTopPos + 'px'
  711. });
  712. if (self.changeBgSize) {
  713. if (self.nzHeight > self.nzWidth) {
  714. if (self.options.zoomType === 'lens') {
  715. self.zoomLens.css({
  716. backgroundSize: '' +
  717. (self.largeWidth / self.newvalueheight) + 'px ' +
  718. (self.largeHeight / self.newvalueheight) + 'px'
  719. });
  720. }
  721. self.zoomWindow.css({
  722. backgroundSize: '' +
  723. (self.largeWidth / self.newvalueheight) + 'px ' +
  724. (self.largeHeight / self.newvalueheight) + 'px'
  725. });
  726. }
  727. else {
  728. if (self.options.zoomType === 'lens') {
  729. self.zoomLens.css({
  730. backgroundSize: '' +
  731. (self.largeWidth / self.newvaluewidth) + 'px ' +
  732. (self.largeHeight / self.newvaluewidth) + 'px'
  733. });
  734. }
  735. self.zoomWindow.css({
  736. backgroundSize: '' +
  737. (self.largeWidth / self.newvaluewidth) + 'px ' +
  738. (self.largeHeight / self.newvaluewidth) + 'px'
  739. });
  740. }
  741. self.changeBgSize = false;
  742. }
  743. self.setWindowPosition(e);
  744. }
  745. //if tint zoom
  746. if (self.options.tint && self.options.zoomType !== 'inner') {
  747. self.setTintPosition(e);
  748. }
  749. //set the css background position
  750. if (self.options.zoomType === 'window') {
  751. self.setWindowPosition(e);
  752. }
  753. if (self.options.zoomType === 'inner') {
  754. self.setWindowPosition(e);
  755. }
  756. if (self.options.showLens) {
  757. if (self.fullwidth && self.options.zoomType !== 'lens') {
  758. self.lensLeftPos = 0;
  759. }
  760. self.zoomLens.css({
  761. left: self.lensLeftPos,
  762. top: self.lensTopPos
  763. });
  764. }
  765. } //end else
  766. },
  767. showHideZoomContainer: function (change) {
  768. var self = this;
  769. if (change === 'show') {
  770. if (self.zoomContainer) {
  771. self.zoomContainer.show();
  772. }
  773. }
  774. if (change === 'hide') {
  775. if (self.zoomContainer) {
  776. self.zoomContainer.hide();
  777. }
  778. }
  779. },
  780. showHideWindow: function (change) {
  781. var self = this;
  782. if (change === 'show') {
  783. if (!self.isWindowActive && self.zoomWindow) {
  784. self.options.onShow(self);
  785. if (self.options.zoomWindowFadeIn) {
  786. self.zoomWindow.stop(true, true, false).fadeIn(self.options.zoomWindowFadeIn);
  787. }
  788. else {
  789. self.zoomWindow.show();
  790. }
  791. self.isWindowActive = true;
  792. }
  793. }
  794. if (change === 'hide') {
  795. if (self.isWindowActive) {
  796. if (self.options.zoomWindowFadeOut) {
  797. self.zoomWindow.stop(true, true).fadeOut(self.options.zoomWindowFadeOut, function () {
  798. if (self.loop) {
  799. //stop moving the zoom window when zoom window is faded out
  800. clearInterval(self.loop);
  801. self.loop = false;
  802. }
  803. });
  804. }
  805. else {
  806. self.zoomWindow.hide();
  807. }
  808. self.options.onHide(self);
  809. self.isWindowActive = false;
  810. }
  811. }
  812. },
  813. showHideLens: function (change) {
  814. var self = this;
  815. if (change === 'show') {
  816. if (!self.isLensActive) {
  817. if (self.zoomLens) {
  818. if (self.options.lensFadeIn) {
  819. self.zoomLens.stop(true, true, false).fadeIn(self.options.lensFadeIn);
  820. }
  821. else {
  822. self.zoomLens.show();
  823. }
  824. }
  825. self.isLensActive = true;
  826. }
  827. }
  828. if (change === 'hide') {
  829. if (self.isLensActive) {
  830. if (self.zoomLens) {
  831. if (self.options.lensFadeOut) {
  832. self.zoomLens.stop(true, true).fadeOut(self.options.lensFadeOut);
  833. }
  834. else {
  835. self.zoomLens.hide();
  836. }
  837. }
  838. self.isLensActive = false;
  839. }
  840. }
  841. },
  842. showHideTint: function (change) {
  843. var self = this;
  844. if (change === 'show') {
  845. if (!self.isTintActive && self.zoomTint) {
  846. if (self.options.zoomTintFadeIn) {
  847. self.zoomTint.css('opacity', self.options.tintOpacity).animate().stop(true, true).fadeIn('slow');
  848. }
  849. else {
  850. self.zoomTint.css('opacity', self.options.tintOpacity).animate();
  851. self.zoomTint.show();
  852. }
  853. self.isTintActive = true;
  854. }
  855. }
  856. if (change === 'hide') {
  857. if (self.isTintActive) {
  858. if (self.options.zoomTintFadeOut) {
  859. self.zoomTint.stop(true, true).fadeOut(self.options.zoomTintFadeOut);
  860. }
  861. else {
  862. self.zoomTint.hide();
  863. }
  864. self.isTintActive = false;
  865. }
  866. }
  867. },
  868. setLensPosition: function (e) {
  869. },
  870. setWindowPosition: function (e) {
  871. //return obj.slice( 0, count );
  872. var self = this;
  873. if (!isNaN(self.options.zoomWindowPosition)) {
  874. switch (self.options.zoomWindowPosition) {
  875. case 1: //done
  876. self.windowOffsetTop = (self.options.zoomWindowOffsetY);//DONE - 1
  877. self.windowOffsetLeft = (+self.nzWidth); //DONE 1, 2, 3, 4, 16
  878. break;
  879. case 2:
  880. if (self.options.zoomWindowHeight > self.nzHeight) { //positive margin
  881. self.windowOffsetTop = ((self.options.zoomWindowHeight / 2) - (self.nzHeight / 2)) * (-1);
  882. self.windowOffsetLeft = (self.nzWidth); //DONE 1, 2, 3, 4, 16
  883. }
  884. else { //negative margin
  885. $.noop();
  886. }
  887. break;
  888. case 3: //done
  889. self.windowOffsetTop = (self.nzHeight - self.zoomWindow.height() - (self.options.borderSize * 2)); //DONE 3,9
  890. self.windowOffsetLeft = (self.nzWidth); //DONE 1, 2, 3, 4, 16
  891. break;
  892. case 4: //done
  893. self.windowOffsetTop = (self.nzHeight); //DONE - 4,5,6,7,8
  894. self.windowOffsetLeft = (self.nzWidth); //DONE 1, 2, 3, 4, 16
  895. break;
  896. case 5: //done
  897. self.windowOffsetTop = (self.nzHeight); //DONE - 4,5,6,7,8
  898. self.windowOffsetLeft = (self.nzWidth - self.zoomWindow.width() - (self.options.borderSize * 2)); //DONE - 5,15
  899. break;
  900. case 6:
  901. if (self.options.zoomWindowHeight > self.nzHeight) { //positive margin
  902. self.windowOffsetTop = (self.nzHeight); //DONE - 4,5,6,7,8
  903. self.windowOffsetLeft = ((self.options.zoomWindowWidth / 2) - (self.nzWidth / 2) + (self.options.borderSize * 2)) * (-1);
  904. }
  905. else { //negative margin
  906. $.noop();
  907. }
  908. break;
  909. case 7: //done
  910. self.windowOffsetTop = (self.nzHeight); //DONE - 4,5,6,7,8
  911. self.windowOffsetLeft = 0; //DONE 7, 13
  912. break;
  913. case 8: //done
  914. self.windowOffsetTop = (self.nzHeight); //DONE - 4,5,6,7,8
  915. self.windowOffsetLeft = (self.zoomWindow.width() + (self.options.borderSize * 2)) * (-1); //DONE 8,9,10,11,12
  916. break;
  917. case 9: //done
  918. self.windowOffsetTop = (self.nzHeight - self.zoomWindow.height() - (self.options.borderSize * 2)); //DONE 3,9
  919. self.windowOffsetLeft = (self.zoomWindow.width() + (self.options.borderSize * 2)) * (-1); //DONE 8,9,10,11,12
  920. break;
  921. case 10:
  922. if (self.options.zoomWindowHeight > self.nzHeight) { //positive margin
  923. self.windowOffsetTop = ((self.options.zoomWindowHeight / 2) - (self.nzHeight / 2)) * (-1);
  924. self.windowOffsetLeft = (self.zoomWindow.width() + (self.options.borderSize * 2)) * (-1); //DONE 8,9,10,11,12
  925. }
  926. else { //negative margin
  927. $.noop();
  928. }
  929. break;
  930. case 11:
  931. self.windowOffsetTop = (self.options.zoomWindowOffsetY);
  932. self.windowOffsetLeft = (self.zoomWindow.width() + (self.options.borderSize * 2)) * (-1); //DONE 8,9,10,11,12
  933. break;
  934. case 12: //done
  935. self.windowOffsetTop = (self.zoomWindow.height() + (self.options.borderSize * 2)) * (-1); //DONE 12,13,14,15,16
  936. self.windowOffsetLeft = (self.zoomWindow.width() + (self.options.borderSize * 2)) * (-1); //DONE 8,9,10,11,12
  937. break;
  938. case 13: //done
  939. self.windowOffsetTop = (self.zoomWindow.height() + (self.options.borderSize * 2)) * (-1); //DONE 12,13,14,15,16
  940. self.windowOffsetLeft = (0); //DONE 7, 13
  941. break;
  942. case 14:
  943. if (self.options.zoomWindowHeight > self.nzHeight) { //positive margin
  944. self.windowOffsetTop = (self.zoomWindow.height() + (self.options.borderSize * 2)) * (-1); //DONE 12,13,14,15,16
  945. self.windowOffsetLeft = ((self.options.zoomWindowWidth / 2) - (self.nzWidth / 2) + (self.options.borderSize * 2)) * (-1);
  946. }
  947. else { //negative margin
  948. $.noop();
  949. }
  950. break;
  951. case 15://done
  952. self.windowOffsetTop = (self.zoomWindow.height() + (self.options.borderSize * 2)) * (-1); //DONE 12,13,14,15,16
  953. self.windowOffsetLeft = (self.nzWidth - self.zoomWindow.width() - (self.options.borderSize * 2)); //DONE - 5,15
  954. break;
  955. case 16: //done
  956. self.windowOffsetTop = (self.zoomWindow.height() + (self.options.borderSize * 2)) * (-1); //DONE 12,13,14,15,16
  957. self.windowOffsetLeft = (self.nzWidth); //DONE 1, 2, 3, 4, 16
  958. break;
  959. default: //done
  960. self.windowOffsetTop = (self.options.zoomWindowOffsetY);//DONE - 1
  961. self.windowOffsetLeft = (self.nzWidth); //DONE 1, 2, 3, 4, 16
  962. }
  963. } //end isNAN
  964. else {
  965. // For BC purposes, treat passed element as ID if element not found
  966. self.externalContainer = $(self.options.zoomWindowPosition);
  967. if (!self.externalContainer.length) {
  968. self.externalContainer = $('#' + self.options.zoomWindowPosition);
  969. }
  970. self.externalContainerWidth = self.externalContainer.width();
  971. self.externalContainerHeight = self.externalContainer.height();
  972. self.externalContainerOffset = self.externalContainer.offset();
  973. self.windowOffsetTop = self.externalContainerOffset.top;//DONE - 1
  974. self.windowOffsetLeft = self.externalContainerOffset.left; //DONE 1, 2, 3, 4, 16
  975. }
  976. self.isWindowSet = true;
  977. self.windowOffsetTop = self.windowOffsetTop + self.options.zoomWindowOffsetY;
  978. self.windowOffsetLeft = self.windowOffsetLeft + self.options.zoomWindowOffsetX;
  979. self.zoomWindow.css({
  980. top: self.windowOffsetTop,
  981. left: self.windowOffsetLeft
  982. });
  983. if (self.options.zoomType === 'inner') {
  984. self.zoomWindow.css({
  985. top: 0,
  986. left: 0
  987. });
  988. }
  989. self.windowLeftPos = ((e.pageX - self.nzOffset.left) * self.widthRatio - self.zoomWindow.width() / 2) * -1;
  990. self.windowTopPos = ((e.pageY - self.nzOffset.top) * self.heightRatio - self.zoomWindow.height() / 2) * -1;
  991. if (self.Etoppos) {
  992. self.windowTopPos = 0;
  993. }
  994. if (self.Eloppos) {
  995. self.windowLeftPos = 0;
  996. }
  997. if (self.Eboppos) {
  998. self.windowTopPos = (self.largeHeight / self.currentZoomLevel - self.zoomWindow.height()) * (-1);
  999. }
  1000. if (self.Eroppos) {
  1001. self.windowLeftPos = ((self.largeWidth / self.currentZoomLevel - self.zoomWindow.width()) * (-1));
  1002. }
  1003. //stops micro movements
  1004. if (self.fullheight) {
  1005. self.windowTopPos = 0;
  1006. }
  1007. if (self.fullwidth) {
  1008. self.windowLeftPos = 0;
  1009. }
  1010. //set the css background position
  1011. if (self.options.zoomType === 'window' || self.options.zoomType === 'inner') {
  1012. if (self.zoomLock === 1) {
  1013. //overrides for images not zoomable
  1014. if (self.widthRatio <= 1) {
  1015. self.windowLeftPos = 0;
  1016. }
  1017. if (self.heightRatio <= 1) {
  1018. self.windowTopPos = 0;
  1019. }
  1020. }
  1021. // adjust images less than the window height
  1022. if (self.options.zoomType === 'window') {
  1023. if (self.largeHeight < self.options.zoomWindowHeight) {
  1024. self.windowTopPos = 0;
  1025. }
  1026. if (self.largeWidth < self.options.zoomWindowWidth) {
  1027. self.windowLeftPos = 0;
  1028. }
  1029. }
  1030. //set the zoomwindow background position
  1031. if (self.options.easing) {
  1032. // if(self.changeZoom){
  1033. // clearInterval(self.loop);
  1034. // self.changeZoom = false;
  1035. // self.loop = false;
  1036. // }
  1037. //set the pos to 0 if not set
  1038. if (!self.xp) {
  1039. self.xp = 0;
  1040. }
  1041. if (!self.yp) {
  1042. self.yp = 0;
  1043. }
  1044. var interval = 16;
  1045. if (Number.isInteger(parseInt(self.options.easing))) {
  1046. interval = parseInt(self.options.easing);
  1047. }
  1048. //if loop not already started, then run it
  1049. if (!self.loop) {
  1050. self.loop = setInterval(function () {
  1051. //using zeno's paradox
  1052. self.xp += (self.windowLeftPos - self.xp) / self.options.easingAmount;
  1053. self.yp += (self.windowTopPos - self.yp) / self.options.easingAmount;
  1054. if (self.scrollingLock) {
  1055. clearInterval(self.loop);
  1056. self.xp = self.windowLeftPos;
  1057. self.yp = self.windowTopPos;
  1058. self.xp = ((e.pageX - self.nzOffset.left) * self.widthRatio - self.zoomWindow.width() / 2) * (-1);
  1059. self.yp = (((e.pageY - self.nzOffset.top) * self.heightRatio - self.zoomWindow.height() / 2) * (-1));
  1060. if (self.changeBgSize) {
  1061. if (self.nzHeight > self.nzWidth) {
  1062. if (self.options.zoomType === 'lens') {
  1063. self.zoomLens.css({
  1064. backgroundSize: '' +
  1065. (self.largeWidth / self.newvalueheight) + 'px ' +
  1066. (self.largeHeight / self.newvalueheight) + 'px'
  1067. });
  1068. }
  1069. self.zoomWindow.css({
  1070. backgroundSize: '' +
  1071. (self.largeWidth / self.newvalueheight) + 'px ' +
  1072. (self.largeHeight / self.newvalueheight) + 'px'
  1073. });
  1074. }
  1075. else {
  1076. if (self.options.zoomType !== 'lens') {
  1077. self.zoomLens.css({
  1078. backgroundSize: '' +
  1079. (self.largeWidth / self.newvaluewidth) + 'px ' +
  1080. (self.largeHeight / self.newvalueheight) + 'px'
  1081. });
  1082. }
  1083. self.zoomWindow.css({
  1084. backgroundSize: '' +
  1085. (self.largeWidth / self.newvaluewidth) + 'px ' +
  1086. (self.largeHeight / self.newvaluewidth) + 'px'
  1087. });
  1088. }
  1089. /*
  1090. if(!self.bgxp){self.bgxp = self.largeWidth/self.newvalue;}
  1091. if(!self.bgyp){self.bgyp = self.largeHeight/self.newvalue ;}
  1092. if (!self.bgloop){
  1093. self.bgloop = setInterval(function(){
  1094. self.bgxp += (self.largeWidth/self.newvalue - self.bgxp) / self.options.easingAmount;
  1095. self.bgyp += (self.largeHeight/self.newvalue - self.bgyp) / self.options.easingAmount;
  1096. self.zoomWindow.css('background-size', self.bgxp + 'px ' + self.bgyp + 'px' );
  1097. }, 16);
  1098. }
  1099. */
  1100. self.changeBgSize = false;
  1101. }
  1102. self.zoomWindow.css({
  1103. backgroundPosition: '' + self.windowLeftPos + 'px ' + self.windowTopPos + 'px'
  1104. });
  1105. self.scrollingLock = false;
  1106. self.loop = false;
  1107. }
  1108. else if (Math.round(Math.abs(self.xp - self.windowLeftPos) + Math.abs(self.yp - self.windowTopPos)) < 1) {
  1109. //stops micro movements
  1110. clearInterval(self.loop);
  1111. self.zoomWindow.css({
  1112. backgroundPosition: '' + self.windowLeftPos + 'px ' + self.windowTopPos + 'px'
  1113. });
  1114. self.loop = false;
  1115. }
  1116. else {
  1117. if (self.changeBgSize) {
  1118. if (self.nzHeight > self.nzWidth) {
  1119. if (self.options.zoomType === 'lens') {
  1120. self.zoomLens.css({
  1121. backgroundSize: '' +
  1122. (self.largeWidth / self.newvalueheight) + 'px ' +
  1123. (self.largeHeight / self.newvalueheight) + 'px'
  1124. });
  1125. }
  1126. self.zoomWindow.css({
  1127. backgroundSize: '' +
  1128. (self.largeWidth / self.newvalueheight) + 'px ' +
  1129. (self.largeHeight / self.newvalueheight) + 'px'
  1130. });
  1131. }
  1132. else {
  1133. if (self.options.zoomType !== 'lens') {
  1134. self.zoomLens.css({
  1135. backgroundSize: '' +
  1136. (self.largeWidth / self.newvaluewidth) + 'px ' +
  1137. (self.largeHeight / self.newvaluewidth) + 'px'
  1138. });
  1139. }
  1140. self.zoomWindow.css({
  1141. backgroundSize: '' +
  1142. (self.largeWidth / self.newvaluewidth) + 'px ' +
  1143. (self.largeHeight / self.newvaluewidth) + 'px'
  1144. });
  1145. }
  1146. self.changeBgSize = false;
  1147. }
  1148. self.zoomWindow.css({
  1149. backgroundPosition: '' + self.xp + 'px ' + self.yp + 'px'
  1150. });
  1151. }
  1152. }, interval);
  1153. }
  1154. }
  1155. else {
  1156. if (self.changeBgSize) {
  1157. if (self.nzHeight > self.nzWidth) {
  1158. if (self.options.zoomType === 'lens') {
  1159. self.zoomLens.css({
  1160. backgroundSize: '' +
  1161. (self.largeWidth / self.newvalueheight) + 'px ' +
  1162. (self.largeHeight / self.newvalueheight) + 'px'
  1163. });
  1164. }
  1165. self.zoomWindow.css({
  1166. backgroundSize: '' +
  1167. (self.largeWidth / self.newvalueheight) + 'px ' +
  1168. (self.largeHeight / self.newvalueheight) + 'px'
  1169. });
  1170. }
  1171. else {
  1172. if (self.options.zoomType === 'lens') {
  1173. self.zoomLens.css({
  1174. backgroundSize: '' +
  1175. (self.largeWidth / self.newvaluewidth) + 'px ' +
  1176. (self.largeHeight / self.newvaluewidth) + 'px'
  1177. });
  1178. }
  1179. if ((self.largeHeight / self.newvaluewidth) < self.options.zoomWindowHeight) {
  1180. self.zoomWindow.css({
  1181. backgroundSize: '' +
  1182. (self.largeWidth / self.newvaluewidth) + 'px ' +
  1183. (self.largeHeight / self.newvaluewidth) + 'px'
  1184. });
  1185. }
  1186. else {
  1187. self.zoomWindow.css({
  1188. backgroundSize: '' +
  1189. (self.largeWidth / self.newvalueheight) + 'px ' +
  1190. (self.largeHeight / self.newvalueheight) + 'px'
  1191. });
  1192. }
  1193. }
  1194. self.changeBgSize = false;
  1195. }
  1196. self.zoomWindow.css({
  1197. backgroundPosition: '' +
  1198. self.windowLeftPos + 'px ' +
  1199. self.windowTopPos + 'px'
  1200. });
  1201. }
  1202. }
  1203. },
  1204. setTintPosition: function (e) {
  1205. var self = this;
  1206. var zoomLensWidth = self.zoomLens.width();
  1207. var zoomLensHeight = self.zoomLens.height();
  1208. self.updateOffset(self);
  1209. self.tintpos = ((e.pageX - self.nzOffset.left) - (zoomLensWidth / 2)) * -1;
  1210. self.tintposy = ((e.pageY - self.nzOffset.top) - zoomLensHeight / 2) * -1;
  1211. if (self.Etoppos) {
  1212. self.tintposy = 0;
  1213. }
  1214. if (self.Eloppos) {
  1215. self.tintpos = 0;
  1216. }
  1217. if (self.Eboppos) {
  1218. self.tintposy = (self.nzHeight - zoomLensHeight - (self.options.lensBorderSize * 2)) * (-1);
  1219. }
  1220. if (self.Eroppos) {
  1221. self.tintpos = ((self.nzWidth - zoomLensWidth - (self.options.lensBorderSize * 2)) * (-1));
  1222. }
  1223. if (self.options.tint) {
  1224. //stops micro movements
  1225. if (self.fullheight) {
  1226. self.tintposy = 0;
  1227. }
  1228. if (self.fullwidth) {
  1229. self.tintpos = 0;
  1230. }
  1231. self.zoomTintImage.css({
  1232. left: self.tintpos,
  1233. top: self.tintposy
  1234. });
  1235. }
  1236. },
  1237. swaptheimage: function (smallimage, largeimage) {
  1238. var self = this;
  1239. var newImg = new Image();
  1240. if (self.options.loadingIcon && !self.spinner) {
  1241. var styleAttr = {
  1242. background: 'url("' + self.options.loadingIcon + '") no-repeat',
  1243. height: self.nzHeight,
  1244. width: self.nzWidth,
  1245. zIndex: 2000,
  1246. position: 'absolute',
  1247. backgroundPosition: 'center center',
  1248. };
  1249. if (self.options.zoomType === 'inner') {
  1250. styleAttr.setProperty('top', 0);
  1251. }
  1252. self.spinner = $('<div class="ezp-spinner"></div>')
  1253. .css(styleAttr);
  1254. self.$elem.after(self.spinner);
  1255. } else if (self.spinner) {
  1256. self.spinner.show();
  1257. }
  1258. self.options.onImageSwap(self.$elem);
  1259. newImg.onload = function () {
  1260. self.largeWidth = newImg.width;
  1261. self.largeHeight = newImg.height;
  1262. self.zoomImage = largeimage;
  1263. self.zoomWindow.css({
  1264. backgroundSize: '' + self.largeWidth + 'px ' + self.largeHeight + 'px'
  1265. });
  1266. self.swapAction(smallimage, largeimage);
  1267. return;
  1268. };
  1269. self.setImageSource(newImg, largeimage); // this must be done AFTER setting onload
  1270. },
  1271. swapAction: function (smallimage, largeimage) {
  1272. var self = this;
  1273. var elemWidth = self.$elem.width();
  1274. var elemHeight = self.$elem.height();
  1275. var newImg2 = new Image();
  1276. newImg2.onload = function () {
  1277. //re-calculate values
  1278. self.nzHeight = newImg2.height;
  1279. self.nzWidth = newImg2.width;
  1280. self.options.onImageSwapComplete(self.$elem);
  1281. self.doneCallback();
  1282. return;
  1283. };
  1284. self.setImageSource(newImg2, smallimage);
  1285. //reset the zoomlevel to that initially set in options
  1286. self.currentZoomLevel = self.options.zoomLevel;
  1287. self.options.maxZoomLevel = false;
  1288. //swaps the main image
  1289. //self.$elem.attr('src',smallimage);
  1290. //swaps the zoom image
  1291. if (self.options.zoomType === 'lens') {
  1292. self.zoomLens.css('background-image', 'url("' + largeimage + '")');
  1293. }
  1294. if (self.options.zoomType === 'window') {
  1295. self.zoomWindow.css('background-image', 'url("' + largeimage + '")');
  1296. }
  1297. if (self.options.zoomType === 'inner') {
  1298. self.zoomWindow.css('background-image', 'url("' + largeimage + '")');
  1299. }
  1300. self.currentImage = largeimage;
  1301. if (self.options.imageCrossfade) {
  1302. var oldImg = self.$elem;
  1303. var newImg = oldImg.clone();
  1304. self.$elem.attr('src', smallimage);
  1305. self.$elem.after(newImg);
  1306. newImg.stop(true).fadeOut(self.options.imageCrossfade, function () {
  1307. $(this).remove();
  1308. });
  1309. // if(self.options.zoomType === 'inner'){
  1310. //remove any attributes on the cloned image so we can resize later
  1311. self.$elem.width('auto').removeAttr('width');
  1312. self.$elem.height('auto').removeAttr('height');
  1313. // }
  1314. oldImg.fadeIn(self.options.imageCrossfade);
  1315. if (self.options.tint && self.options.zoomType !== 'inner') {
  1316. var oldImgTint = self.zoomTintImage;
  1317. var newImgTint = oldImgTint.clone();
  1318. self.zoomTintImage.attr('src', largeimage);
  1319. self.zoomTintImage.after(newImgTint);
  1320. newImgTint.stop(true).fadeOut(self.options.imageCrossfade, function () {
  1321. $(this).remove();
  1322. });
  1323. oldImgTint.fadeIn(self.options.imageCrossfade);
  1324. //self.zoomTintImage.attr('width',elem.data('image'));
  1325. //resize the tint window
  1326. self.zoomTint.css({
  1327. height: elemHeight,
  1328. width: elemWidth
  1329. });
  1330. }
  1331. self.zoomContainer.css({
  1332. 'height': elemHeight,
  1333. 'width': elemWidth
  1334. });
  1335. if (self.options.zoomType === 'inner') {
  1336. if (!self.options.constrainType) {
  1337. self.zoomWrap.parent().css({
  1338. 'height': elemHeight,
  1339. 'width': elemWidth
  1340. });
  1341. self.zoomWindow.css({
  1342. 'height': elemHeight,
  1343. 'width': elemWidth
  1344. });
  1345. }
  1346. }
  1347. if (self.options.imageCrossfade) {
  1348. self.zoomWrap.css({
  1349. 'height': elemHeight,
  1350. 'width': elemWidth
  1351. });
  1352. }
  1353. }
  1354. else {
  1355. self.$elem.attr('src', smallimage);
  1356. if (self.options.tint) {
  1357. self.zoomTintImage.attr('src', largeimage);
  1358. //self.zoomTintImage.attr('width',elem.data('image'));
  1359. self.zoomTintImage.attr('height', elemHeight);
  1360. //self.zoomTintImage.attr('src') = elem.data('image');
  1361. self.zoomTintImage.css('height', elemHeight);
  1362. self.zoomTint.css('height', elemHeight);
  1363. }
  1364. self.zoomContainer.css({
  1365. 'height': elemHeight,
  1366. 'width': elemWidth
  1367. });
  1368. if (self.options.imageCrossfade) {
  1369. self.zoomWrap.css({
  1370. 'height': elemHeight,
  1371. 'width': elemWidth
  1372. });
  1373. }
  1374. }
  1375. if (self.options.constrainType) {
  1376. //This will contrain the image proportions
  1377. if (self.options.constrainType === 'height') {
  1378. var autoWDimension = {
  1379. 'height': self.options.constrainSize,
  1380. 'width': 'auto'
  1381. };
  1382. self.zoomContainer.css(autoWDimension);
  1383. if (self.options.imageCrossfade) {
  1384. self.zoomWrap.css(autoWDimension);
  1385. self.constwidth = self.zoomWrap.width();
  1386. }
  1387. else {
  1388. self.$elem.css(autoWDimension);
  1389. self.constwidth = elemWidth;
  1390. }
  1391. var constWDim = {
  1392. 'height': self.options.constrainSize,
  1393. 'width': self.constwidth
  1394. };
  1395. if (self.options.zoomType === 'inner') {
  1396. self.zoomWrap.parent().css(constWDim);
  1397. self.zoomWindow.css(constWDim);
  1398. }
  1399. if (self.options.tint) {
  1400. self.tintContainer.css(constWDim);
  1401. self.zoomTint.css(constWDim);
  1402. self.zoomTintImage.css(constWDim);
  1403. }
  1404. }
  1405. if (self.options.constrainType === 'width') {
  1406. var autoHDimension = {
  1407. 'height': 'auto',
  1408. 'width': self.options.constrainSize
  1409. };
  1410. self.zoomContainer.css(autoHDimension);
  1411. if (self.options.imageCrossfade) {
  1412. self.zoomWrap.css(autoHDimension);
  1413. self.constheight = self.zoomWrap.height();
  1414. }
  1415. else {
  1416. self.$elem.css(autoHDimension);
  1417. self.constheight = elemHeight;
  1418. }
  1419. var constHDim = {
  1420. 'height': self.constheight,
  1421. 'width': self.options.constrainSize
  1422. };
  1423. if (self.options.zoomType === 'inner') {
  1424. self.zoomWrap.parent().css(constHDim);
  1425. self.zoomWindow.css(constHDim);
  1426. }
  1427. if (self.options.tint) {
  1428. self.tintContainer.css(constHDim);
  1429. self.zoomTint.css(constHDim);
  1430. self.zoomTintImage.css(constHDim);
  1431. }
  1432. }
  1433. }
  1434. },
  1435. doneCallback: function () {
  1436. var self = this;
  1437. if (self.options.loadingIcon && !!self.spinner && !!self.spinner.length) {
  1438. self.spinner.hide();
  1439. }
  1440. self.updateOffset(self);
  1441. self.nzWidth = self.$elem.width();
  1442. self.nzHeight = self.$elem.height();
  1443. // reset the zoomlevel back to default
  1444. self.currentZoomLevel = self.options.zoomLevel;
  1445. //ratio of the large to small image
  1446. self.widthRatio = self.largeWidth / self.nzWidth;
  1447. self.heightRatio = self.largeHeight / self.nzHeight;
  1448. //NEED TO ADD THE LENS SIZE FOR ROUND
  1449. // adjust images less than the window height
  1450. if (self.options.zoomType === 'window') {
  1451. if (self.nzHeight < self.options.zoomWindowHeight / self.heightRatio) {
  1452. self.lensHeight = self.nzHeight;
  1453. }
  1454. else {
  1455. self.lensHeight = self.options.zoomWindowHeight / self.heightRatio;
  1456. }
  1457. if (self.nzWidth < self.options.zoomWindowWidth) {
  1458. self.lensWidth = self.nzWidth;
  1459. }
  1460. else {
  1461. self.lensWidth = self.options.zoomWindowWidth / self.widthRatio;
  1462. }
  1463. if (self.zoomLens) {
  1464. self.zoomLens.css({
  1465. 'width': self.lensWidth,
  1466. 'height': self.lensHeight
  1467. });
  1468. }
  1469. }
  1470. },
  1471. getCurrentImage: function () {
  1472. var self = this;
  1473. return self.zoomImage;
  1474. },
  1475. getGalleryList: function () {
  1476. var self = this;
  1477. //loop through the gallery options and set them in list for fancybox
  1478. self.gallerylist = [];
  1479. if (self.options.gallery) {
  1480. $('#' + self.options.gallery + ' a').each(function () {
  1481. var imgSrc = '';
  1482. if ($(this).data(self.options.attrImageZoomSrc)) {
  1483. imgSrc = $(this).data(self.options.attrImageZoomSrc);
  1484. }
  1485. else if ($(this).data('image')) {
  1486. imgSrc = $(this).data('image');
  1487. }
  1488. //put the current image at the start
  1489. if (imgSrc === self.zoomImage) {
  1490. self.gallerylist.unshift({
  1491. href: '' + imgSrc + '',
  1492. title: $(this).find('img').attr('title')
  1493. });
  1494. }
  1495. else {
  1496. self.gallerylist.push({
  1497. href: '' + imgSrc + '',
  1498. title: $(this).find('img').attr('title')
  1499. });
  1500. }
  1501. });
  1502. }
  1503. //if no gallery - return current image
  1504. else {
  1505. self.gallerylist.push({
  1506. href: '' + self.zoomImage + '',
  1507. title: $(this).find('img').attr('title')
  1508. });
  1509. }
  1510. return self.gallerylist;
  1511. },
  1512. changeZoomLevel: function (value) {
  1513. var self = this;
  1514. //flag a zoom, so can adjust the easing during setPosition
  1515. self.scrollingLock = true;
  1516. //round to two decimal places
  1517. self.newvalue = parseFloat(value).toFixed(2);
  1518. var newvalue = self.newvalue;
  1519. //maxwidth & Maxheight of the image
  1520. var maxheightnewvalue = self.largeHeight / ((self.options.zoomWindowHeight / self.nzHeight) * self.nzHeight);
  1521. var maxwidthtnewvalue = self.largeWidth / ((self.options.zoomWindowWidth / self.nzWidth) * self.nzWidth);
  1522. //calculate new heightratio
  1523. if (self.options.zoomType !== 'inner') {
  1524. if (maxheightnewvalue <= newvalue) {
  1525. self.heightRatio = (self.largeHeight / maxheightnewvalue) / self.nzHeight;
  1526. self.newvalueheight = maxheightnewvalue;
  1527. self.fullheight = true;
  1528. }
  1529. else {
  1530. self.heightRatio = (self.largeHeight / newvalue) / self.nzHeight;
  1531. self.newvalueheight = newvalue;
  1532. self.fullheight = false;
  1533. }
  1534. // calculate new width ratio
  1535. if (maxwidthtnewvalue <= newvalue) {
  1536. self.widthRatio = (self.largeWidth / maxwidthtnewvalue) / self.nzWidth;
  1537. self.newvaluewidth = maxwidthtnewvalue;
  1538. self.fullwidth = true;
  1539. }
  1540. else {
  1541. self.widthRatio = (self.largeWidth / newvalue) / self.nzWidth;
  1542. self.newvaluewidth = newvalue;
  1543. self.fullwidth = false;
  1544. }
  1545. if (self.options.zoomType === 'lens') {
  1546. if (maxheightnewvalue <= newvalue) {
  1547. self.fullwidth = true;
  1548. self.newvaluewidth = maxheightnewvalue;
  1549. } else {
  1550. self.widthRatio = (self.largeWidth / newvalue) / self.nzWidth;
  1551. self.newvaluewidth = newvalue;
  1552. self.fullwidth = false;
  1553. }
  1554. }
  1555. }
  1556. if (self.options.zoomType === 'inner') {
  1557. maxheightnewvalue = parseFloat(self.largeHeight / self.nzHeight).toFixed(2);
  1558. maxwidthtnewvalue = parseFloat(self.largeWidth / self.nzWidth).toFixed(2);
  1559. if (newvalue > maxheightnewvalue) {
  1560. newvalue = maxheightnewvalue;
  1561. }
  1562. if (newvalue > maxwidthtnewvalue) {
  1563. newvalue = maxwidthtnewvalue;
  1564. }
  1565. if (maxheightnewvalue <= newvalue) {
  1566. self.heightRatio = (self.largeHeight / newvalue) / self.nzHeight;
  1567. if (newvalue > maxheightnewvalue) {
  1568. self.newvalueheight = maxheightnewvalue;
  1569. } else {
  1570. self.newvalueheight = newvalue;
  1571. }
  1572. self.fullheight = true;
  1573. }
  1574. else {
  1575. self.heightRatio = (self.largeHeight / newvalue) / self.nzHeight;
  1576. if (newvalue > maxheightnewvalue) {
  1577. self.newvalueheight = maxheightnewvalue;
  1578. } else {
  1579. self.newvalueheight = newvalue;
  1580. }
  1581. self.fullheight = false;
  1582. }
  1583. if (maxwidthtnewvalue <= newvalue) {
  1584. self.widthRatio = (self.largeWidth / newvalue) / self.nzWidth;
  1585. if (newvalue > maxwidthtnewvalue) {
  1586. self.newvaluewidth = maxwidthtnewvalue;
  1587. } else {
  1588. self.newvaluewidth = newvalue;
  1589. }
  1590. self.fullwidth = true;
  1591. }
  1592. else {
  1593. self.widthRatio = (self.largeWidth / newvalue) / self.nzWidth;
  1594. self.newvaluewidth = newvalue;
  1595. self.fullwidth = false;
  1596. }
  1597. } //end inner
  1598. var scrcontinue = false;
  1599. if (self.options.zoomType === 'inner') {
  1600. if (self.nzWidth >= self.nzHeight) {
  1601. if (self.newvaluewidth <= maxwidthtnewvalue) {
  1602. scrcontinue = true;
  1603. }
  1604. else {
  1605. scrcontinue = false;
  1606. self.fullheight = true;
  1607. self.fullwidth = true;
  1608. }
  1609. }
  1610. if (self.nzHeight > self.nzWidth) {
  1611. if (self.newvaluewidth <= maxwidthtnewvalue) {
  1612. scrcontinue = true;
  1613. }
  1614. else {
  1615. scrcontinue = false;
  1616. self.fullheight = true;
  1617. self.fullwidth = true;
  1618. }
  1619. }
  1620. }
  1621. if (self.options.zoomType !== 'inner') {
  1622. scrcontinue = true;
  1623. }
  1624. if (scrcontinue) {
  1625. self.zoomLock = 0;
  1626. self.changeZoom = true;
  1627. //if lens height is less than image height
  1628. if (((self.options.zoomWindowHeight) / self.heightRatio) <= self.nzHeight) {
  1629. self.currentZoomLevel = self.newvalueheight;
  1630. if (self.options.zoomType !== 'lens' && self.options.zoomType !== 'inner') {
  1631. self.changeBgSize = true;
  1632. self.zoomLens.css({
  1633. height: self.options.zoomWindowHeight / self.heightRatio
  1634. });
  1635. }
  1636. if (self.options.zoomType === 'lens' || self.options.zoomType === 'inner') {
  1637. self.changeBgSize = true;
  1638. }
  1639. }
  1640. if ((self.options.zoomWindowWidth / self.widthRatio) <= self.nzWidth) {
  1641. if (self.options.zoomType !== 'inner') {
  1642. if (self.newvaluewidth > self.newvalueheight) {
  1643. self.currentZoomLevel = self.newvaluewidth;
  1644. }
  1645. }
  1646. if (self.options.zoomType !== 'lens' && self.options.zoomType !== 'inner') {
  1647. self.changeBgSize = true;
  1648. self.zoomLens.css({
  1649. width: self.options.zoomWindowWidth / self.widthRatio
  1650. });
  1651. }
  1652. if (self.options.zoomType === 'lens' || self.options.zoomType === 'inner') {
  1653. self.changeBgSize = true;
  1654. }
  1655. }
  1656. if (self.options.zoomType === 'inner') {
  1657. self.changeBgSize = true;
  1658. if (self.nzWidth > self.nzHeight) {
  1659. self.currentZoomLevel = self.newvaluewidth;
  1660. }
  1661. else if (self.nzHeight >= self.nzWidth) {
  1662. self.currentZoomLevel = self.newvaluewidth;
  1663. }
  1664. }
  1665. } //under
  1666. //sets the boundry change, called in setWindowPos
  1667. self.setPosition(self.currentLoc);
  1668. //
  1669. },
  1670. closeAll: function () {
  1671. var self = this;
  1672. if (self.zoomWindow) {
  1673. self.zoomWindow.hide();
  1674. }
  1675. if (self.zoomLens) {
  1676. self.zoomLens.hide();
  1677. }
  1678. if (self.zoomTint) {
  1679. self.zoomTint.hide();
  1680. }
  1681. },
  1682. updateOffset: function (self) {
  1683. if (self.options.zoomContainerAppendTo !== 'body') {
  1684. self.nzOffset = self.$elem.offset();
  1685. var appendedPosition = $(self.options.zoomContainerAppendTo).offset();
  1686. self.nzOffset.top = self.$elem.offset().top - appendedPosition.top;
  1687. self.nzOffset.left = self.$elem.offset().left - appendedPosition.left;
  1688. } else {
  1689. self.nzOffset = self.$elem.offset();
  1690. }
  1691. },
  1692. changeState: function (value) {
  1693. var self = this;
  1694. if (value === 'enable') {
  1695. self.options.zoomEnabled = true;
  1696. }
  1697. if (value === 'disable') {
  1698. self.options.zoomEnabled = false;
  1699. }
  1700. },
  1701. responsiveConfig: function (options) {
  1702. if (options.respond && options.respond.length > 0) {
  1703. return $.extend({}, options, this.configByScreenWidth(options));
  1704. }
  1705. return options;
  1706. },
  1707. configByScreenWidth: function (options) {
  1708. var screenWidth = $(window).width();
  1709. var config = $.grep(options.respond, function (item) {
  1710. var range = item.range.split('-');
  1711. return (screenWidth >= range[0]) && (screenWidth <= range[1]);
  1712. });
  1713. if (config.length > 0) {
  1714. return config[0];
  1715. } else {
  1716. return options;
  1717. }
  1718. }
  1719. };
  1720. $.fn.ezPlus = function (options) {
  1721. return this.each(function () {
  1722. var elevate = Object.create(EZP);
  1723. elevate.init(options, this);
  1724. $.data(this, 'ezPlus', elevate);
  1725. });
  1726. };
  1727. $.fn.ezPlus.options = {
  1728. attrImageZoomSrc: 'zoom-image', // attribute to plugin use for zoom
  1729. borderColour: '#888',
  1730. borderSize: 4,
  1731. constrainSize: false, //in pixels the dimensions you want to constrain on
  1732. constrainType: false, //width or height
  1733. containLensZoom: false,
  1734. cursor: 'inherit', // user should set to what they want the cursor as, if they have set a click function
  1735. debug: false,
  1736. easing: false,
  1737. easingAmount: 12,
  1738. enabled: true,
  1739. gallery: false,
  1740. galleryActiveClass: 'zoomGalleryActive',
  1741. gallerySelector: false,
  1742. galleryItem: 'a',
  1743. galleryEvent: 'click',
  1744. imageCrossfade: false,
  1745. lensBorderColour: '#000',
  1746. lensBorderSize: 1,
  1747. lensColour: 'white', //colour of the lens background
  1748. lensFadeIn: false,
  1749. lensFadeOut: false,
  1750. lensOpacity: 0.4, //opacity of the lens
  1751. lensShape: 'square', //can be 'round'
  1752. lensSize: 200,
  1753. lenszoom: false,
  1754. loadingIcon: true, //http://www.example.com/spinner.gif
  1755. // This change will allow to decide if you want to decrease
  1756. // zoom of one of the dimensions once the other reached it's top value,
  1757. // or keep the aspect ratio, default behaviour still being as always,
  1758. // allow to continue zooming out, so it keeps retrocompatibility.
  1759. mantainZoomAspectRatio: false,
  1760. maxZoomLevel: false,
  1761. minZoomLevel: 1.01,
  1762. //minZoomLevel: false,
  1763. onComplete: $.noop,
  1764. onDestroy: $.noop,
  1765. onImageClick: $.noop,
  1766. onImageSwap: $.noop,
  1767. onImageSwapComplete: $.noop,
  1768. onShow: $.noop,
  1769. onHide: $.noop,
  1770. onZoomedImageLoaded: $.noop,
  1771. preloading: 1, //by default, load all the images, if 0, then only load images after activated (PLACEHOLDER FOR NEXT VERSION)
  1772. respond: [],
  1773. responsive: true,
  1774. scrollZoom: false, //allow zoom on mousewheel, true to activate
  1775. scrollZoomIncrement: 0.1, //steps of the scrollzoom
  1776. showLens: true,
  1777. tint: false, //enable the tinting
  1778. tintColour: '#333', //default tint color, can be anything, red, #ccc, rgb(0,0,0)
  1779. tintOpacity: 0.4, //opacity of the tint
  1780. touchEnabled: true,
  1781. zoomActivation: 'hover', // Can also be click (PLACEHOLDER FOR NEXT VERSION)
  1782. zoomContainerAppendTo: 'body', //zoom container parent selector
  1783. zoomId: -1, // identifier for the zoom container
  1784. zoomLevel: 1, //default zoom level of image
  1785. zoomTintFadeIn: false,
  1786. zoomTintFadeOut: false,
  1787. zoomType: 'window', //window is default, also 'lens' available -
  1788. zoomWindowAlwaysShow: false,
  1789. zoomWindowBgColour: '#fff',
  1790. zoomWindowFadeIn: false,
  1791. zoomWindowFadeOut: false,
  1792. zoomWindowHeight: 400,
  1793. zoomWindowOffsetX: 0,
  1794. zoomWindowOffsetY: 0,
  1795. zoomWindowPosition: 1, //Possible values: 1-16, but we can also position with a selector string.
  1796. zoomWindowWidth: 400,
  1797. zoomEnabled: true, //false disables zoomwindow from showing
  1798. zIndex: 999
  1799. };
  1800. })(window.jQuery, window, document);