1 line
4.4 KiB
JavaScript
1 line
4.4 KiB
JavaScript
|
!function(){var t=window.Adaptive||{},s=window.Mobify=window.Mobify||{};void 0===t.$&&(s.$=s.$||window.$||window.Zepto||window.jQuery);var i,e,o=t.$||s.$;s.UI=s.UI||{classPrefix:"m-"},s.UI.Magnifik=((e=function(t,s){this.options=o.extend({},e.defaults,s),this.options.classNames=o.extend(i.classNames,this.options.classNames),this.options.imageStyle.width=100*this.options.ratio+"%",this.options.stage||(this.options.stage=o("body"),this.options.global=!0),this.$element=o(t),this.bind()}).defaults=i={stage:void 0,classNames:{zooming:"zooming",close:"close",control:"magnifikControl",canvas:"magnifikCanvas",thumb:"magnifikThumb",full:"magnifikFull"},ratio:2,seekImage:!0,clickCloses:!0,activationEvent:"click",canvasStyle:{position:"absolute",width:"100%",height:"100%",overflow:"auto","-webkit-overflow-scrolling":"touch"},imageStyle:{position:"absolute",top:"0",left:"0",maxWidth:"none",maxHeight:"none"},stageHTML:function(){return'<div class="'+this._getClass("canvas")+'"><img class="'+this._getClass("thumb")+'"><img class="'+this._getClass("full")+'"></div>'},globalStyle:function(){var t="."+this._getClass("zooming");return t+" { overflow: hidden; padding-top:0px}"+t+" > * { display: none !important; }"+t+" > ."+this._getClass("control")+" { display: block !important; }"}},e.prototype.unbind=function(){return this.bind(!0)},e.prototype.makeElems=function(){if(this.$stage=this.options.stage,this.$canvas=o(this.options.stageHTML.call(this)).addClass(this._getClass("control")),this.$canvas.first().css(this.options.canvasStyle),this.$thumb=this.$canvas.find("."+this._getClass("thumb")).css(this.options.imageStyle),this.$full=this.$canvas.find("."+this._getClass("full")).css(this.options.imageStyle),this.options.clickCloses&&this.$canvas.first().addClass(this._getClass("close")),this.options.global){if(!o('style[data-magnifik="'+this._getClass("zooming")+'"]').length){var t=document.createElement("style"),s=this.options.globalStyle.call(this);t.setAttribute("type","text/css"),t.styleSheet?t.styleSheet.cssText=s:t.appendChild(document.createTextNode(s)),o("head")[0].appendChild(t)}}else this.$stage.css("position","relative");var i="."+this._getClass("close");this.$close=this.$canvas.find(i).add(this.$canvas.filter(i)),this.bindClose("bind")},e.prototype.close=function(t){this.isOpen&&(this.isOpen=!1,this.$element.trigger("magnifik:closing"),this.$canvas.detach(),this.$stage.removeClass(this._getClass("zooming")),this.options.global&&(document.body.scrollTop=this.oldScrollTop),this.$element.trigger("magnifik:close"))},e.prototype.open=function(t){if(t.preventDefault(),!this.isOpen){this.isOpen=!0,this.$element.trigger("magnifik:opening"),this.$stage||this.makeElems();var s,i,e=.5,n=.5,a=o(t.target);if("IMG"!==t.target.tagName){var l=this.$element;this.options.seekImage&&(l=l.add(this.$element.parents()));for(var h=0;h<l.length;++h)if((s=o(l[h]).find("img")).length){a=s;break}}else e=t.offsetX/a.prop("offsetWidth"),n=t.offsetY/a.prop("offsetHeight");i=a.filter("[href]").add(a.parent("[href]")).attr("href")||a.attr("src"),this.$thumb.attr("src",a.attr("src")),this.$full.attr("src",i),this.options.global&&(this.oldScrollTop=document.body.scrollTop),this.$stage.append(this.$canvas),this.$stage.addClass(this._getClass("zooming"));var r=a.prop("naturalHeight")/a.prop("naturalWidth"),p=this.$thumb.prop("offsetWidth"),c=this.$canvas.prop("offsetWidth"),d=p,g=this.$canvas.prop("offsetHeight"),f=p*r;this.$canvas.prop("scrollLeft",Math.max(0,Math.min(d-c,d*e-c/2))),this.$canvas.prop("scrollTop",Math.max(0,Math.min(f-g,f*n-g/2))),this.$element.trigger("magnifik:open")}},e.prototype.bindClose=function(t){this.$close&&this.$close[t](this.options.activationEvent,this.boundClose)},e.prototype.bind=function(t){var s=this,i=t?"unbind":"bind";this.boundClose=this.boundClose||function(t){return s.close.apply(s,arguments)},this.boundOpen=this.boundOpen||function(t){return s.open.apply(s,arguments)},this.$element[i](this.options.activationEvent,this.boundOpen),this.bindClose(i)},e.prototype._getClass=function(t){var i=this.options.classPrefix;return void
|