-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiSlideshow.min.js
More file actions
1 lines (1 loc) · 16.9 KB
/
Copy pathtiSlideshow.min.js
File metadata and controls
1 lines (1 loc) · 16.9 KB
1
(function(e){function t(t,n,r){this.container=t;this.options=n;this.maskId="";this.isOpen=false;this.imageList=[];this.currentImageIndex=0;e.tiSlideshow.interfaces[r]=this;if(this.options.auto)this.open()}t.prototype.open=function(){if(this.isOpen)return;if(!this.beforeOpen())return;this.isOpen=true;this.imageList=[];this.currentImageIndex=0;var t="tiSlideshowExposeMask";while(e("#"+t).length){t+="i"}this.maskId=t;var n='<div class="tiSlideshowPlaceSliderActions"></div>';var r='<div id="'+this.maskId+'" class="tiSlideshowExposeMask" style="opacity: '+this.options.opacity+"; background-color: "+this.options.mask+'; "></div>';var i='<div class="tiSlideshowPlaceControl"><div class="tiSlideshowPlaceControlThumbnailsScroll"><div class="tiSlideshowPlaceControlThumbnails"></div></div><a href="#" class="tiSlideshowPlaceControlActions"></a><a href="#" class="tiSlideshowPlaceControlClose"></a></div>';var s='<div class="tiSlideshowPlace"><div class="tiSlideshowPlaceSlider"><div class="tiSlideshowPlaceSliderPicture"></div><a href="#" class="tiSlideshowPlaceSliderPrevious"></a><a href="#" class="tiSlideshowPlaceSliderNext"></a>'+n+"</div>"+i+"</div>";e("body").append(r);e("body").append(s);if(navigator.appName=="Microsoft Internet Explorer"){e(".tiSlideshowPlaceControl").css("border","1px solid white")}var o=this;e(o.container).children("img").each(function(){var t="";if(e(this).attr("data-src")!=""&&e(this).attr("data-src")!=null)t=e(this).attr("data-src");else t=e(this).attr("src");o.imageList.push(t);var n='<a href="#" class="tiSlideshowPlaceControlThumbnailsThumbnail"><img src="'+o.getThumbnailSrc(t)+'" alt="thumbnail" /></a>';e(".tiSlideshowPlaceControlThumbnails").append(n)});o.initThumbnailsEvent();o.currentImageIndex=o.options.beginIndex;if(o.currentImageIndex>=0&&parseInt(o.currentImageIndex)<parseInt(o.imageList.length)){this.showCurrentImage()}else if(o.imageList.length>0){o.currentImageIndex=0;o.showCurrentImage()}this.changeOptions();this.touchSlideManager();e(window).scrollTop(0);e(".tiSlideshowExposeMask").show();e(".tiSlideshowPlace").show();this.keyManager();this.onOpen()};t.prototype.close=function(){if(!this.isOpen)return;if(!this.beforeClose())return;e(".tiSlideshowExposeMask").remove();e(".tiSlideshowPlace").remove();e("body").unbind("touchmove",e.tiSlideshow.preventTouchmove);this.isOpen=false;this.keyManager();this.onClose()};t.prototype.keyManager=function(){var t=this;if(this.isOpen){e(document).keydown(function(e){if(e.which==37)t.previous();if(e.which==39)t.next();if(e.which==27)t.close()})}else{e(document).unbind("keydown")}};t.prototype.touchSlideManager=function(){var t=this;e(".tiSlideshowPlaceSliderPicture").unbind("touchmove");e(".tiSlideshowPlaceSliderPicture").bind("touchmove",function(n){var r=n.originalEvent.touches[0].pageX;if(t.lastTouchSlideX>0){var i=t.lastTouchSlideX-r;var s=e(".tiSlideshowPlaceSliderPicture").position().left;e(".tiSlideshowPlaceSliderPicture").css("left",parseInt(s-i)+"px")}t.lastTouchSlideX=r;if(e(".tiSlideshowPlaceSliderPicture").position().left>0&&e(".tiSlideshowPlaceSliderPicture").position().left>e(".tiSlideshowPlaceSliderPicture").width()/2){if(t.previous()){e(".tiSlideshowPlaceSliderPicture").css("left",0);t.lastTouchSlideX=0}}if(e(".tiSlideshowPlaceSliderPicture").position().left<0&&e(".tiSlideshowPlaceSliderPicture").position().left<-e(".tiSlideshowPlaceSliderPicture").width()/2){if(t.next()){e(".tiSlideshowPlaceSliderPicture").css("left",0);t.lastTouchSlideX=0}}});e(".tiSlideshowPlaceSliderPicture").unbind("touchstart");e(".tiSlideshowPlaceSliderPicture").bind("touchstart",function(e){t.lastTouchSlideX=0});e(".tiSlideshowPlaceSliderPicture").unbind("touchend");e(".tiSlideshowPlaceSliderPicture").bind("touchend",function(n){e(".tiSlideshowPlaceSliderPicture").animate({left:0},200);t.lastTouchSlideX=0})};t.prototype.showCurrentImage=function(t){var n=this;e(".tiSlideshowPlaceSliderPicture").html('<img src="'+n.imageList[n.currentImageIndex]+'" alt="picture" style="display: hidden;"/>');if(!e(".tiSlideshowPlaceSliderPicture img").height()||!e(".tiSlideshowPlaceSliderPicture img").width()){e(".tiSlideshowPlaceSliderPicture img").load(function(){e(".tiSlideshowPlaceSliderPicture img").data("originalHeight",this.height);e(".tiSlideshowPlaceSliderPicture img").data("originalWidth",this.width);e.tiSlideshow.adjustSize();e(".tiSlideshowPlaceSliderPicture img").show();e(".tiSlideshowPlaceControlThumbnailsSelected").removeClass("tiSlideshowPlaceControlThumbnailsSelected");e(".tiSlideshowPlaceControlThumbnails .tiSlideshowPlaceControlThumbnailsThumbnail:eq("+n.currentImageIndex+")").addClass("tiSlideshowPlaceControlThumbnailsSelected");if(t)t()})}else{e(".tiSlideshowPlaceSliderPicture img").data("originalHeight",e(".tiSlideshowPlaceSliderPicture img").height());e(".tiSlideshowPlaceSliderPicture img").data("originalWidth",e(".tiSlideshowPlaceSliderPicture img").width());e.tiSlideshow.adjustSize();e(".tiSlideshowPlaceSliderPicture img").show();e(".tiSlideshowPlaceControlThumbnailsSelected").removeClass("tiSlideshowPlaceControlThumbnailsSelected");e(".tiSlideshowPlaceControlThumbnails .tiSlideshowPlaceControlThumbnailsThumbnail:eq("+n.currentImageIndex+")").addClass("tiSlideshowPlaceControlThumbnailsSelected");if(t)t()}};t.prototype.changeOptions=function(t){var n=this;this.options=e.extend({},this.options,t);e("#"+this.maskId).css("background-color",this.options.mask);e("#"+this.maskId).css("opacity",this.options.opacity);if(this.options.tactile){e(".tiSlideshowPlaceControlThumbnailsThumbnail").each(function(){e(this).replaceWith('<span class="tiSlideshowPlaceControlThumbnailsThumbnail">'+e(this).html()+"</span>")});e(".tiSlideshowPlaceControlClose").replaceWith('<span class="tiSlideshowPlaceControlClose"></span>');e(".tiSlideshowPlaceControlActions").replaceWith('<span class="tiSlideshowPlaceControlActions"></span>');e(".tiSlideshowPlaceSlider .tiSlideshowPlaceSliderPrevious").replaceWith('<span class="tiSlideshowPlaceSliderPrevious"></span>');e(".tiSlideshowPlaceSlider .tiSlideshowPlaceSliderNext").replaceWith('<span class="tiSlideshowPlaceSliderNext"></span>');e("body").bind("touchmove",e.tiSlideshow.preventTouchmove)}else{e(".tiSlideshowPlaceControlThumbnailsThumbnail").each(function(){e(this).replaceWith('<a href="#" class="tiSlideshowPlaceControlThumbnailsThumbnail">'+e(this).html()+"</a>")});e(".tiSlideshowPlaceControlClose").replaceWith('<a href="#" class="tiSlideshowPlaceControlClose"></a>');e(".tiSlideshowPlaceControlActions").replaceWith('<a href="#" class="tiSlideshowPlaceControlActions"></a>');e(".tiSlideshowPlaceSlider .tiSlideshowPlaceSliderPrevious").replaceWith('<a href="#" class="tiSlideshowPlaceSliderPrevious"></a>');e(".tiSlideshowPlaceSlider .tiSlideshowPlaceSliderNext").replaceWith('<a href="#" class="tiSlideshowPlaceSliderNext"></a>');e("body").unbind("touchmove",e.tiSlideshow.preventTouchmove)}e(".tiSlideshowPlaceSliderPrevious").click(function(){n.previous();return false});e(".tiSlideshowPlaceSliderNext").click(function(){n.next();return false});e(".tiSlideshowPlaceControlClose").click(function(){n.close();return false});e(".tiSlideshowPlaceControlActions").click(function(){n.actions();return false});n.initThumbnailsEvent();if(this.options.closeButton)e(".tiSlideshowPlaceControlClose").width(100);else e(".tiSlideshowPlaceControlClose").width(0);if(this.options.slideButtons){e(".tiSlideshowPlaceSliderPrevious, .tiSlideshowPlaceSliderNext").show()}else e(".tiSlideshowPlaceSliderPrevious, .tiSlideshowPlaceSliderNext").hide();if(this.options.slideButtons){if(this.imageList.length==0){e(".tiSlideshowPlaceSliderPrevious, .tiSlideshowPlaceSliderNext").hide()}else if(this.options.infiniteSlide){if(this.currentImageIndex==0)e(".tiSlideshowPlaceSliderPrevious").show();if(this.currentImageIndex==this.imageList.length-1)e(".tiSlideshowPlaceSliderNext").show()}else{if(this.currentImageIndex==0)e(".tiSlideshowPlaceSliderPrevious").hide();else e(".tiSlideshowPlaceSliderPrevious").show();if(this.currentImageIndex==this.imageList.length-1)e(".tiSlideshowPlaceSliderNext").hide();else e(".tiSlideshowPlaceSliderNext").show()}}if(this.options.thumbnails){e(".tiSlideshowPlaceControlThumbnailsScroll").show()}else{e(".tiSlideshowPlaceControlThumbnailsScroll").hide()}e(".tiSlideshowPlaceSliderActions").empty();if(this.options.actions&&this.options.actions.length>0){e(".tiSlideshowPlaceControlActions").width(100);var r=0;while(r<this.options.actions.length){if(this.options.actions[r]){var i="";if(this.options.tactile)i='<span class="tiSlideshowPlaceSliderActionsButton">'+this.options.actions[r].title+"</span>";else i='<a href="#" class="tiSlideshowPlaceSliderActionsButton">'+this.options.actions[r].title+"</a>";e(".tiSlideshowPlaceSliderActions").append(i);e(".tiSlideshowPlaceSliderActionsButton:last-child").click(function(){if(!e(this).hasClass("unclickable")){var t=e.proxy(n.options.actions[e(this).index()].callback,e(this));t()}else return false})}r++}}else{e(".tiSlideshowPlaceControlActions").width(0)}e.tiSlideshow.adjustSize()};t.prototype.next=function(){var t=this;var n=t.currentImageIndex;var r=parseInt(t.currentImageIndex)+1;if(t.options.infiniteSlide){if(r>=t.imageList.length)r=0}if(r<parseInt(t.imageList.length)&&r>=0){if(!this.beforeSlide(t.currentImageIndex,r))return false;t.currentImageIndex=r;if(this.options.slideButtons){if(this.options.infiniteSlide){if(this.currentImageIndex==0)e(".tiSlideshowPlaceSliderPrevious").show();if(this.currentImageIndex==this.imageList.length-1)e(".tiSlideshowPlaceSliderNext").show()}else{if(this.currentImageIndex==0)e(".tiSlideshowPlaceSliderPrevious").hide();else e(".tiSlideshowPlaceSliderPrevious").show();if(this.currentImageIndex==this.imageList.length-1)e(".tiSlideshowPlaceSliderNext").hide();else e(".tiSlideshowPlaceSliderNext").show()}}this.showCurrentImage(function(){t.onSlide(n,t.currentImageIndex)});return true}return false};t.prototype.previous=function(){var t=this;var n=t.currentImageIndex;var r=parseInt(t.currentImageIndex)-1;if(t.options.infiniteSlide){if(r<0)r=t.imageList.length-1}if(r<parseInt(t.imageList.length)&&r>=0){if(!t.beforeSlide(t.currentImageIndex,r))return false;t.currentImageIndex=r;if(this.options.slideButtons){if(this.options.infiniteSlide){if(this.currentImageIndex==0)e(".tiSlideshowPlaceSliderPrevious").show();if(this.currentImageIndex==this.imageList.length-1)e(".tiSlideshowPlaceSliderNext").show()}else{if(this.currentImageIndex==0)e(".tiSlideshowPlaceSliderPrevious").hide();else e(".tiSlideshowPlaceSliderPrevious").show();if(this.currentImageIndex==this.imageList.length-1)e(".tiSlideshowPlaceSliderNext").hide();else e(".tiSlideshowPlaceSliderNext").show()}}this.showCurrentImage(function(){t.onSlide(n,t.currentImageIndex)});return true}return false};t.prototype.initThumbnailsEvent=function(){var t=this;e(".tiSlideshowPlaceControlThumbnails .tiSlideshowPlaceControlThumbnailsThumbnail img").load(function(){e(this).data("originalHeight",this.height);e(this).data("originalWidth",this.width);e.tiSlideshow.adjustSize()});e(".tiSlideshowPlaceControlThumbnails .tiSlideshowPlaceControlThumbnailsThumbnail:eq("+t.currentImageIndex+")").addClass("tiSlideshowPlaceControlThumbnailsSelected");e(".tiSlideshowPlaceControlThumbnailsThumbnail").click(function(){var n=e(this).index()-t.currentImageIndex;while(n){if(n>0){t.next();n--}else{t.previous();n++}}return false});var n=0;e(".tiSlideshowPlaceControlThumbnailsThumbnail").each(function(){n+=e(this).outerWidth(true)});e(".tiSlideshowPlaceControlThumbnails").width(n);if(t.options.tactile){e(".tiSlideshowPlaceControlThumbnails").unbind("touchmove");e(".tiSlideshowPlaceControlThumbnailsScroll").bind("touchmove",function(n){var r=n.originalEvent.touches[0].pageX;if(t.lastTouchX>0){var i=t.lastTouchX-r;var s=e(".tiSlideshowPlaceControlThumbnailsScroll").scrollLeft();e(".tiSlideshowPlaceControlThumbnailsScroll").scrollLeft(s+i)}t.lastTouchX=r});e(".tiSlideshowPlaceControlThumbnailsScroll").unbind("touchstart");e(".tiSlideshowPlaceControlThumbnailsScroll").bind("touchstart",function(e){t.lastTouchX=0})}};t.prototype.getThumbnailSrc=function(e){var t;var n="";if(e.indexOf("/")>=0){t=e.split("/");t.pop();t=t.join("/");if(t[t.length-1]!="/")t=t+"/";n=t}var r=e;if(e.indexOf("/")>=0){t=e.split("/");r=t[t.length-1]}var i=r;if(r.indexOf(".")>=0){t=r.split(".");t.pop();i=t.join()}var s="";if(r.indexOf(".")>=0){t=r.split(".");s="."+t[t.length-1]}var o=this.options.thumbnailName;var u=new RegExp("(%PATH%)","g");o=o.replace(u,n);u=new RegExp("(%FULL_NAME%)","g");o=o.replace(u,r);u=new RegExp("(%NAME%)","g");o=o.replace(u,i);u=new RegExp("(%EXT%)","g");o=o.replace(u,s);return o};t.prototype.actions=function(){if(e(".tiSlideshowPlaceSliderActions").css("display")=="none"){e(".tiSlideshowPlaceSliderActions").show("fast")}else{e(".tiSlideshowPlaceSliderActions").hide(300)}};t.prototype.beforeOpen=function(){var t=e.proxy(this.options.beforeOpen,this.container);var n=t();if(n==0||n==false)return false;return true};t.prototype.onOpen=function(){var t=e.proxy(this.options.onOpen,this.container);var n=t();if(n==0||n==false)return false;return true};t.prototype.beforeClose=function(){var t=e.proxy(this.options.beforeClose,this.container);var n=t();if(n==0||n==false)return false;return true};t.prototype.onClose=function(){var t=e.proxy(this.options.onClose,this.container);var n=t();if(n==0||n==false)return false;return true};t.prototype.beforeSlide=function(t,n){var r=e.proxy(this.options.beforeSlide,this.container);var i=r(t,n);if(i==0||i==false)return false;return true};t.prototype.onSlide=function(t,n){var r=e.proxy(this.options.onSlide,this.container);var i=r(t,n);if(i==0||i==false)return false;return true};e.tiSlideshow={name:"tiSlideshow",author:"Emeric Kasbarian",version:"1.0.2",interfaces:[],options:{auto:false,mask:"#000",opacity:.9,closeButton:true,slideButtons:true,infiniteSlide:false,thumbnails:true,tactile:false,beginIndex:0,thumbnailName:"%PATH%%FULL_NAME%",actions:[],beforeOpen:function(){},onOpen:function(){},beforeClose:function(){},onClose:function(){},beforeSlide:function(){},onSlide:function(){}},tiSlideshow:function(n){var r=e.extend({},e.tiSlideshow.options,n);var i;return this.each(function(){if(typeof n=="string"){if(e(this).data("tiSlideshow")){i=e.tiSlideshow.interfaces[e(this).data("id")];if(n=="open")i.open();if(n=="close")i.close();if(n=="next")i.next();if(n=="previous")i.previous()}}else{if(e(this).data("tiSlideshow")){e.tiSlideshow.interfaces[e(this).data("id")].changeOptions(n);if(e.tiSlideshow.interfaces[e(this).data("id")].options.auto)e(this).tiSlideshow("open")}else{var s=e.tiSlideshow.interfaces.length;e(this).data("tiSlideshow",true);e(this).data("id",s);new t(e(this),r,s)}}})},retrieveOpenedTiSlideshow:function(){if(!e(".tiSlideshowExposeMask").length)return null;var t=e(".tiSlideshowExposeMask").attr("id");for(var n in e.tiSlideshow.interfaces){if(e.tiSlideshow.interfaces[n].maskId==t)return e.tiSlideshow.interfaces[n]}return null},adjustSize:function(){var t=e.tiSlideshow.retrieveOpenedTiSlideshow();if(!t)return;var n=e(window).height();var r=e(window).width();if(n-100>0)e(".tiSlideshowPlaceSlider").height(n-100);else e(".tiSlideshowPlaceSlider").height(0);e(".tiSlideshowPlaceSliderActions").height(e(".tiSlideshowPlaceSlider").height());var i=parseInt((e(".tiSlideshowPlaceSlider").height()-e(".tiSlideshowPlaceSliderPrevious").height())/2);var s=parseInt((e(".tiSlideshowPlaceSlider").height()-e(".tiSlideshowPlaceSliderNext").height())/2);e(".tiSlideshowPlaceSliderPrevious").css("top",i+"px");e(".tiSlideshowPlaceSliderNext").css("top",s+"px");if(e(".tiSlideshowPlaceControlThumbnailsScroll").data("jsp"))e(".tiSlideshowPlaceControlThumbnailsScroll").data("jsp").destroy();if(r-200>0){e(".tiSlideshowPlaceControlThumbnailsScroll").width(r-200)}else e(".tiSlideshowPlaceControlThumbnailsScroll").width(0);e(".tiSlideshowPlaceControlThumbnailsThumbnail").each(function(){var t=e(this).height();var n=e(this).width();if(e(this).find("img").data("originalHeight")&&e(this).find("img").data("originalWidth")){var r=e(this).find("img").data("originalHeight");var i=e(this).find("img").data("originalWidth");if(r>t||i>n){if(r>t){i=i*t/r;r=t}if(i>n){r=r*n/i;i=n}e(this).find("img").height(r);e(this).find("img").width(i);var s=parseInt((t-r)/2);if(s<0)s=0;e(this).find("img").css("margin-top",s+"px")}}});if(!e(".tiSlideshowPlaceControlThumbnailsScroll").data("jsp")){if(e.fn.jScrollPane)e(".tiSlideshowPlaceControlThumbnailsScroll").jScrollPane()}else{e(".tiSlideshowPlaceControlThumbnailsScroll").data("jsp").reinitialise()}var o=parseInt(e(".tiSlideshowPlaceSlider").height());var u=parseInt(e(".tiSlideshowPlaceSlider").width());var a=e(".tiSlideshowPlaceSliderPicture img");if(!a.data("originalHeight")||!a.data("originalWidth")){return}var f=parseInt(a.data("originalHeight"));var l=parseInt(a.data("originalWidth"));e(".tiSlideshowPlaceSliderPicture img").css("margin-top","0px");if(f>o||l>u){if(f>o){l=l*o/f;f=o}if(l>u){f=f*u/l;l=u}}e(".tiSlideshowPlaceSliderPicture img").height(f);e(".tiSlideshowPlaceSliderPicture img").width(l);var c=parseInt((o-f)/2);if(c<0)c=0;e(".tiSlideshowPlaceSliderPicture img").css("margin-top",c+"px")},preventTouchmove:function(e){e.preventDefault()}};e.fn.tiSlideshow=e.tiSlideshow.tiSlideshow;e(window).resize(e.tiSlideshow.adjustSize)})(jQuery)