thumbnail.min.js 8.11 KB
N2Require("SmartSliderWidgetThumbnailDefault",[],[],function(i,t,s){"use strict";function e(t,s){this.slider=window[t],this.slider.started(i.proxy(this.start,this,t,s))}return e.prototype.start=function(t,s){if(this.slider.sliderElement.data("thumbnail"))return!1;this.slider.sliderElement.data("thumbnail",this),this.parameters=i.extend({captionSize:0,minimumThumbnailCount:1.5,invertGroupDirection:0},s),this.ratio=1,this.hidden=!1,this.forceHidden=!1,this.forceHiddenCB=null,this.group=2,this.itemPerPane=1,this.currentI=0,this.offset=0,this.horizontal={prop:"width",Prop:"Width",sideProp:nextend.rtl.left,invProp:"height"},this.vertical={prop:"height",Prop:"Height",sideProp:"top",invProp:"width"},this.group=parseInt(s.group),this.orientation=s.orientation,"vertical"==this.orientation&&(this.goToDot=this._goToDot),this.outerBar=this.slider.sliderElement.find(".nextend-thumbnail-default"),this.bar=this.outerBar.find(".nextend-thumbnail-inner"),this.scroller=this.bar.find(".nextend-thumbnail-scroller");var e="universalclick";if("mouseenter"==s.action&&(e="mouseenter"),this.dots=this.scroller.find("> div").on(e,i.proxy(this.onDotClick,this)),this.images=this.dots.find(".n2-ss-thumb-image"),nextend.rtl.isRtl?(this.previous=this.outerBar.find(".nextend-thumbnail-next").on("click",i.proxy(this.previousPane,this)),this.next=this.outerBar.find(".nextend-thumbnail-previous").on("click",i.proxy(this.nextPane,this))):(this.previous=this.outerBar.find(".nextend-thumbnail-previous").on("click",i.proxy(this.previousPane,this)),this.next=this.outerBar.find(".nextend-thumbnail-next").on("click",i.proxy(this.nextPane,this))),this.slider.isShuffled){for(var o=0;o<this.slider.realSlides.length;o++){var r=this.slider.realSlides[o];this.dots.eq(r.originalIndex).appendTo(this.scroller)}this.dots=this.scroller.find("> div")}if(this.thumbnailDimension={widthLocal:this.dots.width(),width:this.dots.outerWidth(!0),height:this.dots.outerHeight(!0),widthBorder:parseInt(this.dots.css("borderLeftWidth"))+parseInt(this.dots.css("borderRightWidth")),heightBorder:parseInt(this.dots.css("borderTopWidth"))+parseInt(this.dots.css("borderBottomWidth"))},this.thumbnailDimension.widthMargin=this.thumbnailDimension.width-this.dots.outerWidth(),this.thumbnailDimension.heightMargin=this.thumbnailDimension.height-this.dots.outerHeight(),this.imageDimension={width:this.images.outerWidth(!0),height:this.images.outerHeight(!0)},this.sideDimension=.25*this.thumbnailDimension[this[this.orientation].prop],"horizontal"==this.orientation?(this.scroller.height(this.thumbnailDimension.height*this.group),this.bar.height(this.scroller.outerHeight(!0))):(this.scroller.width(this.thumbnailDimension.width*this.group),this.bar.width(this.scroller.outerWidth(!0))),this.slider.sliderElement.on({BeforeVisible:i.proxy(this.onReady,this),sliderSwitchTo:i.proxy(this.onSlideSwitch,this)}),this.slider.firstSlideReady.done(i.proxy(this.onFirstSlideSet,this)),0==s.overlay){var h=!1;switch(s.area){case 1:h="Top";break;case 12:h="Bottom";break;case 5:h="Left";break;case 8:h="Right"}h&&(this.offset=parseFloat(this.outerBar.data("offset")),this.slider.responsive.addStaticMargin(h,this))}},e.prototype.onFirstSlideSet=function(i){this.activateDots(i.index),this.goToDot(i.index)},e.prototype.onReady=function(){this.slider.sliderElement.on("SliderResize",i.proxy(this.onSliderResize,this)),this.onSliderResize()},e.prototype.onSliderResize=function(){null!==this.forceHiddenCB&&this.forceHiddenCB.call(this),this.adjustScrollerSize();var i=this.slider.currentSlide.index;this.activateDots(i),this.goToDot(i)},e.prototype.adjustScrollerSize=function(){var i=this[this.orientation].prop,t=Math.ceil(this.dots.length/this.group)*this.thumbnailDimension[i]*this.ratio,s=this.scroller["outer"+this[this.orientation].Prop]()-this.scroller[i](),e=this.slider.dimensions["thumbnail"+i];e>=t+s?this.scroller[i](e-s):this.scroller[i](t),"horizontal"==this.orientation?this.scroller.height(this.dots.outerHeight(!0)*this.group):this.scroller.width(this.dots.outerWidth(!0)*this.group)},e.prototype.onDotClick=function(i){this.slider.directionalChangeToReal(this.dots.index(i.currentTarget))},e.prototype.onSlideSwitch=function(i,t,s){this.activateDots(t),this.goToDot(s)},e.prototype.activateDots=function(i){this.dots.filter(".n2-active").removeClass("n2-active");for(var t=this.slider.slides[i].slides,s=0;s<t.length;s++)this.dots.eq(t[s].index).addClass("n2-active")},e.prototype.previousPane=function(){this.goToDot(this.currentI-this.itemPerPane*this.group)},e.prototype.nextPane=function(){this.goToDot(this.currentI+this.itemPerPane*this.group)},e.prototype.goToDot=function(i){var t=this[this.orientation],s=1,e=this.slider.dimensions["thumbnail"+t.prop],o=this.sideDimension,r=e-2*o,h=r/this.thumbnailDimension[t.prop];if(h<=this.parameters.minimumThumbnailCount&&(o=.1*e,r=e-2*o,s=r/(this.parameters.minimumThumbnailCount*this.thumbnailDimension[t.prop]),h=r/(this.thumbnailDimension[t.prop]*s)),this.ratio!=s){var n={};n[t.prop]=parseInt(this.thumbnailDimension[t.prop]*s-this.thumbnailDimension[t.prop+"Margin"]-this.thumbnailDimension[t.prop+"Border"]),n[t.invProp]=parseInt((this.thumbnailDimension[t.invProp]-this.parameters.captionSize)*s-this.thumbnailDimension[t.prop+"Margin"]+this.parameters.captionSize-this.thumbnailDimension[t.invProp+"Border"]),this.dots.css(n);var a=this.dots.width()/this.thumbnailDimension.widthLocal;n={},n[t.prop]=Math.ceil(this.imageDimension[t.prop]*a),n[t.invProp]=Math.ceil(this.imageDimension[t.invProp]*a),this.images.css(n),this.bar.css(t.invProp,"auto"),this.ratio=s,this.slider.responsive.doNormalizedResize(),this.adjustScrollerSize()}h=Math.floor(h),i=Math.max(0,Math.min(this.dots.length-1,i));var d,l={};d=this.parameters.invertGroupDirection?Math.floor(i%Math.ceil(this.dots.length/this.group)/h):Math.floor(i/this.group/h);var p=-(this.scroller["outer"+t.Prop]()-e);d==Math.floor((this.dots.length-1)/this.group/h)?(l[t.sideProp]=-(d*h*this.thumbnailDimension[t.prop]*s),0==d?this.previous.removeClass("n2-active"):this.previous.addClass("n2-active"),this.next.removeClass("n2-active")):d>0?(l[t.sideProp]=-(d*h*this.thumbnailDimension[t.prop]*s-o),this.previous.addClass("n2-active"),this.next.addClass("n2-active")):(l[t.sideProp]=0,this.previous.removeClass("n2-active"),this.next.addClass("n2-active")),p>=l[t.sideProp]&&(l[t.sideProp]=p,this.next.removeClass("n2-active")),NextendTween.to(this.scroller,.5,l).play(),this.currentI=i,this.itemPerPane=h},e.prototype._goToDot=function(t){if(!this.forceHidden){var s=this[this.orientation],e=this.slider.dimensions["thumbnail"+s.prop],o=(e-2*this.sideDimension)/this.thumbnailDimension[s.prop];if(0!=e&&o<this.parameters.minimumThumbnailCount-.5?this.hidden||("horizontal"==this.orientation?this.outerBar.css("height",0):this.outerBar.css("width",0),this.hidden=!0,this.forceHidden=!0,setTimeout(i.proxy(function(){this.forceHiddenCB=function(){this.forceHiddenCB=null,this.forceHidden=!1}},this),300),this.slider.responsive.doNormalizedResize()):this.hidden&&o>=this.parameters.minimumThumbnailCount+.5&&(this.hidden=!1,"horizontal"==this.orientation?this.outerBar.css("height",""):this.outerBar.css("width",""),this.slider.responsive.doNormalizedResize()),!this.hidden){o=Math.floor(o),t=Math.max(0,Math.min(this.dots.length-1,t));var r,h={};r=this.parameters.invertGroupDirection?Math.floor(t%Math.ceil(this.dots.length/this.group)/o):Math.floor(t/this.group/o);var n=-(this.scroller["outer"+s.Prop]()-e);r==Math.floor((this.dots.length-1)/this.group/o)?(h[s.sideProp]=-(r*o*this.thumbnailDimension[s.prop]),0==r?this.previous.removeClass("n2-active"):this.previous.addClass("n2-active"),this.next.removeClass("n2-active")):r>0?(h[s.sideProp]=-(r*o*this.thumbnailDimension[s.prop]-this.sideDimension),this.previous.addClass("n2-active"),this.next.addClass("n2-active")):(h[s.sideProp]=0,this.previous.removeClass("n2-active"),this.next.addClass("n2-active")),n>=h[s.sideProp]&&(h[s.sideProp]=n,this.next.removeClass("n2-active")),NextendTween.to(this.scroller,.5,h).play()}this.currentI=t,this.itemPerPane=o}},e.prototype.isVisible=function(){return this.outerBar.is(":visible")},e.prototype.getSize=function(){return"horizontal"==this.orientation?this.outerBar.height()+this.offset:this.outerBar.width()+this.offset},e});