Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / resources / jquery / jquery.cycle.all.js
1 /*!
2 * jQuery Cycle Plugin (with Transition Definitions)
3 * Examples and documentation at: http://jquery.malsup.com/cycle/
4 * Copyright (c) 2007-2010 M. Alsup
5 * Version: 2.9999 (13-NOV-2011)
6 * Dual licensed under the MIT and GPL licenses.
7 * http://jquery.malsup.com/license.html
8 * Requires: jQuery v1.3.2 or later
9 */
10 ;(function($, undefined) {
11
12 var ver = '2.9999';
13
14 // if $.support is not defined (pre jQuery 1.3) add what I need
15 if ($.support == undefined) {
16 $.support = {
17 opacity: !($.browser.msie)
18 };
19 }
20
21 function debug(s) {
22 $.fn.cycle.debug && log(s);
23 }
24 function log() {
25 window.console && console.log && console.log('[cycle] ' + Array.prototype.join.call(arguments,' '));
26 }
27 $.expr[':'].paused = function(el) {
28 return el.cyclePause;
29 }
30
31
32 // the options arg can be...
33 // a number - indicates an immediate transition should occur to the given slide index
34 // a string - 'pause', 'resume', 'toggle', 'next', 'prev', 'stop', 'destroy' or the name of a transition effect (ie, 'fade', 'zoom', etc)
35 // an object - properties to control the slideshow
36 //
37 // the arg2 arg can be...
38 // the name of an fx (only used in conjunction with a numeric value for 'options')
39 // the value true (only used in first arg == 'resume') and indicates
40 // that the resume should occur immediately (not wait for next timeout)
41
42 $.fn.cycle = function(options, arg2) {
43 var o = { s: this.selector, c: this.context };
44
45 // in 1.3+ we can fix mistakes with the ready state
46 if (this.length === 0 && options != 'stop') {
47 if (!$.isReady && o.s) {
48 log('DOM not ready, queuing slideshow');
49 $(function() {
50 $(o.s,o.c).cycle(options,arg2);
51 });
52 return this;
53 }
54 // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
55 log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
56 return this;
57 }
58
59 // iterate the matched nodeset
60 return this.each(function() {
61 var opts = handleArguments(this, options, arg2);
62 if (opts === false)
63 return;
64
65 opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink;
66
67 // stop existing slideshow for this container (if there is one)
68 if (this.cycleTimeout)
69 clearTimeout(this.cycleTimeout);
70 this.cycleTimeout = this.cyclePause = 0;
71
72 var $cont = $(this);
73 var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children();
74 var els = $slides.get();
75
76 var opts2 = buildOptions($cont, $slides, els, opts, o);
77 if (opts2 === false)
78 return;
79
80 if (els.length < 2) {
81 log('terminating; too few slides: ' + els.length);
82 return;
83 }
84
85 var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.backwards);
86
87 // if it's an auto slideshow, kick it off
88 if (startTime) {
89 startTime += (opts2.delay || 0);
90 if (startTime < 10)
91 startTime = 10;
92 debug('first timeout: ' + startTime);
93 this.cycleTimeout = setTimeout(function(){go(els,opts2,0,!opts.backwards)}, startTime);
94 }
95 });
96 };
97
98 function triggerPause(cont, byHover, onPager) {
99 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);
105 }
106
107 // process the args that were passed to the plugin fn
108 function handleArguments(cont, options, arg2) {
109 if (cont.cycleStop == undefined)
110 cont.cycleStop = 0;
111 if (options === undefined || options === null)
112 options = {};
113 if (options.constructor == String) {
114 switch(options) {
115 case 'destroy':
116 case 'stop':
117 var opts = $(cont).data('cycle.opts');
118 if (!opts)
119 return false;
120 cont.cycleStop++; // callbacks look for change
121 if (cont.cycleTimeout)
122 clearTimeout(cont.cycleTimeout);
123 cont.cycleTimeout = 0;
124 opts.elements && $(opts.elements).stop();
125 $(cont).removeData('cycle.opts');
126 if (options == 'destroy')
127 destroy(opts);
128 return false;
129 case 'toggle':
130 cont.cyclePause = (cont.cyclePause === 1) ? 0 : 1;
131 checkInstantResume(cont.cyclePause, arg2, cont);
132 triggerPause(cont);
133 return false;
134 case 'pause':
135 cont.cyclePause = 1;
136 triggerPause(cont);
137 return false;
138 case 'resume':
139 cont.cyclePause = 0;
140 checkInstantResume(false, arg2, cont);
141 triggerPause(cont);
142 return false;
143 case 'prev':
144 case 'next':
145 var opts = $(cont).data('cycle.opts');
146 if (!opts) {
147 log('options not found, "prev/next" ignored');
148 return false;
149 }
150 $.fn.cycle[options](opts);
151 return false;
152 default:
153 options = { fx: options };
154 };
155 return options;
156 }
157 else if (options.constructor == Number) {
158 // go to the requested slide
159 var num = options;
160 options = $(cont).data('cycle.opts');
161 if (!options) {
162 log('options not found, can not advance slide');
163 return false;
164 }
165 if (num < 0 || num >= options.elements.length) {
166 log('invalid slide index: ' + num);
167 return false;
168 }
169 options.nextSlide = num;
170 if (cont.cycleTimeout) {
171 clearTimeout(cont.cycleTimeout);
172 cont.cycleTimeout = 0;
173 }
174 if (typeof arg2 == 'string')
175 options.oneTimeFx = arg2;
176 go(options.elements, options, 1, num >= options.currSlide);
177 return false;
178 }
179 return options;
180
181 function checkInstantResume(isPaused, arg2, cont) {
182 if (!isPaused && arg2 === true) { // resume now!
183 var options = $(cont).data('cycle.opts');
184 if (!options) {
185 log('options not found, can not resume');
186 return false;
187 }
188 if (cont.cycleTimeout) {
189 clearTimeout(cont.cycleTimeout);
190 cont.cycleTimeout = 0;
191 }
192 go(options.elements, options, 1, !options.backwards);
193 }
194 }
195 };
196
197 function removeFilter(el, opts) {
198 if (!$.support.opacity && opts.cleartype && el.style.filter) {
199 try { el.style.removeAttribute('filter'); }
200 catch(smother) {} // handle old opera versions
201 }
202 };
203
204 // unbind event handlers
205 function destroy(opts) {
206 if (opts.next)
207 $(opts.next).unbind(opts.prevNextEvent);
208 if (opts.prev)
209 $(opts.prev).unbind(opts.prevNextEvent);
210
211 if (opts.pager || opts.pagerAnchorBuilder)
212 $.each(opts.pagerAnchors || [], function() {
213 this.unbind().remove();
214 });
215 opts.pagerAnchors = null;
216 if (opts.destroy) // callback
217 opts.destroy(opts);
218 };
219
220 // one-time initialization
221 function buildOptions($cont, $slides, els, options, o) {
222 var startingSlideSpecified;
223 // support metadata plugin (v1.0 and v2.0)
224 var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
225 var meta = $.isFunction($cont.data) ? $cont.data(opts.metaAttr) : null;
226 if (meta)
227 opts = $.extend(opts, meta);
228 if (opts.autostop)
229 opts.countdown = opts.autostopCount || els.length;
230
231 var cont = $cont[0];
232 $cont.data('cycle.opts', opts);
233 opts.$cont = $cont;
234 opts.stopCount = cont.cycleStop;
235 opts.elements = els;
236 opts.before = opts.before ? [opts.before] : [];
237 opts.after = opts.after ? [opts.after] : [];
238
239 // push some after callbacks
240 if (!$.support.opacity && opts.cleartype)
241 opts.after.push(function() { removeFilter(this, opts); });
242 if (opts.continuous)
243 opts.after.push(function() { go(els,opts,0,!opts.backwards); });
244
245 saveOriginalOpts(opts);
246
247 // clearType corrections
248 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg)
249 clearTypeFix($slides);
250
251 // container requires non-static position so that slides can be position within
252 if ($cont.css('position') == 'static')
253 $cont.css('position', 'relative');
254 if (opts.width)
255 $cont.width(opts.width);
256 if (opts.height && opts.height != 'auto')
257 $cont.height(opts.height);
258
259 if (opts.startingSlide != undefined) {
260 opts.startingSlide = parseInt(opts.startingSlide,10);
261 if (opts.startingSlide >= els.length || opts.startSlide < 0)
262 opts.startingSlide = 0; // catch bogus input
263 else
264 startingSlideSpecified = true;
265 }
266 else if (opts.backwards)
267 opts.startingSlide = els.length - 1;
268 else
269 opts.startingSlide = 0;
270
271 // if random, mix up the slide array
272 if (opts.random) {
273 opts.randomMap = [];
274 for (var i = 0; i < els.length; i++)
275 opts.randomMap.push(i);
276 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
277 if (startingSlideSpecified) {
278 // try to find the specified starting slide and if found set start slide index in the map accordingly
279 for ( var cnt = 0; cnt < els.length; cnt++ ) {
280 if ( opts.startingSlide == opts.randomMap[cnt] ) {
281 opts.randomIndex = cnt;
282 }
283 }
284 }
285 else {
286 opts.randomIndex = 1;
287 opts.startingSlide = opts.randomMap[1];
288 }
289 }
290 else if (opts.startingSlide >= els.length)
291 opts.startingSlide = 0; // catch bogus input
292 opts.currSlide = opts.startingSlide || 0;
293 var first = opts.startingSlide;
294
295 // set position and zIndex on all the slides
296 $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) {
297 var z;
298 if (opts.backwards)
299 z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i;
300 else
301 z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i;
302 $(this).css('z-index', z)
303 });
304
305 // make sure first slide is visible
306 $(els[first]).css('opacity',1).show(); // opacity bit needed to handle restart use case
307 removeFilter(els[first], opts);
308
309 // stretch slides
310 if (opts.fit) {
311 if (!opts.aspect) {
312 if (opts.width)
313 $slides.width(opts.width);
314 if (opts.height && opts.height != 'auto')
315 $slides.height(opts.height);
316 } else {
317 $slides.each(function(){
318 var $slide = $(this);
319 var ratio = (opts.aspect === true) ? $slide.width()/$slide.height() : opts.aspect;
320 if( opts.width && $slide.width() != opts.width ) {
321 $slide.width( opts.width );
322 $slide.height( opts.width / ratio );
323 }
324
325 if( opts.height && $slide.height() < opts.height ) {
326 $slide.height( opts.height );
327 $slide.width( opts.height * ratio );
328 }
329 });
330 }
331 }
332
333 if (opts.center && ((!opts.fit) || opts.aspect)) {
334 $slides.each(function(){
335 var $slide = $(this);
336 $slide.css({
337 "margin-left": opts.width ?
338 ((opts.width - $slide.width()) / 2) + "px" :
339 0,
340 "margin-top": opts.height ?
341 ((opts.height - $slide.height()) / 2) + "px" :
342 0
343 });
344 });
345 }
346
347 if (opts.center && !opts.fit && !opts.slideResize) {
348 $slides.each(function(){
349 var $slide = $(this);
350 $slide.css({
351 "margin-left": opts.width ? ((opts.width - $slide.width()) / 2) + "px" : 0,
352 "margin-top": opts.height ? ((opts.height - $slide.height()) / 2) + "px" : 0
353 });
354 });
355 }
356
357 // stretch container
358 var reshape = opts.containerResize && !$cont.innerHeight();
359 if (reshape) { // do this only if container has no size http://tinyurl.com/da2oa9
360 var maxw = 0, maxh = 0;
361 for(var j=0; j < els.length; j++) {
362 var $e = $(els[j]), e = $e[0], w = $e.outerWidth(), h = $e.outerHeight();
363 if (!w) w = e.offsetWidth || e.width || $e.attr('width');
364 if (!h) h = e.offsetHeight || e.height || $e.attr('height');
365 maxw = w > maxw ? w : maxw;
366 maxh = h > maxh ? h : maxh;
367 }
368 if (maxw > 0 && maxh > 0)
369 $cont.css({width:maxw+'px',height:maxh+'px'});
370 }
371
372 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44
373 if (opts.pause)
374 $cont.hover(
375 function(){
376 pauseFlag = true;
377 this.cyclePause++;
378 triggerPause(cont, true);
379 },
380 function(){
381 pauseFlag && this.cyclePause--;
382 triggerPause(cont, true);
383 }
384 );
385
386 if (supportMultiTransitions(opts) === false)
387 return false;
388
389 // apparently a lot of people use image slideshows without height/width attributes on the images.
390 // Cycle 2.50+ requires the sizing info for every slide; this block tries to deal with that.
391 var requeue = false;
392 options.requeueAttempts = options.requeueAttempts || 0;
393 $slides.each(function() {
394 // try to get height/width of each slide
395 var $el = $(this);
396 this.cycleH = (opts.fit && opts.height) ? opts.height : ($el.height() || this.offsetHeight || this.height || $el.attr('height') || 0);
397 this.cycleW = (opts.fit && opts.width) ? opts.width : ($el.width() || this.offsetWidth || this.width || $el.attr('width') || 0);
398
399 if ( $el.is('img') ) {
400 // sigh.. sniffing, hacking, shrugging... this crappy hack tries to account for what browsers do when
401 // an image is being downloaded and the markup did not include sizing info (height/width attributes);
402 // there seems to be some "default" sizes used in this situation
403 var loadingIE = ($.browser.msie && this.cycleW == 28 && this.cycleH == 30 && !this.complete);
404 var loadingFF = ($.browser.mozilla && this.cycleW == 34 && this.cycleH == 19 && !this.complete);
405 var loadingOp = ($.browser.opera && ((this.cycleW == 42 && this.cycleH == 19) || (this.cycleW == 37 && this.cycleH == 17)) && !this.complete);
406 var loadingOther = (this.cycleH == 0 && this.cycleW == 0 && !this.complete);
407 // don't requeue for images that are still loading but have a valid size
408 if (loadingIE || loadingFF || loadingOp || loadingOther) {
409 if (o.s && opts.requeueOnImageNotLoaded && ++options.requeueAttempts < 100) { // track retry count so we don't loop forever
410 log(options.requeueAttempts,' - img slide not loaded, requeuing slideshow: ', this.src, this.cycleW, this.cycleH);
411 setTimeout(function() {$(o.s,o.c).cycle(options)}, opts.requeueTimeout);
412 requeue = true;
413 return false; // break each loop
414 }
415 else {
416 log('could not determine size of image: '+this.src, this.cycleW, this.cycleH);
417 }
418 }
419 }
420 return true;
421 });
422
423 if (requeue)
424 return false;
425
426 opts.cssBefore = opts.cssBefore || {};
427 opts.cssAfter = opts.cssAfter || {};
428 opts.cssFirst = opts.cssFirst || {};
429 opts.animIn = opts.animIn || {};
430 opts.animOut = opts.animOut || {};
431
432 $slides.not(':eq('+first+')').css(opts.cssBefore);
433 $($slides[first]).css(opts.cssFirst);
434
435 if (opts.timeout) {
436 opts.timeout = parseInt(opts.timeout,10);
437 // ensure that timeout and speed settings are sane
438 if (opts.speed.constructor == String)
439 opts.speed = $.fx.speeds[opts.speed] || parseInt(opts.speed,10);
440 if (!opts.sync)
441 opts.speed = opts.speed / 2;
442
443 var buffer = opts.fx == 'none' ? 0 : opts.fx == 'shuffle' ? 500 : 250;
444 while((opts.timeout - opts.speed) < buffer) // sanitize timeout
445 opts.timeout += opts.speed;
446 }
447 if (opts.easing)
448 opts.easeIn = opts.easeOut = opts.easing;
449 if (!opts.speedIn)
450 opts.speedIn = opts.speed;
451 if (!opts.speedOut)
452 opts.speedOut = opts.speed;
453
454 opts.slideCount = els.length;
455 opts.currSlide = opts.lastSlide = first;
456 if (opts.random) {
457 if (++opts.randomIndex == els.length)
458 opts.randomIndex = 0;
459 opts.nextSlide = opts.randomMap[opts.randomIndex];
460 }
461 else if (opts.backwards)
462 opts.nextSlide = opts.startingSlide == 0 ? (els.length-1) : opts.startingSlide-1;
463 else
464 opts.nextSlide = opts.startingSlide >= (els.length-1) ? 0 : opts.startingSlide+1;
465
466 // run transition init fn
467 if (!opts.multiFx) {
468 var init = $.fn.cycle.transitions[opts.fx];
469 if ($.isFunction(init))
470 init($cont, $slides, opts);
471 else if (opts.fx != 'custom' && !opts.multiFx) {
472 log('unknown transition: ' + opts.fx,'; slideshow terminating');
473 return false;
474 }
475 }
476
477 // fire artificial events
478 var e0 = $slides[first];
479 if (!opts.skipInitializationCallbacks) {
480 if (opts.before.length)
481 opts.before[0].apply(e0, [e0, e0, opts, true]);
482 if (opts.after.length)
483 opts.after[0].apply(e0, [e0, e0, opts, true]);
484 }
485 if (opts.next)
486 $(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,1)});
487 if (opts.prev)
488 $(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,0)});
489 if (opts.pager || opts.pagerAnchorBuilder)
490 buildPager(els,opts);
491
492 exposeAddSlide(opts, els);
493
494 return opts;
495 };
496
497 // save off original opts so we can restore after clearing state
498 function saveOriginalOpts(opts) {
499 opts.original = { before: [], after: [] };
500 opts.original.cssBefore = $.extend({}, opts.cssBefore);
501 opts.original.cssAfter = $.extend({}, opts.cssAfter);
502 opts.original.animIn = $.extend({}, opts.animIn);
503 opts.original.animOut = $.extend({}, opts.animOut);
504 $.each(opts.before, function() { opts.original.before.push(this); });
505 $.each(opts.after, function() { opts.original.after.push(this); });
506 };
507
508 function supportMultiTransitions(opts) {
509 var i, tx, txs = $.fn.cycle.transitions;
510 // look for multiple effects
511 if (opts.fx.indexOf(',') > 0) {
512 opts.multiFx = true;
513 opts.fxs = opts.fx.replace(/\s*/g,'').split(',');
514 // discard any bogus effect names
515 for (i=0; i < opts.fxs.length; i++) {
516 var fx = opts.fxs[i];
517 tx = txs[fx];
518 if (!tx || !txs.hasOwnProperty(fx) || !$.isFunction(tx)) {
519 log('discarding unknown transition: ',fx);
520 opts.fxs.splice(i,1);
521 i--;
522 }
523 }
524 // if we have an empty list then we threw everything away!
525 if (!opts.fxs.length) {
526 log('No valid transitions named; slideshow terminating.');
527 return false;
528 }
529 }
530 else if (opts.fx == 'all') { // auto-gen the list of transitions
531 opts.multiFx = true;
532 opts.fxs = [];
533 for (p in txs) {
534 tx = txs[p];
535 if (txs.hasOwnProperty(p) && $.isFunction(tx))
536 opts.fxs.push(p);
537 }
538 }
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]);
545 }
546 debug('randomized fx sequence: ',opts.fxs);
547 }
548 return true;
549 };
550
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)
556 opts.countdown++;
557 els[prepend?'unshift':'push'](s);
558 if (opts.els)
559 opts.els[prepend?'unshift':'push'](s); // shuffle needs this
560 opts.slideCount = els.length;
561
562 // add the slide to the random map and resort
563 if (opts.random) {
564 opts.randomMap.push(opts.slideCount-1);
565 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
566 }
567
568 $s.css('position','absolute');
569 $s[prepend?'prependTo':'appendTo'](opts.$cont);
570
571 if (prepend) {
572 opts.currSlide++;
573 opts.nextSlide++;
574 }
575
576 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg)
577 clearTypeFix($s);
578
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();
585
586 $s.css(opts.cssBefore);
587
588 if (opts.pager || opts.pagerAnchorBuilder)
589 $.fn.cycle.createPagerAnchor(els.length-1, s, $(opts.pager), els, opts);
590
591 if ($.isFunction(opts.onAddSlide))
592 opts.onAddSlide($s);
593 else
594 $s.hide(); // default behavior
595 };
596 }
597
598 // reset internal state; we do this on every pass in order to support multiple effects
599 $.fn.cycle.resetState = function(opts, fx) {
600 fx = fx || 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);
606 opts.fxFn = null;
607 $.each(opts.original.before, function() { opts.before.push(this); });
608 $.each(opts.original.after, function() { opts.after.push(this); });
609
610 // re-init
611 var init = $.fn.cycle.transitions[fx];
612 if ($.isFunction(init))
613 init(opts.$cont, $(opts.elements), opts);
614 };
615
616 // this is the main engine fn, it handles the timeouts, callbacks and slide index mgmt
617 function go(els, opts, manual, fwd) {
618 // opts.busy is true if we're in the middle of an animation
619 if (manual && opts.busy && opts.manualTrump) {
620 // let manual transitions requests trump active ones
621 debug('manualTrump in go(), stopping active transition');
622 $(els).stop(true,true);
623 opts.busy = 0;
624 }
625 // don't begin another timeout-based transition if there is one active
626 if (opts.busy) {
627 debug('transition active, ignoring new tx request');
628 return;
629 }
630
631 var p = opts.$cont[0], curr = els[opts.currSlide], next = els[opts.nextSlide];
632
633 // stop cycling if we have an outstanding stop request
634 if (p.cycleStop != opts.stopCount || p.cycleTimeout === 0 && !manual)
635 return;
636
637 // check to see if we should stop cycling based on autostop options
638 if (!manual && !p.cyclePause && !opts.bounce &&
639 ((opts.autostop && (--opts.countdown <= 0)) ||
640 (opts.nowrap && !opts.random && opts.nextSlide < opts.currSlide))) {
641 if (opts.end)
642 opts.end(opts);
643 return;
644 }
645
646 // if slideshow is paused, only transition on a manual trigger
647 var changed = false;
648 if ((manual || !p.cyclePause) && (opts.nextSlide != opts.currSlide)) {
649 changed = true;
650 var fx = opts.fx;
651 // keep trying to get the slide size if we don't have it yet
652 curr.cycleH = curr.cycleH || $(curr).height();
653 curr.cycleW = curr.cycleW || $(curr).width();
654 next.cycleH = next.cycleH || $(next).height();
655 next.cycleW = next.cycleW || $(next).width();
656
657 // support multiple transition types
658 if (opts.multiFx) {
659 if (fwd && (opts.lastFx == undefined || ++opts.lastFx >= opts.fxs.length))
660 opts.lastFx = 0;
661 else if (!fwd && (opts.lastFx == undefined || --opts.lastFx < 0))
662 opts.lastFx = opts.fxs.length - 1;
663 fx = opts.fxs[opts.lastFx];
664 }
665
666 // one-time fx overrides apply to: $('div').cycle(3,'zoom');
667 if (opts.oneTimeFx) {
668 fx = opts.oneTimeFx;
669 opts.oneTimeFx = null;
670 }
671
672 $.fn.cycle.resetState(opts, fx);
673
674 // run the before callbacks
675 if (opts.before.length)
676 $.each(opts.before, function(i,o) {
677 if (p.cycleStop != opts.stopCount) return;
678 o.apply(next, [curr, next, opts, fwd]);
679 });
680
681 // stage the after callacks
682 var after = function() {
683 opts.busy = 0;
684 $.each(opts.after, function(i,o) {
685 if (p.cycleStop != opts.stopCount) return;
686 o.apply(next, [curr, next, opts, fwd]);
687 });
688 if (!p.cycleStop) {
689 // queue next transition
690 queueNext();
691 }
692 };
693
694 debug('tx firing('+fx+'); currSlide: ' + opts.currSlide + '; nextSlide: ' + opts.nextSlide);
695
696 // get ready to perform the transition
697 opts.busy = 1;
698 if (opts.fxFn) // fx function provided?
699 opts.fxFn(curr, next, opts, after, fwd, manual && opts.fastOnEvent);
700 else if ($.isFunction($.fn.cycle[opts.fx])) // fx plugin ?
701 $.fn.cycle[opts.fx](curr, next, opts, after, fwd, manual && opts.fastOnEvent);
702 else
703 $.fn.cycle.custom(curr, next, opts, after, fwd, manual && opts.fastOnEvent);
704 }
705 else {
706 queueNext();
707 }
708
709 if (changed || opts.nextSlide == opts.currSlide) {
710 // calculate the next slide
711 opts.lastSlide = opts.currSlide;
712 if (opts.random) {
713 opts.currSlide = opts.nextSlide;
714 if (++opts.randomIndex == els.length) {
715 opts.randomIndex = 0;
716 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
717 }
718 opts.nextSlide = opts.randomMap[opts.randomIndex];
719 if (opts.nextSlide == opts.currSlide)
720 opts.nextSlide = (opts.currSlide == opts.slideCount - 1) ? 0 : opts.currSlide + 1;
721 }
722 else if (opts.backwards) {
723 var roll = (opts.nextSlide - 1) < 0;
724 if (roll && opts.bounce) {
725 opts.backwards = !opts.backwards;
726 opts.nextSlide = 1;
727 opts.currSlide = 0;
728 }
729 else {
730 opts.nextSlide = roll ? (els.length-1) : opts.nextSlide-1;
731 opts.currSlide = roll ? 0 : opts.nextSlide+1;
732 }
733 }
734 else { // sequence
735 var roll = (opts.nextSlide + 1) == els.length;
736 if (roll && opts.bounce) {
737 opts.backwards = !opts.backwards;
738 opts.nextSlide = els.length-2;
739 opts.currSlide = els.length-1;
740 }
741 else {
742 opts.nextSlide = roll ? 0 : opts.nextSlide+1;
743 opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
744 }
745 }
746 }
747 if (changed && opts.pager)
748 opts.updateActivePagerLink(opts.pager, opts.currSlide, opts.activePagerClass);
749
750 function queueNext() {
751 // stage the next transition
752 var ms = 0, timeout = opts.timeout;
753 if (opts.timeout && !opts.continuous) {
754 ms = getTimeout(els[opts.currSlide], els[opts.nextSlide], opts, fwd);
755 if (opts.fx == 'shuffle')
756 ms -= opts.speedOut;
757 }
758 else if (opts.continuous && p.cyclePause) // continuous shows work off an after callback, not this timer logic
759 ms = 10;
760 if (ms > 0)
761 p.cycleTimeout = setTimeout(function(){ go(els, opts, 0, !opts.backwards) }, ms);
762 }
763 };
764
765 // invoked after transition
766 $.fn.cycle.updateActivePagerLink = function(pager, currSlide, clsName) {
767 $(pager).each(function() {
768 $(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);
769 });
770 };
771
772 // calculate timeout value for current transition
773 function getTimeout(curr, next, opts, fwd) {
774 if (opts.timeoutFn) {
775 // call user provided calc fn
776 var t = opts.timeoutFn.call(curr,curr,next,opts,fwd);
777 while (opts.fx != 'none' && (t - opts.speed) < 250) // sanitize timeout
778 t += opts.speed;
779 debug('calculated timeout: ' + t + '; speed: ' + opts.speed);
780 if (t !== false)
781 return t;
782 }
783 return opts.timeout;
784 };
785
786 // expose next/prev function, caller must pass in state
787 $.fn.cycle.next = function(opts) { advance(opts,1); };
788 $.fn.cycle.prev = function(opts) { advance(opts,0);};
789
790 // advance slide forward or back
791 function advance(opts, moveForward) {
792 var val = moveForward ? 1 : -1;
793 var els = opts.elements;
794 var p = opts.$cont[0], timeout = p.cycleTimeout;
795 if (timeout) {
796 clearTimeout(timeout);
797 p.cycleTimeout = 0;
798 }
799 if (opts.random && val < 0) {
800 // move back to the previously display slide
801 opts.randomIndex--;
802 if (--opts.randomIndex == -2)
803 opts.randomIndex = els.length-2;
804 else if (opts.randomIndex == -1)
805 opts.randomIndex = els.length-1;
806 opts.nextSlide = opts.randomMap[opts.randomIndex];
807 }
808 else if (opts.random) {
809 opts.nextSlide = opts.randomMap[opts.randomIndex];
810 }
811 else {
812 opts.nextSlide = opts.currSlide + val;
813 if (opts.nextSlide < 0) {
814 if (opts.nowrap) return false;
815 opts.nextSlide = els.length - 1;
816 }
817 else if (opts.nextSlide >= els.length) {
818 if (opts.nowrap) return false;
819 opts.nextSlide = 0;
820 }
821 }
822
823 var cb = opts.onPrevNextEvent || opts.prevNextClick; // prevNextClick is deprecated
824 if ($.isFunction(cb))
825 cb(val > 0, opts.nextSlide, els[opts.nextSlide]);
826 go(els, opts, 1, moveForward);
827 return false;
828 };
829
830 function buildPager(els, opts) {
831 var $p = $(opts.pager);
832 $.each(els, function(i,o) {
833 $.fn.cycle.createPagerAnchor(i,o,$p,els,opts);
834 });
835 opts.updateActivePagerLink(opts.pager, opts.startingSlide, opts.activePagerClass);
836 };
837
838 $.fn.cycle.createPagerAnchor = function(i, el, $p, els, opts) {
839 var a;
840 if ($.isFunction(opts.pagerAnchorBuilder)) {
841 a = opts.pagerAnchorBuilder(i,el);
842 debug('pagerAnchorBuilder('+i+', el) returned: ' + a);
843 }
844 else
845 a = '<a href="#">'+(i+1)+'</a>';
846
847 if (!a)
848 return;
849 var $a = $(a);
850 // don't reparent if anchor is in the dom
851 if ($a.parents('body').length === 0) {
852 var arr = [];
853 if ($p.length > 1) {
854 $p.each(function() {
855 var $clone = $a.clone(true);
856 $(this).append($clone);
857 arr.push($clone[0]);
858 });
859 $a = $(arr);
860 }
861 else {
862 $a.appendTo($p);
863 }
864 }
865
866 opts.pagerAnchors = opts.pagerAnchors || [];
867 opts.pagerAnchors.push($a);
868
869 var pagerFn = function(e) {
870 e.preventDefault();
871 opts.nextSlide = i;
872 var p = opts.$cont[0], timeout = p.cycleTimeout;
873 if (timeout) {
874 clearTimeout(timeout);
875 p.cycleTimeout = 0;
876 }
877 var cb = opts.onPagerEvent || opts.pagerClick; // pagerClick is deprecated
878 if ($.isFunction(cb))
879 cb(opts.nextSlide, els[opts.nextSlide]);
880 go(els,opts,1,opts.currSlide < i); // trigger the trans
881 // return false; // <== allow bubble
882 }
883
884 if ( /mouseenter|mouseover/i.test(opts.pagerEvent) ) {
885 $a.hover(pagerFn, function(){/* no-op */} );
886 }
887 else {
888 $a.bind(opts.pagerEvent, pagerFn);
889 }
890
891 if ( ! /^click/.test(opts.pagerEvent) && !opts.allowPagerClickBubble)
892 $a.bind('click.cycle', function(){return false;}); // suppress click
893
894 var cont = opts.$cont[0];
895 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44
896 if (opts.pauseOnPagerHover) {
897 $a.hover(
898 function() {
899 pauseFlag = true;
900 cont.cyclePause++;
901 triggerPause(cont,true,true);
902 }, function() {
903 pauseFlag && cont.cyclePause--;
904 triggerPause(cont,true,true);
905 }
906 );
907 }
908 };
909
910 // helper fn to calculate the number of slides between the current and the next
911 $.fn.cycle.hopsFromLast = function(opts, fwd) {
912 var hops, l = opts.lastSlide, c = opts.currSlide;
913 if (fwd)
914 hops = c > l ? c - l : opts.slideCount - l;
915 else
916 hops = c < l ? l - c : l + opts.slideCount - c;
917 return hops;
918 };
919
920 // fix clearType problems in ie6 by setting an explicit bg color
921 // (otherwise text slides look horrible during a fade transition)
922 function clearTypeFix($slides) {
923 debug('applying clearType background-color hack');
924 function hex(s) {
925 s = parseInt(s,10).toString(16);
926 return s.length < 2 ? '0'+s : s;
927 };
928 function getBg(e) {
929 for ( ; e && e.nodeName.toLowerCase() != 'html'; e = e.parentNode) {
930 var v = $.css(e,'background-color');
931 if (v && v.indexOf('rgb') >= 0 ) {
932 var rgb = v.match(/\d+/g);
933 return '#'+ hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
934 }
935 if (v && v != 'transparent')
936 return v;
937 }
938 return '#ffffff';
939 };
940 $slides.each(function() { $(this).css('background-color', getBg(this)); });
941 };
942
943 // reset common props before the next transition
944 $.fn.cycle.commonReset = function(curr,next,opts,w,h,rev) {
945 $(opts.elements).not(curr).hide();
946 if (typeof opts.cssBefore.opacity == 'undefined')
947 opts.cssBefore.opacity = 1;
948 opts.cssBefore.display = 'block';
949 if (opts.slideResize && w !== false && next.cycleW > 0)
950 opts.cssBefore.width = next.cycleW;
951 if (opts.slideResize && h !== false && next.cycleH > 0)
952 opts.cssBefore.height = next.cycleH;
953 opts.cssAfter = opts.cssAfter || {};
954 opts.cssAfter.display = 'none';
955 $(curr).css('zIndex',opts.slideCount + (rev === true ? 1 : 0));
956 $(next).css('zIndex',opts.slideCount + (rev === true ? 0 : 1));
957 };
958
959 // the actual fn for effecting a transition
960 $.fn.cycle.custom = function(curr, next, opts, cb, fwd, speedOverride) {
961 var $l = $(curr), $n = $(next);
962 var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut;
963 $n.css(opts.cssBefore);
964 if (speedOverride) {
965 if (typeof speedOverride == 'number')
966 speedIn = speedOut = speedOverride;
967 else
968 speedIn = speedOut = 1;
969 easeIn = easeOut = null;
970 }
971 var fn = function() {
972 $n.animate(opts.animIn, speedIn, easeIn, function() {
973 cb();
974 });
975 };
976 $l.animate(opts.animOut, speedOut, easeOut, function() {
977 $l.css(opts.cssAfter);
978 if (!opts.sync)
979 fn();
980 });
981 if (opts.sync) fn();
982 };
983
984 // transition definitions - only fade is defined here, transition pack defines the rest
985 $.fn.cycle.transitions = {
986 fade: function($cont, $slides, opts) {
987 $slides.not(':eq('+opts.currSlide+')').css('opacity',0);
988 opts.before.push(function(curr,next,opts) {
989 $.fn.cycle.commonReset(curr,next,opts);
990 opts.cssBefore.opacity = 0;
991 });
992 opts.animIn = { opacity: 1 };
993 opts.animOut = { opacity: 0 };
994 opts.cssBefore = { top: 0, left: 0 };
995 }
996 };
997
998 $.fn.cycle.ver = function() { return ver; };
999
1000 // override these globally if you like (they are all optional)
1001 $.fn.cycle.defaults = {
1002 activePagerClass: 'activeSlide', // class name used for the active pager link
1003 after: null, // transition callback (scope set to element that was shown): function(currSlideElement, nextSlideElement, options, forwardFlag)
1004 allowPagerClickBubble: false, // allows or prevents click event on pager anchors from bubbling
1005 animIn: null, // properties that define how the slide animates in
1006 animOut: null, // properties that define how the slide animates out
1007 aspect: false, // preserve aspect ratio during fit resizing, cropping if necessary (must be used with fit option)
1008 autostop: 0, // true to end slideshow after X transitions (where X == slide count)
1009 autostopCount: 0, // number of transitions (optionally used with autostop to define X)
1010 backwards: false, // true to start slideshow at last slide and move backwards through the stack
1011 before: null, // transition callback (scope set to element to be shown): function(currSlideElement, nextSlideElement, options, forwardFlag)
1012 center: null, // set to true to have cycle add top/left margin to each slide (use with width and height options)
1013 cleartype: !$.support.opacity, // true if clearType corrections should be applied (for IE)
1014 cleartypeNoBg: false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
1015 containerResize: 1, // resize container to fit largest slide
1016 continuous: 0, // true to start next transition immediately after current one completes
1017 cssAfter: null, // properties that defined the state of the slide after transitioning out
1018 cssBefore: null, // properties that define the initial state of the slide before transitioning in
1019 delay: 0, // additional delay (in ms) for first transition (hint: can be negative)
1020 easeIn: null, // easing for "in" transition
1021 easeOut: null, // easing for "out" transition
1022 easing: null, // easing method for both in and out transitions
1023 end: null, // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options)
1024 fastOnEvent: 0, // force fast transitions when triggered manually (via pager or prev/next); value == time in ms
1025 fit: 0, // force slides to fit container
1026 fx: 'fade', // name of transition effect (or comma separated names, ex: 'fade,scrollUp,shuffle')
1027 fxFn: null, // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag)
1028 height: 'auto', // container height (if the 'fit' option is true, the slides will be set to this height as well)
1029 manualTrump: true, // causes manual transition to stop an active transition instead of being ignored
1030 metaAttr: 'cycle',// data- attribute that holds the option data for the slideshow
1031 next: null, // element, jQuery object, or jQuery selector string for the element to use as event trigger for next slide
1032 nowrap: 0, // true to prevent slideshow from wrapping
1033 onPagerEvent: null, // callback fn for pager events: function(zeroBasedSlideIndex, slideElement)
1034 onPrevNextEvent: null,// callback fn for prev/next events: function(isNext, zeroBasedSlideIndex, slideElement)
1035 pager: null, // element, jQuery object, or jQuery selector string for the element to use as pager container
1036 pagerAnchorBuilder: null, // callback fn for building anchor links: function(index, DOMelement)
1037 pagerEvent: 'click.cycle', // name of event which drives the pager navigation
1038 pause: 0, // true to enable "pause on hover"
1039 pauseOnPagerHover: 0, // true to pause when hovering over pager link
1040 prev: null, // element, jQuery object, or jQuery selector string for the element to use as event trigger for previous slide
1041 prevNextEvent:'click.cycle',// event which drives the manual transition to the previous or next slide
1042 random: 0, // true for random, false for sequence (not applicable to shuffle fx)
1043 randomizeEffects: 1, // valid when multiple effects are used; true to make the effect sequence random
1044 requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded
1045 requeueTimeout: 250, // ms delay for requeue
1046 rev: 0, // causes animations to transition in reverse (for effects that support it such as scrollHorz/scrollVert/shuffle)
1047 shuffle: null, // coords for shuffle animation, ex: { top:15, left: 200 }
1048 skipInitializationCallbacks: false, // set to true to disable the first before/after callback that occurs prior to any transition
1049 slideExpr: null, // expression for selecting slides (if something other than all children is required)
1050 slideResize: 1, // force slide width/height to fixed size before every transition
1051 speed: 1000, // speed of the transition (any valid fx speed value)
1052 speedIn: null, // speed of the 'in' transition
1053 speedOut: null, // speed of the 'out' transition
1054 startingSlide: undefined, // zero-based index of the first slide to be displayed
1055 sync: 1, // true if in/out transitions should occur simultaneously
1056 timeout: 4000, // milliseconds between slide transitions (0 to disable auto advance)
1057 timeoutFn: null, // callback for determining per-slide timeout value: function(currSlideElement, nextSlideElement, options, forwardFlag)
1058 updateActivePagerLink: null, // callback fn invoked to update the active pager link (adds/removes activePagerClass style)
1059 width: null // container width (if the 'fit' option is true, the slides will be set to this width as well)
1060 };
1061
1062 })(jQuery);
1063
1064
1065 /*!
1066 * jQuery Cycle Plugin Transition Definitions
1067 * This script is a plugin for the jQuery Cycle Plugin
1068 * Examples and documentation at: http://malsup.com/jquery/cycle/
1069 * Copyright (c) 2007-2010 M. Alsup
1070 * Version: 2.73
1071 * Dual licensed under the MIT and GPL licenses:
1072 * http://www.opensource.org/licenses/mit-license.php
1073 * http://www.gnu.org/licenses/gpl.html
1074 */
1075 (function($) {
1076
1077 //
1078 // These functions define slide initialization and properties for the named
1079 // transitions. To save file size feel free to remove any of these that you
1080 // don't need.
1081 //
1082 $.fn.cycle.transitions.none = function($cont, $slides, opts) {
1083 opts.fxFn = function(curr,next,opts,after){
1084 $(next).show();
1085 $(curr).hide();
1086 after();
1087 };
1088 };
1089
1090 // not a cross-fade, fadeout only fades out the top slide
1091 $.fn.cycle.transitions.fadeout = function($cont, $slides, opts) {
1092 $slides.not(':eq('+opts.currSlide+')').css({ display: 'block', 'opacity': 1 });
1093 opts.before.push(function(curr,next,opts,w,h,rev) {
1094 $(curr).css('zIndex',opts.slideCount + (!rev === true ? 1 : 0));
1095 $(next).css('zIndex',opts.slideCount + (!rev === true ? 0 : 1));
1096 });
1097 opts.animIn.opacity = 1;
1098 opts.animOut.opacity = 0;
1099 opts.cssBefore.opacity = 1;
1100 opts.cssBefore.display = 'block';
1101 opts.cssAfter.zIndex = 0;
1102 };
1103
1104 // scrollUp/Down/Left/Right
1105 $.fn.cycle.transitions.scrollUp = function($cont, $slides, opts) {
1106 $cont.css('overflow','hidden');
1107 opts.before.push($.fn.cycle.commonReset);
1108 var h = $cont.height();
1109 opts.cssBefore.top = h;
1110 opts.cssBefore.left = 0;
1111 opts.cssFirst.top = 0;
1112 opts.animIn.top = 0;
1113 opts.animOut.top = -h;
1114 };
1115 $.fn.cycle.transitions.scrollDown = function($cont, $slides, opts) {
1116 $cont.css('overflow','hidden');
1117 opts.before.push($.fn.cycle.commonReset);
1118 var h = $cont.height();
1119 opts.cssFirst.top = 0;
1120 opts.cssBefore.top = -h;
1121 opts.cssBefore.left = 0;
1122 opts.animIn.top = 0;
1123 opts.animOut.top = h;
1124 };
1125 $.fn.cycle.transitions.scrollLeft = function($cont, $slides, opts) {
1126 $cont.css('overflow','hidden');
1127 opts.before.push($.fn.cycle.commonReset);
1128 var w = $cont.width();
1129 opts.cssFirst.left = 0;
1130 opts.cssBefore.left = w;
1131 opts.cssBefore.top = 0;
1132 opts.animIn.left = 0;
1133 opts.animOut.left = 0-w;
1134 };
1135 $.fn.cycle.transitions.scrollRight = function($cont, $slides, opts) {
1136 $cont.css('overflow','hidden');
1137 opts.before.push($.fn.cycle.commonReset);
1138 var w = $cont.width();
1139 opts.cssFirst.left = 0;
1140 opts.cssBefore.left = -w;
1141 opts.cssBefore.top = 0;
1142 opts.animIn.left = 0;
1143 opts.animOut.left = w;
1144 };
1145 $.fn.cycle.transitions.scrollHorz = function($cont, $slides, opts) {
1146 $cont.css('overflow','hidden').width();
1147 opts.before.push(function(curr, next, opts, fwd) {
1148 if (opts.rev)
1149 fwd = !fwd;
1150 $.fn.cycle.commonReset(curr,next,opts);
1151 opts.cssBefore.left = fwd ? (next.cycleW-1) : (1-next.cycleW);
1152 opts.animOut.left = fwd ? -curr.cycleW : curr.cycleW;
1153 });
1154 opts.cssFirst.left = 0;
1155 opts.cssBefore.top = 0;
1156 opts.animIn.left = 0;
1157 opts.animOut.top = 0;
1158 };
1159 $.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) {
1160 $cont.css('overflow','hidden');
1161 opts.before.push(function(curr, next, opts, fwd) {
1162 if (opts.rev)
1163 fwd = !fwd;
1164 $.fn.cycle.commonReset(curr,next,opts);
1165 opts.cssBefore.top = fwd ? (1-next.cycleH) : (next.cycleH-1);
1166 opts.animOut.top = fwd ? curr.cycleH : -curr.cycleH;
1167 });
1168 opts.cssFirst.top = 0;
1169 opts.cssBefore.left = 0;
1170 opts.animIn.top = 0;
1171 opts.animOut.left = 0;
1172 };
1173
1174 // slideX/slideY
1175 $.fn.cycle.transitions.slideX = function($cont, $slides, opts) {
1176 opts.before.push(function(curr, next, opts) {
1177 $(opts.elements).not(curr).hide();
1178 $.fn.cycle.commonReset(curr,next,opts,false,true);
1179 opts.animIn.width = next.cycleW;
1180 });
1181 opts.cssBefore.left = 0;
1182 opts.cssBefore.top = 0;
1183 opts.cssBefore.width = 0;
1184 opts.animIn.width = 'show';
1185 opts.animOut.width = 0;
1186 };
1187 $.fn.cycle.transitions.slideY = function($cont, $slides, opts) {
1188 opts.before.push(function(curr, next, opts) {
1189 $(opts.elements).not(curr).hide();
1190 $.fn.cycle.commonReset(curr,next,opts,true,false);
1191 opts.animIn.height = next.cycleH;
1192 });
1193 opts.cssBefore.left = 0;
1194 opts.cssBefore.top = 0;
1195 opts.cssBefore.height = 0;
1196 opts.animIn.height = 'show';
1197 opts.animOut.height = 0;
1198 };
1199
1200 // shuffle
1201 $.fn.cycle.transitions.shuffle = function($cont, $slides, opts) {
1202 var i, w = $cont.css('overflow', 'visible').width();
1203 $slides.css({left: 0, top: 0});
1204 opts.before.push(function(curr,next,opts) {
1205 $.fn.cycle.commonReset(curr,next,opts,true,true,true);
1206 });
1207 // only adjust speed once!
1208 if (!opts.speedAdjusted) {
1209 opts.speed = opts.speed / 2; // shuffle has 2 transitions
1210 opts.speedAdjusted = true;
1211 }
1212 opts.random = 0;
1213 opts.shuffle = opts.shuffle || {left:-w, top:15};
1214 opts.els = [];
1215 for (i=0; i < $slides.length; i++)
1216 opts.els.push($slides[i]);
1217
1218 for (i=0; i < opts.currSlide; i++)
1219 opts.els.push(opts.els.shift());
1220
1221 // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!)
1222 opts.fxFn = function(curr, next, opts, cb, fwd) {
1223 if (opts.rev)
1224 fwd = !fwd;
1225 var $el = fwd ? $(curr) : $(next);
1226 $(next).css(opts.cssBefore);
1227 var count = opts.slideCount;
1228 $el.animate(opts.shuffle, opts.speedIn, opts.easeIn, function() {
1229 var hops = $.fn.cycle.hopsFromLast(opts, fwd);
1230 for (var k=0; k < hops; k++)
1231 fwd ? opts.els.push(opts.els.shift()) : opts.els.unshift(opts.els.pop());
1232 if (fwd) {
1233 for (var i=0, len=opts.els.length; i < len; i++)
1234 $(opts.els[i]).css('z-index', len-i+count);
1235 }
1236 else {
1237 var z = $(curr).css('z-index');
1238 $el.css('z-index', parseInt(z,10)+1+count);
1239 }
1240 $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() {
1241 $(fwd ? this : curr).hide();
1242 if (cb) cb();
1243 });
1244 });
1245 };
1246 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 });
1247 };
1248
1249 // turnUp/Down/Left/Right
1250 $.fn.cycle.transitions.turnUp = function($cont, $slides, opts) {
1251 opts.before.push(function(curr, next, opts) {
1252 $.fn.cycle.commonReset(curr,next,opts,true,false);
1253 opts.cssBefore.top = next.cycleH;
1254 opts.animIn.height = next.cycleH;
1255 opts.animOut.width = next.cycleW;
1256 });
1257 opts.cssFirst.top = 0;
1258 opts.cssBefore.left = 0;
1259 opts.cssBefore.height = 0;
1260 opts.animIn.top = 0;
1261 opts.animOut.height = 0;
1262 };
1263 $.fn.cycle.transitions.turnDown = function($cont, $slides, opts) {
1264 opts.before.push(function(curr, next, opts) {
1265 $.fn.cycle.commonReset(curr,next,opts,true,false);
1266 opts.animIn.height = next.cycleH;
1267 opts.animOut.top = curr.cycleH;
1268 });
1269 opts.cssFirst.top = 0;
1270 opts.cssBefore.left = 0;
1271 opts.cssBefore.top = 0;
1272 opts.cssBefore.height = 0;
1273 opts.animOut.height = 0;
1274 };
1275 $.fn.cycle.transitions.turnLeft = function($cont, $slides, opts) {
1276 opts.before.push(function(curr, next, opts) {
1277 $.fn.cycle.commonReset(curr,next,opts,false,true);
1278 opts.cssBefore.left = next.cycleW;
1279 opts.animIn.width = next.cycleW;
1280 });
1281 opts.cssBefore.top = 0;
1282 opts.cssBefore.width = 0;
1283 opts.animIn.left = 0;
1284 opts.animOut.width = 0;
1285 };
1286 $.fn.cycle.transitions.turnRight = function($cont, $slides, opts) {
1287 opts.before.push(function(curr, next, opts) {
1288 $.fn.cycle.commonReset(curr,next,opts,false,true);
1289 opts.animIn.width = next.cycleW;
1290 opts.animOut.left = curr.cycleW;
1291 });
1292 $.extend(opts.cssBefore, { top: 0, left: 0, width: 0 });
1293 opts.animIn.left = 0;
1294 opts.animOut.width = 0;
1295 };
1296
1297 // zoom
1298 $.fn.cycle.transitions.zoom = function($cont, $slides, opts) {
1299 opts.before.push(function(curr, next, opts) {
1300 $.fn.cycle.commonReset(curr,next,opts,false,false,true);
1301 opts.cssBefore.top = next.cycleH/2;
1302 opts.cssBefore.left = next.cycleW/2;
1303 $.extend(opts.animIn, { top: 0, left: 0, width: next.cycleW, height: next.cycleH });
1304 $.extend(opts.animOut, { width: 0, height: 0, top: curr.cycleH/2, left: curr.cycleW/2 });
1305 });
1306 opts.cssFirst.top = 0;
1307 opts.cssFirst.left = 0;
1308 opts.cssBefore.width = 0;
1309 opts.cssBefore.height = 0;
1310 };
1311
1312 // fadeZoom
1313 $.fn.cycle.transitions.fadeZoom = function($cont, $slides, opts) {
1314 opts.before.push(function(curr, next, opts) {
1315 $.fn.cycle.commonReset(curr,next,opts,false,false);
1316 opts.cssBefore.left = next.cycleW/2;
1317 opts.cssBefore.top = next.cycleH/2;
1318 $.extend(opts.animIn, { top: 0, left: 0, width: next.cycleW, height: next.cycleH });
1319 });
1320 opts.cssBefore.width = 0;
1321 opts.cssBefore.height = 0;
1322 opts.animOut.opacity = 0;
1323 };
1324
1325 // blindX
1326 $.fn.cycle.transitions.blindX = function($cont, $slides, opts) {
1327 var w = $cont.css('overflow','hidden').width();
1328 opts.before.push(function(curr, next, opts) {
1329 $.fn.cycle.commonReset(curr,next,opts);
1330 opts.animIn.width = next.cycleW;
1331 opts.animOut.left = curr.cycleW;
1332 });
1333 opts.cssBefore.left = w;
1334 opts.cssBefore.top = 0;
1335 opts.animIn.left = 0;
1336 opts.animOut.left = w;
1337 };
1338 // blindY
1339 $.fn.cycle.transitions.blindY = function($cont, $slides, opts) {
1340 var h = $cont.css('overflow','hidden').height();
1341 opts.before.push(function(curr, next, opts) {
1342 $.fn.cycle.commonReset(curr,next,opts);
1343 opts.animIn.height = next.cycleH;
1344 opts.animOut.top = curr.cycleH;
1345 });
1346 opts.cssBefore.top = h;
1347 opts.cssBefore.left = 0;
1348 opts.animIn.top = 0;
1349 opts.animOut.top = h;
1350 };
1351 // blindZ
1352 $.fn.cycle.transitions.blindZ = function($cont, $slides, opts) {
1353 var h = $cont.css('overflow','hidden').height();
1354 var w = $cont.width();
1355 opts.before.push(function(curr, next, opts) {
1356 $.fn.cycle.commonReset(curr,next,opts);
1357 opts.animIn.height = next.cycleH;
1358 opts.animOut.top = curr.cycleH;
1359 });
1360 opts.cssBefore.top = h;
1361 opts.cssBefore.left = w;
1362 opts.animIn.top = 0;
1363 opts.animIn.left = 0;
1364 opts.animOut.top = h;
1365 opts.animOut.left = w;
1366 };
1367
1368 // growX - grow horizontally from centered 0 width
1369 $.fn.cycle.transitions.growX = function($cont, $slides, opts) {
1370 opts.before.push(function(curr, next, opts) {
1371 $.fn.cycle.commonReset(curr,next,opts,false,true);
1372 opts.cssBefore.left = this.cycleW/2;
1373 opts.animIn.left = 0;
1374 opts.animIn.width = this.cycleW;
1375 opts.animOut.left = 0;
1376 });
1377 opts.cssBefore.top = 0;
1378 opts.cssBefore.width = 0;
1379 };
1380 // growY - grow vertically from centered 0 height
1381 $.fn.cycle.transitions.growY = function($cont, $slides, opts) {
1382 opts.before.push(function(curr, next, opts) {
1383 $.fn.cycle.commonReset(curr,next,opts,true,false);
1384 opts.cssBefore.top = this.cycleH/2;
1385 opts.animIn.top = 0;
1386 opts.animIn.height = this.cycleH;
1387 opts.animOut.top = 0;
1388 });
1389 opts.cssBefore.height = 0;
1390 opts.cssBefore.left = 0;
1391 };
1392
1393 // curtainX - squeeze in both edges horizontally
1394 $.fn.cycle.transitions.curtainX = function($cont, $slides, opts) {
1395 opts.before.push(function(curr, next, opts) {
1396 $.fn.cycle.commonReset(curr,next,opts,false,true,true);
1397 opts.cssBefore.left = next.cycleW/2;
1398 opts.animIn.left = 0;
1399 opts.animIn.width = this.cycleW;
1400 opts.animOut.left = curr.cycleW/2;
1401 opts.animOut.width = 0;
1402 });
1403 opts.cssBefore.top = 0;
1404 opts.cssBefore.width = 0;
1405 };
1406 // curtainY - squeeze in both edges vertically
1407 $.fn.cycle.transitions.curtainY = function($cont, $slides, opts) {
1408 opts.before.push(function(curr, next, opts) {
1409 $.fn.cycle.commonReset(curr,next,opts,true,false,true);
1410 opts.cssBefore.top = next.cycleH/2;
1411 opts.animIn.top = 0;
1412 opts.animIn.height = next.cycleH;
1413 opts.animOut.top = curr.cycleH/2;
1414 opts.animOut.height = 0;
1415 });
1416 opts.cssBefore.height = 0;
1417 opts.cssBefore.left = 0;
1418 };
1419
1420 // cover - curr slide covered by next slide
1421 $.fn.cycle.transitions.cover = function($cont, $slides, opts) {
1422 var d = opts.direction || 'left';
1423 var w = $cont.css('overflow','hidden').width();
1424 var h = $cont.height();
1425 opts.before.push(function(curr, next, opts) {
1426 $.fn.cycle.commonReset(curr,next,opts);
1427 if (d == 'right')
1428 opts.cssBefore.left = -w;
1429 else if (d == 'up')
1430 opts.cssBefore.top = h;
1431 else if (d == 'down')
1432 opts.cssBefore.top = -h;
1433 else
1434 opts.cssBefore.left = w;
1435 });
1436 opts.animIn.left = 0;
1437 opts.animIn.top = 0;
1438 opts.cssBefore.top = 0;
1439 opts.cssBefore.left = 0;
1440 };
1441
1442 // uncover - curr slide moves off next slide
1443 $.fn.cycle.transitions.uncover = function($cont, $slides, opts) {
1444 var d = opts.direction || 'left';
1445 var w = $cont.css('overflow','hidden').width();
1446 var h = $cont.height();
1447 opts.before.push(function(curr, next, opts) {
1448 $.fn.cycle.commonReset(curr,next,opts,true,true,true);
1449 if (d == 'right')
1450 opts.animOut.left = w;
1451 else if (d == 'up')
1452 opts.animOut.top = -h;
1453 else if (d == 'down')
1454 opts.animOut.top = h;
1455 else
1456 opts.animOut.left = -w;
1457 });
1458 opts.animIn.left = 0;
1459 opts.animIn.top = 0;
1460 opts.cssBefore.top = 0;
1461 opts.cssBefore.left = 0;
1462 };
1463
1464 // toss - move top slide and fade away
1465 $.fn.cycle.transitions.toss = function($cont, $slides, opts) {
1466 var w = $cont.css('overflow','visible').width();
1467 var h = $cont.height();
1468 opts.before.push(function(curr, next, opts) {
1469 $.fn.cycle.commonReset(curr,next,opts,true,true,true);
1470 // provide default toss settings if animOut not provided
1471 if (!opts.animOut.left && !opts.animOut.top)
1472 $.extend(opts.animOut, { left: w*2, top: -h/2, opacity: 0 });
1473 else
1474 opts.animOut.opacity = 0;
1475 });
1476 opts.cssBefore.left = 0;
1477 opts.cssBefore.top = 0;
1478 opts.animIn.left = 0;
1479 };
1480
1481 // wipe - clip animation
1482 $.fn.cycle.transitions.wipe = function($cont, $slides, opts) {
1483 var w = $cont.css('overflow','hidden').width();
1484 var h = $cont.height();
1485 opts.cssBefore = opts.cssBefore || {};
1486 var clip;
1487 if (opts.clip) {
1488 if (/l2r/.test(opts.clip))
1489 clip = 'rect(0px 0px '+h+'px 0px)';
1490 else if (/r2l/.test(opts.clip))
1491 clip = 'rect(0px '+w+'px '+h+'px '+w+'px)';
1492 else if (/t2b/.test(opts.clip))
1493 clip = 'rect(0px '+w+'px 0px 0px)';
1494 else if (/b2t/.test(opts.clip))
1495 clip = 'rect('+h+'px '+w+'px '+h+'px 0px)';
1496 else if (/zoom/.test(opts.clip)) {
1497 var top = parseInt(h/2,10);
1498 var left = parseInt(w/2,10);
1499 clip = 'rect('+top+'px '+left+'px '+top+'px '+left+'px)';
1500 }
1501 }
1502
1503 opts.cssBefore.clip = opts.cssBefore.clip || clip || 'rect(0px 0px 0px 0px)';
1504
1505 var d = opts.cssBefore.clip.match(/(\d+)/g);
1506 var t = parseInt(d[0],10), r = parseInt(d[1],10), b = parseInt(d[2],10), l = parseInt(d[3],10);
1507
1508 opts.before.push(function(curr, next, opts) {
1509 if (curr == next) return;
1510 var $curr = $(curr), $next = $(next);
1511 $.fn.cycle.commonReset(curr,next,opts,true,true,false);
1512 opts.cssAfter.display = 'block';
1513
1514 var step = 1, count = parseInt((opts.speedIn / 13),10) - 1;
1515 (function f() {
1516 var tt = t ? t - parseInt(step * (t/count),10) : 0;
1517 var ll = l ? l - parseInt(step * (l/count),10) : 0;
1518 var bb = b < h ? b + parseInt(step * ((h-b)/count || 1),10) : h;
1519 var rr = r < w ? r + parseInt(step * ((w-r)/count || 1),10) : w;
1520 $next.css({ clip: 'rect('+tt+'px '+rr+'px '+bb+'px '+ll+'px)' });
1521 (step++ <= count) ? setTimeout(f, 13) : $curr.css('display', 'none');
1522 })();
1523 });
1524 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 });
1525 opts.animIn = { left: 0 };
1526 opts.animOut = { left: 0 };
1527 };
1528
1529 })(jQuery);