PageRenderTime 50ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/files/cycle/2.9999.5/jquery.cycle.all.js

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