diff --git a/dist/js/jquery.desoslide.js b/dist/js/jquery.desoslide.js index e22b08b..bff4396 100644 --- a/dist/js/jquery.desoslide.js +++ b/dist/js/jquery.desoslide.js @@ -168,11 +168,6 @@ */ app.loadImages(); - /** - * Handling transition effect - */ - app.effectHandler(); - /** * Adding wraper */ @@ -238,7 +233,13 @@ * Function that handles the effect */ effectHandler: function() { - if(p.effect !== 'random') { + if(p.effect === 'random') { + /** + * Get a random effect + */ + current_effect = app.getRandomEffect(); + console.log($(p.main.container).selector +': '+ current_effect); + } else { /** * Incorrect effect value */ @@ -252,13 +253,7 @@ } else { current_effect = p.effect; } - } else { - /** - * Get a random effect - */ - current_effect = app.getRandomEffect(); } - console.log(current_effect); }, /** @@ -267,7 +262,7 @@ getRandomEffect: function() { var result, count = 0; - for(var prop in effects) { + for(var prop in app.effects) { if(Math.random() < 1 / ++count) { result = prop; } @@ -385,7 +380,7 @@ /** * Data */ - var src = $thumbs.find('a').eq(img_to_show).attr('href'); + var src = $thumbs.find('a').eq(img_to_show).attr('href'); alt = $thumbs.find('img').eq(img_to_show).attr('alt'); caption = $thumbs.find('img').eq(img_to_show).data('desoslide-caption'); href = $thumbs.find('img').eq(img_to_show).data('desoslide-href'); @@ -395,6 +390,11 @@ */ app.checkData(); + /** + * Handling transition effect + */ + app.effectHandler(); + $(p.main.container).find('img').attr({ 'src': src, 'alt': alt, @@ -412,7 +412,7 @@ * Adding overlay */ app.addOverlay(); - }); + }); /** * Starting the loop diff --git a/dist/js/jquery.desoslide.min.js b/dist/js/jquery.desoslide.min.js index 9dfc7b5..b0512c2 100644 --- a/dist/js/jquery.desoslide.min.js +++ b/dist/js/jquery.desoslide.min.js @@ -1,7 +1 @@ -/*! -* Version 1.2.3.1 -* jQuery: desoSlide plugin - jquery.desoslide.js -* Copyright - 2013 - https://github.com/sylouuu/desoslide -* This source code is under the MIT License -*/ -!function(e){"use strict";e.fn.desoSlide=function(n){var a,t,i,o,r,s,d,l={main:{container:!1,cssClass:"",insertion:"append"},auto:{load:!0,start:!1},first:0,interval:3e3,effect:"fade",overlay:"always",caption:!1,controls:{enable:!0,keys:!0},events:{thumbClick:!1,prev:!1,pause:!1,play:!1,next:!1,completed:!1}},c=e.extend(!0,{},l,n),p=function(){var e=0;return function(n,a){clearTimeout(e),e=setTimeout(n,a)}}(),f=this,u=f.find("li"),m=u.length,h=c.first,v=e(c.main.container).find(".desoSlide-overlay"),g=c.interval<1500?1500:c.interval,y=!1,w=!1,k={checks:function(){f.length||k.resultHandler("error",f.selector+" doesn't exist."),c.main.container?e(c.main.container).length||k.resultHandler("error",e(c.main.container).selector+" doesn't exist."):k.resultHandler("error",'You must specify the "main.container" option. Check out the documentation.');var n=["always","hover","none"];-1===n.indexOf(c.overlay)&&k.resultHandler("error",'Incorrect value for the "overlay" option. Check out the documentation.'),h>=m&&(0===m?k.resultHandler("error","You must have at least 1 thumbnail."):k.resultHandler("error",'The "first" option must be between 0 and '+(m-1)+"."))},checkData:function(){!c.caption||void 0!==i&&""!==i||k.resultHandler("warning","The captions are enabled and the data-desoslide-caption attribute is missing on a thumb. Add it or disable captions. Check out the documention."),(void 0===t||""===t)&&k.resultHandler("warning","The alt attribute is missing on a thumb, it's mandatory on tags.")},init:function(){k.checks(),k.loadImages(),k.effectHandler(),k.addWrapper(),k.displayImg(),k.events()},loadImages:function(){c.auto.load&&u.find("a").each(function(n,a){e("",{src:a.href,alt:""}).hide().appendTo("body")})},effectHandler:function(){s={fade:{"in":"fadeIn",out:"fadeOut"},sideFade:{"in":"fadeInLeft",out:"fadeOutRight"},sideFadeBig:{"in":"fadeInLeftBig",out:"fadeOutRightBig"},flip:{"in":"flipInX",out:"flipOutX"},light:{"in":"lightSpeedIn",out:"lightSpeedOut"},roll:{"in":"rollIn",out:"rollOut"},rotate:{"in":"rotateIn",out:"rotateOut"}},s.hasOwnProperty(c.effect)||(c.effect=l.effect,k.resultHandler("error",'Incorrect value for the "effect" option. Default value is used. Check out the documentation.'))},outEffect:function(){e(c.main.container).find("img").removeClass("animated "+s[c.effect].in).addClass("animated "+s[c.effect].out),setTimeout(function(){k.displayImg()},900)},addWrapper:function(){var n=e("
",{"class":"desoSlide-wrapper"}),a=e("").addClass(c.main.cssClass).css("opacity",0);switch(c.main.insertion){case"prepend":a.prependTo(e(c.main.container)).wrap(n);break;case"append":a.appendTo(e(c.main.container)).wrap(n);break;case"replace":e(c.main.container).html(a).wrapInner(n);break;default:k.resultHandler("error",'Incorrect value for the "insertion" option. Check out the documentation.')}},addSpinner:function(){d=e("
").addClass("desoSlide-spinner"),e(c.main.container).css("text-align","center").prepend(d)},removeSpinner:function(){d.length&&d.remove()},displayImg:function(){k.resultHandler(),a=0,0>h&&(h=m-1),h>=m&&(h=0),a=h;var n=u.find("a").eq(a).attr("href");t=u.find("img").eq(a).attr("alt"),i=u.find("img").eq(a).data("desoslide-caption"),o=u.find("img").eq(a).data("desoslide-href"),k.checkData(),e(c.main.container).find("img").attr({src:n,alt:t,"data-desoslide-caption":i}).one("load",function(){e(this).removeClass("animated "+s[c.effect].out).addClass("animated "+s[c.effect].in).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){k.addOverlay()}),c.auto.start&&(h++,y=setTimeout(function(){k.outEffect()},g))})},addOverlay:function(){if("none"!==c.overlay){if(c.caption||c.controls.enable){var n=e(c.main.container).find("img").position(),a=parseInt(e(c.main.container).find("img").css("border-left-width"),10),t=e(c.main.container).find("img").width()+a,i=e(c.main.container).find("img").height()+a;0===e(c.main.container).find(".desoSlide-overlay").length&&e("
",{"class":"desoSlide-overlay"}).appendTo(e(c.main.container).find(".desoSlide-wrapper")),v=e(c.main.container).find(".desoSlide-overlay");var o=parseInt(v.css("padding-top").replace("px",""),10),r=parseInt(v.css("padding-bottom").replace("px",""),10),s=parseInt(v.css("padding-left").replace("px",""),10),d=parseInt(v.css("padding-right").replace("px",""),10),l=parseInt(v.css("height").replace("px",""),10)-(s+d);l=parseInt(i,10)-l-(o+r);var p=n.top+l,f=n.left;v.css({left:f+"px",top:p+"px",width:t+"px"}),"always"===c.overlay&&v.animate({opacity:.7},500),c.caption&&(k.updateCaption(),k.addLink())}else k.addLink();c.controls.enable&&k.addControls()}},updateCaption:function(){v.html(i)},addLink:function(){var n=e(c.main.container).find("a.desoslide-link").length>0?!0:!1,a=void 0!==o&&""!==o?!0:!1,t=e("",{"class":"desoslide-link",href:o,target:"_blank"});n&&a?e(c.main.container).find("a.desoslide-link").attr("href",o):n&&!a?e(c.main.container).find("a.desoslide-link").replaceWith(t):!n&&a&&e(c.main.container).find(".desoSlide-wrapper").append(t)},addControls:function(){e(c.main.container).find(".desoSlide-controls-wrapper").remove();var n='',a='',t='',i='',o=e("
",{"class":"desoSlide-controls-wrapper"}).append(n+a+t+i);o.css({width:v.css("width"),left:v.css("left")}),e(c.main.container).find("a.desoslide-link").length>0?o.appendTo(e(c.main.container).find("a.desoslide-link")):o.appendTo(e(c.main.container).find(".desoSlide-wrapper")),r=e(c.main.container).find(".desoSlide-controls-wrapper"),r.length&&(c.auto.start?r.find('a[href="#play"]').hide().parent().find('a[href="#pause"]').show():r.find('a[href="#pause"]').hide().parent().find('a[href="#play"]').show())},pause:function(){c.auto.start&&y&&(c.auto.start=!1,clearTimeout(y),h--,r&&r.find('a[href="#pause"]').hide().parent().find('a[href="#play"]').show())},play:function(){c.auto.start||(c.auto.start=!0,a===h&&h++,k.outEffect(),r&&r.find('a[href="#play"]').hide().parent().find('a[href="#pause"]').show())},resultHandler:function(e,n){if(!w)switch(e){case"error":void 0!==console&&console.error("desoSlide: "+n),c.events.completed&&c.events.completed("error"),w=e;break;case"warning":void 0!==console&&console.warn("desoSlide: "+n),c.events.completed&&c.events.completed("warning");break;default:c.events.completed&&c.events.completed("success")}},events:function(){u.find("a").on("click",function(n){n.preventDefault();var a=e(this),t=a.parent("li").index();t!==h&&(v.animate({opacity:0}),h=t,k.outEffect(),k.pause()),c.events.thumbClick&&c.events.thumbClick()}),u.find("img").on({mouseover:function(){e(this).stop(!0,!0).animate({opacity:.7},"normal")},mouseout:function(){e(this).stop(!0,!0).animate({opacity:1},"fast")}}),"hover"===c.overlay&&e(c.main.container).on({mouseover:function(){v.stop().animate({opacity:.7},400)},mouseleave:function(){v.stop().animate({opacity:0},400)}}),c.controls.enable&&c.controls.keys&&e(document).on("keydown",function(n){switch(n.which){case 37:e(c.main.container).trigger("prev.desoslide");break;case 39:e(c.main.container).trigger("next.desoslide");break;case 32:n.preventDefault(),e(c.main.container).trigger(c.auto.start?"pause.desoslide":"play")}}),e(c.main.container).on("click",".desoSlide-controls-wrapper a",e(c.main.container),function(n){switch(n.preventDefault(),e(this).attr("href")){case"#prev":e(c.main.container).trigger("prev.desoslide");break;case"#pause":e(c.main.container).trigger("pause.desoslide");break;case"#play":e(c.main.container).trigger("play.desoslide");break;case"#next":e(c.main.container).trigger("next.desoslide")}}),e(c.main.container).on("prev.desoslide",function(){k.pause(),h--,k.outEffect(),c.events.prev&&c.events.prev()}),e(c.main.container).on("pause.desoslide",function(){k.pause(),c.events.pause&&c.events.pause()}),e(c.main.container).on("play.desoslide",function(){k.play(),c.events.play&&c.events.play()}),e(c.main.container).on("next.desoslide",function(){k.pause(),h++,k.outEffect(),c.events.next&&c.events.next()}),"none"!==c.overlay&&e(window).bind("resize",function(){p(function(){k.addOverlay()},100)})}};return k.addSpinner(),e(window).load(function(){k.removeSpinner(),k.init()}),this}}(jQuery); \ No newline at end of file +!function(e){"use strict";e.fn.desoSlide=function(n){var a,t,i,o,r,s,d,c={main:{container:!1,cssClass:"",insertion:"append"},auto:{load:!0,start:!1},first:0,interval:3e3,effect:"fade",overlay:"always",caption:!1,controls:{enable:!0,keys:!0},events:{thumbClick:!1,prev:!1,pause:!1,play:!1,next:!1,completed:!1}},l=e.extend(!0,{},c,n),p=function(){var e=0;return function(n,a){clearTimeout(e),e=setTimeout(n,a)}}(),f=this,u=f.find("li"),m=u.length,h=l.first,v=e(l.main.container).find(".desoSlide-overlay"),g=l.interval<1500?1500:l.interval,y=!1,w=!1,k={checks:function(){f.length||k.resultHandler("error",f.selector+" doesn't exist."),l.main.container?e(l.main.container).length||k.resultHandler("error",e(l.main.container).selector+" doesn't exist."):k.resultHandler("error",'You must specify the "main.container" option. Check out the documentation.');var n=["always","hover","none"];-1===n.indexOf(l.overlay)&&k.resultHandler("error",'Incorrect value for the "overlay" option. Check out the documentation.'),h>=m&&(0===m?k.resultHandler("error","You must have at least 1 thumbnail."):k.resultHandler("error",'The "first" option must be between 0 and '+(m-1)+"."))},checkData:function(){!l.caption||void 0!==i&&""!==i||k.resultHandler("warning","The captions are enabled and the data-desoslide-caption attribute is missing on a thumb. Add it or disable captions. Check out the documention."),(void 0===t||""===t)&&k.resultHandler("warning","The alt attribute is missing on a thumb, it's mandatory on tags.")},init:function(){k.checks(),k.loadImages(),k.addWrapper(),k.displayImg(),k.events()},effects:{fade:{"in":"fadeIn",out:"fadeOut"},sideFade:{"in":"fadeInLeft",out:"fadeOutRight"},sideFadeBig:{"in":"fadeInLeftBig",out:"fadeOutRightBig"},flip:{"in":"flipInX",out:"flipOutX"},light:{"in":"lightSpeedIn",out:"lightSpeedOut"},roll:{"in":"rollIn",out:"rollOut"},rotate:{"in":"rotateIn",out:"rotateOut"}},loadImages:function(){l.auto.load&&u.find("a").each(function(n,a){e("",{src:a.href,alt:""}).hide().appendTo("body")})},effectHandler:function(){"random"===l.effect?(s=k.getRandomEffect(),console.log(e(l.main.container).selector+": "+s)):k.effects.hasOwnProperty(l.effect)?s=l.effect:(s=c.effect,k.resultHandler("error",'Incorrect value for the "effect" option. Default value is used. Check out the documentation.'))},getRandomEffect:function(){var e,n=0;for(var a in k.effects)Math.random()<1/++n&&(e=a);return e},outEffect:function(){e(l.main.container).find("img").removeClass("animated "+k.effects[s].in).addClass("animated "+k.effects[s].out),setTimeout(function(){k.displayImg()},900)},addWrapper:function(){var n=e("
",{"class":"desoSlide-wrapper"}),a=e("").addClass(l.main.cssClass).css("opacity",0);switch(l.main.insertion){case"prepend":a.prependTo(e(l.main.container)).wrap(n);break;case"append":a.appendTo(e(l.main.container)).wrap(n);break;case"replace":e(l.main.container).html(a).wrapInner(n);break;default:k.resultHandler("error",'Incorrect value for the "insertion" option. Check out the documentation.')}},addSpinner:function(){d=e("
").addClass("desoSlide-spinner"),e(l.main.container).css("text-align","center").prepend(d)},removeSpinner:function(){d.length&&d.remove()},displayImg:function(){k.resultHandler(),a=0,0>h&&(h=m-1),h>=m&&(h=0),a=h;var n=u.find("a").eq(a).attr("href");t=u.find("img").eq(a).attr("alt"),i=u.find("img").eq(a).data("desoslide-caption"),o=u.find("img").eq(a).data("desoslide-href"),k.checkData(),k.effectHandler(),e(l.main.container).find("img").attr({src:n,alt:t,"data-desoslide-caption":i}).one("load",function(){e(this).removeClass("animated "+k.effects[s].out).addClass("animated "+k.effects[s].in).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){k.addOverlay()}),l.auto.start&&(h++,y=setTimeout(function(){k.outEffect()},g))})},addOverlay:function(){if("none"!==l.overlay){if(l.caption||l.controls.enable){var n=e(l.main.container).find("img").position(),a=parseInt(e(l.main.container).find("img").css("border-left-width"),10),t=e(l.main.container).find("img").width()+a,i=e(l.main.container).find("img").height()+a;0===e(l.main.container).find(".desoSlide-overlay").length&&e("
",{"class":"desoSlide-overlay"}).appendTo(e(l.main.container).find(".desoSlide-wrapper")),v=e(l.main.container).find(".desoSlide-overlay");var o=parseInt(v.css("padding-top").replace("px",""),10),r=parseInt(v.css("padding-bottom").replace("px",""),10),s=parseInt(v.css("padding-left").replace("px",""),10),d=parseInt(v.css("padding-right").replace("px",""),10),c=parseInt(v.css("height").replace("px",""),10)-(s+d);c=parseInt(i,10)-c-(o+r);var p=n.top+c,f=n.left;v.css({left:f+"px",top:p+"px",width:t+"px"}),"always"===l.overlay&&v.animate({opacity:.7},500),l.caption&&(k.updateCaption(),k.addLink())}else k.addLink();l.controls.enable&&k.addControls()}},updateCaption:function(){v.html(i)},addLink:function(){var n=e(l.main.container).find("a.desoslide-link").length>0?!0:!1,a=void 0!==o&&""!==o?!0:!1,t=e("",{"class":"desoslide-link",href:o,target:"_blank"});n&&a?e(l.main.container).find("a.desoslide-link").attr("href",o):n&&!a?e(l.main.container).find("a.desoslide-link").replaceWith(t):!n&&a&&e(l.main.container).find(".desoSlide-wrapper").append(t)},addControls:function(){e(l.main.container).find(".desoSlide-controls-wrapper").remove();var n='',a='',t='',i='',o=e("
",{"class":"desoSlide-controls-wrapper"}).append(n+a+t+i);o.css({width:v.css("width"),left:v.css("left")}),e(l.main.container).find("a.desoslide-link").length>0?o.appendTo(e(l.main.container).find("a.desoslide-link")):o.appendTo(e(l.main.container).find(".desoSlide-wrapper")),r=e(l.main.container).find(".desoSlide-controls-wrapper"),r.length&&(l.auto.start?r.find('a[href="#play"]').hide().parent().find('a[href="#pause"]').show():r.find('a[href="#pause"]').hide().parent().find('a[href="#play"]').show())},pause:function(){l.auto.start&&y&&(l.auto.start=!1,clearTimeout(y),h--,r&&r.find('a[href="#pause"]').hide().parent().find('a[href="#play"]').show())},play:function(){l.auto.start||(l.auto.start=!0,a===h&&h++,k.outEffect(),r&&r.find('a[href="#play"]').hide().parent().find('a[href="#pause"]').show())},resultHandler:function(e,n){if(!w)switch(e){case"error":void 0!==console&&console.error("desoSlide: "+n),l.events.completed&&l.events.completed("error"),w=e;break;case"warning":void 0!==console&&console.warn("desoSlide: "+n),l.events.completed&&l.events.completed("warning");break;default:l.events.completed&&l.events.completed("success")}},events:function(){u.find("a").on("click",function(n){n.preventDefault();var a=e(this),t=a.parent("li").index();t!==h&&(v.animate({opacity:0}),h=t,k.outEffect(),k.pause()),l.events.thumbClick&&l.events.thumbClick()}),u.find("img").on({mouseover:function(){e(this).stop(!0,!0).animate({opacity:.7},"normal")},mouseout:function(){e(this).stop(!0,!0).animate({opacity:1},"fast")}}),"hover"===l.overlay&&e(l.main.container).on({mouseover:function(){v.stop().animate({opacity:.7},400)},mouseleave:function(){v.stop().animate({opacity:0},400)}}),l.controls.enable&&l.controls.keys&&e(document).on("keydown",function(n){switch(n.which){case 37:e(l.main.container).trigger("prev.desoslide");break;case 39:e(l.main.container).trigger("next.desoslide");break;case 32:n.preventDefault(),e(l.main.container).trigger(l.auto.start?"pause.desoslide":"play")}}),e(l.main.container).on("click",".desoSlide-controls-wrapper a",e(l.main.container),function(n){switch(n.preventDefault(),e(this).attr("href")){case"#prev":e(l.main.container).trigger("prev.desoslide");break;case"#pause":e(l.main.container).trigger("pause.desoslide");break;case"#play":e(l.main.container).trigger("play.desoslide");break;case"#next":e(l.main.container).trigger("next.desoslide")}}),e(l.main.container).on("prev.desoslide",function(){k.pause(),h--,k.outEffect(),l.events.prev&&l.events.prev()}),e(l.main.container).on("pause.desoslide",function(){k.pause(),l.events.pause&&l.events.pause()}),e(l.main.container).on("play.desoslide",function(){k.play(),l.events.play&&l.events.play()}),e(l.main.container).on("next.desoslide",function(){k.pause(),h++,k.outEffect(),l.events.next&&l.events.next()}),"none"!==l.overlay&&e(window).bind("resize",function(){p(function(){k.addOverlay()},100)})}};return k.addSpinner(),e(window).load(function(){k.removeSpinner(),k.init()}),this}}(jQuery); \ No newline at end of file