/** * 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()<=640){j.plugin.addclass("pgw-narrow").removeclass("pgw-wide")}else{j.plugin.addclass("pgw-wide").removeclass("pgw-narrow")}return true};var g=function(){j.plugin.removeclass("pgwslideshow").removeclass(j.config.mainclassname);j.plugin.wrap('
');j.plugin=j.plugin.parent();j.plugin.wrap('
');j.plugin=j.plugin.parent();j.plugin.prepend('
');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('');j.plugin.find(".ps-current").append('');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('');var s=a('
  • ');if(t.image){s.html(''+(t.title?t.title:')}else{if(t.thumbnail){s.html(''+(t.title?t.title:')}}if(t.link){s.html('"+s.html()+"")}j.plugin.find(".ps-current > ul").append(s);a(this).css("cursor","pointer").click(function(u){u.preventdefault();l(t.id)});r++});if(j.config.displaylist){c();j.plugin.find(".ps-list").prepend('');j.plugin.find(".ps-list").append('');j.plugin.find(".ps-list").show()}else{j.plugin.find(".ps-list").hide()}if(j.config.autoslide){j.plugin.on("mouseenter",function(){clearinterval(j.intervalevent);j.intervalevent=null}).on("mouseleave",function(){k()})}j.plugin.find(".ps-current > ul > li").hide();l(1);j.plugin.find(".ps-current > ul > li.elt_1 img").on("load",function(){e();var s=j.plugin.find(".ps-current > ul > li.elt_1 img").height();h(s)});e();j.plugin.show();return true};var d=function(x){var v={};var t=x.find("a").attr("href");if((typeof t!="undefined")&&(t!="")){v.link=t;var u=x.find("a").attr("target");if((typeof u!="undefined")&&(u!="")){v.linktarget=u}}var s=x.find("img").attr("src");if((typeof s!="undefined")&&(s!="")){v.thumbnail=s}var y=x.find("img").attr("data-large-src");if((typeof y!="undefined")&&(y!="")){v.image=y}var r=x.find("img").attr("alt");if((typeof r!="undefined")&&(r!="")){v.title=r}var w=x.find("img").attr("data-description");if((typeof w!="undefined")&&(w!="")){v.description=w}return v};var m=function(r){var t="";if(r.title){t+="

    "+r.title+"

    "}if(r.description){if(t!="")t+="

    "+r.description+"

    "}if(t!=""){if(r.link){t='"+t+""}if(typeof j.plugin.find(".ps-caption").fadein=="function"){j.plugin.find(".ps-caption").html(t);j.plugin.find(".ps-caption").fadein(j.config.transitionduration/2)}else{j.plugin.find(".ps-caption").html(t);j.plugin.find(".ps-caption").show()}}j.plugin.find(".ps-list > ul > li .ps-item").removeclass("ps-selected");j.plugin.find(".ps-list > ul > li.elt_"+r.id+" .ps-item").addclass("ps-selected");if(j.config.displaylist){b();n()}if(j.config.displaycontrols){if(typeof j.plugin.find(".ps-current > .ps-prev").fadein=="function"){j.plugin.find(".ps-current > .ps-prev, .ps-current > .ps-next").fadein(j.config.transitionduration/2)}else{j.plugin.find(".ps-current > .ps-prev, .ps-current > .ps-next").show()}}if(typeof j.config.afterslide=="function"){j.config.afterslide(r.id)}var s=j.plugin.find(".ps-current .elt_"+r.id+" img").height();h(s,true);return true};var f=function(u){var t=j.plugin.find(".ps-current > ul");t.find("li").not(".elt_"+j.currentslide).not(".elt_"+u.id).each(function(){if(typeof a(this).stop=="function"){a(this).stop()}a(this).css("position","").css("z-index",1).hide()});if(j.currentslide>0){var r=t.find(".elt_"+j.currentslide);if(typeof r.animate!="function"){r.animate=function(v,w,x){r.css(v);if(x){x()}}}if(typeof r.stop=="function"){r.stop()}r.css("position","absolute").animate({opacity:0},j.config.transitionduration,function(){r.css("position","").css("z-index",1).hide()})}j.currentslide=u.id;var s=t.find(".elt_"+u.id);if(typeof s.animate!="function"){s.animate=function(v,w,x){s.css(v);if(x){x()}}}if(typeof s.stop=="function"){s.stop()}s.css("position","absolute").show().animate({opacity:1},j.config.transitionduration,function(){s.css("position","").css("z-index",2).css("display","block");m(u)});return true};var o=function(v,y){var u=j.plugin.find(".ps-current > ul");if(typeof y=="undefined"){y="left"}if(j.currentslide==0){u.find(".elt_1").css({position:"",left:"",opacity:1,"z-index":2}).show();j.plugin.find(".ps-list > li.elt_1").css("opacity","1");m(v)}else{if(j.transitioninprogress){return false}j.transitioninprogress=true;var x=u.width();if(y=="left"){var r=-x;var w=x}else{var r=x;var w=-x}var s=u.find(".elt_"+j.currentslide);if(typeof s.animate!="function"){s.animate=function(z,a,b){s.css(z);if(b){b()}}}s.css("position","absolute").animate({left:r},j.config.transitionduration,function(){s.css("position","").css("z-index",1).css("left","").css("opacity",0).hide()});var t=u.find(".elt_"+v.id);if(typeof t.animate!="function"){t.animate=function(z,a,b){t.css(z);if(b){b()}}}t.css("position","absolute").css("left",w).css("opacity",1).show().animate({left:0},j.config.transitionduration,function(){t.css("position","").css("left","").css("z-index",2).show();j.transitioninprogress=false;m(v)})}j.currentslide=v.id;return true};var l=function(r,t,u){if(r==j.currentslide){return false}var s=j.data[r-1];if(typeof s=="undefined"){throw new error("pgwslideshow - the element "+r+" is undefined");return false}if(typeof u=="undefined"){u="left"}if(typeof j.config.beforeslide=="function"){j.config.beforeslide(r)}if(typeof j.plugin.find(".ps-caption").fadeout=="function"){j.plugin.find(".ps-caption, .ps-prev, .ps-next").fadeout(j.config.transitionduration/2)}else{j.plugin.find(".ps-caption, .ps-prev, .ps-next").hide()}if(j.config.transitioneffect=="sliding"){o(s,u)}else{f(s)}if(typeof t!="undefined"&&j.config.autoslide){k()}return true};var k=function(){clearinterval(j.intervalevent);if(j.slidecount>1&&j.config.autoslide){j.intervalevent=setinterval(function(){if(j.currentslide+1<=j.slidecount){var r=j.currentslide+1}else{var r=1}l(r)},j.config.intervalduration)}return true};var b=function(){if(!j.config.displaylist){return false}c();var w=j.plugin.find(".ps-list");var u=w.width();var r=j.plugin.find(".ps-list > ul");var v=r.width();if(v>u){/*r.css("margin","0 45px");*/var t=parseint(r.css("margin-left"));var s=parseint(r.css("margin-right"));u-=(t+s);w.find(".ps-prev").show().unbind("click").click(function(){var y=parseint(r.css("left"));var x=y+u;if(y==0){x=-(v-u)}else{if(x>0){x=0}}if(typeof r.animate=="function"){r.animate({left:x},j.config.transitionduration)}else{r.css("left",x)}});w.find(".ps-next").show().unbind("click").click(function(){var y=parseint(r.css("left"));var x=y-u;var z=-(v-u);if(y==z){x=0}else{if(x ul").on("touchmove",function(c){try{if(c.originalevent.touches[0].clientx){var g=(j.touchlistlastposition==false?0:j.touchlistlastposition);nbpixels=(j.touchlistlastposition==false?1:math.abs(g-c.originalevent.touches[0].clientx));j.touchlistlastposition=c.originalevent.touches[0].clientx;var x="";if(g>c.originalevent.touches[0].clientx){x="left"}else{if(ga){r.css("left",y)}}else{if(x=="right"){var y=f+nbpixels;if(y<0){r.css("left",y)}else{r.css("left",0)}}}}catch(c){j.touchlistlastposition=false}});j.plugin.find(".ps-list > ul").on("touchend",function(x){j.touchlistlastposition=false})}}else{var t=parseint((u-v)/2);r.css("left",0);w.find(".ps-prev").hide();w.find(".ps-next").hide();j.plugin.find(".ps-list > ul").unbind("touchstart touchmove touchend")}return true};var n=function(){var a=j.plugin.find(".ps-list").width();var y=j.plugin.find(".ps-list > ul");var z=y.width();var t=parseint(y.css("margin-left"));var x=parseint(y.css("margin-right"));a-=(t+x);var w=math.abs(parseint(y.css("left")));var r=w+a;var u=j.plugin.find(".ps-list .ps-selected").position().left;var s=u+j.plugin.find(".ps-list .ps-selected").width();if((ur)||(z>a&&r>s)){var v=-(z-a);if(-u=1){var r=j.currentslide-1}else{var r=j.slidecount}l(r,true,"right");return true};j.destroy=function(r){clearinterval(j.intervalevent);if(typeof r!="undefined"){j.plugin.find(".ps-list > ul > li").each(function(){a(this).attr("style",null).removeclass().unbind("click");a(this).html(a(this).find("span").html())});j.plugin.find(".ps-current").remove();j.plugin.find(".ps-list").find(".ps-prev, .ps-next").remove();j.plugin.find(".ps-list > ul").addclass(j.config.mainclassname).attr("style","");j.plugin.find(".ps-list > ul").unwrap().unwrap();j.hide()}else{j.parent().parent().remove()}j.plugin=null;j.data=[];j.config={};j.currentslide=0;j.slidecount=0;j.resizeevent=null;j.intervalevent=null;j.touchfirstposition=null;j.window=null;return true};j.reload=function(r){j.destroy(true);j=this;j.plugin=this;j.window=a(window);j.plugin.show();j.config=a.extend({},i,r);g();j.window.resize(function(){cleartimeout(j.resizeevent);j.resizeevent=settimeout(function(){e();var s=j.plugin.find(".ps-current > ul > li.elt_"+j.currentslide+" img").css("max-height","").height();h(s);if(j.config.displaylist){b();n()}},100)});if(j.config.autoslide){k()}return true};p();return this}})(window.zepto||window.jquery);