1/*! 2 * jQuery Cycle Plugin (with Transition Definitions) 3 * Examples and documentation at: http://jquery.malsup.com/cycle/ 4 * Copyright (c) 2007-2013 M. Alsup 5 * Version: 3.0.3 (11-JUL-2013) 6 * Dual licensed under the MIT and GPL licenses. 7 * http://jquery.malsup.com/license.html 8 * Requires: jQuery v1.7.1 or later 9 */ 10;(function($, undefined) { 11"use strict"; 12 13var ver = '3.0.3'; 14 15function debug(s) { 16 if ($.fn.cycle.debug) 17 log(s); 18} 19function log() { 20 /*global console */ 21 if (window.console && console.log) 22 console.log('[cycle] ' + Array.prototype.join.call(arguments,' ')); 23} 24$.expr[':'].paused = function(el) { 25 return el.cyclePause; 26}; 27 28 29// the options arg can be... 30// a number - indicates an immediate transition should occur to the given slide index 31// a string - 'pause', 'resume', 'toggle', 'next', 'prev', 'stop', 'destroy' or the name of a transition effect (ie, 'fade', 'zoom', etc) 32// an object - properties to control the slideshow 33// 34// the arg2 arg can be... 35// the name of an fx (only used in conjunction with a numeric value for 'options') 36// the value true (only used in first arg == 'resume') and indicates 37// that the resume should occur immediately (not wait for next timeout) 38 39$.fn.cycle = function(options, arg2) { 40 var o = { s: this.selector, c: this.context }; 41 42 // in 1.3+ we can fix mistakes with the ready state 43 if (this.length === 0 && options != 'stop') { 44 if (!$.isReady && o.s) { 45 log('DOM not ready, queuing slideshow'); 46 $(function() { 47 $(o.s,o.c).cycle(options,arg2); 48 }); 49 return this; 50 } 51 // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready() 52 log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)')); 53 return this; 54 } 55 56 // iterate the matched nodeset 57 return this.each(function() { 58 var opts = handleArguments(this, options, arg2); 59 if (opts === false) 60 return; 61 62 opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink; 63 64 // stop existing slideshow for this container (if there is one) 65 if (this.cycleTimeout) 66 clearTimeout(this.cycleTimeout); 67 this.cycleTimeout = this.cyclePause = 0; 68 this.cycleStop = 0; // issue #108 69 70 var $cont = $(this); 71 var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children(); 72 var els = $slides.get(); 73 74 if (els.length < 2) { 75 log('terminating; too few slides: ' + els.length); 76 return; 77 } 78 79 var opts2 = buildOptions($cont, $slides, els, opts, o); 80 if (opts2 === false) 81 return; 82 83 var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.backwards); 84 85 // if it's an auto slideshow, kick it off 86 if (startTime) { 87 startTime += (opts2.delay || 0); 88 if (startTime < 10) 89 startTime = 10; 90 debug('first timeout: ' + startTime); 91 this.cycleTimeout = setTimeout(function(){go(els,opts2,0,!opts.backwards);}, startTime); 92 } 93 }); 94}; 95 96function triggerPause(cont, byHover, onPager) { 97 var opts = $(cont).data('cycle.opts'); 98 if (!opts) 99 return; 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 if (opts.elements) 125 $(opts.elements).stop(); 126 $(cont).removeData('cycle.opts'); 127 if (options == 'destroy') 128 destroy(cont, opts); 129 return false; 130 case 'toggle': 131 cont.cyclePause = (cont.cyclePause === 1) ? 0 : 1; 132 checkInstantResume(cont.cyclePause, arg2, cont); 133 triggerPause(cont); 134 return false; 135 case 'pause': 136 cont.cyclePause = 1; 137 triggerPause(cont); 138 return false;
139 case 'resume': 140 cont.cyclePause = 0; 141 checkInstantResume(false, arg2, cont); 142 triggerPause(cont); 143 return false; 144 case 'prev': 145 case 'next': 146 opts = $(cont).data('cycle.opts'); 147 if (!opts) { 148 log('options not found, "prev/next" ignored'); 149 return false; 150 } 151 if (typeof arg2 == 'string') 152 opts.oneTimeFx = arg2; 153 $.fn.cycle[options](opts); 154 return false; 155 default: 156 options = { fx: options }; 157 } 158 return options; 159 } 160 else if (options.constructor == Number) { 161 // go to the requested slide 162 var num = options; 163 options = $(cont).data('cycle.opts'); 164 if (!options) { 165 log('options not found, can not advance slide'); 166 return false; 167 } 168 if (num < 0 || num >= options.elements.length) { 169 log('invalid slide index: ' + num); 170 return false; 171 } 172 options.nextSlide = num; 173 if (cont.cycleTimeout) { 174 clearTimeout(cont.cycleTimeout); 175 cont.cycleTimeout = 0; 176 } 177 if (typeof arg2 == 'string') 178 options.oneTimeFx = arg2; 179 go(options.elements, options, 1, num >= options.currSlide); 180 return false; 181 } 182 return options; 183 184 function checkInstantResume(isPaused, arg2, cont) { 185 if (!isPaused && arg2 === true) { // resume now! 186 var options = $(cont).data('cycle.opts'); 187 if (!options) { 188 log('options not found, can not resume'); 189 return false; 190 } 191 if (cont.cycleTimeout) { 192 clearTimeout(cont.cycleTimeout); 193 cont.cycleTimeout = 0; 194 } 195 go(options.elements, options, 1, !options.backwards); 196 } 197 } 198} 199 200function removeFilter(el, opts) { 201 if (!$.support.opacity && opts.cleartype && el.style.filter) { 202 try { el.style.removeAttribute('filter'); } 203 catch(smother) {} // handle old opera versions 204 } 205} 206 207// unbind event handlers 208function destroy(cont, opts) { 209 if (opts.next) 210 $(opts.next).unbind(opts.prevNextEvent); 211 if (opts.prev) 212 $(opts.prev).unbind(opts.prevNextEvent); 213 214 if (opts.pager || opts.pagerAnchorBuilder) 215 $.each(opts.pagerAnchors || [], function() { 216 this.unbind().remove(); 217 }); 218 opts.pagerAnchors = null; 219 $(cont).unbind('mouseenter.cycle mouseleave.cycle'); 220 if (opts.destroy) // callback 221 opts.destroy(opts); 222} 223 224// one-time initialization 225function buildOptions($cont, $slides, els, options, o) { 226 var startingSlideSpecified; 227 // support metadata plugin (v1.0 and v2.0) 228 var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {}); 229 var meta = $.isFunction($cont.data) ? $cont.data(opts.metaAttr) : null; 230 if (meta) 231 opts = $.extend(opts, meta); 232 if (opts.autostop) 233 opts.countdown = opts.autostopCount || els.length; 234 235 var cont = $cont[0]; 236 $cont.data('cycle.opts', opts); 237 opts.$cont = $cont; 238 opts.stopCount = cont.cycleStop; 239 opts.elements = els; 240 opts.before = opts.before ? [opts.before] : []; 241 opts.after = opts.after ? [opts.after] : []; 242 243 // push some after callbacks 244 if (!$.support.opacity && opts.cleartype) 245 opts.after.push(function() { removeFilter(this, opts); }); 246 if (opts.continuous) 247 opts.after.push(function() { go(els,opts,0,!opts.backwards); }); 248 249 saveOriginalOpts(opts); 250 251 // clearType corrections 252 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg) 253 clearTypeFix($slides); 254 255 // container requires non-static position so that slides can be position within 256 if ($cont.css('position') == 'static') 257 $cont.css('position', 'relative'); 258 if (opts.width) 259 $cont.width(opts.width); 260 if (opts.height && opts.height != 'auto') 261 $cont.height(opts.height); 262 263 if (opts.startingSlide !== undefined) { 264 opts.startingSlide = parseInt(opts.startingSlide,10); 265 if (opts.startingSlide >= els.length || opts.startSlide < 0) { 266 opts.startingSlide = 0; // catch bogus input 267 } else { 268 startingSlideSpecified = true; 269 } 270 } else if (opts.backwards) { 271 opts.startingSlide = els.length - 1; 272 } else { 273 opts.startingSlide = 0; 274 } 275 276 // if random, mix up the slide array 277 if (opts.random) { 278 opts.randomMap = []; 279 for (var i = 0; i < els.length; i++) 280 opts.randomMap.push(i); 281 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;}); 282 if (startingSlideSpecified) { 283 // try to find the specified starting slide and if found set start slide index in the map accordingly 284 for ( var cnt = 0; cnt < els.length; cnt++ ) { 285 if ( opts.startingSlide == opts.randomMap[cnt] ) { 286 opts.randomIndex = cnt; 287 } 288 } 289 } 290 else { 291 opts.randomIndex = 1; 292 opts.startingSlide = opts.randomMap[1]; 293 } 294 } 295 else if (opts.startingSlide >= els.length) 296 opts.startingSlide = 0; // catch bogus input 297 opts.currSlide = opts.startingSlide || 0; 298 var first = opts.startingSlide; 299 300 // set position and zIndex on all the slides
301 $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) { 302 var z; 303 if (opts.backwards) { 304 z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i; 305 } else { 306 z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i; 307 } 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() < 1; 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 $cont.animate({width:maxw+'px',height:maxh+'px'}); 377 if (opts.containerResizeHeight && maxh > 0) 378 //$cont.css({height:maxh+'px'}); 379 $cont.animate({height:maxh+'px'}); 380 } 381 382 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44 383 if (opts.pause) 384 $cont.bind('mouseenter.cycle', function(){ 385 pauseFlag = true; 386 this.cyclePause++; 387 triggerPause(cont, true); 388 }).bind('mouseleave.cycle', function(){ 389 if (pauseFlag) 390 this.cyclePause--; 391 triggerPause(cont, true); 392 }); 393 394 if (supportMultiTransitions(opts) === false) 395 return false; 396 397 // apparently a lot of people use image slideshows without height/width attributes on the images. 398 // Cycle 2.50+ requires the sizing info for every slide; this block tries to deal with that. 399 var requeue = false; 400 options.requeueAttempts = options.requeueAttempts || 0; 401 $slides.each(function() { 402 // try to get height/width of each slide 403 var $el = $(this); 404 this.cycleH = (opts.fit && opts.height) ? opts.height : ($el.height() || this.offsetHeight || this.height || $el.attr('height') || 0); 405 this.cycleW = (opts.fit && opts.width) ? opts.width : ($el.width() || this.offsetWidth || this.width || $el.attr('width') || 0); 406 407 if ( $el.is('img') ) { 408 var loading = (this.cycleH === 0 && this.cycleW === 0 && !this.complete); 409 // don't requeue for images that are still loading but have a valid size 410 if (loading) { 411 if (o.s && opts.requeueOnImageNotLoaded && ++options.requeueAttempts < 100) { // track retry count so we don't loop forever 412 log(options.requeueAttempts,' - img slide not loaded, requeuing slideshow: ', this.src, this.cycleW, this.cycleH); 413 setTimeout(function() {$(o.s,o.c).cycle(options);}, opts.requeueTimeout); 414 requeue = true; 415 return false; // break each loop 416 } 417 else { 418 log('could not determine size of image: '+this.src, this.cycleW, this.cycleH); 419 } 420 } 421 } 422 return true; 423 }); 424 425 if (requeue) 426 return false;
427 428 opts.cssBefore = opts.cssBefore || {}; 429 opts.cssAfter = opts.cssAfter || {}; 430 opts.cssFirst = opts.cssFirst || {}; 431 opts.animIn = opts.animIn || {}; 432 opts.animOut = opts.animOut || {}; 433 434 $slides.not(':eq('+first+')').css(opts.cssBefore); 435 $($slides[first]).css(opts.cssFirst); 436 437 if (opts.timeout) { 438 opts.timeout = parseInt(opts.timeout,10); 439 // ensure that timeout and speed settings are sane 440 if (opts.speed.constructor == String) 441 opts.speed = $.fx.speeds[opts.speed] || parseInt(opts.speed,10); 442 if (!opts.sync) 443 opts.speed = opts.speed / 2; 444 445 var buffer = opts.fx == 'none' ? 0 : opts.fx == 'shuffle' ? 500 : 250; 446 while((opts.timeout - opts.speed) < buffer) // sanitize timeout 447 opts.timeout += opts.speed; 448 } 449 if (opts.easing) 450 opts.easeIn = opts.easeOut = opts.easing; 451 if (!opts.speedIn) 452 opts.speedIn = opts.speed; 453 if (!opts.speedOut) 454 opts.speedOut = opts.speed; 455 456 opts.slideCount = els.length; 457 opts.currSlide = opts.lastSlide = first; 458 if (opts.random) { 459 if (++opts.randomIndex == els.length) 460 opts.randomIndex = 0; 461 opts.nextSlide = opts.randomMap[opts.randomIndex]; 462 } 463 else if (opts.backwards) { 464 opts.nextSlide = opts.startingSlide === 0 ? (els.length-1) : opts.startingSlide-1; 465 } else { 466 opts.nextSlide = opts.startingSlide >= (els.length-1) ? 0 : opts.startingSlide+1; 467} 468 469 // run transition init fn 470 if (!opts.multiFx) { 471 var init = $.fn.cycle.transitions[opts.fx]; 472 if ($.isFunction(init)) 473 init($cont, $slides, opts); 474 else if (opts.fx != 'custom' && !opts.multiFx) { 475 log('unknown transition: ' + opts.fx,'; slideshow terminating'); 476 return false; 477 } 478 } 479 480 // fire artificial events 481 var e0 = $slides[first]; 482 if (!opts.skipInitializationCallbacks) { 483 if (opts.before.length) 484 opts.before[0].apply(e0, [e0, e0, opts, true]); 485 if (opts.after.length) 486 opts.after[0].apply(e0, [e0, e0, opts, true]); 487 } 488 if (opts.next) 489 $(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,1);}); 490 if (opts.prev) 491 $(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,0);}); 492 if (opts.pager || opts.pagerAnchorBuilder) 493 buildPager(els,opts); 494 495 exposeAddSlide(opts, els); 496 497 return opts; 498} 499 500// save off original opts so we can restore after clearing state 501function saveOriginalOpts(opts) { 502 opts.original = { before: [], after: [] }; 503 opts.original.cssBefore = $.extend({}, opts.cssBefore); 504 opts.original.cssAfter = $.extend({}, opts.cssAfter); 505 opts.original.animIn = $.extend({}, opts.animIn); 506 opts.original.animOut = $.extend({}, opts.animOut); 507 $.each(opts.before, function() { opts.original.before.push(this); }); 508 $.each(opts.after, function() { opts.original.after.push(this); }); 509} 510 511function supportMultiTransitions(opts) { 512 var i, tx, txs = $.fn.cycle.transitions; 513 // look for multiple effects 514 if (opts.fx.indexOf(',') > 0) { 515 opts.multiFx = true; 516 opts.fxs = opts.fx.replace(/\s*/g,'').split(','); 517 // discard any bogus effect names 518 for (i=0; i < opts.fxs.length; i++) { 519 var fx = opts.fxs[i]; 520 tx = txs[fx]; 521 if (!tx || !txs.hasOwnProperty(fx) || !$.isFunction(tx)) { 522 log('discarding unknown transition: ',fx); 523 opts.fxs.splice(i,1); 524 i--; 525 } 526 } 527 // if we have an empty list then we threw everything away! 528 if (!opts.fxs.length) { 529 log('No valid transitions named; slideshow terminating.'); 530 return false; 531 } 532 } 533 else if (opts.fx == 'all') { // auto-gen the list of transitions 534 opts.multiFx = true; 535 opts.fxs = []; 536 for (var p in txs) { 537 if (txs.hasOwnProperty(p)) { 538 tx = txs[p]; 539 if (txs.hasOwnProperty(p) && $.isFunction(tx)) 540 opts.fxs.push(p); 541 } 542 } 543 } 544 if (opts.multiFx && opts.randomizeEffects) { 545 // munge the fxs array to make effect selection random 546 var r1 = Math.floor(Math.random() * 20) + 30; 547 for (i = 0; i < r1; i++) { 548 var r2 = Math.floor(Math.random() * opts.fxs.length); 549 opts.fxs.push(opts.fxs.splice(r2,1)[0]); 550 } 551 debug('randomized fx sequence: ',opts.fxs); 552 } 553 return true; 554} 555 556// provide a mechanism for adding slides after the slideshow has started 557function exposeAddSlide(opts, els) { 558 opts.addSlide = function(newSlide, prepend) {
559 var $s = $(newSlide), s = $s[0]; 560 if (!opts.autostopCount) 561 opts.countdown++; 562 els[prepend?'unshift':'push'](s); 563 if (opts.els) 564 opts.els[prepend?'unshift':'push'](s); // shuffle needs this 565 opts.slideCount = els.length; 566 567 // add the slide to the random map and resort 568 if (opts.random) { 569 opts.randomMap.push(opts.slideCount-1); 570 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;}); 571 } 572 573 $s.css('position','absolute'); 574 $s[prepend?'prependTo':'appendTo'](opts.$cont); 575 576 if (prepend) { 577 opts.currSlide++; 578 opts.nextSlide++; 579 } 580 581 if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg) 582 clearTypeFix($s); 583 584 if (opts.fit && opts.width) 585 $s.width(opts.width); 586 if (opts.fit && opts.height && opts.height != 'auto') 587 $s.height(opts.height); 588 s.cycleH = (opts.fit && opts.height) ? opts.height : $s.height(); 589 s.cycleW = (opts.fit && opts.width) ? opts.width : $s.width(); 590 591 $s.css(opts.cssBefore); 592 593 if (opts.pager || opts.pagerAnchorBuilder) 594 $.fn.cycle.createPagerAnchor(els.length-1, s, $(opts.pager), els, opts); 595 596 if ($.isFunction(opts.onAddSlide)) 597 opts.onAddSlide($s); 598 else 599 $s.hide(); // default behavior 600 }; 601} 602 603// reset internal state; we do this on every pass in order to support multiple effects 604$.fn.cycle.resetState = function(opts, fx) { 605 fx = fx || opts.fx; 606 opts.before = []; opts.after = []; 607 opts.cssBefore = $.extend({}, opts.original.cssBefore); 608 opts.cssAfter = $.extend({}, opts.original.cssAfter); 609 opts.animIn = $.extend({}, opts.original.animIn); 610 opts.animOut = $.extend({}, opts.original.animOut); 611 opts.fxFn = null; 612 $.each(opts.original.before, function() { opts.before.push(this); }); 613 $.each(opts.original.after, function() { opts.after.push(this); }); 614 615 // re-init 616 var init = $.fn.cycle.transitions[fx]; 617 if ($.isFunction(init)) 618 init(opts.$cont, $(opts.elements), opts); 619}; 620 621// this is the main engine fn, it handles the timeouts, callbacks and slide index mgmt 622function go(els, opts, manual, fwd) { 623 var p = opts.$cont[0], curr = els[opts.currSlide], next = els[opts.nextSlide]; 624 625 // opts.busy is true if we're in the middle of an animation 626 if (manual && opts.busy && opts.manualTrump) { 627 // let manual transitions requests trump active ones 628 debug('manualTrump in go(), stopping active transition'); 629 $(els).stop(true,true); 630 opts.busy = 0; 631 clearTimeout(p.cycleTimeout); 632 } 633 634 // don't begin another timeout-based transition if there is one active 635 if (opts.busy) { 636 debug('transition active, ignoring new tx request'); 637 return; 638 } 639 640 641 // stop cycling if we have an outstanding stop request 642 if (p.cycleStop != opts.stopCount || p.cycleTimeout === 0 && !manual) 643 return; 644 645 // check to see if we should stop cycling based on autostop options 646 if (!manual && !p.cyclePause && !opts.bounce && 647 ((opts.autostop && (--opts.countdown <= 0)) || 648 (opts.nowrap && !opts.random && opts.nextSlide < opts.currSlide))) { 649 if (opts.end) 650 opts.end(opts); 651 return; 652 } 653 654 // if slideshow is paused, only transition on a manual trigger 655 var changed = false; 656 if ((manual || !p.cyclePause) && (opts.nextSlide != opts.currSlide)) { 657 changed = true; 658 var fx = opts.fx; 659 // keep trying to get the slide size if we don't have it yet 660 curr.cycleH = curr.cycleH || $(curr).height(); 661 curr.cycleW = curr.cycleW || $(curr).width(); 662 next.cycleH = next.cycleH || $(next).height(); 663 next.cycleW = next.cycleW || $(next).width(); 664 665 // support multiple transition types 666 if (opts.multiFx) { 667 if (fwd && (opts.lastFx === undefined || ++opts.lastFx >= opts.fxs.length)) 668 opts.lastFx = 0; 669 else if (!fwd && (opts.lastFx === undefined || --opts.lastFx < 0)) 670 opts.lastFx = opts.fxs.length - 1; 671 fx = opts.fxs[opts.lastFx]; 672 } 673 674 // one-time fx overrides apply to: $('div').cycle(3,'zoom'); 675 if (opts.oneTimeFx) { 676 fx = opts.oneTimeFx; 677 opts.oneTimeFx = null; 678 } 679 680 $.fn.cycle.resetState(opts, fx); 681 682 // run the before callbacks 683 if (opts.before.length) 684 $.each(opts.before, function(i,o) { 685 if (p.cycleStop != opts.stopCount) return; 686 o.apply(next, [curr, next, opts, fwd]); 687 }); 688 689 // stage the after callacks 690 var after = function() { 691 opts.busy = 0; 692 $.each(opts.after, function(i,o) { 693 if (p.cycleStop != opts.stopCount) return; 694 o.apply(next, [curr, next, opts, fwd]); 695 }); 696 if (!p.cycleStop) { 697 // queue next transition 698 queueNext(); 699 } 700 }; 701 702 debug('tx firing('+fx+'); currSlide: ' + opts.currSlide + '; nextSlide: ' + opts.nextSlide); 703 704 // get ready to perform the transition 705 opts.busy = 1; 706 if (opts.fxFn) { // fx function provided? 707 opts.fxFn(curr, next, opts, after, fwd, manual && opts.fastOnEvent); 708 } else if ($.isFunction($.fn.cycle[opts.fx])) { // fx plugin ? 709 $.fn.cycle[opts.fx](curr, next, opts, after, fwd, manual && opts.fastOnEvent); 710 } else { 711 $.fn.cycle.custom(curr, next, opts, after, fwd, manual && opts.fastOnEvent); 712 } 713 } 714 else { 715 queueNext(); 716 } 717 718 if (changed || opts.nextSlide == opts.currSlide) { 719 // calculate the next slide 720 var roll; 721 opts.lastSlide = opts.currSlide; 722 if (opts.random) { 723 opts.currSlide = opts.nextSlide; 724 if (++opts.randomIndex == els.length) { 725 opts.randomIndex = 0; 726 opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;}); 727 } 728 opts.nextSlide = opts.randomMap[opts.randomIndex]; 729 if (opts.nextSlide == opts.currSlide) 730 opts.nextSlide = (opts.currSlide == opts.slideCount - 1) ? 0 : opts.currSlide + 1; 731 } 732 else if (opts.backwards) { 733 roll = (opts.nextSlide - 1) < 0; 734 if (roll && opts.bounce) { 735 opts.backwards = !opts.backwards; 736 opts.nextSlide = 1; 737 opts.currSlide = 0; 738 } 739 else { 740 opts.nextSlide = roll ? (els.length-1) : opts.nextSlide-1; 741 opts.currSlide = roll ? 0 : opts.nextSlide+1; 742 } 743 } 744 else { // sequence 745 roll = (opts.nextSlide + 1) == els.length; 746 if (roll && opts.bounce) { 747 opts.backwards = !opts.backwards; 748 opts.nextSlide = els.length-2; 749 opts.currSlide = els.length-1; 750 } 751 else { 752 opts.nextSlide = roll ? 0 : opts.nextSlide+1; 753 opts.currSlide = roll ? els.length-1 : opts.nextSlide-1; 754 } 755 } 756 } 757 if (changed && opts.pager) 758 opts.updateActivePagerLink(opts.pager, opts.currSlide, opts.activePagerClass); 759 760 function queueNext() { 761 // stage the next transition 762 var ms = 0, timeout = opts.timeout; 763 if (opts.timeout && !opts.continuous) { 764 ms = getTimeout(els[opts.currSlide], els[opts.nextSlide], opts, fwd); 765 if (opts.fx == 'shuffle') 766 ms -= opts.speedOut; 767 } 768 else if (opts.continuous && p.cyclePause) // continuous shows work off an after callback, not this timer logic 769 ms = 10; 770 if (ms > 0) 771 p.cycleTimeout = setTimeout(function(){ go(els, opts, 0, !opts.backwards); }, ms); 772 } 773} 774 775// invoked after transition 776$.fn.cycle.updateActivePagerLink = function(pager, currSlide, clsName) { 777 $(pager).each(function() { 778 $(this).children().removeClass(clsName).eq(currSlide).addClass(clsName); 779 }); 780}; 781 782// calculate timeout value for current transition 783function getTimeout(curr, next, opts, fwd) { 784 if (opts.timeoutFn) { 785 // call user provided calc fn 786 var t = opts.timeoutFn.call(curr,curr,next,opts,fwd); 787 while (opts.fx != 'none' && (t - opts.speed) < 250) // sanitize timeout 788 t += opts.speed;
789 debug('calculated timeout: ' + t + '; speed: ' + opts.speed); 790 if (t !== false) 791 return t; 792 } 793 return opts.timeout; 794} 795 796// expose next/prev function, caller must pass in state 797$.fn.cycle.next = function(opts) { advance(opts,1); }; 798$.fn.cycle.prev = function(opts) { advance(opts,0);}; 799 800// advance slide forward or back 801function advance(opts, moveForward) { 802 var val = moveForward ? 1 : -1; 803 var els = opts.elements; 804 var p = opts.$cont[0], timeout = p.cycleTimeout; 805 if (timeout) { 806 clearTimeout(timeout); 807 p.cycleTimeout = 0; 808 } 809 if (opts.random && val < 0) { 810 // move back to the previously display slide 811 opts.randomIndex--; 812 if (--opts.randomIndex == -2) 813 opts.randomIndex = els.length-2; 814 else if (opts.randomIndex == -1) 815 opts.randomIndex = els.length-1; 816 opts.nextSlide = opts.randomMap[opts.randomIndex]; 817 } 818 else if (opts.random) { 819 opts.nextSlide = opts.randomMap[opts.randomIndex]; 820 } 821 else { 822 opts.nextSlide = opts.currSlide + val; 823 if (opts.nextSlide < 0) { 824 if (opts.nowrap) return false; 825 opts.nextSlide = els.length - 1; 826 } 827 else if (opts.nextSlide >= els.length) { 828 if (opts.nowrap) return false; 829 opts.nextSlide = 0; 830 } 831 } 832 833 var cb = opts.onPrevNextEvent || opts.prevNextClick; // prevNextClick is deprecated 834 if ($.isFunction(cb)) 835 cb(val > 0, opts.nextSlide, els[opts.nextSlide]); 836 go(els, opts, 1, moveForward); 837 return false; 838} 839 840function buildPager(els, opts) { 841 var $p = $(opts.pager); 842 $.each(els, function(i,o) { 843 $.fn.cycle.createPagerAnchor(i,o,$p,els,opts); 844 }); 845 opts.updateActivePagerLink(opts.pager, opts.startingSlide, opts.activePagerClass); 846} 847 848$.fn.cycle.createPagerAnchor = function(i, el, $p, els, opts) { 849 var a; 850 if ($.isFunction(opts.pagerAnchorBuilder)) { 851 a = opts.pagerAnchorBuilder(i,el); 852 debug('pagerAnchorBuilder('+i+', el) returned: ' + a); 853 } 854 else { 855 a = '<a href="#"></a>'; 856} 857 858 if (!a) 859 return; 860 var $a = $(a); 861 // don't reparent if anchor is in the dom 862 if ($a.parents('body').length === 0) { 863 var arr = []; 864 if ($p.length > 1) { 865 $p.each(function() { 866 var $clone = $a.clone(true); 867 $(this).append($clone); 868 arr.push($clone[0]); 869 }); 870 $a = $(arr); 871 } 872 else { 873 $a.appendTo($p); 874 } 875 } 876 877 opts.pagerAnchors = opts.pagerAnchors || []; 878 opts.pagerAnchors.push($a); 879 880 var pagerFn = function(e) { 881 e.preventDefault(); 882 opts.nextSlide = i; 883 var p = opts.$cont[0], timeout = p.cycleTimeout; 884 if (timeout) { 885 clearTimeout(timeout); 886 p.cycleTimeout = 0; 887 } 888 var cb = opts.onPagerEvent || opts.pagerClick; // pagerClick is deprecated 889 if ($.isFunction(cb)) 890 cb(opts.nextSlide, els[opts.nextSlide]); 891 go(els,opts,1,opts.currSlide < i); // trigger the trans 892// return false; // <== allow bubble 893 }; 894 895 if ( /mouseenter|mouseover/i.test(opts.pagerEvent) ) { 896 $a.hover(pagerFn, function(){/* no-op */} ); 897 } 898 else { 899 $a.bind(opts.pagerEvent, pagerFn); 900 } 901 902 if ( ! /^click/.test(opts.pagerEvent) && !opts.allowPagerClickBubble) 903 $a.bind('click.cycle', function(){return false;}); // suppress click 904 905 var cont = opts.$cont[0]; 906 var pauseFlag = false; // https://github.com/malsup/cycle/issues/44 907 if (opts.pauseOnPagerHover) { 908 $a.hover( 909 function() { 910 pauseFlag = true; 911 cont.cyclePause++; 912 triggerPause(cont,true,true); 913 }, function() { 914 if (pauseFlag) 915 cont.cyclePause--; 916 triggerPause(cont,true,true); 917 } 918 ); 919 } 920}; 921 922// helper fn to calculate the number of slides between the current and the next 923$.fn.cycle.hopsFromLast = function(opts, fwd) { 924 var hops, l = opts.lastSlide, c = opts.currSlide; 925 if (fwd) 926 hops = c > l ? c - l : opts.slideCount - l; 927 else 928 hops = c < l ? l - c : l + opts.slideCount - c; 929 return hops; 930}; 931 932// fix clearType problems in ie6 by setting an explicit bg color 933// (otherwise text slides look horrible during a fade transition) 934function clearTypeFix($slides) { 935 debug('applying clearType background-color hack'); 936 function hex(s) { 937 s = parseInt(s,10).toString(16); 938 return s.length < 2 ? '0'+s : s; 939 } 940 function getBg(e) { 941 for ( ; e && e.nodeName.toLowerCase() != 'html'; e = e.parentNode) { 942 var v = $.css(e,'background-color'); 943 if (v && v.indexOf('rgb') >= 0 ) { 944 var rgb = v.match(/\d+/g); 945 return '#'+ hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]); 946 } 947 if (v && v != 'transparent') 948 return v; 949 } 950 return '#ffffff'; 951 } 952 $slides.each(function() { $(this).css('background-color', getBg(this)); }); 953} 954 955// reset common props before the next transition 956$.fn.cycle.commonReset = function(curr,next,opts,w,h,rev) { 957 $(opts.elements).not(curr).hide(); 958 if (typeof opts.cssBefore.opacity == 'undefined') 959 opts.cssBefore.opacity = 1; 960 opts.cssBefore.display = 'block'; 961 if (opts.slideResize && w !== false && next.cycleW > 0) 962 opts.cssBefore.width = next.cycleW; 963 if (opts.slideResize && h !== false && next.cycleH > 0) 964 opts.cssBefore.height = next.cycleH; 965 opts.cssAfter = opts.cssAfter || {}; 966 opts.cssAfter.display = 'none'; 967 $(curr).css('zIndex',opts.slideCount + (rev === true ? 1 : 0)); 968 $(next).css('zIndex',opts.slideCount + (rev === true ? 0 : 1)); 969}; 970 971// the actual fn for effecting a transition 972$.fn.cycle.custom = function(curr, next, opts, cb, fwd, speedOverride) { 973 var $l = $(curr), $n = $(next); 974 var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animInDelay = opts.animInDelay, animOutDelay = opts.animOutDelay;
975 $n.css(opts.cssBefore); 976 if (speedOverride) { 977 if (typeof speedOverride == 'number') 978 speedIn = speedOut = speedOverride; 979 else 980 speedIn = speedOut = 1; 981 easeIn = easeOut = null; 982 } 983 var fn = function() { 984 $n.delay(animInDelay).animate(opts.animIn, speedIn, easeIn, function() { 985 cb(); 986 }); 987 }; 988 $l.delay(animOutDelay).animate(opts.animOut, speedOut, easeOut, function() { 989 $l.css(opts.cssAfter); 990 if (!opts.sync) 991 fn(); 992 }); 993 if (opts.sync) fn(); 994}; 995 996// transition definitions - only fade is defined here, transition pack defines the rest 997$.fn.cycle.transitions = { 998 fade: function($cont, $slides, opts) { 999 $slides.not(':eq('+opts.currSlide+')').css('opacity',0); 1000 opts.before.push(function(curr,next,opts) { 1001 $.fn.cycle.commonReset(curr,next,opts); 1002 opts.cssBefore.opacity = 0; 1003 }); 1004 opts.animIn = { opacity: 1 }; 1005 opts.animOut = { opacity: 0 }; 1006 opts.cssBefore = { top: 0, left: 0 }; 1007 } 1008}; 1009 1010$.fn.cycle.ver = function() { return ver; }; 1011 1012// override these globally if you like (they are all optional) 1013$.fn.cycle.defaults = { 1014 activePagerClass: 'activeSlide', // class name used for the active pager link 1015 after: null, // transition callback (scope set to element that was shown): function(currSlideElement, nextSlideElement, options, forwardFlag) 1016 allowPagerClickBubble: false, // allows or prevents click event on pager anchors from bubbling 1017 animIn: null, // properties that define how the slide animates in 1018 animInDelay: 0, // allows delay before next slide transitions in 1019 animOut: null, // properties that define how the slide animates out 1020 animOutDelay: 0, // allows delay before current slide transitions 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 opts.cssAfter.display = ''; 1448 if (d == 'right') 1449 opts.cssBefore.left = -w; 1450 else if (d == 'up') 1451 opts.cssBefore.top = h; 1452 else if (d == 'down') 1453 opts.cssBefore.top = -h; 1454 else 1455 opts.cssBefore.left = w; 1456 }); 1457 opts.animIn.left = 0; 1458 opts.animIn.top = 0; 1459 opts.cssBefore.top = 0; 1460 opts.cssBefore.left = 0; 1461}; 1462 1463// uncover - curr slide moves off next slide 1464$.fn.cycle.transitions.uncover = function($cont, $slides, opts) { 1465 var d = opts.direction || 'left'; 1466 var w = $cont.css('overflow','hidden').width(); 1467 var h = $cont.height(); 1468 opts.before.push(function(curr, next, opts) { 1469 $.fn.cycle.commonReset(curr,next,opts,true,true,true); 1470 if (d == 'right') 1471 opts.animOut.left = w; 1472 else if (d == 'up') 1473 opts.animOut.top = -h; 1474 else if (d == 'down') 1475 opts.animOut.top = h; 1476 else 1477 opts.animOut.left = -w; 1478 }); 1479 opts.animIn.left = 0; 1480 opts.animIn.top = 0; 1481 opts.cssBefore.top = 0; 1482 opts.cssBefore.left = 0; 1483}; 1484 1485// toss - move top slide and fade away 1486$.fn.cycle.transitions.toss = function($cont, $slides, opts) { 1487 var w = $cont.css('overflow','visible').width(); 1488 var h = $cont.height(); 1489 opts.before.push(function(curr, next, opts) { 1490 $.fn.cycle.commonReset(curr,next,opts,true,true,true); 1491 // provide default toss settings if animOut not provided 1492 if (!opts.animOut.left && !opts.animOut.top) 1493 $.extend(opts.animOut, { left: w*2, top: -h/2, opacity: 0 }); 1494 else 1495 opts.animOut.opacity = 0; 1496 }); 1497 opts.cssBefore.left = 0; 1498 opts.cssBefore.top = 0; 1499 opts.animIn.left = 0; 1500}; 1501 1502// wipe - clip animation 1503$.fn.cycle.transitions.wipe = function($cont, $slides, opts) { 1504 var w = $cont.css('overflow','hidden').width(); 1505 var h = $cont.height(); 1506 opts.cssBefore = opts.cssBefore || {}; 1507 var clip; 1508 if (opts.clip) { 1509 if (/l2r/.test(opts.clip)) 1510 clip = 'rect(0px 0px '+h+'px 0px)'; 1511 else if (/r2l/.test(opts.clip)) 1512 clip = 'rect(0px '+w+'px '+h+'px '+w+'px)'; 1513 else if (/t2b/.test(opts.clip)) 1514 clip = 'rect(0px '+w+'px 0px 0px)'; 1515 else if (/b2t/.test(opts.clip)) 1516 clip = 'rect('+h+'px '+w+'px '+h+'px 0px)'; 1517 else if (/zoom/.test(opts.clip)) { 1518 var top = parseInt(h/2,10); 1519 var left = parseInt(w/2,10); 1520 clip = 'rect('+top+'px '+left+'px '+top+'px '+left+'px)'; 1521 } 1522 } 1523 1524 opts.cssBefore.clip = opts.cssBefore.clip || clip || 'rect(0px 0px 0px 0px)'; 1525 1526 var d = opts.cssBefore.clip.match(/(\d+)/g); 1527 var t = parseInt(d[0],10), r = parseInt(d[1],10), b = parseInt(d[2],10), l = parseInt(d[3],10); 1528 1529 opts.before.push(function(curr, next, opts) { 1530 if (curr == next) return; 1531 var $curr = $(curr), $next = $(next); 1532 $.fn.cycle.commonReset(curr,next,opts,true,true,false); 1533 opts.cssAfter.display = 'block'; 1534 1535 var step = 1, count = parseInt((opts.speedIn / 13),10) - 1; 1536 (function f() { 1537 var tt = t ? t - parseInt(step * (t/count),10) : 0; 1538 var ll = l ? l - parseInt(step * (l/count),10) : 0; 1539 var bb = b < h ? b + parseInt(step * ((h-b)/count || 1),10) : h; 1540 var rr = r < w ? r + parseInt(step * ((w-r)/count || 1),10) : w; 1541 $next.css({ clip: 'rect('+tt+'px '+rr+'px '+bb+'px '+ll+'px)' }); 1542 (step++ <= count) ? setTimeout(f, 13) : $curr.css('display', 'none'); 1543 })(); 1544 }); 1545 $.extend(opts.cssBefore, { display: 'block', opacity: 1, top: 0, left: 0 }); 1546 opts.animIn = { left: 0 }; 1547 opts.animOut = { left: 0 }; 1548}; 1549 1550})(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.