/*! * Twenty Twenty JS. * https://github.com/zurb/twentytwenty * * Copyright 2018 zurb * Released under the ISC License * https://github.com/zurb/twentytwenty/blob/master/LICENSE.md */ !function(t){t.fn.twentytwenty=function(e){e=t.extend({default_offset_pct:.5,orientation:"horizontal",move_on_hover:!1},e);return this.each(function(){var n=e.default_offset_pct,i=t(this),s=e.orientation,a="vertical"===s?"down":"left",o="vertical"===s?"up":"right",d=Boolean(e.move_on_hover),f=i.find("img:first"),w=i.find("img:last"),c=i.find(".twentytwenty-handle"),r=i.find(".twentytwenty-overlay");t(this).hasClass("twentytwenty-container")||(i.wrap("
"),i.append("
"),f=i.find("img:first"),w=i.find("img:last"),i.append("
"),(c=i.find(".twentytwenty-handle")).append(""),c.append(""),i.addClass("twentytwenty-container"),f.addClass("twentytwenty-before"),w.addClass("twentytwenty-after"),(r=i.find(".twentytwenty-overlay")).append("
"),r.append("
"));var l=function(t){var e,n,a,o=(e=t,n=f.width(),a=f.height(),{w:n+"px",h:a+"px",cw:e*n+"px",ch:e*a+"px"});c.css("vertical"===s?"top":"left","vertical"===s?o.ch:o.cw),function(t){"vertical"===s?f.css("clip","rect(0,"+t.w+","+t.ch+",0)"):f.css("clip","rect(0,"+t.cw+","+t.h+",0)"),i.css("height",t.h)}(o)};t(window).on("resize.twentytwenty",function(t){l(n)});var v=0,y=0;c.on("movestart",function(t){(t.distX>t.distY&&t.distX<-t.distY||t.distX-t.distY)&&"vertical"!==s?t.preventDefault():(t.distXt.distY&&t.distX>-t.distY)&&"vertical"===s&&t.preventDefault(),i.addClass("active"),v=i.offset().left,offsetY=i.offset().top,y=f.width(),imgHeight=f.height()}),c.on("moveend",function(t){d||i.removeClass("active")}),c.on("move",function(t){i.hasClass("active")&&((n="vertical"===s?(t.pageY-offsetY)/imgHeight:(t.pageX-v)/y)<0&&(n=0),n>1&&(n=1),l(n))}),i.find("img").on("mousedown",function(t){t.preventDefault()}),d&&(i.on("mouseenter",function(t){i.addClass("active"),v=i.offset().left,offsetY=i.offset().top,y=f.width(),imgHeight=f.height()}),i.on("mouseleave",function(t){i.removeClass("active")}),i.on("mousemove",function(t){i.hasClass("active")&&((n="vertical"===s?(t.pageY-offsetY)/imgHeight:(t.pageX-v)/y)<0&&(n=0),n>1&&(n=1),l(n))})),t(window).trigger("resize.twentytwenty")})}}(jQuery);