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