PageRenderTime 116ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/files/cycle/2.9999.6/jquery.cycle.all.js

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