annotate static/js/jquery.cycle.all3.0.3.js @ 881:13f2d4393ec4

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