PageRenderTime 39ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/files/cycle/3.0.2/jquery.cycle.all.js

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