Mercurial > public > sg101
comparison static/js/jquery.cycle.all3.0.3.js @ 693:ad69236e8501
For issue #52, update many 3rd party Javascript libraries.
Updated to jquery 1.10.2, jquery ui 1.10.3.
This broke a lot of stuff.
- Found a newer version of the jquery cycle all plugin (3.0.3).
- Updated JPlayer to 2.4.0.
- Updated to MarkItUp 1.1.14. This also required me to add multiline attributes
set to true on various buttons in the markdown set.
- As per a stackoverflow post, added some code to get multiline titles in
a jQuery UI dialog. They removed that functionality but allow you to put it
back.
Tweaked the MarkItUp preview CSS to show blockquotes in italic.
Did not update TinyMCE at this time. I'm not using the JQuery version and this
version appears to work ok for now.
What I should do is make a repo for MarkItUp and do a vendor branch thing so
I don't have to futz around diffing directories to figure out if I'll lose
changes when I update.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 04 Sep 2013 19:55:20 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
692:4a49d4ac319f | 693:ad69236e8501 |
---|---|
1 /*! | |
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 | |
9 */ | |
10 ;(function($, undefined) { | |
11 "use strict"; | |
12 | |
13 var ver = '3.0.3'; | |
14 | |
15 function debug(s) { | |
16 if ($.fn.cycle.debug) | |
17 log(s); | |
18 } | |
19 function log() { | |
20 /*global console */ | |
21 if (window.console && console.log) | |
22 console.log('[cycle] ' + Array.prototype.join.call(arguments,' ')); | |
23 } | |
24 $.expr[':'].paused = function(el) { | |
25 return el.cyclePause; | |
26 }; | |
27 | |
28 | |
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 | |
33 // | |
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) | |
38 | |
39 $.fn.cycle = function(options, arg2) { | |
40 var o = { s: this.selector, c: this.context }; | |
41 | |
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'); | |
46 $(function() { | |
47 $(o.s,o.c).cycle(options,arg2); | |
48 }); | |
49 return this; | |
50 } | |
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)')); | |
53 return this; | |
54 } | |
55 | |
56 // iterate the matched nodeset | |
57 return this.each(function() { | |
58 var opts = handleArguments(this, options, arg2); | |
59 if (opts === false) | |
60 return; | |
61 | |
62 opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink; | |
63 | |
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 | |
69 | |
70 var $cont = $(this); | |
71 var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children(); | |
72 var els = $slides.get(); | |
73 | |
74 if (els.length < 2) { | |
75 log('terminating; too few slides: ' + els.length); | |
76 return; | |
77 } | |
78 | |
79 var opts2 = buildOptions($cont, $slides, els, opts, o); | |
80 if (opts2 === false) | |
81 return; | |
82 | |
83 var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.backwards); | |
84 | |
85 // if it's an auto slideshow, kick it off | |
86 if (startTime) { | |
87 startTime += (opts2.delay || 0); | |
88 if (startTime < 10) | |
89 startTime = 10; | |
90 debug('first timeout: ' + startTime); | |
91 this.cycleTimeout = setTimeout(function(){go(els,opts2,0,!opts.backwards);}, startTime); | |
92 } | |
93 }); | |
94 }; | |
95 | |
96 function triggerPause(cont, byHover, onPager) { | |
97 var opts = $(cont).data('cycle.opts'); | |
98 if (!opts) | |
99 return; | |
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 if (opts.elements) | |
125 $(opts.elements).stop(); | |
126 $(cont).removeData('cycle.opts'); | |
127 if (options == 'destroy') | |
128 destroy(cont, opts); | |
129 return false; | |
130 case 'toggle': | |
131 cont.cyclePause = (cont.cyclePause === 1) ? 0 : 1; | |
132 checkInstantResume(cont.cyclePause, arg2, cont); | |
133 triggerPause(cont); | |
134 return false; | |
135 case 'pause': | |
136 cont.cyclePause = 1; | |
137 triggerPause(cont); | |
138 return false; | |
139 case 'resume': | |
140 cont.cyclePause = 0; | |
141 checkInstantResume(false, arg2, cont); | |
142 triggerPause(cont); | |
143 return false; | |
144 case 'prev': | |
145 case 'next': | |
146 opts = $(cont).data('cycle.opts'); | |
147 if (!opts) { | |
148 log('options not found, "prev/next" ignored'); | |
149 return false; | |
150 } | |
151 if (typeof arg2 == 'string') | |
152 opts.oneTimeFx = arg2; | |
153 $.fn.cycle[options](opts); | |
154 return false; | |
155 default: | |
156 options = { fx: options }; | |
157 } | |
158 return options; | |
159 } | |
160 else if (options.constructor == Number) { | |
161 // go to the requested slide | |
162 var num = options; | |
163 options = $(cont).data('cycle.opts'); | |
164 if (!options) { | |
165 log('options not found, can not advance slide'); | |
166 return false; | |
167 } | |
168 if (num < 0 || num >= options.elements.length) { | |
169 log('invalid slide index: ' + num); | |
170 return false; | |
171 } | |
172 options.nextSlide = num; | |
173 if (cont.cycleTimeout) { | |
174 clearTimeout(cont.cycleTimeout); | |
175 cont.cycleTimeout = 0; | |
176 } | |
177 if (typeof arg2 == 'string') | |
178 options.oneTimeFx = arg2; | |
179 go(options.elements, options, 1, num >= options.currSlide); | |
180 return false; | |
181 } | |
182 return options; | |
183 | |
184 function checkInstantResume(isPaused, arg2, cont) { | |
185 if (!isPaused && arg2 === true) { // resume now! | |
186 var options = $(cont).data('cycle.opts'); | |
187 if (!options) { | |
188 log('options not found, can not resume'); | |
189 return false; | |
190 } | |
191 if (cont.cycleTimeout) { | |
192 clearTimeout(cont.cycleTimeout); | |
193 cont.cycleTimeout = 0; | |
194 } | |
195 go(options.elements, options, 1, !options.backwards); | |
196 } | |
197 } | |
198 } | |
199 | |
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 | |
204 } | |
205 } | |
206 | |
207 // unbind event handlers | |
208 function destroy(cont, opts) { | |
209 if (opts.next) | |
210 $(opts.next).unbind(opts.prevNextEvent); | |
211 if (opts.prev) | |
212 $(opts.prev).unbind(opts.prevNextEvent); | |
213 | |
214 if (opts.pager || opts.pagerAnchorBuilder) | |
215 $.each(opts.pagerAnchors || [], function() { | |
216 this.unbind().remove(); | |
217 }); | |
218 opts.pagerAnchors = null; | |
219 $(cont).unbind('mouseenter.cycle mouseleave.cycle'); | |
220 if (opts.destroy) // callback | |
221 opts.destroy(opts); | |
222 } | |
223 | |
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; | |
230 if (meta) | |
231 opts = $.extend(opts, meta); | |
232 if (opts.autostop) | |
233 opts.countdown = opts.autostopCount || els.length; | |
234 | |
235 var cont = $cont[0]; | |
236 $cont.data('cycle.opts', opts); | |
237 opts.$cont = $cont; | |
238 opts.stopCount = cont.cycleStop; | |
239 opts.elements = els; | |
240 opts.before = opts.before ? [opts.before] : []; | |
241 opts.after = opts.after ? [opts.after] : []; | |
242 | |
243 // push some after callbacks | |
244 if (!$.support.opacity && opts.cleartype) | |
245 opts.after.push(function() { removeFilter(this, opts); }); | |
246 if (opts.continuous) | |
247 opts.after.push(function() { go(els,opts,0,!opts.backwards); }); | |
248 | |
249 saveOriginalOpts(opts); | |
250 | |
251 // clearType corrections | |
252 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg) | |
253 clearTypeFix($slides); | |
254 | |
255 // container requires non-static position so that slides can be position within | |
256 if ($cont.css('position') == 'static') | |
257 $cont.css('position', 'relative'); | |
258 if (opts.width) | |
259 $cont.width(opts.width); | |
260 if (opts.height && opts.height != 'auto') | |
261 $cont.height(opts.height); | |
262 | |
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 | |
267 else | |
268 startingSlideSpecified = true; | |
269 } | |
270 else if (opts.backwards) | |
271 opts.startingSlide = els.length - 1; | |
272 else | |
273 opts.startingSlide = 0; | |
274 | |
275 // if random, mix up the slide array | |
276 if (opts.random) { | |
277 opts.randomMap = []; | |
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; | |
286 } | |
287 } | |
288 } | |
289 else { | |
290 opts.randomIndex = 1; | |
291 opts.startingSlide = opts.randomMap[1]; | |
292 } | |
293 } | |
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; | |
298 | |
299 // set position and zIndex on all the slides | |
300 $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) { | |
301 var z; | |
302 if (opts.backwards) | |
303 z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i; | |
304 else | |
305 z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i; | |
306 $(this).css('z-index', z); | |
307 }); | |
308 | |
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); | |
312 | |
313 // stretch slides | |
314 if (opts.fit) { | |
315 if (!opts.aspect) { | |
316 if (opts.width) | |
317 $slides.width(opts.width); | |
318 if (opts.height && opts.height != 'auto') | |
319 $slides.height(opts.height); | |
320 } else { | |
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 ); | |
327 } | |
328 | |
329 if( opts.height && $slide.height() < opts.height ) { | |
330 $slide.height( opts.height ); | |
331 $slide.width( opts.height * ratio ); | |
332 } | |
333 }); | |
334 } | |
335 } | |
336 | |
337 if (opts.center && ((!opts.fit) || opts.aspect)) { | |
338 $slides.each(function(){ | |
339 var $slide = $(this); | |
340 $slide.css({ | |
341 "margin-left": opts.width ? | |
342 ((opts.width - $slide.width()) / 2) + "px" : | |
343 0, | |
344 "margin-top": opts.height ? | |
345 ((opts.height - $slide.height()) / 2) + "px" : | |
346 0 | |
347 }); | |
348 }); | |
349 } | |
350 | |
351 if (opts.center && !opts.fit && !opts.slideResize) { | |
352 $slides.each(function(){ | |
353 var $slide = $(this); | |
354 $slide.css({ | |
355 "margin-left": opts.width ? ((opts.width - $slide.width()) / 2) + "px" : 0, | |
356 "margin-top": opts.height ? ((opts.height - $slide.height()) / 2) + "px" : 0 | |
357 }); | |
358 }); | |
359 } | |
360 | |
361 // stretch container | |
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; | |
371 } | |
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'}); | |
376 } | |
377 | |
378 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44 | |
379 if (opts.pause) | |
380 $cont.bind('mouseenter.cycle', function(){ | |
381 pauseFlag = true; | |
382 this.cyclePause++; | |
383 triggerPause(cont, true); | |
384 }).bind('mouseleave.cycle', function(){ | |
385 if (pauseFlag) | |
386 this.cyclePause--; | |
387 triggerPause(cont, true); | |
388 }); | |
389 | |
390 if (supportMultiTransitions(opts) === false) | |
391 return false; | |
392 | |
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. | |
395 var requeue = false; | |
396 options.requeueAttempts = options.requeueAttempts || 0; | |
397 $slides.each(function() { | |
398 // try to get height/width of each slide | |
399 var $el = $(this); | |
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); | |
402 | |
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 | |
406 if (loading) { | |
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); | |
410 requeue = true; | |
411 return false; // break each loop | |
412 } | |
413 else { | |
414 log('could not determine size of image: '+this.src, this.cycleW, this.cycleH); | |
415 } | |
416 } | |
417 } | |
418 return true; | |
419 }); | |
420 | |
421 if (requeue) | |
422 return false; | |
423 | |
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 || {}; | |
429 | |
430 $slides.not(':eq('+first+')').css(opts.cssBefore); | |
431 $($slides[first]).css(opts.cssFirst); | |
432 | |
433 if (opts.timeout) { | |
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); | |
438 if (!opts.sync) | |
439 opts.speed = opts.speed / 2; | |
440 | |
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; | |
444 } | |
445 if (opts.easing) | |
446 opts.easeIn = opts.easeOut = opts.easing; | |
447 if (!opts.speedIn) | |
448 opts.speedIn = opts.speed; | |
449 if (!opts.speedOut) | |
450 opts.speedOut = opts.speed; | |
451 | |
452 opts.slideCount = els.length; | |
453 opts.currSlide = opts.lastSlide = first; | |
454 if (opts.random) { | |
455 if (++opts.randomIndex == els.length) | |
456 opts.randomIndex = 0; | |
457 opts.nextSlide = opts.randomMap[opts.randomIndex]; | |
458 } | |
459 else if (opts.backwards) | |
460 opts.nextSlide = opts.startingSlide === 0 ? (els.length-1) : opts.startingSlide-1; | |
461 else | |
462 opts.nextSlide = opts.startingSlide >= (els.length-1) ? 0 : opts.startingSlide+1; | |
463 | |
464 // run transition init fn | |
465 if (!opts.multiFx) { | |
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'); | |
471 return false; | |
472 } | |
473 } | |
474 | |
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]); | |
482 } | |
483 if (opts.next) | |
484 $(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,1);}); | |
485 if (opts.prev) | |
486 $(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,0);}); | |
487 if (opts.pager || opts.pagerAnchorBuilder) | |
488 buildPager(els,opts); | |
489 | |
490 exposeAddSlide(opts, els); | |
491 | |
492 return opts; | |
493 } | |
494 | |
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); }); | |
504 } | |
505 | |
506 function supportMultiTransitions(opts) { | |
507 var i, tx, txs = $.fn.cycle.transitions; | |
508 // look for multiple effects | |
509 if (opts.fx.indexOf(',') > 0) { | |
510 opts.multiFx = true; | |
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]; | |
515 tx = txs[fx]; | |
516 if (!tx || !txs.hasOwnProperty(fx) || !$.isFunction(tx)) { | |
517 log('discarding unknown transition: ',fx); | |
518 opts.fxs.splice(i,1); | |
519 i--; | |
520 } | |
521 } | |
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.'); | |
525 return false; | |
526 } | |
527 } | |
528 else if (opts.fx == 'all') { // auto-gen the list of transitions | |
529 opts.multiFx = true; | |
530 opts.fxs = []; | |
531 for (var p in txs) { | |
532 if (txs.hasOwnProperty(p)) { | |
533 tx = txs[p]; | |
534 if (txs.hasOwnProperty(p) && $.isFunction(tx)) | |
535 opts.fxs.push(p); | |
536 } | |
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 var p = opts.$cont[0], curr = els[opts.currSlide], next = els[opts.nextSlide]; | |
619 | |
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); | |
625 opts.busy = 0; | |
626 clearTimeout(p.cycleTimeout); | |
627 } | |
628 | |
629 // don't begin another timeout-based transition if there is one active | |
630 if (opts.busy) { | |
631 debug('transition active, ignoring new tx request'); | |
632 return; | |
633 } | |
634 | |
635 | |
636 // stop cycling if we have an outstanding stop request | |
637 if (p.cycleStop != opts.stopCount || p.cycleTimeout === 0 && !manual) | |
638 return; | |
639 | |
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))) { | |
644 if (opts.end) | |
645 opts.end(opts); | |
646 return; | |
647 } | |
648 | |
649 // if slideshow is paused, only transition on a manual trigger | |
650 var changed = false; | |
651 if ((manual || !p.cyclePause) && (opts.nextSlide != opts.currSlide)) { | |
652 changed = true; | |
653 var fx = opts.fx; | |
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(); | |
659 | |
660 // support multiple transition types | |
661 if (opts.multiFx) { | |
662 if (fwd && (opts.lastFx === undefined || ++opts.lastFx >= opts.fxs.length)) | |
663 opts.lastFx = 0; | |
664 else if (!fwd && (opts.lastFx === undefined || --opts.lastFx < 0)) | |
665 opts.lastFx = opts.fxs.length - 1; | |
666 fx = opts.fxs[opts.lastFx]; | |
667 } | |
668 | |
669 // one-time fx overrides apply to: $('div').cycle(3,'zoom'); | |
670 if (opts.oneTimeFx) { | |
671 fx = opts.oneTimeFx; | |
672 opts.oneTimeFx = null; | |
673 } | |
674 | |
675 $.fn.cycle.resetState(opts, fx); | |
676 | |
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]); | |
682 }); | |
683 | |
684 // stage the after callacks | |
685 var after = function() { | |
686 opts.busy = 0; | |
687 $.each(opts.after, function(i,o) { | |
688 if (p.cycleStop != opts.stopCount) return; | |
689 o.apply(next, [curr, next, opts, fwd]); | |
690 }); | |
691 if (!p.cycleStop) { | |
692 // queue next transition | |
693 queueNext(); | |
694 } | |
695 }; | |
696 | |
697 debug('tx firing('+fx+'); currSlide: ' + opts.currSlide + '; nextSlide: ' + opts.nextSlide); | |
698 | |
699 // get ready to perform the transition | |
700 opts.busy = 1; | |
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); | |
705 else | |
706 $.fn.cycle.custom(curr, next, opts, after, fwd, manual && opts.fastOnEvent); | |
707 } | |
708 else { | |
709 queueNext(); | |
710 } | |
711 | |
712 if (changed || opts.nextSlide == opts.currSlide) { | |
713 // calculate the next slide | |
714 var roll; | |
715 opts.lastSlide = opts.currSlide; | |
716 if (opts.random) { | |
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;}); | |
721 } | |
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; | |
725 } | |
726 else if (opts.backwards) { | |
727 roll = (opts.nextSlide - 1) < 0; | |
728 if (roll && opts.bounce) { | |
729 opts.backwards = !opts.backwards; | |
730 opts.nextSlide = 1; | |
731 opts.currSlide = 0; | |
732 } | |
733 else { | |
734 opts.nextSlide = roll ? (els.length-1) : opts.nextSlide-1; | |
735 opts.currSlide = roll ? 0 : opts.nextSlide+1; | |
736 } | |
737 } | |
738 else { // sequence | |
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; | |
744 } | |
745 else { | |
746 opts.nextSlide = roll ? 0 : opts.nextSlide+1; | |
747 opts.currSlide = roll ? els.length-1 : opts.nextSlide-1; | |
748 } | |
749 } | |
750 } | |
751 if (changed && opts.pager) | |
752 opts.updateActivePagerLink(opts.pager, opts.currSlide, opts.activePagerClass); | |
753 | |
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') | |
760 ms -= opts.speedOut; | |
761 } | |
762 else if (opts.continuous && p.cyclePause) // continuous shows work off an after callback, not this timer logic | |
763 ms = 10; | |
764 if (ms > 0) | |
765 p.cycleTimeout = setTimeout(function(){ go(els, opts, 0, !opts.backwards); }, ms); | |
766 } | |
767 } | |
768 | |
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); | |
773 }); | |
774 }; | |
775 | |
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 | |
782 t += opts.speed; | |
783 debug('calculated timeout: ' + t + '; speed: ' + opts.speed); | |
784 if (t !== false) | |
785 return t; | |
786 } | |
787 return opts.timeout; | |
788 } | |
789 | |
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);}; | |
793 | |
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; | |
799 if (timeout) { | |
800 clearTimeout(timeout); | |
801 p.cycleTimeout = 0; | |
802 } | |
803 if (opts.random && val < 0) { | |
804 // move back to the previously display slide | |
805 opts.randomIndex--; | |
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]; | |
811 } | |
812 else if (opts.random) { | |
813 opts.nextSlide = opts.randomMap[opts.randomIndex]; | |
814 } | |
815 else { | |
816 opts.nextSlide = opts.currSlide + val; | |
817 if (opts.nextSlide < 0) { | |
818 if (opts.nowrap) return false; | |
819 opts.nextSlide = els.length - 1; | |
820 } | |
821 else if (opts.nextSlide >= els.length) { | |
822 if (opts.nowrap) return false; | |
823 opts.nextSlide = 0; | |
824 } | |
825 } | |
826 | |
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); | |
831 return false; | |
832 } | |
833 | |
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); | |
838 }); | |
839 opts.updateActivePagerLink(opts.pager, opts.startingSlide, opts.activePagerClass); | |
840 } | |
841 | |
842 $.fn.cycle.createPagerAnchor = function(i, el, $p, els, opts) { | |
843 var a; | |
844 if ($.isFunction(opts.pagerAnchorBuilder)) { | |
845 a = opts.pagerAnchorBuilder(i,el); | |
846 debug('pagerAnchorBuilder('+i+', el) returned: ' + a); | |
847 } | |
848 else | |
849 a = '<a href="#">'+(i+1)+'</a>'; | |
850 | |
851 if (!a) | |
852 return; | |
853 var $a = $(a); | |
854 // don't reparent if anchor is in the dom | |
855 if ($a.parents('body').length === 0) { | |
856 var arr = []; | |
857 if ($p.length > 1) { | |
858 $p.each(function() { | |
859 var $clone = $a.clone(true); | |
860 $(this).append($clone); | |
861 arr.push($clone[0]); | |
862 }); | |
863 $a = $(arr); | |
864 } | |
865 else { | |
866 $a.appendTo($p); | |
867 } | |
868 } | |
869 | |
870 opts.pagerAnchors = opts.pagerAnchors || []; | |
871 opts.pagerAnchors.push($a); | |
872 | |
873 var pagerFn = function(e) { | |
874 e.preventDefault(); | |
875 opts.nextSlide = i; | |
876 var p = opts.$cont[0], timeout = p.cycleTimeout; | |
877 if (timeout) { | |
878 clearTimeout(timeout); | |
879 p.cycleTimeout = 0; | |
880 } | |
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 | |
886 }; | |
887 | |
888 if ( /mouseenter|mouseover/i.test(opts.pagerEvent) ) { | |
889 $a.hover(pagerFn, function(){/* no-op */} ); | |
890 } | |
891 else { | |
892 $a.bind(opts.pagerEvent, pagerFn); | |
893 } | |
894 | |
895 if ( ! /^click/.test(opts.pagerEvent) && !opts.allowPagerClickBubble) | |
896 $a.bind('click.cycle', function(){return false;}); // suppress click | |
897 | |
898 var cont = opts.$cont[0]; | |
899 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44 | |
900 if (opts.pauseOnPagerHover) { | |
901 $a.hover( | |
902 function() { | |
903 pauseFlag = true; | |
904 cont.cyclePause++; | |
905 triggerPause(cont,true,true); | |
906 }, function() { | |
907 if (pauseFlag) | |
908 cont.cyclePause--; | |
909 triggerPause(cont,true,true); | |
910 } | |
911 ); | |
912 } | |
913 }; | |
914 | |
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; | |
918 if (fwd) | |
919 hops = c > l ? c - l : opts.slideCount - l; | |
920 else | |
921 hops = c < l ? l - c : l + opts.slideCount - c; | |
922 return hops; | |
923 }; | |
924 | |
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'); | |
929 function hex(s) { | |
930 s = parseInt(s,10).toString(16); | |
931 return s.length < 2 ? '0'+s : s; | |
932 } | |
933 function getBg(e) { | |
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]); | |
939 } | |
940 if (v && v != 'transparent') | |
941 return v; | |
942 } | |
943 return '#ffffff'; | |
944 } | |
945 $slides.each(function() { $(this).css('background-color', getBg(this)); }); | |
946 } | |
947 | |
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)); | |
962 }; | |
963 | |
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); | |
969 if (speedOverride) { | |
970 if (typeof speedOverride == 'number') | |
971 speedIn = speedOut = speedOverride; | |
972 else | |
973 speedIn = speedOut = 1; | |
974 easeIn = easeOut = null; | |
975 } | |
976 var fn = function() { | |
977 $n.delay(animInDelay).animate(opts.animIn, speedIn, easeIn, function() { | |
978 cb(); | |
979 }); | |
980 }; | |
981 $l.delay(animOutDelay).animate(opts.animOut, speedOut, easeOut, function() { | |
982 $l.css(opts.cssAfter); | |
983 if (!opts.sync) | |
984 fn(); | |
985 }); | |
986 if (opts.sync) fn(); | |
987 }; | |
988 | |
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; | |
996 }); | |
997 opts.animIn = { opacity: 1 }; | |
998 opts.animOut = { opacity: 0 }; | |
999 opts.cssBefore = { top: 0, left: 0 }; | |
1000 } | |
1001 }; | |
1002 | |
1003 $.fn.cycle.ver = function() { return ver; }; | |
1004 | |
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) | |
1068 }; | |
1069 | |
1070 })(jQuery); | |
1071 | |
1072 | |
1073 /*! | |
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 | |
1078 * Version: 2.73 | |
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 | |
1082 */ | |
1083 (function($) { | |
1084 "use strict"; | |
1085 | |
1086 // | |
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 | |
1089 // don't need. | |
1090 // | |
1091 $.fn.cycle.transitions.none = function($cont, $slides, opts) { | |
1092 opts.fxFn = function(curr,next,opts,after){ | |
1093 $(next).show(); | |
1094 $(curr).hide(); | |
1095 after(); | |
1096 }; | |
1097 }; | |
1098 | |
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)); | |
1105 }); | |
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; | |
1111 }; | |
1112 | |
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; | |
1123 }; | |
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; | |
1133 }; | |
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; | |
1143 }; | |
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; | |
1153 }; | |
1154 $.fn.cycle.transitions.scrollHorz = function($cont, $slides, opts) { | |
1155 $cont.css('overflow','hidden').width(); | |
1156 opts.before.push(function(curr, next, opts, fwd) { | |
1157 if (opts.rev) | |
1158 fwd = !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; | |
1162 }); | |
1163 opts.cssFirst.left = 0; | |
1164 opts.cssBefore.top = 0; | |
1165 opts.animIn.left = 0; | |
1166 opts.animOut.top = 0; | |
1167 }; | |
1168 $.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) { | |
1169 $cont.css('overflow','hidden'); | |
1170 opts.before.push(function(curr, next, opts, fwd) { | |
1171 if (opts.rev) | |
1172 fwd = !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; | |
1176 }); | |
1177 opts.cssFirst.top = 0; | |
1178 opts.cssBefore.left = 0; | |
1179 opts.animIn.top = 0; | |
1180 opts.animOut.left = 0; | |
1181 }; | |
1182 | |
1183 // slideX/slideY | |
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; | |
1189 }); | |
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; | |
1195 }; | |
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; | |
1201 }); | |
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; | |
1207 }; | |
1208 | |
1209 // shuffle | |
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); | |
1215 }); | |
1216 // only adjust speed once! | |
1217 if (!opts.speedAdjusted) { | |
1218 opts.speed = opts.speed / 2; // shuffle has 2 transitions | |
1219 opts.speedAdjusted = true; | |
1220 } | |
1221 opts.random = 0; | |
1222 opts.shuffle = opts.shuffle || {left:-w, top:15}; | |
1223 opts.els = []; | |
1224 for (i=0; i < $slides.length; i++) | |
1225 opts.els.push($slides[i]); | |
1226 | |
1227 for (i=0; i < opts.currSlide; i++) | |
1228 opts.els.push(opts.els.shift()); | |
1229 | |
1230 // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!) | |
1231 opts.fxFn = function(curr, next, opts, cb, fwd) { | |
1232 if (opts.rev) | |
1233 fwd = !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++) { | |
1240 if (fwd) | |
1241 opts.els.push(opts.els.shift()); | |
1242 else | |
1243 opts.els.unshift(opts.els.pop()); | |
1244 } | |
1245 if (fwd) { | |
1246 for (var i=0, len=opts.els.length; i < len; i++) | |
1247 $(opts.els[i]).css('z-index', len-i+count); | |
1248 } | |
1249 else { | |
1250 var z = $(curr).css('z-index'); | |
1251 $el.css('z-index', parseInt(z,10)+1+count); | |
1252 } | |
1253 $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() { | |
1254 $(fwd ? this : curr).hide(); | |
1255 if (cb) cb(); | |
1256 }); | |
1257 }); | |
1258 }; | |
1259 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 }); | |
1260 }; | |
1261 | |
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; | |
1269 }); | |
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; | |
1275 }; | |
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; | |
1281 }); | |
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; | |
1287 }; | |
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; | |
1293 }); | |
1294 opts.cssBefore.top = 0; | |
1295 opts.cssBefore.width = 0; | |
1296 opts.animIn.left = 0; | |
1297 opts.animOut.width = 0; | |
1298 }; | |
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; | |
1304 }); | |
1305 $.extend(opts.cssBefore, { top: 0, left: 0, width: 0 }); | |
1306 opts.animIn.left = 0; | |
1307 opts.animOut.width = 0; | |
1308 }; | |
1309 | |
1310 // zoom | |
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 }); | |
1318 }); | |
1319 opts.cssFirst.top = 0; | |
1320 opts.cssFirst.left = 0; | |
1321 opts.cssBefore.width = 0; | |
1322 opts.cssBefore.height = 0; | |
1323 }; | |
1324 | |
1325 // fadeZoom | |
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 }); | |
1332 }); | |
1333 opts.cssBefore.width = 0; | |
1334 opts.cssBefore.height = 0; | |
1335 opts.animOut.opacity = 0; | |
1336 }; | |
1337 | |
1338 // blindX | |
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; | |
1345 }); | |
1346 opts.cssBefore.left = w; | |
1347 opts.cssBefore.top = 0; | |
1348 opts.animIn.left = 0; | |
1349 opts.animOut.left = w; | |
1350 }; | |
1351 // blindY | |
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; | |
1358 }); | |
1359 opts.cssBefore.top = h; | |
1360 opts.cssBefore.left = 0; | |
1361 opts.animIn.top = 0; | |
1362 opts.animOut.top = h; | |
1363 }; | |
1364 // blindZ | |
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; | |
1372 }); | |
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; | |
1379 }; | |
1380 | |
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; | |
1389 }); | |
1390 opts.cssBefore.top = 0; | |
1391 opts.cssBefore.width = 0; | |
1392 }; | |
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; | |
1401 }); | |
1402 opts.cssBefore.height = 0; | |
1403 opts.cssBefore.left = 0; | |
1404 }; | |
1405 | |
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; | |
1415 }); | |
1416 opts.cssBefore.top = 0; | |
1417 opts.cssBefore.width = 0; | |
1418 }; | |
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; | |
1428 }); | |
1429 opts.cssBefore.height = 0; | |
1430 opts.cssBefore.left = 0; | |
1431 }; | |
1432 | |
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 = ''; | |
1441 if (d == 'right') | |
1442 opts.cssBefore.left = -w; | |
1443 else if (d == 'up') | |
1444 opts.cssBefore.top = h; | |
1445 else if (d == 'down') | |
1446 opts.cssBefore.top = -h; | |
1447 else | |
1448 opts.cssBefore.left = w; | |
1449 }); | |
1450 opts.animIn.left = 0; | |
1451 opts.animIn.top = 0; | |
1452 opts.cssBefore.top = 0; | |
1453 opts.cssBefore.left = 0; | |
1454 }; | |
1455 | |
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); | |
1463 if (d == 'right') | |
1464 opts.animOut.left = w; | |
1465 else if (d == 'up') | |
1466 opts.animOut.top = -h; | |
1467 else if (d == 'down') | |
1468 opts.animOut.top = h; | |
1469 else | |
1470 opts.animOut.left = -w; | |
1471 }); | |
1472 opts.animIn.left = 0; | |
1473 opts.animIn.top = 0; | |
1474 opts.cssBefore.top = 0; | |
1475 opts.cssBefore.left = 0; | |
1476 }; | |
1477 | |
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 }); | |
1487 else | |
1488 opts.animOut.opacity = 0; | |
1489 }); | |
1490 opts.cssBefore.left = 0; | |
1491 opts.cssBefore.top = 0; | |
1492 opts.animIn.left = 0; | |
1493 }; | |
1494 | |
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 || {}; | |
1500 var clip; | |
1501 if (opts.clip) { | |
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)'; | |
1514 } | |
1515 } | |
1516 | |
1517 opts.cssBefore.clip = opts.cssBefore.clip || clip || 'rect(0px 0px 0px 0px)'; | |
1518 | |
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); | |
1521 | |
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'; | |
1527 | |
1528 var step = 1, count = parseInt((opts.speedIn / 13),10) - 1; | |
1529 (function f() { | |
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'); | |
1536 })(); | |
1537 }); | |
1538 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 }); | |
1539 opts.animIn = { left: 0 }; | |
1540 opts.animOut = { left: 0 }; | |
1541 }; | |
1542 | |
1543 })(jQuery); |