/** * PgwSlider - Version 2.3 * * 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.pgwSlider=function(n){var g={mainClassName:"pgwSlider",listPosition:"right",selectionMode:"click",transitionEffect:"fading",autoSlide:true,displayList:true,displayControls:false,touchControls:true,verticalCentering:false,adaptiveHeight:false,maxHeight:null,beforeSlide:null,afterSlide:null,adaptiveDuration:200,transitionDuration:500,intervalDuration:3000};if(this.length==0){return this}else{if(this.length>1){this.each(function(){a(this).pgwSlider(n)});return this}}var l=this;l.plugin=this;l.data=[];l.config={};l.currentSlide=0;l.slideCount=0;l.resizeEvent=null;l.intervalEvent=null;l.touchFirstPosition=null;l.transitionInProgress=false;l.window=a(window);var m=function(){l.config=a.extend({},g,n);e();if(l.config.autoSlide){h()}return true};var b=function(p){var q={};var s=p.find("a").attr("href");if((typeof s!="undefined")&&(s!="")){q.link=s;var v=p.find("a").attr("target");if((typeof v!="undefined")&&(v!="")){q.linkTarget=v}}var o=p.find("img").attr("src");if((typeof o!="undefined")&&(o!="")){q.thumbnail=o}var w=p.find("img").attr("data-large-src");if((typeof w!="undefined")&&(w!="")){q.image=w}var t=p.find("span").text();if((typeof t!="undefined")&&(t!="")&&(t!=null)){q.title=t}else{var r=p.find("img").attr("alt");if((typeof r!="undefined")&&(r!="")){q.title=r}}var u=p.find("img").attr("data-description");if((typeof u!="undefined")&&(u!="")){q.description=u}return q};var f=function(o,p){if(l.config.maxHeight){if(l.plugin.width()>480&&o>l.config.maxHeight){o=l.config.maxHeight}else{if(l.plugin.width()<=480){if(o+l.plugin.find(".ps-list").height()>l.config.maxHeight){o=l.config.maxHeight-l.plugin.find(".ps-list").height()}}}}clearTimeout(l.resizeEvent);l.resizeEvent=setTimeout(function(){var q=((o-((l.slideCount-1)*6))/l.slideCount);var r=(100/l.slideCount);l.plugin.find(".ps-list > li").css({width:r+"%"});if(typeof p!="undefined"&&p&&l.config.maxHeight==null){if(typeof l.plugin.find(".ps-current").animate=="function"){l.plugin.find(".ps-current").animate({height:o},l.config.adaptiveDuration,function(){l.plugin.find(".ps-list > li").animate({height:q},l.config.adaptiveDuration)})}else{l.plugin.find(".ps-current").css("height",o);l.plugin.find(".ps-list > li").css("height",q)}}else{l.plugin.find(".ps-current").css("height",o);l.plugin.find(".ps-list > li").css("height",q)}if(l.config.verticalCentering){l.plugin.find(".ps-list > li").each(function(){if((q>50)&&(a(this).find("img").height()>q)){var s=Math.round((a(this).find("img").height()-q)/2);a(this).find("img").css("margin-top",-s)}else{if(a(this).find("img").height() ul > li").each(function(){var s=(a(this).css("display")=="none")?false:true;if(!s){a(this).show()}if(a(this).show().find("img").height()>o){var t=Math.round((a(this).find("img").height()-o)/2);a(this).find("img").css("margin-top",-t)}else{if(a(this).show().find("img").height()');l.plugin=l.plugin.parent();l.plugin.prepend('
    ');l.slideCount=l.plugin.find(".ps-list > li").length;if(l.slideCount==0){throw new Error("PgwSlider - No slider item has been found");return false}if(l.config.displayControls&&l.slideCount>1){l.plugin.find(".ps-current").prepend('');l.plugin.find(".ps-current").append('');l.plugin.find(".ps-current .ps-prev").click(function(){l.previousSlide()});l.plugin.find(".ps-current .ps-next").click(function(){l.nextSlide()})}if(!l.config.displayList){l.plugin.find(".ps-current").css("width","100%");l.plugin.find(".ps-list").hide()}var o=1;l.plugin.find(".ps-list > li").each(function(){var q=b(a(this));q.id=o;l.data.push(q);a(this).addClass("elt_"+q.id);if(q.title){if(a(this).find("span").length==1){if(a(this).find("span").text()==""){a(this).find("span").text(q.title)}}else{a(this).find("img").after(""+q.title+"")}}var p=a('
  • ');if(q.image){p.html(''+(q.title?q.title:')}else{if(q.thumbnail){p.html(''+(q.title?q.title:')}}if(q.link){p.html('"+p.html()+"")}l.plugin.find(".ps-current > ul").append(p);if((l.config.selectionMode=="mouseOver")&&(l.config.transitionEffect=="fading")){a(this).css("cursor","default").click(function(r){r.preventDefault()}).bind("mouseenter",function(r){i(q.id)});a(this).find("a").css("cursor","default")}else{a(this).css("cursor","pointer").click(function(r){r.preventDefault();i(q.id)})}o++});if(l.config.listPosition=="left"){l.plugin.addClass("listOnTheLeft")}if(l.config.autoSlide){l.plugin.on("mouseenter",function(){clearInterval(l.intervalEvent);l.intervalEvent=null}).on("mouseleave",function(){h()})}i(1);l.plugin.find(".ps-current > ul > li.elt_1 img").on("load",function(){c();var p=l.plugin.find(".ps-current > ul > li.elt_1 img").height();f(p);l.window.resize(function(){c();var q=l.plugin.find(".ps-current > ul > li.elt_"+l.currentSlide+" img").height();f(q,l.config.adaptiveHeight)})});if(l.config.touchControls&&l.slideCount>1){l.plugin.find(".ps-current").on("touchstart",function(p){try{if(p.originalEvent.touches[0].clientX&&l.touchFirstPosition==null){l.touchFirstPosition=p.originalEvent.touches[0].clientX}}catch(p){l.touchFirstPosition=null}});l.plugin.find(".ps-current").on("touchmove",function(p){try{if(p.originalEvent.touches[0].clientX&&l.touchFirstPosition!=null){if(p.originalEvent.touches[0].clientX>(l.touchFirstPosition+50)){l.touchFirstPosition=null;l.previousSlide()}else{if(p.originalEvent.touches[0].clientX<(l.touchFirstPosition-50)){l.touchFirstPosition=null;l.nextSlide()}}}}catch(p){l.touchFirstPosition=null}});l.plugin.find(".ps-current").on("touchend",function(p){l.touchFirstPosition=null})}return true};var j=function(o){var q="";if(o.title){q+=""+o.title+""}if(o.description){if(q!=""){q+="
    "}q+=o.description}if(q!=""){if(o.link){q='"+q+""}if(typeof l.plugin.find(".ps-caption").fadeIn=="function"){l.plugin.find(".ps-caption").html(q);l.plugin.find(".ps-caption").fadeIn(l.config.transitionDuration/2)}else{l.plugin.find(".ps-caption").html(q);l.plugin.find(".ps-caption").show()}}if(l.config.displayControls){if(typeof l.plugin.find(".ps-current > .ps-prev").fadeIn=="function"){l.plugin.find(".ps-current > .ps-prev, .ps-current > .ps-next").fadeIn(l.config.transitionDuration/2)}else{l.plugin.find(".ps-current > .ps-prev, .ps-current > .ps-next").show()}}if(typeof l.config.afterSlide=="function"){l.config.afterSlide(o.id)}if(l.config.adaptiveHeight){var p=l.plugin.find(".ps-current .elt_"+o.id+" img").height();f(p,true)}return true};var d=function(r){var q=l.plugin.find(".ps-current > ul");l.plugin.find(".ps-list > li").css("opacity","0.6");l.plugin.find(".ps-list > li.elt_"+r.id).css("opacity","1");q.find("li").not(".elt_"+l.currentSlide).not(".elt_"+r.id).each(function(){if(typeof a(this).stop=="function"){a(this).stop()}a(this).css("position","").css("z-index",1).hide()});if(l.currentSlide>0){var o=q.find(".elt_"+l.currentSlide);if(typeof o.animate!="function"){o.animate=function(s,t,u){o.css(s);if(u){u()}}}if(typeof o.stop=="function"){o.stop()}o.css("position","absolute").animate({opacity:0},l.config.transitionDuration,function(){o.css("position","").css("z-index",1).hide()})}l.currentSlide=r.id;var p=q.find(".elt_"+r.id);if(typeof p.animate!="function"){p.animate=function(s,t,u){p.css(s);if(u){u()}}}if(typeof p.stop=="function"){p.stop()}p.css("position","absolute").show().animate({opacity:1},l.config.transitionDuration,function(){p.css("position","").css("z-index",2).show();j(r)});return true};var k=function(s,v){var r=l.plugin.find(".ps-current > ul");if(typeof v=="undefined"){v="left"}if(l.currentSlide==0){r.find(".elt_1").css({position:"",left:"",opacity:1,"z-index":2}).show();l.plugin.find(".ps-list > li.elt_1").css("opacity","1");j(s)}else{if(l.transitionInProgress){return false}l.transitionInProgress=true;var u=r.width();if(v=="left"){var o=-u;var t=u}else{var o=u;var t=-u}var p=r.find(".elt_"+l.currentSlide);if(typeof p.animate!="function"){p.animate=function(w,x,y){p.css(w);if(y){y()}}}p.css("position","absolute").animate({left:o},l.config.transitionDuration,function(){p.css("position","").css("z-index",1).css("left","").css("opacity",0).hide()});var q=r.find(".elt_"+s.id);if(typeof q.animate!="function"){q.animate=function(w,x,y){q.css(w);if(y){y()}}}q.css("position","absolute").css("left",t).css("opacity",1).show().animate({left:0},l.config.transitionDuration,function(){q.css("position","").css("left","").css("z-index",2).show();l.transitionInProgress=false;l.plugin.find(".ps-list > li").css("opacity","0.6");l.plugin.find(".ps-list > li.elt_"+s.id).css("opacity","1");j(s)})}l.currentSlide=s.id;return true};var i=function(o,q,r){if(o==l.currentSlide){return false}var p=l.data[o-1];if(typeof p=="undefined"){throw new Error("PgwSlider - The element "+o+" is undefined");return false}if(typeof r=="undefined"){r="left"}if(typeof l.config.beforeSlide=="function"){l.config.beforeSlide(o)}if(typeof l.plugin.find(".ps-caption").fadeOut=="function"){l.plugin.find(".ps-caption, .ps-prev, .ps-next").fadeOut(l.config.transitionDuration/2)}else{l.plugin.find(".ps-caption, .ps-prev, .ps-next").hide()}if(l.config.transitionEffect=="sliding"){k(p,r)}else{d(p)}if(typeof q!="undefined"&&l.config.autoSlide){h()}return true};var h=function(){clearInterval(l.intervalEvent);if(l.slideCount>1&&l.config.autoSlide){l.intervalEvent=setInterval(function(){if(l.currentSlide+1<=l.slideCount){var o=l.currentSlide+1}else{var o=1}i(o)},l.config.intervalDuration)}return true};l.startSlide=function(){l.config.autoSlide=true;h();return true};l.stopSlide=function(){l.config.autoSlide=false;clearInterval(l.intervalEvent);return true};l.getCurrentSlide=function(){return l.currentSlide};l.getSlideCount=function(){return l.slideCount};l.displaySlide=function(o){i(o,true);return true};l.nextSlide=function(){if(l.currentSlide+1<=l.slideCount){var o=l.currentSlide+1}else{var o=1}i(o,true,"left");return true};l.previousSlide=function(){if(l.currentSlide-1>=1){var o=l.currentSlide-1}else{var o=l.slideCount}i(o,true,"right");return true};l.destroy=function(o){clearInterval(l.intervalEvent);if(typeof o!="undefined"){l.plugin.find(".ps-list > li").each(function(){a(this).attr("style",null).removeClass().css("cursor","").unbind("click").unbind("mouseenter");a(this).find("a").css("cursor","");a(this).find("img").attr("style",null)});l.plugin.find(".ps-list").addClass(l.config.mainClassName).removeClass("ps-list");l.plugin.find(".ps-current").unwrap().remove();l.hide()}else{l.parent().remove()}l.plugin=null;l.data=[];l.config={};l.currentSlide=0;l.slideCount=0;l.resizeEvent=null;l.intervalEvent=null;l.touchFirstPosition=null;l.transitionInProgress=false;l.window=null;return true};l.reload=function(o){l.destroy(true);l=this;l.plugin=this;l.window=a(window);l.plugin.show();l.config=a.extend({},g,o);e();if(l.config.autoSlide){h()}return true};m();return this}})(window.Zepto||window.jQuery);