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