jquery.ez-plus.js 85 KB

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