// colorbox v1.3.18.1 - a full featured, light-weight, customizable lightbox based on jquery 1.3+ // copyright (c) 2011 jack moore - jack@colorpowered.com // licensed under the mit license: http://www.opensource.org/licenses/mit-license.php (function ($, document, window) { var // default settings object. // see http://jacklmoore.com/colorbox for details. defaults = { transition: "elastic", speed: 300, width: false, initialwidth: "600", innerwidth: false, maxwidth: false, height: false, initialheight: "450", innerheight: false, maxheight: false, scalephotos: true, scrolling: true, inline: false, html: false, iframe: false, fastiframe: true, photo: false, href: false, title: false, rel: false, opacity: 0.9, 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, top: false, bottom: false, left: false, right: false, fixed: false, data: undefined }, // abstracting the html and event identifiers for easy rebranding colorbox = 'colorbox', prefix = 'cbox', boxelement = prefix + 'element', // 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', // special handling for ie isie = $.browser.msie && !$.support.opacity, // detects ie6,7,8. ie9 supports opacity. feature detection alone gave a false positive on at least one phone browser and on some development versions of chrome, hence the user-agent test. 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, $groupcontrols, // variables for cached values or use across multiple functions settings, interfaceheight, interfacewidth, loadedheight, loadedwidth, element, index, photo, open, active, closing, loadingtimer, publicmethod, div = "div"; // **************** // helper functions // **************** // convience function for creating new jquery objects function $tag(tag, id, css) { var element = document.createelement(tag); if (id) { element.id = prefix + id; } if (css) { element.style.csstext = css; } return $(element); } // determine the next and previous members in a group. function getindex(increment) { var max = $related.length, newindex = (index + increment) % max; return (newindex < 0) ? max + newindex : newindex; } // convert '%' and 'px' values to integers function setsize(size, dimension) { return math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : $window.height()) / 100) : 1) * parseint(size, 10)); } // 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|jpe?g|bmp|ico)((#|\?).*)?$/i.test(url); } // assigns function results to their respective properties function makesettings() { var i; settings = $.extend({}, $.data(element, colorbox)); for (i in settings) { if ($.isfunction(settings[i]) && i.slice(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; if (typeof settings.href === "string") { settings.href = $.trim(settings.href); } } function trigger(event, callback) { $.event.trigger(event); if (callback) { callback.call(element); } } // 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, function () { publicmethod.next(); start(); }); $box.removeclass(classname + "on").addclass(classname + "off"); }; if (settings.slideshowauto) { start(); } else { stop(); } } else { $box.removeclass(classname + "off " + classname + "on"); } } function launch(target) { if (!closing) { element = target; makesettings(); $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(); 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('resize.' + event_ie6); } trigger(event_open, settings.onopen); $groupcontrols.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; options = options || {}; publicmethod.init(); if (!$this[0]) { if ($this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit. return $this; } // if no selector was given (ie. $.colorbox()), create a temporary element to work with $this = $(''); options.open = true; // assume an immediate open } if (callback) { options.oncomplete = callback; } $this.each(function () { $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options)); $(this).addclass(boxelement); }); if (($.isfunction(options.open) && options.open.call($this)) || options.open) { 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 minimizes the burdon on the browser by only // having to run once, instead of each time colorbox is opened. publicmethod.init = function () { if (!$box) { // if the body is not present yet, wait for dom ready if (!$('body')[0]) { $(publicmethod.init); return; } // create the markup and append to body $window = $(window); $box = $tag(div).attr({id: colorbox, 'class': isie ? prefix + (isie6 ? 'ie6' : 'ie') : ''}); $overlay = $tag(div, "overlay", isie6 ? 'position:absolute' : '').hide(); $wrap = $tag(div, "wrapper"); $content = $tag(div, "content").append( $loaded = $tag(div, "loadedcontent", 'width:0; height:0; overflow:hidden'), $loadingoverlay = $tag(div, "loadingoverlay").add($tag(div, "loadinggraphic")), $title = $tag(div, "title"), $current = $tag(div, "current"), $next = $tag(div, "next"), $prev = $tag(div, "previous"), $slideshow = $tag(div, "slideshow").bind(event_open, slideshow), $close = $tag(div, "close") ); $wrap.append( // the 3x3 grid that makes up colorbox $tag(div).append( $tag(div, "topleft"), $topborder = $tag(div, "topcenter"), $tag(div, "topright") ), $tag(div, false, 'clear:left').append( $leftborder = $tag(div, "middleleft"), $content, $rightborder = $tag(div, "middleright") ), $tag(div, false, 'clear:left').append( $tag(div, "bottomleft"), $bottomborder = $tag(div, "bottomcenter"), $tag(div, "bottomright") ) ).find('div div').css({'float': 'left'}); $loadingbay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none'); $('body').prepend($overlay, $box.append($wrap, $loadingbay)); // 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. // anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly. $next.click(function () { publicmethod.next(); }); $prev.click(function () { publicmethod.prev(); }); $close.click(function () { publicmethod.close(); }); $groupcontrols = $next.add($prev).add($current).add($slideshow); $overlay.click(function () { if (settings.overlayclose) { publicmethod.close(); } }); // set navigation key bindings $(document).bind('keydown.' + prefix, function (e) { var key = e.keycode; if (open && settings.esckey && key === 27) { e.preventdefault(); publicmethod.close(); } if (open && settings.arrowkey && $related[1]) { if (key === 37) { e.preventdefault(); $prev.click(); } else if (key === 39) { e.preventdefault(); $next.click(); } } }); } }; publicmethod.remove = function () { $box.add($overlay).remove(); $box = null; $('.' + boxelement).removedata(colorbox).removeclass(boxelement); }; publicmethod.position = function (speed, loadedcallback) { var top = 0, left = 0, offset = $box.offset(), scrolltop = $window.scrolltop(), scrollleft = $window.scrollleft(); $window.unbind('resize.' + prefix); // remove the modal so that it doesn't influence the document width/height $box.css({top: -9e4, left: -9e4}); if (settings.fixed && !isie6) { offset.top -= scrolltop; offset.left -= scrollleft; $box.css({position: 'fixed'}); } else { top = scrolltop; left = scrollleft; $box.css({position: 'absolute'}); } // keeps the top and left positions within the browser's viewport. if (settings.right !== false) { left += math.max($window.width() - settings.w - loadedwidth - interfacewidth - setsize(settings.right, 'x'), 0); } else if (settings.left !== false) { left += setsize(settings.left, 'x'); } else { left += math.round(math.max($window.width() - settings.w - loadedwidth - interfacewidth, 0) / 2); } if (settings.bottom !== false) { top += math.max($window.height() - settings.h - loadedheight - interfaceheight - setsize(settings.bottom, 'y'), 0); } else if (settings.top !== false) { top += setsize(settings.top, 'y'); } else { top += math.round(math.max($window.height() - settings.h - loadedheight - interfaceheight, 0) / 2); } $box.css({top: offset.top, left: offset.left}); // setting the speed to 0 to reduce the delay between same-sized content. speed = ($box.width() === settings.w + loadedwidth && $box.height() === settings.h + loadedheight) ? 0 : speed || 0; // 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: top, left: left}, { duration: 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(); } settimeout(function () { // small delay before binding onresize due to an ie8 bug. $window.bind('resize.' + prefix, publicmethod.position); }, 1); }, 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) { $loaded.css({height: "auto"}); settings.h = $loaded.height(); } $loaded.css({height: settings.h}); publicmethod.position(settings.transition === "none" ? 0 : settings.speed); } }; publicmethod.prep = function (object) { if (!open) { return; } var callback, speed = settings.transition === "none" ? 0 : settings.speed; $loaded.remove(); $loaded = $tag(div, 'loadedcontent').append(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. //$(photo).css({'float': 'none', marginleft: 'auto', marginright: 'auto'}); $(photo).css({'float': 'none'}); // 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'; }); } callback = function () { var preload, i, total = $related.length, iframe, frameborder = 'frameborder', allowtransparency = 'allowtransparency', complete, src, img; if (!open) { return; } function removefilter() { if (isie) { $box[0].style.removeattribute('filter'); } } complete = function () { cleartimeout(loadingtimer); $loadingoverlay.hide(); trigger(event_complete, settings.oncomplete); }; if (isie) { //this fadein helps the bicubic resampling to kick-in. if (photo) { $loaded.fadein(100); } } $title.html(settings.title).add($loaded).show(); if (total > 1) { // handle grouping if (typeof settings.current === "string") { $current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show(); } $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next); $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous); if (settings.slideshow) { $slideshow.show(); } // preloads images within a rel group if (settings.preloading) { preload = [ getindex(-1), getindex(1) ]; while ((i = $related[preload.pop()])) { src = $.data(i, colorbox).href || i.href; if ($.isfunction(src)) { src = src.call(i); } if (isimage(src)) { img = new image(); img.src = src; } } } } else { $groupcontrols.hide(); } if (settings.iframe) { iframe = $tag('iframe')[0]; if (frameborder in iframe) { iframe[frameborder] = 0; } if (allowtransparency in iframe) { iframe[allowtransparency] = "true"; } // give the iframe a unique name to prevent caching iframe.name = prefix + (+new date()); if (settings.fastiframe) { complete(); } else { $(iframe).one('load', complete); } iframe.src = settings.href; if (!settings.scrolling) { iframe.scrolling = "no"; } $(iframe).addclass(prefix + 'iframe').appendto($loaded).one(event_purge, function () { iframe.src = "//about:blank"; }); } else { complete(); } if (settings.transition === 'fade') { $box.fadeto(speed, 1, removefilter); } else { removefilter(); } }; if (settings.transition === 'fade') { $box.fadeto(speed, 0, function () { publicmethod.position(0, callback); }); } else { publicmethod.position(speed, callback); } }; publicmethod.load = function (launched) { var href, setresize, prep = publicmethod.prep; active = true; photo = false; element = $related[index]; if (!launched) { makesettings(); } 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; loadingtimer = settimeout(function () { $loadingoverlay.show(); }, 100); 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. $tag(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. prep(" "); } else if (settings.html) { prep(settings.html); } else if (isimage(href)) { $(photo = new image()) .addclass(prefix + 'photo') .error(function () { settings.title = false; prep($tag(div, 'error').text('this image could not be loaded')); }) .load(function () { var percent; photo.onload = null; //stops animated gifs from firing the onload repeatedly. if (settings.scalephotos) { setresize = function () { photo.height -= photo.height * percent; photo.width -= photo.width * percent; }; if (settings.mw && photo.width > settings.mw) { percent = (photo.width - settings.mw) / photo.width; setresize(); } if (settings.mh && photo.height > settings.mh) { percent = (photo.height - settings.mh) / photo.height; setresize(); } } if (settings.h) { photo.style.margintop = math.max(settings.h - photo.height, 0) / 2 + 'px'; } if ($related[1] && (index < $related.length - 1 || settings.loop)) { photo.style.cursor = 'pointer'; photo.onclick = function () { publicmethod.next(); }; } if (isie) { photo.style.msinterpolationmode = 'bicubic'; } settimeout(function () { // a pause because chrome will sometimes report a 0 by 0 size otherwise. prep(photo); }, 1); }); settimeout(function () { // a pause because opera 10.6+ will sometimes not run the onload function otherwise. photo.src = href; }, 1); } else if (href) { $loadingbay.load(href, settings.data, function (data, status, xhr) { prep(status === 'error' ? $tag(div, 'error').text('request unsuccessful: ' + xhr.statustext) : $(this).contents()); }); } }; // navigates to the next page/image in a set. publicmethod.next = function () { if (!active && $related[1] && (index < $related.length - 1 || settings.loop)) { index = getindex(1); publicmethod.load(); } }; publicmethod.prev = function () { if (!active && $related[1] && (index || settings.loop)) { index = getindex(-1); publicmethod.load(); } }; // note: to use this within an iframe use the following format: parent.$.fn.colorbox.close(); publicmethod.close = function () { if (open && !closing) { closing = true; open = false; trigger(event_cleanup, settings.oncleanup); $window.unbind('.' + prefix + ' .' + event_ie6); $overlay.fadeto(200, 0); $box.stop().fadeto(300, 0, function () { $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide(); trigger(event_purge); $loaded.remove(); settimeout(function () { closing = false; trigger(event_closed, settings.onclosed); }, 1); }); } }; // a method for fetching the current element colorbox is referencing. // returns a jquery object. publicmethod.element = function () { return $(element); }; publicmethod.settings = defaults; // bind the live event before dom-ready for maximum performance in ie6 & 7. $('.' + boxelement, document).live('click', function (e) { // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt. // see: http://jacklmoore.com/notes/click-events/ if (!(e.which > 1 || e.shiftkey || e.altkey || e.metakey)) { e.preventdefault(); launch(this); } }); // setup colorbox publicmethod.init(); }(jquery, document, this));