This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
photozoom.min.js
10 lines (10 loc) · 4.07 KB
/
photozoom.min.js
1
2
3
4
5
6
7
8
9
10
/*! PhotoZoom - jQuery Plugin - 0.2.1 - 2014-03-18 | https://github.com/PizzaBrandon/photozoom
* Copyright (c) 2014 by Brandon Belvin | Released under the MIT License | http://brandon.mit-license.org */
(function(h,p){var m=function(e){var b=this,k=e.zoomContainer,f=e.image,a,c;h("#photozoomLens").remove();c=h('<div id="photozoomLens" class="photozoomLens"/>').css({position:"absolute",background:"#fff",border:"2px solid #333",opacity:0.5,display:"none",cursor:"pointer"}).appendTo(f);b.resize=function(){var g=k.zoomRatio||0.25,d=k.zoomBoundary;a={width:Math.round(Math.min(f.width(),d.width*g)),height:Math.round(Math.min(f.height(),d.height*g))};c.css(a);return b};h(document).on("photozoom.imageready",
b.resize);b.moveLens=function(b){if(c){var d=b.x;b=b.y;d=d<a.width/2?0:d>f.width()-a.width/2?f.width()-a.width:d-a.width/2;b=b<a.height/2?0:b>f.height()-a.height/2?f.height()-a.height:b-a.height/2;d={left:d,top:b};c.css(d);return d}};e.pos&&b.moveLens(e.pos);b.show=function(){c&&c.show();return b};b.hide=function(){c&&c.hide();return b};b.destroy=function(){c&&c.remove();f=k=c=null;h(document).off("photozoom.imageready");return b};b.element=function(){return c}},n=function(e){var b=this,k=e.image,
f=e.target;e=e.zoomImage;var a,c,g;h("#photozoomContainer").remove();a=h('<div id="photozoomContainer" class="photozoomContainer"/>').css({position:"absolute",background:"#fff",overflow:"hidden",display:"none"}).appendTo(document.body);b.resize=function(){var d=h(f),c=h(p),d={left:d.offset().left,top:d.offset().top,right:d.offset().left+d.outerWidth(),bottom:d.offset().top+d.outerHeight()};d.top=Math.max(d.top,c.scrollTop());d.bottom=Math.min(d.bottom,c.scrollTop()+c.height());d.width=d.right-d.left;
d.height=d.bottom-d.top;c=b.zoomBoundary=d;a.css({top:c.top,left:c.left,width:c.width,height:c.height});return b};c=new Image;c.onload=function(){b.zoomRatio=k.width()/c.width;b.resize();h(document).trigger("photozoom.imageready")};c.src=e;g=h('<img id="photozoomImage" class="photozoomImage"/>').attr("src",e).css({position:"absolute"}).appendTo(a);b.moveImage=function(a){g.css({top:-a.top/b.zoomRatio,left:-a.left/b.zoomRatio});return b};b.show=function(){a&&a.show();return b};b.hide=function(){a&&
a.hide();return b};b.destroy=function(){g.remove();g=null;a.remove();c=f=k=a=null;return b}},q=function(e){var b=this,k=e.image,f=h(e.gallery);f.find("[data-photozoom-gallery]").on("click.photozoom",function(a){a.preventDefault();a=h(a.currentTarget);var b=a.data();f.find(".thumbnail-selected").removeClass("thumbnail-selected");a.addClass("thumbnail-selected");k.switchImage(b.src,b.zoomSrc)});b.destroy=function(){f.find("[data-photozoom-gallery]").off("click.photozoom");k=f=null;return b};return b};
h.fn.photozoom=function(e){function b(a){if(!c)if(c=a||!0,g.resize().show(),d.resize().show(),a)h(document).on("touchmove.photozoom",f).on("touchend.photozoom",k);else h(document).on("mousemove.photozoom",f),d.element().on("mouseout.photozoom",k)}function k(){c&&(d.hide(),g.hide(),h(document).off("touchmove.photozoom touchend.photozoom mousemove.photozoom"),d.element().off("mouseout.photozoom"),c=!1)}function f(c){var e=c.originalEvent.touches?c.originalEvent.touches[0]:c.originalEvent.changedTouches?
c.originalEvent.changedTouches[0]:null;e?(c.preventDefault(),b("touch"),c=e):b();c={x:c.pageX-a.offset().left,y:c.pageY-a.offset().top};c=d.moveLens(c);g.moveImage(c)}var a=this,c=!1;e=h.extend({clipToBoundaries:!0,target:"#photozoomWindow",gallery:"#photozoomGallery"},e);var g=a.zoomContainer=new n({image:a,target:e.target,zoomImage:a.data().zoomSrc}),d=a.lens=new m({image:a,zoomContainer:g}),l=a.gallery=new q({image:a,gallery:e.gallery});a.on("touchstart.photozoom mouseover.photozoom",f);a.switchImage=
function(b,c){var f=a.find("img");f.attr("src")!==b&&(k(),g.destroy(),d.destroy(),f.attr("src",b),a.attr("href")&&a.attr("href",c),g=a.zoomContainer=new n({image:a,target:e.target,zoomImage:c}),d=a.lens=new m({image:a,zoomContainer:g}))};a.destroy=function(){k();d&&(d.destroy(),d=null);g&&(g.destroy(),g=null);l&&(l.destroy(),l=null);a.off("touchstart.photozoom mouseover.photozoom");return a};return a}})(jQuery,window);