2 * jQuery Cycle Plugin (with Transition Definitions)
3 * Examples and documentation at: http://jquery.malsup.com/cycle/
4 * Copyright (c) 2007-2013 M. Alsup
5 * Version: 3.0.3 (11-JUL-2013)
6 * Dual licensed under the MIT and GPL licenses.
7 * http://jquery.malsup.com/license.html
8 * Requires: jQuery v1.7.1 or later
10 ;(function($, undefined) {
21 if (window.console && console.log)
22 console.log('[cycle] ' + Array.prototype.join.call(arguments,' '));
24 $.expr[':'].paused = function(el) {
29 // the options arg can be...
30 // a number - indicates an immediate transition should occur to the given slide index
31 // a string - 'pause', 'resume', 'toggle', 'next', 'prev', 'stop', 'destroy' or the name of a transition effect (ie, 'fade', 'zoom', etc)
32 // an object - properties to control the slideshow
34 // the arg2 arg can be...
35 // the name of an fx (only used in conjunction with a numeric value for 'options')
36 // the value true (only used in first arg == 'resume') and indicates
37 // that the resume should occur immediately (not wait for next timeout)
39 $.fn.cycle = function(options, arg2) {
40 var o = { s: this.selector, c: this.context };
42 // in 1.3+ we can fix mistakes with the ready state
43 if (this.length === 0 && options != 'stop') {
44 if (!$.isReady && o.s) {
45 log('DOM not ready, queuing slideshow');
47 $(o.s,o.c).cycle(options,arg2);
51 // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
52 log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
56 // iterate the matched nodeset
57 return this.each(function() {
58 var opts = handleArguments(this, options, arg2);
62 opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink;
64 // stop existing slideshow for this container (if there is one)
65 if (this.cycleTimeout)
66 clearTimeout(this.cycleTimeout);
67 this.cycleTimeout = this.cyclePause = 0;
68 this.cycleStop = 0; // issue #108
71 var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children();
72 var els = $slides.get();
75 log('terminating; too few slides: ' + els.length);
79 var opts2 = buildOptions($cont, $slides, els, opts, o);
83 var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.backwards);
85 // if it's an auto slideshow, kick it off
87 startTime += (opts2.delay || 0);
90 debug('first timeout: ' + startTime);
91 this.cycleTimeout = setTimeout(function(){go(els,opts2,0,!opts.backwards);}, startTime);
96 function triggerPause(cont, byHover, onPager) {
97 var opts = $(cont).data('cycle.opts');
100 var paused = !!cont.cyclePause;
101 if (paused && opts.paused)
102 opts.paused(cont, opts, byHover, onPager);
103 else if (!paused && opts.resumed)
104 opts.resumed(cont, opts, byHover, onPager);
107 // process the args that were passed to the plugin fn
108 function handleArguments(cont, options, arg2) {
109 if (cont.cycleStop === undefined)
111 if (options === undefined || options === null)
113 if (options.constructor == String) {
117 var opts = $(cont).data('cycle.opts');
120 cont.cycleStop++; // callbacks look for change
121 if (cont.cycleTimeout)
122 clearTimeout(cont.cycleTimeout);
123 cont.cycleTimeout = 0;
125 $(opts.elements).stop();
126 $(cont).removeData('cycle.opts');
127 if (options == 'destroy')
131 cont.cyclePause = (cont.cyclePause === 1) ? 0 : 1;
132 checkInstantResume(cont.cyclePause, arg2, cont);
141 checkInstantResume(false, arg2, cont);
146 opts = $(cont).data('cycle.opts');
148 log('options not found, "prev/next" ignored');
151 if (typeof arg2 == 'string')
152 opts.oneTimeFx = arg2;
153 $.fn.cycle[options](opts);
156 options = { fx: options };
160 else if (options.constructor == Number) {
161 // go to the requested slide
163 options = $(cont).data('cycle.opts');
165 log('options not found, can not advance slide');
168 if (num < 0 || num >= options.elements.length) {
169 log('invalid slide index: ' + num);
172 options.nextSlide = num;
173 if (cont.cycleTimeout) {
174 clearTimeout(cont.cycleTimeout);
175 cont.cycleTimeout = 0;
177 if (typeof arg2 == 'string')
178 options.oneTimeFx = arg2;
179 go(options.elements, options, 1, num >= options.currSlide);
184 function checkInstantResume(isPaused, arg2, cont) {
185 if (!isPaused && arg2 === true) { // resume now!
186 var options = $(cont).data('cycle.opts');
188 log('options not found, can not resume');
191 if (cont.cycleTimeout) {
192 clearTimeout(cont.cycleTimeout);
193 cont.cycleTimeout = 0;
195 go(options.elements, options, 1, !options.backwards);
200 function removeFilter(el, opts) {
201 if (!$.support.opacity && opts.cleartype && el.style.filter) {
202 try { el.style.removeAttribute('filter'); }
203 catch(smother) {} // handle old opera versions
207 // unbind event handlers
208 function destroy(cont, opts) {
210 $(opts.next).unbind(opts.prevNextEvent);
212 $(opts.prev).unbind(opts.prevNextEvent);
214 if (opts.pager || opts.pagerAnchorBuilder)
215 $.each(opts.pagerAnchors || [], function() {
216 this.unbind().remove();
218 opts.pagerAnchors = null;
219 $(cont).unbind('mouseenter.cycle mouseleave.cycle');
220 if (opts.destroy) // callback
224 // one-time initialization
225 function buildOptions($cont, $slides, els, options, o) {
226 var startingSlideSpecified;
227 // support metadata plugin (v1.0 and v2.0)
228 var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
229 var meta = $.isFunction($cont.data) ? $cont.data(opts.metaAttr) : null;
231 opts = $.extend(opts, meta);
233 opts.countdown = opts.autostopCount || els.length;
236 $cont.data('cycle.opts', opts);
238 opts.stopCount = cont.cycleStop;
240 opts.before = opts.before ? [opts.before] : [];
241 opts.after = opts.after ? [opts.after] : [];
243 // push some after callbacks
244 if (!$.support.opacity && opts.cleartype)
245 opts.after.push(function() { removeFilter(this, opts); });
247 opts.after.push(function() { go(els,opts,0,!opts.backwards); });
249 saveOriginalOpts(opts);
251 // clearType corrections
252 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg)
253 clearTypeFix($slides);
255 // container requires non-static position so that slides can be position within
256 if ($cont.css('position') == 'static')
257 $cont.css('position', 'relative');
259 $cont.width(opts.width);
260 if (opts.height && opts.height != 'auto')
261 $cont.height(opts.height);
263 if (opts.startingSlide !== undefined) {
264 opts.startingSlide = parseInt(opts.startingSlide,10);
265 if (opts.startingSlide >= els.length || opts.startSlide < 0)
266 opts.startingSlide = 0; // catch bogus input
268 startingSlideSpecified = true;
270 else if (opts.backwards)
271 opts.startingSlide = els.length - 1;
273 opts.startingSlide = 0;
275 // if random, mix up the slide array
278 for (var i = 0; i < els.length; i++)
279 opts.randomMap.push(i);
280 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
281 if (startingSlideSpecified) {
282 // try to find the specified starting slide and if found set start slide index in the map accordingly
283 for ( var cnt = 0; cnt < els.length; cnt++ ) {
284 if ( opts.startingSlide == opts.randomMap[cnt] ) {
285 opts.randomIndex = cnt;
290 opts.randomIndex = 1;
291 opts.startingSlide = opts.randomMap[1];
294 else if (opts.startingSlide >= els.length)
295 opts.startingSlide = 0; // catch bogus input
296 opts.currSlide = opts.startingSlide || 0;
297 var first = opts.startingSlide;
299 // set position and zIndex on all the slides
300 $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) {
303 z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i;
305 z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i;
306 $(this).css('z-index', z);
309 // make sure first slide is visible
310 $(els[first]).css('opacity',1).show(); // opacity bit needed to handle restart use case
311 removeFilter(els[first], opts);
317 $slides.width(opts.width);
318 if (opts.height && opts.height != 'auto')
319 $slides.height(opts.height);
321 $slides.each(function(){
322 var $slide = $(this);
323 var ratio = (opts.aspect === true) ? $slide.width()/$slide.height() : opts.aspect;
324 if( opts.width && $slide.width() != opts.width ) {
325 $slide.width( opts.width );
326 $slide.height( opts.width / ratio );
329 if( opts.height && $slide.height() < opts.height ) {
330 $slide.height( opts.height );
331 $slide.width( opts.height * ratio );
337 if (opts.center && ((!opts.fit) || opts.aspect)) {
338 $slides.each(function(){
339 var $slide = $(this);
341 "margin-left": opts.width ?
342 ((opts.width - $slide.width()) / 2) + "px" :
344 "margin-top": opts.height ?
345 ((opts.height - $slide.height()) / 2) + "px" :
351 if (opts.center && !opts.fit && !opts.slideResize) {
352 $slides.each(function(){
353 var $slide = $(this);
355 "margin-left": opts.width ? ((opts.width - $slide.width()) / 2) + "px" : 0,
356 "margin-top": opts.height ? ((opts.height - $slide.height()) / 2) + "px" : 0
362 var reshape = (opts.containerResize || opts.containerResizeHeight) && $cont.innerHeight() < 1;
363 if (reshape) { // do this only if container has no size http://tinyurl.com/da2oa9
364 var maxw = 0, maxh = 0;
365 for(var j=0; j < els.length; j++) {
366 var $e = $(els[j]), e = $e[0], w = $e.outerWidth(), h = $e.outerHeight();
367 if (!w) w = e.offsetWidth || e.width || $e.attr('width');
368 if (!h) h = e.offsetHeight || e.height || $e.attr('height');
369 maxw = w > maxw ? w : maxw;
370 maxh = h > maxh ? h : maxh;
372 if (opts.containerResize && maxw > 0 && maxh > 0)
373 $cont.css({width:maxw+'px',height:maxh+'px'});
374 if (opts.containerResizeHeight && maxh > 0)
375 $cont.css({height:maxh+'px'});
378 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44
380 $cont.bind('mouseenter.cycle', function(){
383 triggerPause(cont, true);
384 }).bind('mouseleave.cycle', function(){
387 triggerPause(cont, true);
390 if (supportMultiTransitions(opts) === false)
393 // apparently a lot of people use image slideshows without height/width attributes on the images.
394 // Cycle 2.50+ requires the sizing info for every slide; this block tries to deal with that.
396 options.requeueAttempts = options.requeueAttempts || 0;
397 $slides.each(function() {
398 // try to get height/width of each slide
400 this.cycleH = (opts.fit && opts.height) ? opts.height : ($el.height() || this.offsetHeight || this.height || $el.attr('height') || 0);
401 this.cycleW = (opts.fit && opts.width) ? opts.width : ($el.width() || this.offsetWidth || this.width || $el.attr('width') || 0);
403 if ( $el.is('img') ) {
404 var loading = (this.cycleH === 0 && this.cycleW === 0 && !this.complete);
405 // don't requeue for images that are still loading but have a valid size
407 if (o.s && opts.requeueOnImageNotLoaded && ++options.requeueAttempts < 100) { // track retry count so we don't loop forever
408 log(options.requeueAttempts,' - img slide not loaded, requeuing slideshow: ', this.src, this.cycleW, this.cycleH);
409 setTimeout(function() {$(o.s,o.c).cycle(options);}, opts.requeueTimeout);
411 return false; // break each loop
414 log('could not determine size of image: '+this.src, this.cycleW, this.cycleH);
424 opts.cssBefore = opts.cssBefore || {};
425 opts.cssAfter = opts.cssAfter || {};
426 opts.cssFirst = opts.cssFirst || {};
427 opts.animIn = opts.animIn || {};
428 opts.animOut = opts.animOut || {};
430 $slides.not(':eq('+first+')').css(opts.cssBefore);
431 $($slides[first]).css(opts.cssFirst);
434 opts.timeout = parseInt(opts.timeout,10);
435 // ensure that timeout and speed settings are sane
436 if (opts.speed.constructor == String)
437 opts.speed = $.fx.speeds[opts.speed] || parseInt(opts.speed,10);
439 opts.speed = opts.speed / 2;
441 var buffer = opts.fx == 'none' ? 0 : opts.fx == 'shuffle' ? 500 : 250;
442 while((opts.timeout - opts.speed) < buffer) // sanitize timeout
443 opts.timeout += opts.speed;
446 opts.easeIn = opts.easeOut = opts.easing;
448 opts.speedIn = opts.speed;
450 opts.speedOut = opts.speed;
452 opts.slideCount = els.length;
453 opts.currSlide = opts.lastSlide = first;
455 if (++opts.randomIndex == els.length)
456 opts.randomIndex = 0;
457 opts.nextSlide = opts.randomMap[opts.randomIndex];
459 else if (opts.backwards)
460 opts.nextSlide = opts.startingSlide === 0 ? (els.length-1) : opts.startingSlide-1;
462 opts.nextSlide = opts.startingSlide >= (els.length-1) ? 0 : opts.startingSlide+1;
464 // run transition init fn
466 var init = $.fn.cycle.transitions[opts.fx];
467 if ($.isFunction(init))
468 init($cont, $slides, opts);
469 else if (opts.fx != 'custom' && !opts.multiFx) {
470 log('unknown transition: ' + opts.fx,'; slideshow terminating');
475 // fire artificial events
476 var e0 = $slides[first];
477 if (!opts.skipInitializationCallbacks) {
478 if (opts.before.length)
479 opts.before[0].apply(e0, [e0, e0, opts, true]);
480 if (opts.after.length)
481 opts.after[0].apply(e0, [e0, e0, opts, true]);
484 $(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,1);});
486 $(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,0);});
487 if (opts.pager || opts.pagerAnchorBuilder)
488 buildPager(els,opts);
490 exposeAddSlide(opts, els);
495 // save off original opts so we can restore after clearing state
496 function saveOriginalOpts(opts) {
497 opts.original = { before: [], after: [] };
498 opts.original.cssBefore = $.extend({}, opts.cssBefore);
499 opts.original.cssAfter = $.extend({}, opts.cssAfter);
500 opts.original.animIn = $.extend({}, opts.animIn);
501 opts.original.animOut = $.extend({}, opts.animOut);
502 $.each(opts.before, function() { opts.original.before.push(this); });
503 $.each(opts.after, function() { opts.original.after.push(this); });
506 function supportMultiTransitions(opts) {
507 var i, tx, txs = $.fn.cycle.transitions;
508 // look for multiple effects
509 if (opts.fx.indexOf(',') > 0) {
511 opts.fxs = opts.fx.replace(/\s*/g,'').split(',');
512 // discard any bogus effect names
513 for (i=0; i < opts.fxs.length; i++) {
514 var fx = opts.fxs[i];
516 if (!tx || !txs.hasOwnProperty(fx) || !$.isFunction(tx)) {
517 log('discarding unknown transition: ',fx);
518 opts.fxs.splice(i,1);
522 // if we have an empty list then we threw everything away!
523 if (!opts.fxs.length) {
524 log('No valid transitions named; slideshow terminating.');
528 else if (opts.fx == 'all') { // auto-gen the list of transitions
532 if (txs.hasOwnProperty(p)) {
534 if (txs.hasOwnProperty(p) && $.isFunction(tx))
539 if (opts.multiFx && opts.randomizeEffects) {
540 // munge the fxs array to make effect selection random
541 var r1 = Math.floor(Math.random() * 20) + 30;
542 for (i = 0; i < r1; i++) {
543 var r2 = Math.floor(Math.random() * opts.fxs.length);
544 opts.fxs.push(opts.fxs.splice(r2,1)[0]);
546 debug('randomized fx sequence: ',opts.fxs);
551 // provide a mechanism for adding slides after the slideshow has started
552 function exposeAddSlide(opts, els) {
553 opts.addSlide = function(newSlide, prepend) {
554 var $s = $(newSlide), s = $s[0];
555 if (!opts.autostopCount)
557 els[prepend?'unshift':'push'](s);
559 opts.els[prepend?'unshift':'push'](s); // shuffle needs this
560 opts.slideCount = els.length;
562 // add the slide to the random map and resort
564 opts.randomMap.push(opts.slideCount-1);
565 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
568 $s.css('position','absolute');
569 $s[prepend?'prependTo':'appendTo'](opts.$cont);
576 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg)
579 if (opts.fit && opts.width)
580 $s.width(opts.width);
581 if (opts.fit && opts.height && opts.height != 'auto')
582 $s.height(opts.height);
583 s.cycleH = (opts.fit && opts.height) ? opts.height : $s.height();
584 s.cycleW = (opts.fit && opts.width) ? opts.width : $s.width();
586 $s.css(opts.cssBefore);
588 if (opts.pager || opts.pagerAnchorBuilder)
589 $.fn.cycle.createPagerAnchor(els.length-1, s, $(opts.pager), els, opts);
591 if ($.isFunction(opts.onAddSlide))
594 $s.hide(); // default behavior
598 // reset internal state; we do this on every pass in order to support multiple effects
599 $.fn.cycle.resetState = function(opts, fx) {
601 opts.before = []; opts.after = [];
602 opts.cssBefore = $.extend({}, opts.original.cssBefore);
603 opts.cssAfter = $.extend({}, opts.original.cssAfter);
604 opts.animIn = $.extend({}, opts.original.animIn);
605 opts.animOut = $.extend({}, opts.original.animOut);
607 $.each(opts.original.before, function() { opts.before.push(this); });
608 $.each(opts.original.after, function() { opts.after.push(this); });
611 var init = $.fn.cycle.transitions[fx];
612 if ($.isFunction(init))
613 init(opts.$cont, $(opts.elements), opts);
616 // this is the main engine fn, it handles the timeouts, callbacks and slide index mgmt
617 function go(els, opts, manual, fwd) {
618 var p = opts.$cont[0], curr = els[opts.currSlide], next = els[opts.nextSlide];
620 // opts.busy is true if we're in the middle of an animation
621 if (manual && opts.busy && opts.manualTrump) {
622 // let manual transitions requests trump active ones
623 debug('manualTrump in go(), stopping active transition');
624 $(els).stop(true,true);
626 clearTimeout(p.cycleTimeout);
629 // don't begin another timeout-based transition if there is one active
631 debug('transition active, ignoring new tx request');
636 // stop cycling if we have an outstanding stop request
637 if (p.cycleStop != opts.stopCount || p.cycleTimeout === 0 && !manual)
640 // check to see if we should stop cycling based on autostop options
641 if (!manual && !p.cyclePause && !opts.bounce &&
642 ((opts.autostop && (--opts.countdown <= 0)) ||
643 (opts.nowrap && !opts.random && opts.nextSlide < opts.currSlide))) {
649 // if slideshow is paused, only transition on a manual trigger
651 if ((manual || !p.cyclePause) && (opts.nextSlide != opts.currSlide)) {
654 // keep trying to get the slide size if we don't have it yet
655 curr.cycleH = curr.cycleH || $(curr).height();
656 curr.cycleW = curr.cycleW || $(curr).width();
657 next.cycleH = next.cycleH || $(next).height();
658 next.cycleW = next.cycleW || $(next).width();
660 // support multiple transition types
662 if (fwd && (opts.lastFx === undefined || ++opts.lastFx >= opts.fxs.length))
664 else if (!fwd && (opts.lastFx === undefined || --opts.lastFx < 0))
665 opts.lastFx = opts.fxs.length - 1;
666 fx = opts.fxs[opts.lastFx];
669 // one-time fx overrides apply to: $('div').cycle(3,'zoom');
670 if (opts.oneTimeFx) {
672 opts.oneTimeFx = null;
675 $.fn.cycle.resetState(opts, fx);
677 // run the before callbacks
678 if (opts.before.length)
679 $.each(opts.before, function(i,o) {
680 if (p.cycleStop != opts.stopCount) return;
681 o.apply(next, [curr, next, opts, fwd]);
684 // stage the after callacks
685 var after = function() {
687 $.each(opts.after, function(i,o) {
688 if (p.cycleStop != opts.stopCount) return;
689 o.apply(next, [curr, next, opts, fwd]);
692 // queue next transition
697 debug('tx firing('+fx+'); currSlide: ' + opts.currSlide + '; nextSlide: ' + opts.nextSlide);
699 // get ready to perform the transition
701 if (opts.fxFn) // fx function provided?
702 opts.fxFn(curr, next, opts, after, fwd, manual && opts.fastOnEvent);
703 else if ($.isFunction($.fn.cycle[opts.fx])) // fx plugin ?
704 $.fn.cycle[opts.fx](curr, next, opts, after, fwd, manual && opts.fastOnEvent);
706 $.fn.cycle.custom(curr, next, opts, after, fwd, manual && opts.fastOnEvent);
712 if (changed || opts.nextSlide == opts.currSlide) {
713 // calculate the next slide
715 opts.lastSlide = opts.currSlide;
717 opts.currSlide = opts.nextSlide;
718 if (++opts.randomIndex == els.length) {
719 opts.randomIndex = 0;
720 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
722 opts.nextSlide = opts.randomMap[opts.randomIndex];
723 if (opts.nextSlide == opts.currSlide)
724 opts.nextSlide = (opts.currSlide == opts.slideCount - 1) ? 0 : opts.currSlide + 1;
726 else if (opts.backwards) {
727 roll = (opts.nextSlide - 1) < 0;
728 if (roll && opts.bounce) {
729 opts.backwards = !opts.backwards;
734 opts.nextSlide = roll ? (els.length-1) : opts.nextSlide-1;
735 opts.currSlide = roll ? 0 : opts.nextSlide+1;
739 roll = (opts.nextSlide + 1) == els.length;
740 if (roll && opts.bounce) {
741 opts.backwards = !opts.backwards;
742 opts.nextSlide = els.length-2;
743 opts.currSlide = els.length-1;
746 opts.nextSlide = roll ? 0 : opts.nextSlide+1;
747 opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
751 if (changed && opts.pager)
752 opts.updateActivePagerLink(opts.pager, opts.currSlide, opts.activePagerClass);
754 function queueNext() {
755 // stage the next transition
756 var ms = 0, timeout = opts.timeout;
757 if (opts.timeout && !opts.continuous) {
758 ms = getTimeout(els[opts.currSlide], els[opts.nextSlide], opts, fwd);
759 if (opts.fx == 'shuffle')
762 else if (opts.continuous && p.cyclePause) // continuous shows work off an after callback, not this timer logic
765 p.cycleTimeout = setTimeout(function(){ go(els, opts, 0, !opts.backwards); }, ms);
769 // invoked after transition
770 $.fn.cycle.updateActivePagerLink = function(pager, currSlide, clsName) {
771 $(pager).each(function() {
772 $(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);
776 // calculate timeout value for current transition
777 function getTimeout(curr, next, opts, fwd) {
778 if (opts.timeoutFn) {
779 // call user provided calc fn
780 var t = opts.timeoutFn.call(curr,curr,next,opts,fwd);
781 while (opts.fx != 'none' && (t - opts.speed) < 250) // sanitize timeout
783 debug('calculated timeout: ' + t + '; speed: ' + opts.speed);
790 // expose next/prev function, caller must pass in state
791 $.fn.cycle.next = function(opts) { advance(opts,1); };
792 $.fn.cycle.prev = function(opts) { advance(opts,0);};
794 // advance slide forward or back
795 function advance(opts, moveForward) {
796 var val = moveForward ? 1 : -1;
797 var els = opts.elements;
798 var p = opts.$cont[0], timeout = p.cycleTimeout;
800 clearTimeout(timeout);
803 if (opts.random && val < 0) {
804 // move back to the previously display slide
806 if (--opts.randomIndex == -2)
807 opts.randomIndex = els.length-2;
808 else if (opts.randomIndex == -1)
809 opts.randomIndex = els.length-1;
810 opts.nextSlide = opts.randomMap[opts.randomIndex];
812 else if (opts.random) {
813 opts.nextSlide = opts.randomMap[opts.randomIndex];
816 opts.nextSlide = opts.currSlide + val;
817 if (opts.nextSlide < 0) {
818 if (opts.nowrap) return false;
819 opts.nextSlide = els.length - 1;
821 else if (opts.nextSlide >= els.length) {
822 if (opts.nowrap) return false;
827 var cb = opts.onPrevNextEvent || opts.prevNextClick; // prevNextClick is deprecated
828 if ($.isFunction(cb))
829 cb(val > 0, opts.nextSlide, els[opts.nextSlide]);
830 go(els, opts, 1, moveForward);
834 function buildPager(els, opts) {
835 var $p = $(opts.pager);
836 $.each(els, function(i,o) {
837 $.fn.cycle.createPagerAnchor(i,o,$p,els,opts);
839 opts.updateActivePagerLink(opts.pager, opts.startingSlide, opts.activePagerClass);
842 $.fn.cycle.createPagerAnchor = function(i, el, $p, els, opts) {
844 if ($.isFunction(opts.pagerAnchorBuilder)) {
845 a = opts.pagerAnchorBuilder(i,el);
846 debug('pagerAnchorBuilder('+i+', el) returned: ' + a);
849 a = '<a href="#">'+(i+1)+'</a>';
854 // don't reparent if anchor is in the dom
855 if ($a.parents('body').length === 0) {
859 var $clone = $a.clone(true);
860 $(this).append($clone);
870 opts.pagerAnchors = opts.pagerAnchors || [];
871 opts.pagerAnchors.push($a);
873 var pagerFn = function(e) {
876 var p = opts.$cont[0], timeout = p.cycleTimeout;
878 clearTimeout(timeout);
881 var cb = opts.onPagerEvent || opts.pagerClick; // pagerClick is deprecated
882 if ($.isFunction(cb))
883 cb(opts.nextSlide, els[opts.nextSlide]);
884 go(els,opts,1,opts.currSlide < i); // trigger the trans
885 // return false; // <== allow bubble
888 if ( /mouseenter|mouseover/i.test(opts.pagerEvent) ) {
889 $a.hover(pagerFn, function(){/* no-op */} );
892 $a.bind(opts.pagerEvent, pagerFn);
895 if ( ! /^click/.test(opts.pagerEvent) && !opts.allowPagerClickBubble)
896 $a.bind('click.cycle', function(){return false;}); // suppress click
898 var cont = opts.$cont[0];
899 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44
900 if (opts.pauseOnPagerHover) {
905 triggerPause(cont,true,true);
909 triggerPause(cont,true,true);
915 // helper fn to calculate the number of slides between the current and the next
916 $.fn.cycle.hopsFromLast = function(opts, fwd) {
917 var hops, l = opts.lastSlide, c = opts.currSlide;
919 hops = c > l ? c - l : opts.slideCount - l;
921 hops = c < l ? l - c : l + opts.slideCount - c;
925 // fix clearType problems in ie6 by setting an explicit bg color
926 // (otherwise text slides look horrible during a fade transition)
927 function clearTypeFix($slides) {
928 debug('applying clearType background-color hack');
930 s = parseInt(s,10).toString(16);
931 return s.length < 2 ? '0'+s : s;
934 for ( ; e && e.nodeName.toLowerCase() != 'html'; e = e.parentNode) {
935 var v = $.css(e,'background-color');
936 if (v && v.indexOf('rgb') >= 0 ) {
937 var rgb = v.match(/\d+/g);
938 return '#'+ hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
940 if (v && v != 'transparent')
945 $slides.each(function() { $(this).css('background-color', getBg(this)); });
948 // reset common props before the next transition
949 $.fn.cycle.commonReset = function(curr,next,opts,w,h,rev) {
950 $(opts.elements).not(curr).hide();
951 if (typeof opts.cssBefore.opacity == 'undefined')
952 opts.cssBefore.opacity = 1;
953 opts.cssBefore.display = 'block';
954 if (opts.slideResize && w !== false && next.cycleW > 0)
955 opts.cssBefore.width = next.cycleW;
956 if (opts.slideResize && h !== false && next.cycleH > 0)
957 opts.cssBefore.height = next.cycleH;
958 opts.cssAfter = opts.cssAfter || {};
959 opts.cssAfter.display = 'none';
960 $(curr).css('zIndex',opts.slideCount + (rev === true ? 1 : 0));
961 $(next).css('zIndex',opts.slideCount + (rev === true ? 0 : 1));
964 // the actual fn for effecting a transition
965 $.fn.cycle.custom = function(curr, next, opts, cb, fwd, speedOverride) {
966 var $l = $(curr), $n = $(next);
967 var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animInDelay = opts.animInDelay, animOutDelay = opts.animOutDelay;
968 $n.css(opts.cssBefore);
970 if (typeof speedOverride == 'number')
971 speedIn = speedOut = speedOverride;
973 speedIn = speedOut = 1;
974 easeIn = easeOut = null;
976 var fn = function() {
977 $n.delay(animInDelay).animate(opts.animIn, speedIn, easeIn, function() {
981 $l.delay(animOutDelay).animate(opts.animOut, speedOut, easeOut, function() {
982 $l.css(opts.cssAfter);
989 // transition definitions - only fade is defined here, transition pack defines the rest
990 $.fn.cycle.transitions = {
991 fade: function($cont, $slides, opts) {
992 $slides.not(':eq('+opts.currSlide+')').css('opacity',0);
993 opts.before.push(function(curr,next,opts) {
994 $.fn.cycle.commonReset(curr,next,opts);
995 opts.cssBefore.opacity = 0;
997 opts.animIn = { opacity: 1 };
998 opts.animOut = { opacity: 0 };
999 opts.cssBefore = { top: 0, left: 0 };
1003 $.fn.cycle.ver = function() { return ver; };
1005 // override these globally if you like (they are all optional)
1006 $.fn.cycle.defaults = {
1007 activePagerClass: 'activeSlide', // class name used for the active pager link
1008 after: null, // transition callback (scope set to element that was shown): function(currSlideElement, nextSlideElement, options, forwardFlag)
1009 allowPagerClickBubble: false, // allows or prevents click event on pager anchors from bubbling
1010 animIn: null, // properties that define how the slide animates in
1011 animInDelay: 0, // allows delay before next slide transitions in
1012 animOut: null, // properties that define how the slide animates out
1013 animOutDelay: 0, // allows delay before current slide transitions out
1014 aspect: false, // preserve aspect ratio during fit resizing, cropping if necessary (must be used with fit option)
1015 autostop: 0, // true to end slideshow after X transitions (where X == slide count)
1016 autostopCount: 0, // number of transitions (optionally used with autostop to define X)
1017 backwards: false, // true to start slideshow at last slide and move backwards through the stack
1018 before: null, // transition callback (scope set to element to be shown): function(currSlideElement, nextSlideElement, options, forwardFlag)
1019 center: null, // set to true to have cycle add top/left margin to each slide (use with width and height options)
1020 cleartype: !$.support.opacity, // true if clearType corrections should be applied (for IE)
1021 cleartypeNoBg: false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
1022 containerResize: 1, // resize container to fit largest slide
1023 containerResizeHeight: 0, // resize containers height to fit the largest slide but leave the width dynamic
1024 continuous: 0, // true to start next transition immediately after current one completes
1025 cssAfter: null, // properties that defined the state of the slide after transitioning out
1026 cssBefore: null, // properties that define the initial state of the slide before transitioning in
1027 delay: 0, // additional delay (in ms) for first transition (hint: can be negative)
1028 easeIn: null, // easing for "in" transition
1029 easeOut: null, // easing for "out" transition
1030 easing: null, // easing method for both in and out transitions
1031 end: null, // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options)
1032 fastOnEvent: 0, // force fast transitions when triggered manually (via pager or prev/next); value == time in ms
1033 fit: 0, // force slides to fit container
1034 fx: 'fade', // name of transition effect (or comma separated names, ex: 'fade,scrollUp,shuffle')
1035 fxFn: null, // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag)
1036 height: 'auto', // container height (if the 'fit' option is true, the slides will be set to this height as well)
1037 manualTrump: true, // causes manual transition to stop an active transition instead of being ignored
1038 metaAttr: 'cycle', // data- attribute that holds the option data for the slideshow
1039 next: null, // element, jQuery object, or jQuery selector string for the element to use as event trigger for next slide
1040 nowrap: 0, // true to prevent slideshow from wrapping
1041 onPagerEvent: null, // callback fn for pager events: function(zeroBasedSlideIndex, slideElement)
1042 onPrevNextEvent: null, // callback fn for prev/next events: function(isNext, zeroBasedSlideIndex, slideElement)
1043 pager: null, // element, jQuery object, or jQuery selector string for the element to use as pager container
1044 pagerAnchorBuilder: null, // callback fn for building anchor links: function(index, DOMelement)
1045 pagerEvent: 'click.cycle', // name of event which drives the pager navigation
1046 pause: 0, // true to enable "pause on hover"
1047 pauseOnPagerHover: 0, // true to pause when hovering over pager link
1048 prev: null, // element, jQuery object, or jQuery selector string for the element to use as event trigger for previous slide
1049 prevNextEvent: 'click.cycle',// event which drives the manual transition to the previous or next slide
1050 random: 0, // true for random, false for sequence (not applicable to shuffle fx)
1051 randomizeEffects: 1, // valid when multiple effects are used; true to make the effect sequence random
1052 requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded
1053 requeueTimeout: 250, // ms delay for requeue
1054 rev: 0, // causes animations to transition in reverse (for effects that support it such as scrollHorz/scrollVert/shuffle)
1055 shuffle: null, // coords for shuffle animation, ex: { top:15, left: 200 }
1056 skipInitializationCallbacks: false, // set to true to disable the first before/after callback that occurs prior to any transition
1057 slideExpr: null, // expression for selecting slides (if something other than all children is required)
1058 slideResize: 1, // force slide width/height to fixed size before every transition
1059 speed: 1000, // speed of the transition (any valid fx speed value)
1060 speedIn: null, // speed of the 'in' transition
1061 speedOut: null, // speed of the 'out' transition
1062 startingSlide: undefined,// zero-based index of the first slide to be displayed
1063 sync: 1, // true if in/out transitions should occur simultaneously
1064 timeout: 4000, // milliseconds between slide transitions (0 to disable auto advance)
1065 timeoutFn: null, // callback for determining per-slide timeout value: function(currSlideElement, nextSlideElement, options, forwardFlag)
1066 updateActivePagerLink: null,// callback fn invoked to update the active pager link (adds/removes activePagerClass style)
1067 width: null // container width (if the 'fit' option is true, the slides will be set to this width as well)
1074 * jQuery Cycle Plugin Transition Definitions
1075 * This script is a plugin for the jQuery Cycle Plugin
1076 * Examples and documentation at: http://malsup.com/jquery/cycle/
1077 * Copyright (c) 2007-2010 M. Alsup
1079 * Dual licensed under the MIT and GPL licenses:
1080 * http://www.opensource.org/licenses/mit-license.php
1081 * http://www.gnu.org/licenses/gpl.html
1087 // These functions define slide initialization and properties for the named
1088 // transitions. To save file size feel free to remove any of these that you
1091 $.fn.cycle.transitions.none = function($cont, $slides, opts) {
1092 opts.fxFn = function(curr,next,opts,after){
1099 // not a cross-fade, fadeout only fades out the top slide
1100 $.fn.cycle.transitions.fadeout = function($cont, $slides, opts) {
1101 $slides.not(':eq('+opts.currSlide+')').css({ display: 'block', 'opacity': 1 });
1102 opts.before.push(function(curr,next,opts,w,h,rev) {
1103 $(curr).css('zIndex',opts.slideCount + (rev !== true ? 1 : 0));
1104 $(next).css('zIndex',opts.slideCount + (rev !== true ? 0 : 1));
1106 opts.animIn.opacity = 1;
1107 opts.animOut.opacity = 0;
1108 opts.cssBefore.opacity = 1;
1109 opts.cssBefore.display = 'block';
1110 opts.cssAfter.zIndex = 0;
1113 // scrollUp/Down/Left/Right
1114 $.fn.cycle.transitions.scrollUp = function($cont, $slides, opts) {
1115 $cont.css('overflow','hidden');
1116 opts.before.push($.fn.cycle.commonReset);
1117 var h = $cont.height();
1118 opts.cssBefore.top = h;
1119 opts.cssBefore.left = 0;
1120 opts.cssFirst.top = 0;
1121 opts.animIn.top = 0;
1122 opts.animOut.top = -h;
1124 $.fn.cycle.transitions.scrollDown = function($cont, $slides, opts) {
1125 $cont.css('overflow','hidden');
1126 opts.before.push($.fn.cycle.commonReset);
1127 var h = $cont.height();
1128 opts.cssFirst.top = 0;
1129 opts.cssBefore.top = -h;
1130 opts.cssBefore.left = 0;
1131 opts.animIn.top = 0;
1132 opts.animOut.top = h;
1134 $.fn.cycle.transitions.scrollLeft = function($cont, $slides, opts) {
1135 $cont.css('overflow','hidden');
1136 opts.before.push($.fn.cycle.commonReset);
1137 var w = $cont.width();
1138 opts.cssFirst.left = 0;
1139 opts.cssBefore.left = w;
1140 opts.cssBefore.top = 0;
1141 opts.animIn.left = 0;
1142 opts.animOut.left = 0-w;
1144 $.fn.cycle.transitions.scrollRight = function($cont, $slides, opts) {
1145 $cont.css('overflow','hidden');
1146 opts.before.push($.fn.cycle.commonReset);
1147 var w = $cont.width();
1148 opts.cssFirst.left = 0;
1149 opts.cssBefore.left = -w;
1150 opts.cssBefore.top = 0;
1151 opts.animIn.left = 0;
1152 opts.animOut.left = w;
1154 $.fn.cycle.transitions.scrollHorz = function($cont, $slides, opts) {
1155 $cont.css('overflow','hidden').width();
1156 opts.before.push(function(curr, next, opts, fwd) {
1159 $.fn.cycle.commonReset(curr,next,opts);
1160 opts.cssBefore.left = fwd ? (next.cycleW-1) : (1-next.cycleW);
1161 opts.animOut.left = fwd ? -curr.cycleW : curr.cycleW;
1163 opts.cssFirst.left = 0;
1164 opts.cssBefore.top = 0;
1165 opts.animIn.left = 0;
1166 opts.animOut.top = 0;
1168 $.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) {
1169 $cont.css('overflow','hidden');
1170 opts.before.push(function(curr, next, opts, fwd) {
1173 $.fn.cycle.commonReset(curr,next,opts);
1174 opts.cssBefore.top = fwd ? (1-next.cycleH) : (next.cycleH-1);
1175 opts.animOut.top = fwd ? curr.cycleH : -curr.cycleH;
1177 opts.cssFirst.top = 0;
1178 opts.cssBefore.left = 0;
1179 opts.animIn.top = 0;
1180 opts.animOut.left = 0;
1184 $.fn.cycle.transitions.slideX = function($cont, $slides, opts) {
1185 opts.before.push(function(curr, next, opts) {
1186 $(opts.elements).not(curr).hide();
1187 $.fn.cycle.commonReset(curr,next,opts,false,true);
1188 opts.animIn.width = next.cycleW;
1190 opts.cssBefore.left = 0;
1191 opts.cssBefore.top = 0;
1192 opts.cssBefore.width = 0;
1193 opts.animIn.width = 'show';
1194 opts.animOut.width = 0;
1196 $.fn.cycle.transitions.slideY = function($cont, $slides, opts) {
1197 opts.before.push(function(curr, next, opts) {
1198 $(opts.elements).not(curr).hide();
1199 $.fn.cycle.commonReset(curr,next,opts,true,false);
1200 opts.animIn.height = next.cycleH;
1202 opts.cssBefore.left = 0;
1203 opts.cssBefore.top = 0;
1204 opts.cssBefore.height = 0;
1205 opts.animIn.height = 'show';
1206 opts.animOut.height = 0;
1210 $.fn.cycle.transitions.shuffle = function($cont, $slides, opts) {
1211 var i, w = $cont.css('overflow', 'visible').width();
1212 $slides.css({left: 0, top: 0});
1213 opts.before.push(function(curr,next,opts) {
1214 $.fn.cycle.commonReset(curr,next,opts,true,true,true);
1216 // only adjust speed once!
1217 if (!opts.speedAdjusted) {
1218 opts.speed = opts.speed / 2; // shuffle has 2 transitions
1219 opts.speedAdjusted = true;
1222 opts.shuffle = opts.shuffle || {left:-w, top:15};
1224 for (i=0; i < $slides.length; i++)
1225 opts.els.push($slides[i]);
1227 for (i=0; i < opts.currSlide; i++)
1228 opts.els.push(opts.els.shift());
1230 // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!)
1231 opts.fxFn = function(curr, next, opts, cb, fwd) {
1234 var $el = fwd ? $(curr) : $(next);
1235 $(next).css(opts.cssBefore);
1236 var count = opts.slideCount;
1237 $el.animate(opts.shuffle, opts.speedIn, opts.easeIn, function() {
1238 var hops = $.fn.cycle.hopsFromLast(opts, fwd);
1239 for (var k=0; k < hops; k++) {
1241 opts.els.push(opts.els.shift());
1243 opts.els.unshift(opts.els.pop());
1246 for (var i=0, len=opts.els.length; i < len; i++)
1247 $(opts.els[i]).css('z-index', len-i+count);
1250 var z = $(curr).css('z-index');
1251 $el.css('z-index', parseInt(z,10)+1+count);
1253 $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() {
1254 $(fwd ? this : curr).hide();
1259 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 });
1262 // turnUp/Down/Left/Right
1263 $.fn.cycle.transitions.turnUp = function($cont, $slides, opts) {
1264 opts.before.push(function(curr, next, opts) {
1265 $.fn.cycle.commonReset(curr,next,opts,true,false);
1266 opts.cssBefore.top = next.cycleH;
1267 opts.animIn.height = next.cycleH;
1268 opts.animOut.width = next.cycleW;
1270 opts.cssFirst.top = 0;
1271 opts.cssBefore.left = 0;
1272 opts.cssBefore.height = 0;
1273 opts.animIn.top = 0;
1274 opts.animOut.height = 0;
1276 $.fn.cycle.transitions.turnDown = function($cont, $slides, opts) {
1277 opts.before.push(function(curr, next, opts) {
1278 $.fn.cycle.commonReset(curr,next,opts,true,false);
1279 opts.animIn.height = next.cycleH;
1280 opts.animOut.top = curr.cycleH;
1282 opts.cssFirst.top = 0;
1283 opts.cssBefore.left = 0;
1284 opts.cssBefore.top = 0;
1285 opts.cssBefore.height = 0;
1286 opts.animOut.height = 0;
1288 $.fn.cycle.transitions.turnLeft = function($cont, $slides, opts) {
1289 opts.before.push(function(curr, next, opts) {
1290 $.fn.cycle.commonReset(curr,next,opts,false,true);
1291 opts.cssBefore.left = next.cycleW;
1292 opts.animIn.width = next.cycleW;
1294 opts.cssBefore.top = 0;
1295 opts.cssBefore.width = 0;
1296 opts.animIn.left = 0;
1297 opts.animOut.width = 0;
1299 $.fn.cycle.transitions.turnRight = function($cont, $slides, opts) {
1300 opts.before.push(function(curr, next, opts) {
1301 $.fn.cycle.commonReset(curr,next,opts,false,true);
1302 opts.animIn.width = next.cycleW;
1303 opts.animOut.left = curr.cycleW;
1305 $.extend(opts.cssBefore, { top: 0, left: 0, width: 0 });
1306 opts.animIn.left = 0;
1307 opts.animOut.width = 0;
1311 $.fn.cycle.transitions.zoom = function($cont, $slides, opts) {
1312 opts.before.push(function(curr, next, opts) {
1313 $.fn.cycle.commonReset(curr,next,opts,false,false,true);
1314 opts.cssBefore.top = next.cycleH/2;
1315 opts.cssBefore.left = next.cycleW/2;
1316 $.extend(opts.animIn, { top: 0, left: 0, width: next.cycleW, height: next.cycleH });
1317 $.extend(opts.animOut, { width: 0, height: 0, top: curr.cycleH/2, left: curr.cycleW/2 });
1319 opts.cssFirst.top = 0;
1320 opts.cssFirst.left = 0;
1321 opts.cssBefore.width = 0;
1322 opts.cssBefore.height = 0;
1326 $.fn.cycle.transitions.fadeZoom = function($cont, $slides, opts) {
1327 opts.before.push(function(curr, next, opts) {
1328 $.fn.cycle.commonReset(curr,next,opts,false,false);
1329 opts.cssBefore.left = next.cycleW/2;
1330 opts.cssBefore.top = next.cycleH/2;
1331 $.extend(opts.animIn, { top: 0, left: 0, width: next.cycleW, height: next.cycleH });
1333 opts.cssBefore.width = 0;
1334 opts.cssBefore.height = 0;
1335 opts.animOut.opacity = 0;
1339 $.fn.cycle.transitions.blindX = function($cont, $slides, opts) {
1340 var w = $cont.css('overflow','hidden').width();
1341 opts.before.push(function(curr, next, opts) {
1342 $.fn.cycle.commonReset(curr,next,opts);
1343 opts.animIn.width = next.cycleW;
1344 opts.animOut.left = curr.cycleW;
1346 opts.cssBefore.left = w;
1347 opts.cssBefore.top = 0;
1348 opts.animIn.left = 0;
1349 opts.animOut.left = w;
1352 $.fn.cycle.transitions.blindY = function($cont, $slides, opts) {
1353 var h = $cont.css('overflow','hidden').height();
1354 opts.before.push(function(curr, next, opts) {
1355 $.fn.cycle.commonReset(curr,next,opts);
1356 opts.animIn.height = next.cycleH;
1357 opts.animOut.top = curr.cycleH;
1359 opts.cssBefore.top = h;
1360 opts.cssBefore.left = 0;
1361 opts.animIn.top = 0;
1362 opts.animOut.top = h;
1365 $.fn.cycle.transitions.blindZ = function($cont, $slides, opts) {
1366 var h = $cont.css('overflow','hidden').height();
1367 var w = $cont.width();
1368 opts.before.push(function(curr, next, opts) {
1369 $.fn.cycle.commonReset(curr,next,opts);
1370 opts.animIn.height = next.cycleH;
1371 opts.animOut.top = curr.cycleH;
1373 opts.cssBefore.top = h;
1374 opts.cssBefore.left = w;
1375 opts.animIn.top = 0;
1376 opts.animIn.left = 0;
1377 opts.animOut.top = h;
1378 opts.animOut.left = w;
1381 // growX - grow horizontally from centered 0 width
1382 $.fn.cycle.transitions.growX = function($cont, $slides, opts) {
1383 opts.before.push(function(curr, next, opts) {
1384 $.fn.cycle.commonReset(curr,next,opts,false,true);
1385 opts.cssBefore.left = this.cycleW/2;
1386 opts.animIn.left = 0;
1387 opts.animIn.width = this.cycleW;
1388 opts.animOut.left = 0;
1390 opts.cssBefore.top = 0;
1391 opts.cssBefore.width = 0;
1393 // growY - grow vertically from centered 0 height
1394 $.fn.cycle.transitions.growY = function($cont, $slides, opts) {
1395 opts.before.push(function(curr, next, opts) {
1396 $.fn.cycle.commonReset(curr,next,opts,true,false);
1397 opts.cssBefore.top = this.cycleH/2;
1398 opts.animIn.top = 0;
1399 opts.animIn.height = this.cycleH;
1400 opts.animOut.top = 0;
1402 opts.cssBefore.height = 0;
1403 opts.cssBefore.left = 0;
1406 // curtainX - squeeze in both edges horizontally
1407 $.fn.cycle.transitions.curtainX = function($cont, $slides, opts) {
1408 opts.before.push(function(curr, next, opts) {
1409 $.fn.cycle.commonReset(curr,next,opts,false,true,true);
1410 opts.cssBefore.left = next.cycleW/2;
1411 opts.animIn.left = 0;
1412 opts.animIn.width = this.cycleW;
1413 opts.animOut.left = curr.cycleW/2;
1414 opts.animOut.width = 0;
1416 opts.cssBefore.top = 0;
1417 opts.cssBefore.width = 0;
1419 // curtainY - squeeze in both edges vertically
1420 $.fn.cycle.transitions.curtainY = function($cont, $slides, opts) {
1421 opts.before.push(function(curr, next, opts) {
1422 $.fn.cycle.commonReset(curr,next,opts,true,false,true);
1423 opts.cssBefore.top = next.cycleH/2;
1424 opts.animIn.top = 0;
1425 opts.animIn.height = next.cycleH;
1426 opts.animOut.top = curr.cycleH/2;
1427 opts.animOut.height = 0;
1429 opts.cssBefore.height = 0;
1430 opts.cssBefore.left = 0;
1433 // cover - curr slide covered by next slide
1434 $.fn.cycle.transitions.cover = function($cont, $slides, opts) {
1435 var d = opts.direction || 'left';
1436 var w = $cont.css('overflow','hidden').width();
1437 var h = $cont.height();
1438 opts.before.push(function(curr, next, opts) {
1439 $.fn.cycle.commonReset(curr,next,opts);
1440 opts.cssAfter.display = '';
1442 opts.cssBefore.left = -w;
1444 opts.cssBefore.top = h;
1445 else if (d == 'down')
1446 opts.cssBefore.top = -h;
1448 opts.cssBefore.left = w;
1450 opts.animIn.left = 0;
1451 opts.animIn.top = 0;
1452 opts.cssBefore.top = 0;
1453 opts.cssBefore.left = 0;
1456 // uncover - curr slide moves off next slide
1457 $.fn.cycle.transitions.uncover = function($cont, $slides, opts) {
1458 var d = opts.direction || 'left';
1459 var w = $cont.css('overflow','hidden').width();
1460 var h = $cont.height();
1461 opts.before.push(function(curr, next, opts) {
1462 $.fn.cycle.commonReset(curr,next,opts,true,true,true);
1464 opts.animOut.left = w;
1466 opts.animOut.top = -h;
1467 else if (d == 'down')
1468 opts.animOut.top = h;
1470 opts.animOut.left = -w;
1472 opts.animIn.left = 0;
1473 opts.animIn.top = 0;
1474 opts.cssBefore.top = 0;
1475 opts.cssBefore.left = 0;
1478 // toss - move top slide and fade away
1479 $.fn.cycle.transitions.toss = function($cont, $slides, opts) {
1480 var w = $cont.css('overflow','visible').width();
1481 var h = $cont.height();
1482 opts.before.push(function(curr, next, opts) {
1483 $.fn.cycle.commonReset(curr,next,opts,true,true,true);
1484 // provide default toss settings if animOut not provided
1485 if (!opts.animOut.left && !opts.animOut.top)
1486 $.extend(opts.animOut, { left: w*2, top: -h/2, opacity: 0 });
1488 opts.animOut.opacity = 0;
1490 opts.cssBefore.left = 0;
1491 opts.cssBefore.top = 0;
1492 opts.animIn.left = 0;
1495 // wipe - clip animation
1496 $.fn.cycle.transitions.wipe = function($cont, $slides, opts) {
1497 var w = $cont.css('overflow','hidden').width();
1498 var h = $cont.height();
1499 opts.cssBefore = opts.cssBefore || {};
1502 if (/l2r/.test(opts.clip))
1503 clip = 'rect(0px 0px '+h+'px 0px)';
1504 else if (/r2l/.test(opts.clip))
1505 clip = 'rect(0px '+w+'px '+h+'px '+w+'px)';
1506 else if (/t2b/.test(opts.clip))
1507 clip = 'rect(0px '+w+'px 0px 0px)';
1508 else if (/b2t/.test(opts.clip))
1509 clip = 'rect('+h+'px '+w+'px '+h+'px 0px)';
1510 else if (/zoom/.test(opts.clip)) {
1511 var top = parseInt(h/2,10);
1512 var left = parseInt(w/2,10);
1513 clip = 'rect('+top+'px '+left+'px '+top+'px '+left+'px)';
1517 opts.cssBefore.clip = opts.cssBefore.clip || clip || 'rect(0px 0px 0px 0px)';
1519 var d = opts.cssBefore.clip.match(/(\d+)/g);
1520 var t = parseInt(d[0],10), r = parseInt(d[1],10), b = parseInt(d[2],10), l = parseInt(d[3],10);
1522 opts.before.push(function(curr, next, opts) {
1523 if (curr == next) return;
1524 var $curr = $(curr), $next = $(next);
1525 $.fn.cycle.commonReset(curr,next,opts,true,true,false);
1526 opts.cssAfter.display = 'block';
1528 var step = 1, count = parseInt((opts.speedIn / 13),10) - 1;
1530 var tt = t ? t - parseInt(step * (t/count),10) : 0;
1531 var ll = l ? l - parseInt(step * (l/count),10) : 0;
1532 var bb = b < h ? b + parseInt(step * ((h-b)/count || 1),10) : h;
1533 var rr = r < w ? r + parseInt(step * ((w-r)/count || 1),10) : w;
1534 $next.css({ clip: 'rect('+tt+'px '+rr+'px '+bb+'px '+ll+'px)' });
1535 (step++ <= count) ? setTimeout(f, 13) : $curr.css('display', 'none');
1538 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 });
1539 opts.animIn = { left: 0 };
1540 opts.animOut = { left: 0 };