PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/files/cycle/2.88/jquery.cycle.all.js

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