/*! colorbox v1.4.33 - 2013-10-31 jquery lightbox and modal window plugin (c) 2013 jack moore - http://www.jacklmoore.com/colorbox license: http://www.opensource.org/licenses/mit-license.php */ (function ($, document, window) { var // default settings object. // see http://jacklmoore.com/colorbox for details. defaults = { // data sources html: false, photo: false, iframe: false, inline: false, // behavior and appearance transition: "elastic", speed: 300, fadeout: 300, width: false, initialwidth: "600", innerwidth: false, maxwidth: false, height: false, initialheight: "450", innerheight: false, maxheight: false, scalephotos: true, scrolling: true, href: false, title: false, rel: false, opacity: 0.9, preloading: true, classname: false, overlayclose: true, esckey: true, arrowkey: true, top: false, bottom: false, left: false, right: false, fixed: false, data: undefined, closebutton: true, fastiframe: true, open: false, reposition: true, loop: true, slideshow: false, slideshowauto: true, slideshowspeed: 2500, slideshowstart: "start slideshow", slideshowstop: "stop slideshow", photoregex: /\.(gif|png|jp(e|g|eg)|bmp|ico|webp)((#|\?).*)?$/i, // alternate image paths for high-res displays retinaimage: false, retinaurl: false, retinasuffix: '@2x.$1', // internationalization current: "image {current} of {total}", previous: "previous", next: "next", close: "close", xhrerror: "this content failed to load.", imgerror: "this image failed to load.", // accessbility returnfocus: true, trapfocus: true, // callbacks onopen: false, onload: false, oncomplete: false, oncleanup: false, onclosed: false }, // 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', // cached jquery object variables $overlay, $box, $wrap, $content, $topborder, $leftborder, $rightborder, $bottomborder, $related, $window, $loaded, $loadingbay, $loadingoverlay, $title, $current, $slideshow, $next, $prev, $close, $groupcontrols, $events = $(''), // $([]) would be prefered, but there is an issue with jquery 1.4.2 // variables for cached values or use across multiple functions settings, interfaceheight, interfacewidth, loadedheight, loadedwidth, element, index, photo, open, active, closing, loadingtimer, publicmethod, div = "div", classname, requests = 0, previouscss = {}, init; // **************** // helper functions // **************** // convenience 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); } // get the window height using innerheight when available to avoid an issue with ios // http://bugs.jquery.com/ticket/6724 function winheight() { return window.innerheight ? window.innerheight : $(window).height(); } // 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() : winheight()) / 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 the regex. function isimage(settings, url) { return settings.photo || settings.photoregex.test(url); } function retinaurl(settings, url) { return settings.retinaurl && window.devicepixelratio > 1 ? url.replace(settings.photoregex, settings.retinasuffix) : url; } function trapfocus(e) { if ('contains' in $box[0] && !$box[0].contains(e.target)) { e.stoppropagation(); $box.focus(); } } // assigns function results to their respective properties function makesettings() { var i, data = $.data(element, colorbox); if (data == null) { settings = $.extend({}, defaults); if (console && console.log) { console.log('error: cboxelement missing settings object'); } } else { settings = $.extend({}, data); } 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 || $(element).data('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) { // for external use $(document).trigger(event); // for internal use $events.triggerhandler(event); if ($.isfunction(callback)) { callback.call(element); } } var slideshow = (function(){ var active, classname = prefix + "slideshow_", click = "click." + prefix, timeout; function clear () { cleartimeout(timeout); } function set() { if (settings.loop || $related[index + 1]) { clear(); timeout = settimeout(publicmethod.next, settings.slideshowspeed); } } function start() { $slideshow .html(settings.slideshowstop) .unbind(click) .one(click, stop); $events .bind(event_complete, set) .bind(event_load, clear); $box.removeclass(classname + "off").addclass(classname + "on"); } function stop() { clear(); $events .unbind(event_complete, set) .unbind(event_load, clear); $slideshow .html(settings.slideshowstart) .unbind(click) .one(click, function () { publicmethod.next(); start(); }); $box.removeclass(classname + "on").addclass(classname + "off"); } function reset() { active = false; $slideshow.hide(); clear(); $events .unbind(event_complete, set) .unbind(event_load, clear); $box.removeclass(classname + "off " + classname + "on"); } return function(){ if (active) { if (!settings.slideshow) { $events.unbind(event_cleanup, reset); reset(); } } else { if (settings.slideshow && $related[1]) { active = true; $events.one(event_cleanup, reset); if (settings.slideshowauto) { start(); } else { stop(); } $slideshow.show(); } } }; }()); function launch(target) { if (!closing) { element = target; makesettings(); $related = $(element); index = 0; if (settings.rel !== 'nofollow') { $related = $('.' + boxelement).filter(function () { var data = $.data(this, colorbox), relrelated; if (data) { relrelated = $(this).data('rel') || data.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; } } $overlay.css({ opacity: parsefloat(settings.opacity), cursor: settings.overlayclose ? "pointer" : "auto", visibility: 'visible' }).show(); if (classname) { $box.add($overlay).removeclass(classname); } if (settings.classname) { $box.add($overlay).addclass(settings.classname); } classname = settings.classname; if (settings.closebutton) { $close.html(settings.close).appendto($content); } else { $close.appendto('
'); } if (!open) { open = active = true; // prevents the page-change action from queuing up if the visitor holds down the left or right keys. // show colorbox so the sizes can be calculated in older versions of jquery $box.css({visibility:'hidden', display:'block'}); $loaded = $tag(div, 'loadedcontent', 'width:0; height:0; overflow:hidden'); $content.css({width:'', height:''}).append($loaded); // cache values needed for size calculations interfaceheight = $topborder.height() + $bottomborder.height() + $content.outerheight(true) - $content.height(); interfacewidth = $leftborder.width() + $rightborder.width() + $content.outerwidth(true) - $content.width(); loadedheight = $loaded.outerheight(true); loadedwidth = $loaded.outerwidth(true); // opens inital empty colorbox prior to content being loaded. settings.w = setsize(settings.initialwidth, 'x'); settings.h = setsize(settings.initialheight, 'y'); $loaded.css({width:'', height:settings.h}); publicmethod.position(); trigger(event_open, settings.onopen); $groupcontrols.add($title).hide(); $box.focus(); if (settings.trapfocus) { // confine focus to the modal // uses event capturing that is not supported in ie8- if (document.addeventlistener) { document.addeventlistener('focus', trapfocus, true); $events.one(event_closed, function () { document.removeeventlistener('focus', trapfocus, true); }); } } // return focus on closing if (settings.returnfocus) { $events.one(event_closed, function () { $(element).focus(); }); } } load(); } } // colorbox's markup needs to be added to the dom prior to being called // so that the browser will go ahead and load the css background images. function appendhtml() { if (!$box && document.body) { init = false; $window = $(window); $box = $tag(div).attr({ id: colorbox, 'class': $.support.opacity === false ? prefix + 'ie' : '', // class for optional ie8 & lower targeted css. role: 'dialog', tabindex: '-1' }).hide(); $overlay = $tag(div, "overlay").hide(); $loadingoverlay = $([$tag(div, "loadingoverlay")[0],$tag(div, "loadinggraphic")[0]]); $wrap = $tag(div, "wrapper"); $content = $tag(div, "content").append( $title = $tag(div, "title"), $current = $tag(div, "current"), $prev = $('').attr({id:prefix+'previous'}), $next = $('').attr({id:prefix+'next'}), $slideshow = $tag('button', "slideshow"), $loadingoverlay ); $close = $('').attr({id:prefix+'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; max-width:none;'); $groupcontrols = $next.add($prev).add($current).add($slideshow); $(document.body).append($overlay, $box.append($wrap, $loadingbay)); } } // add colorbox's event bindings function addbindings() { function clickhandler(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.ctrlkey)) { e.preventdefault(); launch(this); } } if ($box) { if (!init) { init = true; // 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(); }); $overlay.click(function () { if (settings.overlayclose) { publicmethod.close(); } }); // 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] && !e.altkey) { if (key === 37) { e.preventdefault(); $prev.click(); } else if (key === 39) { e.preventdefault(); $next.click(); } } }); if ($.isfunction($.fn.on)) { // for jquery 1.7+ $(document).on('click.'+prefix, '.'+boxelement, clickhandler); } else { // for jquery 1.3.x -> 1.6.x // this code is never reached in jquery 1.9, so do not contact me about 'live' being removed. // this is not here for jquery 1.9, it's here for legacy users. $('.'+boxelement).live('click.'+prefix, clickhandler); } } return true; } return false; } // don't do anything if colorbox already exists. if ($.colorbox) { return; } // append the html when the dom loads $(appendhtml); // **************** // public functions // usage format: $.colorbox.close(); // usage from within an iframe: parent.jquery.colorbox.close(); // **************** publicmethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { var $this = this; options = options || {}; appendhtml(); if (addbindings()) { if ($.isfunction($this)) { // assume a call to $.colorbox $this = $(''); options.open = true; } else if (!$this[0]) { // colorbox being applied to empty collection return $this; } if (callback) { options.oncomplete = callback; } $this.each(function () { $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options)); }).addclass(boxelement); if (($.isfunction(options.open) && options.open.call($this)) || options.open) { launch($this[0]); } } return $this; }; publicmethod.position = function (speed, loadedcallback) { var css, top = 0, left = 0, offset = $box.offset(), scrolltop, scrollleft; $window.unbind('resize.' + prefix); // remove the modal so that it doesn't influence the document width/height $box.css({top: -9e4, left: -9e4}); scrolltop = $window.scrolltop(); scrollleft = $window.scrollleft(); if (settings.fixed) { 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(winheight() - 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(winheight() - settings.h - loadedheight - interfaceheight, 0) / 2); } $box.css({top: offset.top, left: offset.left, visibility:'visible'}); // 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() { $topborder[0].style.width = $bottomborder[0].style.width = $content[0].style.width = (parseint($box[0].style.width,10) - interfacewidth)+'px'; $content[0].style.height = $leftborder[0].style.height = $rightborder[0].style.height = (parseint($box[0].style.height,10) - interfaceheight)+'px'; } css = {width: settings.w + loadedwidth + interfacewidth, height: settings.h + loadedheight + interfaceheight, top: top, left: left}; // setting the speed to 0 if the content hasn't changed size or position if (speed) { var tempspeed = 0; $.each(css, function(i){ if (css[i] !== previouscss[i]) { tempspeed = speed; return; } }); speed = tempspeed; } previouscss = css; if (!speed) { $box.css(css); } $box.dequeue().animate(css, { duration: speed || 0, complete: function () { modaldimensions(); 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 (settings.reposition) { settimeout(function () { // small delay before binding onresize due to an ie8 bug. $window.bind('resize.' + prefix, publicmethod.position); }, 1); } if (loadedcallback) { loadedcallback(); } }, step: modaldimensions }); }; publicmethod.resize = function (options) { var scrolltop; 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) { scrolltop = $loaded.scrolltop(); $loaded.css({height: "auto"}); settings.h = $loaded.height(); } $loaded.css({height: settings.h}); if(scrolltop) { $loaded.scrolltop(scrolltop); } 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.empty().remove(); // using empty first may prevent some ie7 issues. $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'}); callback = function () { var total = $related.length, iframe, frameborder = 'frameborder', allowtransparency = 'allowtransparency', complete; if (!open) { return; } function removefilter() { // needed for ie7 & ie8 in versions of jquery prior to 1.7.2 if ($.support.opacity === false) { $box[0].style.removeattribute('filter'); } } complete = function () { cleartimeout(loadingtimer); $loadingoverlay.hide(); trigger(event_complete, settings.oncomplete); }; $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); slideshow(); // preloads images within a rel group if (settings.preloading) { $.each([getindex(-1), getindex(1)], function(){ var src, img, i = $related[this], data = $.data(i, colorbox); if (data && data.href) { src = data.href; if ($.isfunction(src)) { src = src.call(i); } } else { src = $(i).attr('href'); } if (src && isimage(data, src)) { src = retinaurl(data, src); img = document.createelement('img'); 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"; } if (!settings.scrolling) { iframe.scrolling = "no"; } $(iframe) .attr({ src: settings.href, name: (new date()).gettime(), // give the iframe a unique name to prevent caching 'class': prefix + 'iframe', allowfullscreen : true, // allow html5 video to go fullscreen webkitallowfullscreen : true, mozallowfullscreen : true }) .one('load', complete) .appendto($loaded); $events.one(event_purge, function () { iframe.src = "//about:blank"; }); if (settings.fastiframe) { $(iframe).trigger('load'); } } 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); } }; function load () { var href, setresize, prep = publicmethod.prep, $inline, request = ++requests; active = true; photo = false; element = $related[index]; 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. $inline = $tag(div).hide().insertbefore($(href)[0]); $events.one(event_purge, function () { $inline.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(settings, href)) { href = retinaurl(settings, href); photo = document.createelement('img'); $(photo) .addclass(prefix + 'photo') .bind('error',function () { settings.title = false; prep($tag(div, 'error').html(settings.imgerror)); }) .one('load', function () { var percent; if (request !== requests) { return; } $.each(['alt', 'longdesc', 'aria-describedby'], function(i,val){ var attr = $(element).attr(val) || $(element).attr('data-'+val); if (attr) { photo.setattribute(val, attr); } }); if (settings.retinaimage && window.devicepixelratio > 1) { photo.height = photo.height / window.devicepixelratio; photo.width = photo.width / window.devicepixelratio; } 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.mh - photo.height, 0) / 2 + 'px'; } if ($related[1] && (settings.loop || $related[index + 1])) { photo.style.cursor = 'pointer'; photo.onclick = function () { publicmethod.next(); }; } photo.style.width = photo.width + 'px'; photo.style.height = photo.height + 'px'; 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) { if (request === requests) { prep(status === 'error' ? $tag(div, 'error').html(settings.xhrerror) : $(this).contents()); } }); } } // navigates to the next page/image in a set. publicmethod.next = function () { if (!active && $related[1] && (settings.loop || $related[index + 1])) { index = getindex(1); launch($related[index]); } }; publicmethod.prev = function () { if (!active && $related[1] && (settings.loop || index)) { index = getindex(-1); launch($related[index]); } }; // note: to use this within an iframe use the following format: parent.jquery.colorbox.close(); publicmethod.close = function () { if (open && !closing) { closing = true; open = false; trigger(event_cleanup, settings.oncleanup); $window.unbind('.' + prefix); $overlay.fadeto(settings.fadeout || 0, 0); $box.stop().fadeto(settings.fadeout || 0, 0, function () { $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide(); trigger(event_purge); $loaded.empty().remove(); // using empty first may prevent some ie7 issues. settimeout(function () { closing = false; trigger(event_closed, settings.onclosed); }, 1); }); } }; // removes changes colorbox made to the document, but does not remove the plugin. publicmethod.remove = function () { if (!$box) { return; } $box.stop(); $.colorbox.close(); $box.stop().remove(); $overlay.remove(); closing = false; $box = null; $('.' + boxelement) .removedata(colorbox) .removeclass(boxelement); $(document).unbind('click.'+prefix); }; // a method for fetching the current element colorbox is referencing. // returns a jquery object. publicmethod.element = function () { return $(element); }; publicmethod.settings = defaults; }(jquery, document, window));