// colorbox v1.3.15 - a full featured, light-weight, customizable lightbox based on jquery 1.3+ // copyright (c) 2010 jack moore - jack@colorpowered.com // licensed under the mit license: http://www.opensource.org/licenses/mit-license.php (function ($, window) { var // colorbox default settings. // see http://colorpowered.com/colorbox for details. defaults = { transition: "elastic", speed: 300, width: false, initialwidth: "310", innerwidth: false, maxwidth: false, height: false, initialheight: "450", innerheight: false, maxheight: false, scalephotos: true, scrolling: true, inline: false, html: false, iframe: false, photo: false, href: false, title: false, rel: false, opacity: 0.0, preloading: true, //current: "image {current} of {total}", //previous: "previous", //next: "next", close: "close", open: false, returnfocus: true, loop: true, slideshow: false, slideshowauto: true, slideshowspeed: 2500, slideshowstart: "start slideshow", slideshowstop: "stop slideshow", onopen: false, onload: false, oncomplete: false, oncleanup: false, onclosed: false, overlayclose: true, esckey: true, arrowkey: true }, // abstracting the html and event identifiers for easy rebranding colorbox = 'colorbox', prefix = 'cbox', // events event_open = prefix + '_open', event_load = prefix + '_load', event_complete = prefix + '_complete', event_cleanup = prefix + '_cleanup', event_closed = prefix + '_closed', event_purge = prefix + '_purge', event_loaded = prefix + '_loaded', // special handling for ie isie = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of chrome. isie6 = isie && $.browser.version < 7, event_ie6 = prefix + '_ie6', // cached jquery object variables $overlay, $box, $wrap, $content, $topborder, $leftborder, $rightborder, $bottomborder, $related, $window, $loaded, $loadingbay, $loadingoverlay, $title, $current, $slideshow, $next, $prev, $close, // variables for cached values or use across multiple functions interfaceheight, interfacewidth, loadedheight, loadedwidth, element, index, settings, open, active, closing = false, publicmethod, boxelement = prefix + 'element'; // **************** // helper functions // **************** // jquery object generator to reduce code size function $div(id, css) { id = id ? ' id="' + prefix + id + '"' : ''; css = css ? ' style="' + css + '"' : ''; return $(''); } // convert % values to pixels function setsize(size, dimension) { dimension = dimension === 'x' ? $window.width() : $window.height(); return (typeof size === 'string') ? math.round((/%/.test(size) ? (dimension / 100) * parseint(size, 10) : parseint(size, 10))) : size; } // checks an href to see if it is a photo. // there is a force photo option (photo: true) for hrefs that cannot be matched by this regex. function isimage(url) { return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url); } // assigns function results to their respective settings. this allows functions to be used as values. function process(settings) { for (var i in settings) { if ($.isfunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time. settings[i] = settings[i].call(element); } } settings.rel = settings.rel || element.rel || 'nofollow'; settings.href = settings.href || $(element).attr('href'); settings.title = settings.title || element.title; return settings; } function trigger(event, callback) { if (callback) { callback.call(element); } $.event.trigger(event); } // slideshow functionality function slideshow() { var timeout, classname = prefix + "slideshow_", click = "click." + prefix, start, stop, clear; if (settings.slideshow && $related[1]) { start = function () { $slideshow .text(settings.slideshowstop) .unbind(click) .bind(event_complete, function () { if (index < $related.length - 1 || settings.loop) { timeout = settimeout(publicmethod.next, settings.slideshowspeed); } }) .bind(event_load, function () { cleartimeout(timeout); }) .one(click + ' ' + event_cleanup, stop); $box.removeclass(classname + "off").addclass(classname + "on"); timeout = settimeout(publicmethod.next, settings.slideshowspeed); }; stop = function () { cleartimeout(timeout); $slideshow .text(settings.slideshowstart) .unbind([event_complete, event_load, event_cleanup, click].join(' ')) .one(click, start); $box.removeclass(classname + "on").addclass(classname + "off"); }; if (settings.slideshowauto) { start(); } else { stop(); } } } function launch(elem) { if (!closing) { element = elem; settings = process($.extend({}, $.data(element, colorbox))); $related = $(element); index = 0; if (settings.rel !== 'nofollow') { $related = $('.' + boxelement).filter(function () { var relrelated = $.data(this, colorbox).rel || this.rel; return (relrelated === settings.rel); }); index = $related.index(element); // check direct calls to colorbox. if (index === -1) { $related = $related.add(element); index = $related.length - 1; } } if (!open) { open = active = true; // prevents the page-change action from queuing up if the visitor holds down the left or right keys. $box.show(); if (settings.returnfocus) { try { element.blur(); $(element).one(event_closed, function () { try { this.focus(); } catch (e) { // do nothing } }); } catch (e) { // do nothing } } // +settings.opacity avoids a problem in ie when using non-zero-prefixed-string-values, like '.5' $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayclose ? "pointer" : "auto"}).show(); // opens inital empty colorbox prior to content being loaded. settings.w = setsize(settings.initialwidth, 'x'); settings.h = setsize(settings.initialheight, 'y'); publicmethod.position(0); if (isie6) { $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () { $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrolltop(), left: $window.scrollleft()}); }).trigger('scroll.' + event_ie6); } trigger(event_open, settings.onopen); $current.add($prev).add($next).add($slideshow).add($title).hide(); $close.html(settings.close).show(); } publicmethod.load(true); } } // **************** // public functions // usage format: $.fn.colorbox.close(); // usage from within an iframe: parent.$.fn.colorbox.close(); // **************** publicmethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { var $this = this, autoopen; if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit. return $this; } options = options || {}; if (callback) { options.oncomplete = callback; } if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox() $this = $(''); options.open = true; // assume an immediate open } $this.each(function () { $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options)); $(this).addclass(boxelement); }); autoopen = options.open; if ($.isfunction(autoopen)) { autoopen = autoopen.call($this); } if (autoopen) { launch($this[0]); } return $this; }; // initialize colorbox: store common calculations, preload the interface graphics, append the html. // this preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only // having to run once, instead of each time colorbox is opened. publicmethod.init = function () { // create & append jquery objects $window = $(window); $box = $div().attr({id: colorbox, 'class': isie ? prefix + 'ie' : ''}); $overlay = $div("overlay", isie6 ? 'position:absolute' : '').hide(); $wrap = $div("wrapper"); $content = $div("content").append( $loaded = $div("loadedcontent", 'width:0; height:0; overflow:visible'), $loadingoverlay = $div("loadingoverlay").add($div("loadinggraphic")), $title = $div("title"), $current = $div("current"), $next = $div("next"), $prev = $div("previous"), $slideshow = $div("slideshow").bind(event_open, slideshow), $close = $div("close") ); $wrap.append( // the 3x3 grid that makes up colorbox $div().append( $div("topleft"), $topborder = $div("topcenter"), $div("topright") ), $div(false, 'clear:left').append( $leftborder = $div("middleleft"), $content, $rightborder = $div("middleright") ), $div(false, 'clear:left').append( $div("bottomleft"), $bottomborder = $div("bottomcenter"), $div("bottomright") ) ).children().children().css({'float': 'left'}); $loadingbay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none'); $('body').prepend($overlay, $box.append($wrap, $loadingbay)); $content.children() .hover(function () { $(this).addclass('hover'); }, function () { $(this).removeclass('hover'); }).addclass('hover'); // cache values needed for size calculations interfaceheight = $topborder.height() + $bottomborder.height() + $content.outerheight(true) - $content.height();//subtraction needed for ie6 interfacewidth = $leftborder.width() + $rightborder.width() + $content.outerwidth(true) - $content.width(); loadedheight = $loaded.outerheight(true); loadedwidth = $loaded.outerwidth(true); // setting padding to remove the need to do size conversions during the animation step. $box.css({"padding-bottom": interfaceheight, "padding-right": interfacewidth}).hide(); // setup button events. $next.click(publicmethod.next); $prev.click(publicmethod.prev); $close.click(publicmethod.close); // adding the 'hover' class allowed the browser to load the hover-state // background graphics. the class can now can be removed. $content.children().removeclass('hover'); $('.' + boxelement).live('click', function (e) { // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt. if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlkey || e.shiftkey || e.altkey)) { e.preventdefault(); launch(this); } }); $overlay.click(function () { if (settings.overlayclose) { publicmethod.close(); } }); // set navigation key bindings $(document).bind("keydown", function (e) { if (open && settings.esckey && e.keycode === 27) { e.preventdefault(); publicmethod.close(); } if (open && settings.arrowkey && !active && $related[1]) { if (e.keycode === 37 && (index || settings.loop)) { e.preventdefault(); $prev.click(); } else if (e.keycode === 39 && (index < $related.length - 1 || settings.loop)) { e.preventdefault(); $next.click(); } } }); }; publicmethod.remove = function () { $box.add($overlay).remove(); $('.' + boxelement).die('click').removedata(colorbox).removeclass(boxelement); }; publicmethod.position = function (speed, loadedcallback) { var animate_speed, // keeps the top and left positions within the browser's viewport. postop = math.max(document.documentelement.clientheight - settings.h - loadedheight - interfaceheight, 0) / 2 + $window.scrolltop(), posleft = math.max($window.width() - settings.w - loadedwidth - interfacewidth, 0) / 2 + $window.scrollleft(); // setting the speed to 0 to reduce the delay between same-sized content. animate_speed = ($box.width() === settings.w + loadedwidth && $box.height() === settings.h + loadedheight) ? 0 : speed; // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly, // but it has to be shrank down around the size of div#colorbox when it's done. if not, // it can invoke an obscure ie bug when using iframes. $wrap[0].style.width = $wrap[0].style.height = "9999px"; function modaldimensions(that) { // loading overlay height has to be explicitly set for ie6. $topborder[0].style.width = $bottomborder[0].style.width = $content[0].style.width = that.style.width; $loadingoverlay[0].style.height = $loadingoverlay[1].style.height = $content[0].style.height = $leftborder[0].style.height = $rightborder[0].style.height = that.style.height; } $box.dequeue().animate({width: settings.w + loadedwidth, height: settings.h + loadedheight, top: postop, left: posleft}, { duration: animate_speed, complete: function () { modaldimensions(this); active = false; // shrink the wrapper down to exactly the size of colorbox to avoid a bug in ie's iframe implementation. $wrap[0].style.width = (settings.w + loadedwidth + interfacewidth) + "px"; $wrap[0].style.height = (settings.h + loadedheight + interfaceheight) + "px"; if (loadedcallback) { loadedcallback(); } }, step: function () { modaldimensions(this); } }); }; publicmethod.resize = function (options) { if (open) { options = options || {}; if (options.width) { settings.w = setsize(options.width, 'x') - loadedwidth - interfacewidth; } if (options.innerwidth) { settings.w = setsize(options.innerwidth, 'x'); } $loaded.css({width: settings.w}); if (options.height) { settings.h = setsize(options.height, 'y') - loadedheight - interfaceheight; } if (options.innerheight) { settings.h = setsize(options.innerheight, 'y'); } if (!options.innerheight && !options.height) { var $child = $loaded.wrapinner("
").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be. settings.h = $child.height(); $child.replacewith($child.children()); // ditch the temporary wrapper div used in height calculation } $loaded.css({height: settings.h}); publicmethod.position(settings.transition === "none" ? 0 : settings.speed); } }; publicmethod.prep = function (object) { if (!open) { return; } var photo, speed = settings.transition === "none" ? 0 : settings.speed; $window.unbind('resize.' + prefix); $loaded.remove(); $loaded = $div('loadedcontent').html(object); function getwidth() { settings.w = settings.w || $loaded.width(); settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w; return settings.w; } function getheight() { settings.h = settings.h || $loaded.height(); settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h; return settings.h; } $loaded.hide() .appendto($loadingbay.show())// content has to be appended to the dom for accurate size calculations. .css({width: getwidth(), overflow: settings.scrolling ? 'auto' : 'hidden'}) .css({height: getheight()})// sets the height independently from the width in case the new width influences the value of height. .prependto($content); $loadingbay.hide(); // floating the img removes the bottom line-height and fixed a problem where ie miscalculates the width of the parent element as 100% of the document width. $('#' + prefix + 'photo').css({cssfloat: 'none', marginleft: 'auto', marginright: 'auto'}); // hides select elements in ie6 because they would otherwise sit on top of the overlay. if (isie6) { $('select').not($box.find('select')).filter(function () { return this.style.visibility !== 'hidden'; }).css({'visibility': 'hidden'}).one(event_cleanup, function () { this.style.visibility = 'inherit'; }); } function setposition(s) { var prev, prevsrc, next, nextsrc, total = $related.length, loop = settings.loop; publicmethod.position(s, function () { function defilter() { if (isie) { //ie adds a filter when colorbox fades in and out that can cause problems if the loaded content contains transparent pngs. $box[0].style.removeattribute("filter"); } } if (!open) { return; } if (isie) { //this fadein helps the bicubic resampling to kick-in. if (photo) { $loaded.fadein(100); } } $loaded.show(); trigger(event_loaded); $title.show().html(settings.title); if (total > 1) { // handle grouping if (typeof settings.current === "string") { $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show(); } $next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next); $prev[(loop || index) ? "show" : "hide"]().html(settings.previous); prev = index ? $related[index - 1] : $related[total - 1]; next = index < total - 1 ? $related[index + 1] : $related[0]; if (settings.slideshow) { $slideshow.show(); } // preloads images within a rel group if (settings.preloading) { nextsrc = $.data(next, colorbox).href || next.href; prevsrc = $.data(prev, colorbox).href || prev.href; nextsrc = $.isfunction(nextsrc) ? nextsrc.call(next) : nextsrc; prevsrc = $.isfunction(prevsrc) ? prevsrc.call(prev) : prevsrc; if (isimage(nextsrc)) { $('')[0].src = nextsrc; } if (isimage(prevsrc)) { $('')[0].src = prevsrc; } } } $loadingoverlay.hide(); if (settings.transition === 'fade') { $box.fadeto(speed, 1, function () { defilter(); }); } else { defilter(); } $window.bind('resize.' + prefix, function () { publicmethod.position(0); }); trigger(event_complete, settings.oncomplete); }); } if (settings.transition === 'fade') { $box.fadeto(speed, 0, function () { setposition(0); }); } else { setposition(speed); } }; publicmethod.load = function (launched) { var href, img, setresize, prep = publicmethod.prep; active = true; element = $related[index]; if (!launched) { settings = process($.extend({}, $.data(element, colorbox))); } trigger(event_purge); trigger(event_load, settings.onload); settings.h = settings.height ? setsize(settings.height, 'y') - loadedheight - interfaceheight : settings.innerheight && setsize(settings.innerheight, 'y'); settings.w = settings.width ? setsize(settings.width, 'x') - loadedwidth - interfacewidth : settings.innerwidth && setsize(settings.innerwidth, 'x'); // sets the minimum dimensions for use in image scaling settings.mw = settings.w; settings.mh = settings.h; // re-evaluate the minimum width and height based on maxwidth and maxheight values. // if the width or height exceed the maxwidth or maxheight, use the maximum values instead. if (settings.maxwidth) { settings.mw = setsize(settings.maxwidth, 'x') - loadedwidth - interfacewidth; settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw; } if (settings.maxheight) { settings.mh = setsize(settings.maxheight, 'y') - loadedheight - interfaceheight; settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh; } href = settings.href; $loadingoverlay.show(); if (settings.inline) { // inserts an empty placeholder where inline content is being pulled from. // an event is bound to put inline content back when colorbox closes or loads new content. $div().hide().insertbefore($(href)[0]).one(event_purge, function () { $(this).replacewith($loaded.children()); }); prep($(href)); } else if (settings.iframe) { // iframe element won't be added to the dom until it is ready to be displayed, // to avoid problems with dom-ready js that might be trying to run in that iframe. $box.one(event_loaded, function () { //var iframe = $("