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