forked from appleboy/jquery.slideShow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.slideshow.min.js
17 lines (17 loc) · 6.09 KB
/
jquery.slideshow.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* jquery.slideShow (1.0.8)
* by Marcel Eichner (www.marceleichner.de) <[email protected]>
* and charles kline <[email protected]>
* and Bo-Yi Wu <[email protected]>
*
* this is the compressed source (http://jscompress.com/)
* learn more about this plugin and other projects at:
* http://code.marceleichner.de/project/jquery.slideShow/
*
* Copyright (c) 2009 Marcel Eichner (www.marceleichner.de)
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* NOTE: This script requires jQuery to work. Download jQuery at www.jquery.com
*/
(function(a){a.fn.slideShow=function(b){if(this.length>1){this.each(function(){a(this).slideShow(b)});return this}this.defaults={start:0,interval:3,repeat:true,transition:{mode:"fade",speed:1e3},slideSize:"auto",hoverNavigation:false,slideClick:false,gotoSlide:false,mousePause:false};this.options=a.extend({},this.defaults,b);this.numSlides=this.find(".slide").length;if(this.options.start=="random"||this.options.start=="rnd"){this.current=Math.floor(Math.random()*this.numSlides)+1}else{this.current=this.options.start}if(this.current>=this.numSlides){this.current=this.numSlides-1}this.last=false;this.elm=a(this);this.interval=false;this.mouse={x:0,y:0,over:false};this.init=function(){if(this.find(".slides").length){if(this.options.slideSize=="auto"){this.options.slideSize={width:this.find(".slide:first img").width(),height:this.find(".slide:first img").height()}}if(this.options.slideSize!="none"&&this.options.slideSize!=false){this.find(".slides").css({height:this.options.slideSize.height+"px",width:this.options.slideSize.width+"px",overflow:"hidden"})}}if(this.options.transition.mode!="slideshow"){this.find(".slide").css("position","absolute");this.find(".slide:not(:eq("+this.current+"))").hide()}else{var b=this.numSlides*this.options.slideSize.width;this.find(".slides").css({width:b+"px",position:"absolute"});this.find(".slide").css({width:this.options.slideSize.width+"px","float":"left"})}this.find(".first, .next, .prev, .last, .navigation, .slide, .page, .slides").data("slideShow",this);this.find(".first").click(this.first);this.find(".next").click(this.next);this.find(".prev").click(this.previous);this.find(".last").click(this.last);this.find(".navigation .page:eq("+this.current+")").addClass("selected");this.find(".page").click(function(b){if(!(c=a(this).data("slideShow"))){var c=this}var d=a(this).html();if(!(d=parseInt(a(this).html()-1))){var d=a(this).parents(".navigation").find(".page").index(a(this))}b.preventDefault();c.gotoSlide(d)});this.find(".slide").mousemove(function(b){var c=a(this).data("slideShow");c.mouse.x=Math.abs(b.clientX-a(this).position().left);c.mouse.y=Math.abs(b.clientY-a(this).position().top);if(c.mouse.x>c.options.slideSize.width)c.mouse.x=c.options.slideSize.width;if(c.mouse.y>c.options.slideSize.height)c.mouse.y=c.options.slideSize.height;if(c.options.hoverNavigation){var d=Math.round((c.numSlides-1)*c.mouse.x/c.options.slideSize.width);c.gotoSlide(d,true)}});this.find(".slide").mouseenter(function(){var b=a(this).data("slideShow");b.mouse.over=true;if(!b.options.mousePause){b.stopAuto()}});this.find(".slide").mouseleave(function(){var b=a(this).data("slideShow");b.mouse.over=false;b.auto()});if(typeof this.options.slideClick=="function"){this.find(".slide").click(function(){var b=a(this).data("slideShow");b.options.slideClick(b)})}var c=this.current;this.current=-1;this.gotoSlide(c);if(this.options.interval>0){this.auto()}return this};this.auto=function(){if(!(b=a(this).data("slideShow"))){var b=this}if(!b.interval&&b.options.interval>.001){b.interval=window.setInterval(function(){b.next()},b.options.interval*1e3)}return this};this.isPlaying=function(){if(!(b=a(this).data("slideShow"))){var b=this}return b.interval};this.togglePlayback=function(){if(!(b=a(this).data("slideShow"))){var b=this}if(b.isPlaying()){b.stopAuto()}else{b.auto()}},this.stopAuto=function(){if(!(b=a(this).data("slideShow"))){var b=this}if(b.interval){window.clearInterval(b.interval);b.interval=false}return this};this.first=function(b){if(!(c=a(this).data("slideShow"))){var c=this}return c.gotoSlide(0)};this.next=function(){if(!(b=a(this).data("slideShow"))){var b=this}return b.gotoSlide(+b.current+1)};this.previous=function(){if(!(b=a(this).data("slideShow"))){var b=this}return b.gotoSlide(+b.current-1)};this.last=function(){if(!(b=a(this).data("slideShow"))){var b=this}return b.gotoSlide(+b.numSlides)};this.gotoSlide=function(b,c){if(b<0){b=this.numSlides-1}if(b>=this.numSlides){b=0}if(b===this.current)return this;var d=this.find(".slide:eq("+this.current+")");var e=this.find(".slide:eq("+b+")");var f=function(){a(this).removeClass("selected");if(!(b=a(this).data("slideShow"))){var b=this}b.elm.find(".navigation .page:eq("+b.current+")").addClass("selected");if(b.current>=0){b.elm.find(".navigation .page:not(:eq("+b.current+"))").removeClass("selected")}if(!b.mouse.over){b.auto()}};var g=function(){a(this).removeClass("selected");if(!(b=a(this).data("slideShow"))){var b=this}b.elm.find(".navigation .page:eq("+b.current+")").addClass("selected");if(!b.mouse.over){b.auto()}};var h=function(){if(!(b=a(this).data("slideShow"))){var b=this}if(b.current>=0){b.elm.find(".navigation .page:not(:eq("+b.current+"))").removeClass("selected")}a(this).addClass("selected")};if(!(i=a(this).data("slideShow"))){var i=this}i.stopAuto();if(typeof this.options.gotoSlide=="function"){this.options.gotoSlide(i,b)}if(c){d.hide(1,g);e.show(1,h)}else{if(typeof this.options.transition.mode=="function"){this.call(this.options.transition.mode,e,d)}else{switch(this.options.transition.mode){default:case"fade":d.fadeOut(this.options.transition.speed,g);e.fadeIn(this.options.transition.speed,h);break;case"slide":if(this.current==-1){d.hide(0,g);e.show()}else{d.animate({},{});d.animate({width:"hide"},this.options.transition.speed,g);e.animate({width:"show"},this.options.transition.speed,h)}break;case"slideshow":this.find(".slides").animate({left:b*-this.options.slideSize.width},this.options.transition.speed,f);break}}}this.find(".slides").animate({height:e.height()});this.last=this.current;this.current=b;return this};return this.init()}})(jQuery)