/*! * jquery cycle plugin (with transition definitions) * examples and documentation at: http://jquery.malsup.com/cycle/ * copyright (c) 2007-2010 m. alsup * version: 2.88 (08-jun-2010) * dual licensed under the mit and gpl licenses. * http://jquery.malsup.com/license.html * requires: jquery v1.2.6 or later */ ; (function ($) { var ver = '2.88'; // if $.support is not defined (pre jquery 1.3) add what i need if ($.support == undefined) { $.support = { opacity: !($.browser.msie) }; } function debug(s) { if ($.fn.cycle.debug) log(s); } function log() { if (window.console && window.console.log) window.console.log('[cycle] ' + array.prototype.join.call(arguments, ' ')); }; // the options arg can be... // a number - indicates an immediate transition should occur to the given slide index // a string - 'pause', 'resume', 'toggle', 'next', 'prev', 'stop', 'destroy' or the name of a transition effect (ie, 'fade', 'zoom', etc) // an object - properties to control the slideshow // // the arg2 arg can be... // the name of an fx (only used in conjunction with a numeric value for 'options') // the value true (only used in first arg == 'resume') and indicates // that the resume should occur immediately (not wait for next timeout) $.fn.cycle = function (options, arg2) { var o = { s: this.selector, c: this.context }; // in 1.3+ we can fix mistakes with the ready state if (this.length === 0 && options != 'stop') { if (!$.isready && o.s) { log('dom not ready, queuing slideshow'); $(function () { $(o.s, o.c).cycle(options, arg2); }); return this; } // is your dom ready? http://docs.jquery.com/tutorials:introducing_$(document).ready() log('terminating; zero elements found by selector' + ($.isready ? '' : ' (dom not ready)')); return this; } // iterate the matched nodeset return this.each(function () { var opts = handlearguments(this, options, arg2); if (opts === false) return; opts.updateactivepagerlink = opts.updateactivepagerlink || $.fn.cycle.updateactivepagerlink; // stop existing slideshow for this container (if there is one) if (this.cycletimeout) cleartimeout(this.cycletimeout); this.cycletimeout = this.cyclepause = 0; var $cont = $(this); var $slides = opts.slideexpr ? $(opts.slideexpr, this) : $cont.children(); var els = $slides.get(); if (els.length < 2) { log('terminating; too few slides: ' + els.length); return; } var opts2 = buildoptions($cont, $slides, els, opts, o); if (opts2 === false) return; var starttime = opts2.continuous ? 10 : gettimeout(els[opts2.currslide], els[opts2.nextslide], opts2, !opts2.rev); // if it's an auto slideshow, kick it off if (starttime) { starttime += (opts2.delay || 0); if (starttime < 10) starttime = 10; debug('first timeout: ' + starttime); this.cycletimeout = settimeout(function () { go(els, opts2, 0, (!opts2.rev && !opts.backwards)) }, starttime); } }); }; // process the args that were passed to the plugin fn function handlearguments(cont, options, arg2) { if (cont.cyclestop == undefined) cont.cyclestop = 0; if (options === undefined || options === null) options = {}; if (options.constructor == string) { switch (options) { case 'destroy': case 'stop': var opts = $(cont).data('cycle.opts'); if (!opts) return false; cont.cyclestop++; // callbacks look for change if (cont.cycletimeout) cleartimeout(cont.cycletimeout); cont.cycletimeout = 0; $(cont).removedata('cycle.opts'); if (options == 'destroy') destroy(opts); return false; case 'toggle': cont.cyclepause = (cont.cyclepause === 1) ? 0 : 1; checkinstantresume(cont.cyclepause, arg2, cont); return false; case 'pause': cont.cyclepause = 1; return false; case 'resume': cont.cyclepause = 0; checkinstantresume(false, arg2, cont); return false; case 'prev': case 'next': var opts = $(cont).data('cycle.opts'); if (!opts) { log('options not found, "prev/next" ignored'); return false; } $.fn.cycle[options](opts); return false; default: options = { fx: options }; }; return options; } else if (options.constructor == number) { // go to the requested slide var num = options; options = $(cont).data('cycle.opts'); if (!options) { log('options not found, can not advance slide'); return false; } if (num < 0 || num >= options.elements.length) { log('invalid slide index: ' + num); return false; } options.nextslide = num; if (cont.cycletimeout) { cleartimeout(cont.cycletimeout); cont.cycletimeout = 0; } if (typeof arg2 == 'string') options.onetimefx = arg2; go(options.elements, options, 1, num >= options.currslide); return false; } return options; function checkinstantresume(ispaused, arg2, cont) { if (!ispaused && arg2 === true) { // resume now! var options = $(cont).data('cycle.opts'); if (!options) { log('options not found, can not resume'); return false; } if (cont.cycletimeout) { cleartimeout(cont.cycletimeout); cont.cycletimeout = 0; } go(options.elements, options, 1, (!opts.rev && !opts.backwards)); } } }; function removefilter(el, opts) { if (!$.support.opacity && opts.cleartype && el.style.filter) { try { el.style.removeattribute('filter'); } catch (smother) { } // handle old opera versions } }; // unbind event handlers function destroy(opts) { if (opts.next) $(opts.next).unbind(opts.prevnextevent); if (opts.prev) $(opts.prev).unbind(opts.prevnextevent); if (opts.pager || opts.pageranchorbuilder) $.each(opts.pageranchors || [], function () { this.unbind().remove(); }); opts.pageranchors = null; if (opts.destroy) // callback opts.destroy(opts); }; // one-time initialization function buildoptions($cont, $slides, els, options, o) { // support metadata plugin (v1.0 and v2.0) var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {}); if (opts.autostop) opts.countdown = opts.autostopcount || els.length; var cont = $cont[0]; $cont.data('cycle.opts', opts); opts.$cont = $cont; opts.stopcount = cont.cyclestop; opts.elements = els; opts.before = opts.before ? [opts.before] : []; opts.after = opts.after ? [opts.after] : []; opts.after.unshift(function () { opts.busy = 0; }); // push some after callbacks if (!$.support.opacity && opts.cleartype) opts.after.push(function () { removefilter(this, opts); }); if (opts.continuous) opts.after.push(function () { go(els, opts, 0, (!opts.rev && !opts.backwards)); }); saveoriginalopts(opts); // cleartype corrections if (!$.support.opacity && opts.cleartype && !opts.cleartypenobg) cleartypefix($slides); // container requires non-static position so that slides can be position within if ($cont.css('position') == 'static') $cont.css('position', 'relative'); if (opts.width) $cont.width(opts.width); if (opts.height && opts.height != 'auto') $cont.height(opts.height); if (opts.startingslide) opts.startingslide = parseint(opts.startingslide); else if (opts.backwards) opts.startingslide = els.length - 1; // if random, mix up the slide array if (opts.random) { opts.randommap = []; for (var i = 0; i < els.length; i++) opts.randommap.push(i); opts.randommap.sort(function (a, b) { return math.random() - 0.5; }); opts.randomindex = 1; opts.startingslide = opts.randommap[1]; } else if (opts.startingslide >= els.length) opts.startingslide = 0; // catch bogus input opts.currslide = opts.startingslide || 0; var first = opts.startingslide; // set position and zindex on all the slides $slides.css({ position: 'absolute', top: 0, left: 0 }).hide().each(function (i) { var z; if (opts.backwards) z = first ? i <= first ? els.length + (i - first) : first - i : els.length - i; else z = first ? i >= first ? els.length - (i - first) : first - i : els.length - i; $(this).css('z-index', z) }); // make sure first slide is visible $(els[first]).css('opacity', 1).show(); // opacity bit needed to handle restart use case removefilter(els[first], opts); // stretch slides if (opts.fit && opts.width) $slides.width(opts.width); if (opts.fit && opts.height && opts.height != 'auto') $slides.height(opts.height); // stretch container var reshape = opts.containerresize && !$cont.innerheight(); if (reshape) { // do this only if container has no size http://tinyurl.com/da2oa9 var maxw = 0, maxh = 0; for (var j = 0; j < els.length; j++) { var $e = $(els[j]), e = $e[0], w = $e.outerwidth(), h = $e.outerheight(); if (!w) w = e.offsetwidth || e.width || $e.attr('width') if (!h) h = e.offsetheight || e.height || $e.attr('height'); maxw = w > maxw ? w : maxw; maxh = h > maxh ? h : maxh; } if (maxw > 0 && maxh > 0) $cont.css({ width: maxw + 'px', height: maxh + 'px' }); } if (opts.pause) $cont.hover(function () { this.cyclepause++; }, function () { this.cyclepause--; }); if (supportmultitransitions(opts) === false) return false; // apparently a lot of people use image slideshows without height/width attributes on the images. // cycle 2.50+ requires the sizing info for every slide; this block tries to deal with that. var requeue = false; options.requeueattempts = options.requeueattempts || 0; $slides.each(function () { // try to get height/width of each slide var $el = $(this); this.cycleh = (opts.fit && opts.height) ? opts.height : ($el.height() || this.offsetheight || this.height || $el.attr('height') || 0); this.cyclew = (opts.fit && opts.width) ? opts.width : ($el.width() || this.offsetwidth || this.width || $el.attr('width') || 0); if ($el.is('img')) { // sigh.. sniffing, hacking, shrugging... this crappy hack tries to account for what browsers do when // an image is being downloaded and the markup did not include sizing info (height/width attributes); // there seems to be some "default" sizes used in this situation var loadingie = ($.browser.msie && this.cyclew == 28 && this.cycleh == 30 && !this.complete); var loadingff = ($.browser.mozilla && this.cyclew == 34 && this.cycleh == 19 && !this.complete); var loadingop = ($.browser.opera && ((this.cyclew == 42 && this.cycleh == 19) || (this.cyclew == 37 && this.cycleh == 17)) && !this.complete); var loadingother = (this.cycleh == 0 && this.cyclew == 0 && !this.complete); // don't requeue for images that are still loading but have a valid size if (loadingie || loadingff || loadingop || loadingother) { if (o.s && opts.requeueonimagenotloaded && ++options.requeueattempts < 100) { // track retry count so we don't loop forever log(options.requeueattempts, ' - img slide not loaded, requeuing slideshow: ', this.src, this.cyclew, this.cycleh); settimeout(function () { $(o.s, o.c).cycle(options) }, opts.requeuetimeout); requeue = true; return false; // break each loop } else { log('could not determine size of image: ' + this.src, this.cyclew, this.cycleh); } } } return true; }); if (requeue) return false; opts.cssbefore = opts.cssbefore || {}; opts.animin = opts.animin || {}; opts.animout = opts.animout || {}; $slides.not(':eq(' + first + ')').css(opts.cssbefore); if (opts.cssfirst) $($slides[first]).css(opts.cssfirst); if (opts.timeout) { opts.timeout = parseint(opts.timeout); // ensure that timeout and speed settings are sane if (opts.speed.constructor == string) opts.speed = $.fx.speeds[opts.speed] || parseint(opts.speed); if (!opts.sync) opts.speed = opts.speed / 2; var buffer = opts.fx == 'shuffle' ? 500 : 250; while ((opts.timeout - opts.speed) < buffer) // sanitize timeout opts.timeout += opts.speed; } if (opts.easing) opts.easein = opts.easeout = opts.easing; if (!opts.speedin) opts.speedin = opts.speed; if (!opts.speedout) opts.speedout = opts.speed; opts.slidecount = els.length; opts.currslide = opts.lastslide = first; if (opts.random) { if (++opts.randomindex == els.length) opts.randomindex = 0; opts.nextslide = opts.randommap[opts.randomindex]; } else if (opts.backwards) opts.nextslide = opts.startingslide == 0 ? (els.length - 1) : opts.startingslide - 1; else opts.nextslide = opts.startingslide >= (els.length - 1) ? 0 : opts.startingslide + 1; // run transition init fn if (!opts.multifx) { var init = $.fn.cycle.transitions[opts.fx]; if ($.isfunction(init)) init($cont, $slides, opts); else if (opts.fx != 'custom' && !opts.multifx) { log('unknown transition: ' + opts.fx, '; slideshow terminating'); return false; } } // fire artificial events var e0 = $slides[first]; if (opts.before.length) opts.before[0].apply(e0, [e0, e0, opts, true]); if (opts.after.length > 1) opts.after[1].apply(e0, [e0, e0, opts, true]); if (opts.next) $(opts.next).bind(opts.prevnextevent, function () { return advance(opts, opts.rev ? -1 : 1) }); if (opts.prev) $(opts.prev).bind(opts.prevnextevent, function () { return advance(opts, opts.rev ? 1 : -1) }); if (opts.pager || opts.pageranchorbuilder) buildpager(els, opts); exposeaddslide(opts, els); return opts; }; // save off original opts so we can restore after clearing state function saveoriginalopts(opts) { opts.original = { before: [], after: [] }; opts.original.cssbefore = $.extend({}, opts.cssbefore); opts.original.cssafter = $.extend({}, opts.cssafter); opts.original.animin = $.extend({}, opts.animin); opts.original.animout = $.extend({}, opts.animout); $.each(opts.before, function () { opts.original.before.push(this); }); $.each(opts.after, function () { opts.original.after.push(this); }); }; function supportmultitransitions(opts) { var i, tx, txs = $.fn.cycle.transitions; // look for multiple effects if (opts.fx.indexof(',') > 0) { opts.multifx = true; opts.fxs = opts.fx.replace(/\s*/g, '').split(','); // discard any bogus effect names for (i = 0; i < opts.fxs.length; i++) { var fx = opts.fxs[i]; tx = txs[fx]; if (!tx || !txs.hasownproperty(fx) || !$.isfunction(tx)) { log('discarding unknown transition: ', fx); opts.fxs.splice(i, 1); i--; } } // if we have an empty list then we threw everything away! if (!opts.fxs.length) { log('no valid transitions named; slideshow terminating.'); return false; } } else if (opts.fx == 'all') { // auto-gen the list of transitions opts.multifx = true; opts.fxs = []; for (p in txs) { tx = txs[p]; if (txs.hasownproperty(p) && $.isfunction(tx)) opts.fxs.push(p); } } if (opts.multifx && opts.randomizeeffects) { // munge the fxs array to make effect selection random var r1 = math.floor(math.random() * 20) + 30; for (i = 0; i < r1; i++) { var r2 = math.floor(math.random() * opts.fxs.length); opts.fxs.push(opts.fxs.splice(r2, 1)[0]); } debug('randomized fx sequence: ', opts.fxs); } return true; }; // provide a mechanism for adding slides after the slideshow has started function exposeaddslide(opts, els) { opts.addslide = function (newslide, prepend) { var $s = $(newslide), s = $s[0]; if (!opts.autostopcount) opts.countdown++; els[prepend ? 'unshift' : 'push'](s); if (opts.els) opts.els[prepend ? 'unshift' : 'push'](s); // shuffle needs this opts.slidecount = els.length; $s.css('position', 'absolute'); $s[prepend ? 'prependto' : 'appendto'](opts.$cont); if (prepend) { opts.currslide++; opts.nextslide++; } if (!$.support.opacity && opts.cleartype && !opts.cleartypenobg) cleartypefix($s); if (opts.fit && opts.width) $s.width(opts.width); if (opts.fit && opts.height && opts.height != 'auto') $slides.height(opts.height); s.cycleh = (opts.fit && opts.height) ? opts.height : $s.height(); s.cyclew = (opts.fit && opts.width) ? opts.width : $s.width(); $s.css(opts.cssbefore); if (opts.pager || opts.pageranchorbuilder) $.fn.cycle.createpageranchor(els.length - 1, s, $(opts.pager), els, opts); if ($.isfunction(opts.onaddslide)) opts.onaddslide($s); else $s.hide(); // default behavior }; } // reset internal state; we do this on every pass in order to support multiple effects $.fn.cycle.resetstate = function (opts, fx) { fx = fx || opts.fx; opts.before = []; opts.after = []; opts.cssbefore = $.extend({}, opts.original.cssbefore); opts.cssafter = $.extend({}, opts.original.cssafter); opts.animin = $.extend({}, opts.original.animin); opts.animout = $.extend({}, opts.original.animout); opts.fxfn = null; $.each(opts.original.before, function () { opts.before.push(this); }); $.each(opts.original.after, function () { opts.after.push(this); }); // re-init var init = $.fn.cycle.transitions[fx]; if ($.isfunction(init)) init(opts.$cont, $(opts.elements), opts); }; // this is the main engine fn, it handles the timeouts, callbacks and slide index mgmt function go(els, opts, manual, fwd) { // opts.busy is true if we're in the middle of an animation if (manual && opts.busy && opts.manualtrump) { // let manual transitions requests trump active ones debug('manualtrump in go(), stopping active transition'); $(els).stop(true, true); opts.busy = false; } // don't begin another timeout-based transition if there is one active if (opts.busy) { debug('transition active, ignoring new tx request'); return; } var p = opts.$cont[0], curr = els[opts.currslide], next = els[opts.nextslide]; // stop cycling if we have an outstanding stop request if (p.cyclestop != opts.stopcount || p.cycletimeout === 0 && !manual) return; // check to see if we should stop cycling based on autostop options if (!manual && !p.cyclepause && !opts.bounce && ((opts.autostop && (--opts.countdown <= 0)) || (opts.nowrap && !opts.random && opts.nextslide < opts.currslide))) { if (opts.end) opts.end(opts); return; } // if slideshow is paused, only transition on a manual trigger var changed = false; if ((manual || !p.cyclepause) && (opts.nextslide != opts.currslide)) { changed = true; var fx = opts.fx; // keep trying to get the slide size if we don't have it yet curr.cycleh = curr.cycleh || $(curr).height(); curr.cyclew = curr.cyclew || $(curr).width(); next.cycleh = next.cycleh || $(next).height(); next.cyclew = next.cyclew || $(next).width(); // support multiple transition types if (opts.multifx) { if (opts.lastfx == undefined || ++opts.lastfx >= opts.fxs.length) opts.lastfx = 0; fx = opts.fxs[opts.lastfx]; opts.currfx = fx; } // one-time fx overrides apply to: $('div').cycle(3,'zoom'); if (opts.onetimefx) { fx = opts.onetimefx; opts.onetimefx = null; } $.fn.cycle.resetstate(opts, fx); // run the before callbacks if (opts.before.length) $.each(opts.before, function (i, o) { if (p.cyclestop != opts.stopcount) return; o.apply(next, [curr, next, opts, fwd]); }); // stage the after callacks var after = function () { $.each(opts.after, function (i, o) { if (p.cyclestop != opts.stopcount) return; o.apply(next, [curr, next, opts, fwd]); }); }; debug('tx firing; currslide: ' + opts.currslide + '; nextslide: ' + opts.nextslide); // get ready to perform the transition opts.busy = 1; if (opts.fxfn) // fx function provided? opts.fxfn(curr, next, opts, after, fwd, manual && opts.fastonevent); else if ($.isfunction($.fn.cycle[opts.fx])) // fx plugin ? $.fn.cycle[opts.fx](curr, next, opts, after, fwd, manual && opts.fastonevent); else $.fn.cycle.custom(curr, next, opts, after, fwd, manual && opts.fastonevent); } if (changed || opts.nextslide == opts.currslide) { // calculate the next slide opts.lastslide = opts.currslide; if (opts.random) { opts.currslide = opts.nextslide; if (++opts.randomindex == els.length) opts.randomindex = 0; opts.nextslide = opts.randommap[opts.randomindex]; if (opts.nextslide == opts.currslide) opts.nextslide = (opts.currslide == opts.slidecount - 1) ? 0 : opts.currslide + 1; } else if (opts.backwards) { var roll = (opts.nextslide - 1) < 0; if (roll && opts.bounce) { opts.backwards = !opts.backwards; opts.nextslide = 1; opts.currslide = 0; } else { opts.nextslide = roll ? (els.length - 1) : opts.nextslide - 1; opts.currslide = roll ? 0 : opts.nextslide + 1; } } else { // sequence var roll = (opts.nextslide + 1) == els.length; if (roll && opts.bounce) { opts.backwards = !opts.backwards; opts.nextslide = els.length - 2; opts.currslide = els.length - 1; } else { opts.nextslide = roll ? 0 : opts.nextslide + 1; opts.currslide = roll ? els.length - 1 : opts.nextslide - 1; } } } if (changed && opts.pager) opts.updateactivepagerlink(opts.pager, opts.currslide, opts.activepagerclass); // stage the next transition var ms = 0; if (opts.timeout && !opts.continuous) ms = gettimeout(els[opts.currslide], els[opts.nextslide], opts, fwd); else if (opts.continuous && p.cyclepause) // continuous shows work off an after callback, not this timer logic ms = 10; if (ms > 0) p.cycletimeout = settimeout(function () { go(els, opts, 0, (!opts.rev && !opts.backwards)) }, ms); }; // invoked after transition $.fn.cycle.updateactivepagerlink = function (pager, currslide, clsname) { $(pager).each(function () { $(this).children().removeclass(clsname).eq(currslide).addclass(clsname); }); }; // calculate timeout value for current transition function gettimeout(curr, next, opts, fwd) { if (opts.timeoutfn) { // call user provided calc fn var t = opts.timeoutfn.call(curr, curr, next, opts, fwd); while ((t - opts.speed) < 250) // sanitize timeout t += opts.speed; debug('calculated timeout: ' + t + '; speed: ' + opts.speed); if (t !== false) return t; } return opts.timeout; }; // expose next/prev function, caller must pass in state $.fn.cycle.next = function (opts) { advance(opts, opts.rev ? -1 : 1); }; $.fn.cycle.prev = function (opts) { advance(opts, opts.rev ? 1 : -1); }; // advance slide forward or back function advance(opts, val) { var els = opts.elements; var p = opts.$cont[0], timeout = p.cycletimeout; if (timeout) { cleartimeout(timeout); p.cycletimeout = 0; } if (opts.random && val < 0) { // move back to the previously display slide opts.randomindex--; if (--opts.randomindex == -2) opts.randomindex = els.length - 2; else if (opts.randomindex == -1) opts.randomindex = els.length - 1; opts.nextslide = opts.randommap[opts.randomindex]; } else if (opts.random) { opts.nextslide = opts.randommap[opts.randomindex]; } else { opts.nextslide = opts.currslide + val; if (opts.nextslide < 0) { if (opts.nowrap) return false; opts.nextslide = els.length - 1; } else if (opts.nextslide >= els.length) { if (opts.nowrap) return false; opts.nextslide = 0; } } var cb = opts.onprevnextevent || opts.prevnextclick; // prevnextclick is deprecated if ($.isfunction(cb)) cb(val > 0, opts.nextslide, els[opts.nextslide]); go(els, opts, 1, val >= 0); return false; }; function buildpager(els, opts) { var $p = $(opts.pager); $.each(els, function (i, o) { $.fn.cycle.createpageranchor(i, o, $p, els, opts); }); opts.updateactivepagerlink(opts.pager, opts.startingslide, opts.activepagerclass); }; $.fn.cycle.createpageranchor = function (i, el, $p, els, opts) { var a; if ($.isfunction(opts.pageranchorbuilder)) { a = opts.pageranchorbuilder(i, el); debug('pageranchorbuilder(' + i + ', el) returned: ' + a); } else a = '' + (i + 1) + ''; if (!a) return; var $a = $(a); // don't reparent if anchor is in the dom if ($a.parents('body').length === 0) { var arr = []; if ($p.length > 1) { $p.each(function () { var $clone = $a.clone(true); $(this).append($clone); arr.push($clone[0]); }); $a = $(arr); } else { $a.appendto($p); } } opts.pageranchors = opts.pageranchors || []; opts.pageranchors.push($a); $a.bind(opts.pagerevent, function (e) { e.preventdefault(); opts.nextslide = i; var p = opts.$cont[0], timeout = p.cycletimeout; if (timeout) { cleartimeout(timeout); p.cycletimeout = 0; } var cb = opts.onpagerevent || opts.pagerclick; // pagerclick is deprecated if ($.isfunction(cb)) cb(opts.nextslide, els[opts.nextslide]); go(els, opts, 1, opts.currslide < i); // trigger the trans // return false; // <== allow bubble }); if (!/^click/.test(opts.pagerevent) && !opts.allowpagerclickbubble) $a.bind('click.cycle', function () { return false; }); // suppress click if (opts.pauseonpagerhover) $a.hover(function () { opts.$cont[0].cyclepause++; }, function () { opts.$cont[0].cyclepause--; }); }; // helper fn to calculate the number of slides between the current and the next $.fn.cycle.hopsfromlast = function (opts, fwd) { var hops, l = opts.lastslide, c = opts.currslide; if (fwd) hops = c > l ? c - l : opts.slidecount - l; else hops = c < l ? l - c : l + opts.slidecount - c; return hops; }; // fix cleartype problems in ie6 by setting an explicit bg color // (otherwise text slides look horrible during a fade transition) function cleartypefix($slides) { debug('applying cleartype background-color hack'); function hex(s) { s = parseint(s).tostring(16); return s.length < 2 ? '0' + s : s; }; function getbg(e) { for (; e && e.nodename.tolowercase() != 'html'; e = e.parentnode) { var v = $.css(e, 'background-color'); if (v.indexof('rgb') >= 0) { var rgb = v.match(/\d+/g); return '#' + hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]); } if (v && v != 'transparent') return v; } return '#ffffff'; }; $slides.each(function () { $(this).css('background-color', getbg(this)); }); }; // reset common props before the next transition $.fn.cycle.commonreset = function (curr, next, opts, w, h, rev) { $(opts.elements).not(curr).hide(); opts.cssbefore.opacity = 1; opts.cssbefore.display = 'block'; if (w !== false && next.cyclew > 0) opts.cssbefore.width = next.cyclew; if (h !== false && next.cycleh > 0) opts.cssbefore.height = next.cycleh; opts.cssafter = opts.cssafter || {}; opts.cssafter.display = 'none'; $(curr).css('zindex', opts.slidecount + (rev === true ? 1 : 0)); $(next).css('zindex', opts.slidecount + (rev === true ? 0 : 1)); }; // the actual fn for effecting a transition $.fn.cycle.custom = function (curr, next, opts, cb, fwd, speedoverride) { var $l = $(curr), $n = $(next); var speedin = opts.speedin, speedout = opts.speedout, easein = opts.easein, easeout = opts.easeout; $n.css(opts.cssbefore); if (speedoverride) { if (typeof speedoverride == 'number') speedin = speedout = speedoverride; else speedin = speedout = 1; easein = easeout = null; } var fn = function () { $n.animate(opts.animin, speedin, easein, cb) }; $l.animate(opts.animout, speedout, easeout, function () { if (opts.cssafter) $l.css(opts.cssafter); if (!opts.sync) fn(); }); if (opts.sync) fn(); }; // transition definitions - only fade is defined here, transition pack defines the rest $.fn.cycle.transitions = { fade: function ($cont, $slides, opts) { $slides.not(':eq(' + opts.currslide + ')').css('opacity', 0); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts); opts.cssbefore.opacity = 0; }); opts.animin = { opacity: 1 }; opts.animout = { opacity: 0 }; opts.cssbefore = { top: 0, left: 0 }; } }; $.fn.cycle.ver = function () { return ver; }; // override these globally if you like (they are all optional) $.fn.cycle.defaults = { fx: 'fade', // name of transition effect (or comma separated names, ex: 'fade,scrollup,shuffle') timeout: 4000, // milliseconds between slide transitions (0 to disable auto advance) timeoutfn: null, // callback for determining per-slide timeout value: function(currslideelement, nextslideelement, options, forwardflag) continuous: 0, // true to start next transition immediately after current one completes speed: 1000, // speed of the transition (any valid fx speed value) speedin: null, // speed of the 'in' transition speedout: null, // speed of the 'out' transition next: null, // selector for element to use as event trigger for next slide prev: null, // selector for element to use as event trigger for previous slide // prevnextclick: null, // @deprecated; please use onprevnextevent instead onprevnextevent: null, // callback fn for prev/next events: function(isnext, zerobasedslideindex, slideelement) prevnextevent: 'click.cycle', // event which drives the manual transition to the previous or next slide pager: null, // selector for element to use as pager container //pagerclick null, // @deprecated; please use onpagerevent instead onpagerevent: null, // callback fn for pager events: function(zerobasedslideindex, slideelement) pagerevent: 'click.cycle', // name of event which drives the pager navigation allowpagerclickbubble: false, // allows or prevents click event on pager anchors from bubbling pageranchorbuilder: null, // callback fn for building anchor links: function(index, domelement) before: null, // transition callback (scope set to element to be shown): function(currslideelement, nextslideelement, options, forwardflag) after: null, // transition callback (scope set to element that was shown): function(currslideelement, nextslideelement, options, forwardflag) end: null, // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options) easing: null, // easing method for both in and out transitions easein: null, // easing for "in" transition easeout: null, // easing for "out" transition shuffle: null, // coords for shuffle animation, ex: { top:15, left: 200 } animin: null, // properties that define how the slide animates in animout: null, // properties that define how the slide animates out cssbefore: null, // properties that define the initial state of the slide before transitioning in cssafter: null, // properties that defined the state of the slide after transitioning out fxfn: null, // function used to control the transition: function(currslideelement, nextslideelement, options, aftercalback, forwardflag) height: 'auto', // container height startingslide: 0, // zero-based index of the first slide to be displayed sync: 1, // true if in/out transitions should occur simultaneously random: 0, // true for random, false for sequence (not applicable to shuffle fx) fit: 0, // force slides to fit container containerresize: 1, // resize container to fit largest slide pause: 0, // true to enable "pause on hover" pauseonpagerhover: 0, // true to pause when hovering over pager link autostop: 0, // true to end slideshow after x transitions (where x == slide count) autostopcount: 0, // number of transitions (optionally used with autostop to define x) delay: 0, // additional delay (in ms) for first transition (hint: can be negative) slideexpr: null, // expression for selecting slides (if something other than all children is required) cleartype: !$.support.opacity, // true if cleartype corrections should be applied (for ie) cleartypenobg: false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides) nowrap: 0, // true to prevent slideshow from wrapping fastonevent: 0, // force fast transitions when triggered manually (via pager or prev/next); value == time in ms randomizeeffects: 1, // valid when multiple effects are used; true to make the effect sequence random rev: 0, // causes animations to transition in reverse manualtrump: true, // causes manual transition to stop an active transition instead of being ignored requeueonimagenotloaded: true, // requeue the slideshow if any image slides are not yet loaded requeuetimeout: 250, // ms delay for requeue activepagerclass: 'activeslide', // class name used for the active pager link updateactivepagerlink: null, // callback fn invoked to update the active pager link (adds/removes activepagerclass style) backwards: false // true to start slideshow at last slide and move backwards through the stack }; })(jquery); /*! * jquery cycle plugin transition definitions * this script is a plugin for the jquery cycle plugin * examples and documentation at: http://malsup.com/jquery/cycle/ * copyright (c) 2007-2010 m. alsup * version: 2.72 * dual licensed under the mit and gpl licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ (function ($) { // // these functions define one-time slide initialization for the named // transitions. to save file size feel free to remove any of these that you // don't need. // $.fn.cycle.transitions.none = function ($cont, $slides, opts) { opts.fxfn = function (curr, next, opts, after) { $(next).show(); $(curr).hide(); after(); }; } // scrollup/down/left/right $.fn.cycle.transitions.scrollup = function ($cont, $slides, opts) { $cont.css('overflow', 'hidden'); opts.before.push($.fn.cycle.commonreset); var h = $cont.height(); opts.cssbefore = { top: h, left: 0 }; opts.cssfirst = { top: 0 }; opts.animin = { top: 0 }; opts.animout = { top: -h }; }; $.fn.cycle.transitions.scrolldown = function ($cont, $slides, opts) { $cont.css('overflow', 'hidden'); opts.before.push($.fn.cycle.commonreset); var h = $cont.height(); opts.cssfirst = { top: 0 }; opts.cssbefore = { top: -h, left: 0 }; opts.animin = { top: 0 }; opts.animout = { top: h }; }; $.fn.cycle.transitions.scrollleft = function ($cont, $slides, opts) { $cont.css('overflow', 'hidden'); opts.before.push($.fn.cycle.commonreset); var w = $cont.width(); opts.cssfirst = { left: 0 }; opts.cssbefore = { left: w, top: 0 }; opts.animin = { left: 0 }; opts.animout = { left: 0 - w }; }; $.fn.cycle.transitions.scrollright = function ($cont, $slides, opts) { $cont.css('overflow', 'hidden'); opts.before.push($.fn.cycle.commonreset); var w = $cont.width(); opts.cssfirst = { left: 0 }; opts.cssbefore = { left: -w, top: 0 }; opts.animin = { left: 0 }; opts.animout = { left: w }; }; $.fn.cycle.transitions.scrollhorz = function ($cont, $slides, opts) { $cont.css('overflow', 'hidden').width(); opts.before.push(function (curr, next, opts, fwd) { $.fn.cycle.commonreset(curr, next, opts); opts.cssbefore.left = fwd ? (next.cyclew - 1) : (1 - next.cyclew); opts.animout.left = fwd ? -curr.cyclew : curr.cyclew; }); opts.cssfirst = { left: 0 }; opts.cssbefore = { top: 0 }; opts.animin = { left: 0 }; opts.animout = { top: 0 }; }; $.fn.cycle.transitions.scrollvert = function ($cont, $slides, opts) { $cont.css('overflow', 'hidden'); opts.before.push(function (curr, next, opts, fwd) { $.fn.cycle.commonreset(curr, next, opts); opts.cssbefore.top = fwd ? (1 - next.cycleh) : (next.cycleh - 1); opts.animout.top = fwd ? curr.cycleh : -curr.cycleh; }); opts.cssfirst = { top: 0 }; opts.cssbefore = { left: 0 }; opts.animin = { top: 0 }; opts.animout = { left: 0 }; }; // slidex/slidey $.fn.cycle.transitions.slidex = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $(opts.elements).not(curr).hide(); $.fn.cycle.commonreset(curr, next, opts, false, true); opts.animin.width = next.cyclew; }); opts.cssbefore = { left: 0, top: 0, width: 0 }; opts.animin = { width: 'show' }; opts.animout = { width: 0 }; }; $.fn.cycle.transitions.slidey = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $(opts.elements).not(curr).hide(); $.fn.cycle.commonreset(curr, next, opts, true, false); opts.animin.height = next.cycleh; }); opts.cssbefore = { left: 0, top: 0, height: 0 }; opts.animin = { height: 'show' }; opts.animout = { height: 0 }; }; // shuffle $.fn.cycle.transitions.shuffle = function ($cont, $slides, opts) { var i, w = $cont.css('overflow', 'visible').width(); $slides.css({ left: 0, top: 0 }); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, true, true); }); // only adjust speed once! if (!opts.speedadjusted) { opts.speed = opts.speed / 2; // shuffle has 2 transitions opts.speedadjusted = true; } opts.random = 0; opts.shuffle = opts.shuffle || { left: -w, top: 15 }; opts.els = []; for (i = 0; i < $slides.length; i++) opts.els.push($slides[i]); for (i = 0; i < opts.currslide; i++) opts.els.push(opts.els.shift()); // custom transition fn (hat tip to benjamin sterling for this bit of sweetness!) opts.fxfn = function (curr, next, opts, cb, fwd) { var $el = fwd ? $(curr) : $(next); $(next).css(opts.cssbefore); var count = opts.slidecount; $el.animate(opts.shuffle, opts.speedin, opts.easein, function () { var hops = $.fn.cycle.hopsfromlast(opts, fwd); for (var k = 0; k < hops; k++) fwd ? opts.els.push(opts.els.shift()) : opts.els.unshift(opts.els.pop()); if (fwd) { for (var i = 0, len = opts.els.length; i < len; i++) $(opts.els[i]).css('z-index', len - i + count); } else { var z = $(curr).css('z-index'); $el.css('z-index', parseint(z) + 1 + count); } $el.animate({ left: 0, top: 0 }, opts.speedout, opts.easeout, function () { $(fwd ? this : curr).hide(); if (cb) cb(); }); }); }; opts.cssbefore = { display: 'block', opacity: 1, top: 0, left: 0 }; }; // turnup/down/left/right $.fn.cycle.transitions.turnup = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, false); opts.cssbefore.top = next.cycleh; opts.animin.height = next.cycleh; }); opts.cssfirst = { top: 0 }; opts.cssbefore = { left: 0, height: 0 }; opts.animin = { top: 0 }; opts.animout = { height: 0 }; }; $.fn.cycle.transitions.turndown = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, false); opts.animin.height = next.cycleh; opts.animout.top = curr.cycleh; }); opts.cssfirst = { top: 0 }; opts.cssbefore = { left: 0, top: 0, height: 0 }; opts.animout = { height: 0 }; }; $.fn.cycle.transitions.turnleft = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, false, true); opts.cssbefore.left = next.cyclew; opts.animin.width = next.cyclew; }); opts.cssbefore = { top: 0, width: 0 }; opts.animin = { left: 0 }; opts.animout = { width: 0 }; }; $.fn.cycle.transitions.turnright = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, false, true); opts.animin.width = next.cyclew; opts.animout.left = curr.cyclew; }); opts.cssbefore = { top: 0, left: 0, width: 0 }; opts.animin = { left: 0 }; opts.animout = { width: 0 }; }; // zoom $.fn.cycle.transitions.zoom = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, false, false, true); opts.cssbefore.top = next.cycleh / 2; opts.cssbefore.left = next.cyclew / 2; opts.animin = { top: 0, left: 0, width: next.cyclew, height: next.cycleh }; opts.animout = { width: 0, height: 0, top: curr.cycleh / 2, left: curr.cyclew / 2 }; }); opts.cssfirst = { top: 0, left: 0 }; opts.cssbefore = { width: 0, height: 0 }; }; // fadezoom $.fn.cycle.transitions.fadezoom = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, false, false); opts.cssbefore.left = next.cyclew / 2; opts.cssbefore.top = next.cycleh / 2; opts.animin = { top: 0, left: 0, width: next.cyclew, height: next.cycleh }; }); opts.cssbefore = { width: 0, height: 0 }; opts.animout = { opacity: 0 }; }; // blindx $.fn.cycle.transitions.blindx = function ($cont, $slides, opts) { var w = $cont.css('overflow', 'hidden').width(); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts); opts.animin.width = next.cyclew; opts.animout.left = curr.cyclew; }); opts.cssbefore = { left: w, top: 0 }; opts.animin = { left: 0 }; opts.animout = { left: w }; }; // blindy $.fn.cycle.transitions.blindy = function ($cont, $slides, opts) { var h = $cont.css('overflow', 'hidden').height(); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts); opts.animin.height = next.cycleh; opts.animout.top = curr.cycleh; }); opts.cssbefore = { top: h, left: 0 }; opts.animin = { top: 0 }; opts.animout = { top: h }; }; // blindz $.fn.cycle.transitions.blindz = function ($cont, $slides, opts) { var h = $cont.css('overflow', 'hidden').height(); var w = $cont.width(); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts); opts.animin.height = next.cycleh; opts.animout.top = curr.cycleh; }); opts.cssbefore = { top: h, left: w }; opts.animin = { top: 0, left: 0 }; opts.animout = { top: h, left: w }; }; // growx - grow horizontally from centered 0 width $.fn.cycle.transitions.growx = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, false, true); opts.cssbefore.left = this.cyclew / 2; opts.animin = { left: 0, width: this.cyclew }; opts.animout = { left: 0 }; }); opts.cssbefore = { width: 0, top: 0 }; }; // growy - grow vertically from centered 0 height $.fn.cycle.transitions.growy = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, false); opts.cssbefore.top = this.cycleh / 2; opts.animin = { top: 0, height: this.cycleh }; opts.animout = { top: 0 }; }); opts.cssbefore = { height: 0, left: 0 }; }; // curtainx - squeeze in both edges horizontally $.fn.cycle.transitions.curtainx = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, false, true, true); opts.cssbefore.left = next.cyclew / 2; opts.animin = { left: 0, width: this.cyclew }; opts.animout = { left: curr.cyclew / 2, width: 0 }; }); opts.cssbefore = { top: 0, width: 0 }; }; // curtainy - squeeze in both edges vertically $.fn.cycle.transitions.curtainy = function ($cont, $slides, opts) { opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, false, true); opts.cssbefore.top = next.cycleh / 2; opts.animin = { top: 0, height: next.cycleh }; opts.animout = { top: curr.cycleh / 2, height: 0 }; }); opts.cssbefore = { left: 0, height: 0 }; }; // cover - curr slide covered by next slide $.fn.cycle.transitions.cover = function ($cont, $slides, opts) { var d = opts.direction || 'left'; var w = $cont.css('overflow', 'hidden').width(); var h = $cont.height(); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts); if (d == 'right') opts.cssbefore.left = -w; else if (d == 'up') opts.cssbefore.top = h; else if (d == 'down') opts.cssbefore.top = -h; else opts.cssbefore.left = w; }); opts.animin = { left: 0, top: 0 }; opts.animout = { opacity: 1 }; opts.cssbefore = { top: 0, left: 0 }; }; // uncover - curr slide moves off next slide $.fn.cycle.transitions.uncover = function ($cont, $slides, opts) { var d = opts.direction || 'left'; var w = $cont.css('overflow', 'hidden').width(); var h = $cont.height(); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, true, true); if (d == 'right') opts.animout.left = w; else if (d == 'up') opts.animout.top = -h; else if (d == 'down') opts.animout.top = h; else opts.animout.left = -w; }); opts.animin = { left: 0, top: 0 }; opts.animout = { opacity: 1 }; opts.cssbefore = { top: 0, left: 0 }; }; // toss - move top slide and fade away $.fn.cycle.transitions.toss = function ($cont, $slides, opts) { var w = $cont.css('overflow', 'visible').width(); var h = $cont.height(); opts.before.push(function (curr, next, opts) { $.fn.cycle.commonreset(curr, next, opts, true, true, true); // provide default toss settings if animout not provided if (!opts.animout.left && !opts.animout.top) opts.animout = { left: w * 2, top: -h / 2, opacity: 0 }; else opts.animout.opacity = 0; }); opts.cssbefore = { left: 0, top: 0 }; opts.animin = { left: 0 }; }; // wipe - clip animation $.fn.cycle.transitions.wipe = function ($cont, $slides, opts) { var w = $cont.css('overflow', 'hidden').width(); var h = $cont.height(); opts.cssbefore = opts.cssbefore || {}; var clip; if (opts.clip) { if (/l2r/.test(opts.clip)) clip = 'rect(0px 0px ' + h + 'px 0px)'; else if (/r2l/.test(opts.clip)) clip = 'rect(0px ' + w + 'px ' + h + 'px ' + w + 'px)'; else if (/t2b/.test(opts.clip)) clip = 'rect(0px ' + w + 'px 0px 0px)'; else if (/b2t/.test(opts.clip)) clip = 'rect(' + h + 'px ' + w + 'px ' + h + 'px 0px)'; else if (/zoom/.test(opts.clip)) { var top = parseint(h / 2); var left = parseint(w / 2); clip = 'rect(' + top + 'px ' + left + 'px ' + top + 'px ' + left + 'px)'; } } opts.cssbefore.clip = opts.cssbefore.clip || clip || 'rect(0px 0px 0px 0px)'; var d = opts.cssbefore.clip.match(/(\d+)/g); var t = parseint(d[0]), r = parseint(d[1]), b = parseint(d[2]), l = parseint(d[3]); opts.before.push(function (curr, next, opts) { if (curr == next) return; var $curr = $(curr), $next = $(next); $.fn.cycle.commonreset(curr, next, opts, true, true, false); opts.cssafter.display = 'block'; var step = 1, count = parseint((opts.speedin / 13)) - 1; (function f() { var tt = t ? t - parseint(step * (t / count)) : 0; var ll = l ? l - parseint(step * (l / count)) : 0; var bb = b < h ? b + parseint(step * ((h - b) / count || 1)) : h; var rr = r < w ? r + parseint(step * ((w - r) / count || 1)) : w; $next.css({ clip: 'rect(' + tt + 'px ' + rr + 'px ' + bb + 'px ' + ll + 'px)' }); (step++ <= count) ? settimeout(f, 13) : $curr.css('display', 'none'); })(); }); opts.cssbefore = { display: 'block', opacity: 1, top: 0, left: 0 }; opts.animin = { left: 0 }; opts.animout = { left: 0 }; }; })(jquery);