You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
10 lines
13 KiB
JavaScript
10 lines
13 KiB
JavaScript
2 weeks ago
|
/**
|
||
|
* PgwSlideshow - Version 2.0
|
||
|
*
|
||
|
* Copyright 2014, Jonathan M. Piat
|
||
|
* http://pgwjs.com - http://pagawa.com
|
||
|
*
|
||
|
* Released under the GNU GPLv3 license - http://opensource.org/licenses/gpl-3.0
|
||
|
*/
|
||
|
(function(a){a.fn.pgwSlideshow=function(q){var i={mainClassName:"pgwSlideshow",transitionEffect:"sliding",displayList:true,displayControls:true,touchControls:true,autoSlide:false,beforeSlide:false,afterSlide:false,maxHeight:null,adaptiveDuration:200,transitionDuration:500,intervalDuration:3000};if(this.length==0){return this}else{if(this.length>1){this.each(function(){a(this).pgwSlideshow(q)});return this}}var j=this;j.plugin=this;j.config={};j.data=[];j.currentSlide=0;j.slideCount=0;j.resizeEvent=null;j.intervalEvent=null;j.touchFirstPosition=null;j.touchListLastPosition=false;j.window=a(window);var p=function(){j.config=a.extend({},i,q);g();if(j.config.displayList){b()}j.window.resize(function(){clearTimeout(j.resizeEvent);j.resizeEvent=setTimeout(function(){e();var r=j.plugin.find(".ps-current > ul > li.elt_"+j.currentSlide+" img").height();h(r);if(j.config.displayList){b();n()}},100)});if(j.config.autoSlide){k()}return true};var h=function(r,s){if(j.config.maxHeight){if(r+j.plugin.find(".ps-list").height()>j.config.maxHeight){r=j.config.maxHeight-j.plugin.find(".ps-list").height()}}if(typeof j.plugin.find(".ps-current").animate=="function"){j.plugin.find(".ps-current").stop().animate({height:r},j.config.adaptiveDuration,function(){if(j.config.maxHeight){j.plugin.find(".ps-current > ul > li img").css("max-height",r+"px")}})}else{j.plugin.find(".ps-current").css("height",r);if(j.config.maxHeight){j.plugin.find(".ps-current > ul > li img").css("max-height",r+"px")}}return true};var c=function(){var r=0;j.plugin.show();j.plugin.find(".ps-list > ul > li").show().each(function(){r+=a(this).width()});j.plugin.find(".ps-list > ul").width(r);return true};var e=function(){if(j.plugin.width()<=480){j.plugin.addClass("narrow").removeClass("wide")}else{j.plugin.addClass("wide").removeClass("narrow")}return true};var g=function(){j.plugin.removeClass("pgwSlideshow").removeClass(j.config.mainClassName);j.plugin.wrap('<div class="ps-list"></div>');j.plugin=j.plugin.parent();j.plugin.wrap('<div class="'+j.config.mainClassName+'"></div>');j.plugin=j.plugin.parent();j.plugin.prepend('<div class="ps-current"><ul></ul><span class="ps-caption"></span></div>');j.slideCount=j.plugin.find(".ps-list > ul > li").length;if(j.slideCount==0){throw new Error("pgwSlideshow - No slider item has been found");return false}if(j.slideCount>1){if(j.config.displayControls){j.plugin.find(".ps-current").prepend('<span class="ps-prev"><span class="ps-prevIcon"></span></span>');j.plugin.find(".ps-current").append('<span class="ps-next"><span class="ps-nextIcon"></span></span>');j.plugin.find(".ps-current .ps-prev").click(function(){j.previousSlide()});j.plugin.find(".ps-current .ps-next").click(function(){j.nextSlide()})}if(j.config.touchControls){j.plugin.find(".ps-current").on("touchstart",function(s){try{if(s.originalEvent.touches[0].clientX&&j.touchFirstPosition==null){j.touchFirstPosition=s.originalEvent.touches[0].clientX}}catch(s){j.touchFirstPosition=null}});j.plugin.find(".ps-current").on("touchmove",function(s){try{if(s.originalEvent.touches[0].clientX&&j.touchFirstPosition!=null){if(s.originalEvent.touches[0].clientX>(j.touchFirstPosition+50)){j.touchFirstPosition=null;j.previousSlide()}else{if(s.originalEvent.touches[0].clientX<(j.touchFirstPosition-50)){j.touchFirstPosition=null;j.nextSlide()}}}}catch(s){j.touchFirstPosition=null}});j.plugin.find(".ps-current").on("touchend",function(s){j.touchFirstPosition=null})}}var r=1;j.plugin.find(".ps-list > ul > li").each(function(){var t=d(a(this));t.id=r;j.data.push(t);a(this).addClass("elt_"+t.id);a(this).wrapInner('<span class="ps-item'+(r==1?" ps-selected":"")+'"></span>');var s=a('<li class="elt_'+r+'"></li>');if(t.image){s.html('<img src="'+t.image+'" alt="'+(t.title?t.title:"")+'">')}else{if(t.thumbnail){s.html('<img src="'+t.thumbnail+'" alt="'+(t.title?t.title:"")+'">')}}if(t.link){s.html('<a href="'+t.link+'"'+(t.linkTarget?' target="'+t.linkTarget+'"':"")+">"+s.html()+"</a>")}j.plugin.find(".ps-current > ul").append(s);a(this).css("cursor","pointer").click(function(u){u.preventDefault();l(t.i
|