PageRenderTime 74ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/files/cycle/2.9999.8/jquery.cycle.all.js

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