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