jquery.cycle.all.js 50 KB

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