PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/ajax/libs/jquery.cycle/3.03/jquery.cycle.all.js

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