/*! colorbox 1.6.1 license: mit http://www.jacklmoore.com/colorbox */ (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: "none", speed: 300, fadeout: 300, width: false, initialwidth: "600", innerwidth: false, maxwidth: false, height: false, initialheight: "450", innerheight: false, maxheight: false, scalephotos: true, scrolling: true, 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|jxr|svg)((#|\?).*)?$/i, // alternate image paths for high-res displays retinaimage: false, retinaurl: false, retinasuffix: '@2x.$1', // internationalization current: "image {current} of {total}", previous: "", next: "", 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, rel: function() { return this.rel; }, href: function() { // using this.href would give the absolute url, when the href may have been inteded as a selector (e.g. '#container') return $(this).attr('href'); }, title: function() { return this.title; }, createimg: function() { var img = new image(); var attrs = $(this).data('cbox-img-attrs'); if (typeof attrs === 'object') { $.each(attrs, function(key, val){ img[key] = val; }); } return img; }, createiframe: function() { var iframe = document.createelement('iframe'); var attrs = $(this).data('cbox-iframe-attrs'); if (typeof attrs === 'object') { $.each(attrs, function(key, val){ iframe[key] = val; }); } if ('frameborder' in iframe) { iframe.frameborder = 0; } if ('allowtransparency' in iframe) { iframe.allowtransparency = "true"; } iframe.name = (new date()).gettime(); // give the iframe a unique name to prevent caching iframe.allowfullscreen = true; return iframe; } }, // 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, index, photo, open, active, closing, loadingtimer, publicmethod, div = "div", 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(); } function settings(element, options) { if (options !== object(options)) { options = {}; } this.cache = {}; this.el = element; this.value = function(key) { var dataattr; if (this.cache[key] === undefined) { dataattr = $(this.el).attr('data-cbox-'+key); if (dataattr !== undefined) { this.cache[key] = dataattr; } else if (options[key] !== undefined) { this.cache[key] = options[key]; } else if (defaults[key] !== undefined) { this.cache[key] = defaults[key]; } } return this.cache[key]; }; this.get = function(key) { var value = this.value(key); return $.isfunction(value) ? value.call(this.el, this) : value; }; } // 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.get('photo') || settings.get('photoregex').test(url); } function retinaurl(settings, url) { return settings.get('retinaurl') && window.devicepixelratio > 1 ? url.replace(settings.get('photoregex'), settings.get('retinasuffix')) : url; } function trapfocus(e) { if ('contains' in $box[0] && !$box[0].contains(e.target) && e.target !== $overlay[0]) { e.stoppropagation(); $box.focus(); } } function setclass(str) { if (setclass.str !== str) { $box.add($overlay).removeclass(setclass.str).addclass(str); setclass.str = str; } } function getrelated(rel) { index = 0; if (rel && rel !== false && rel !== 'nofollow') { $related = $('.' + boxelement).filter(function () { var options = $.data(this, colorbox); var settings = new settings(this, options); return (settings.get('rel') === rel); }); index = $related.index(settings.el); // check direct calls to colorbox. if (index === -1) { $related = $related.add(settings.el); index = $related.length - 1; } } else { $related = $(settings.el); } } function trigger(event) { // for external use $(document).trigger(event); // for internal use $events.triggerhandler(event); } var slideshow = (function(){ var active, classname = prefix + "slideshow_", click = "click." + prefix, timeout; function clear () { cleartimeout(timeout); } function set() { if (settings.get('loop') || $related[index + 1]) { clear(); timeout = settimeout(publicmethod.next, settings.get('slideshowspeed')); } } function start() { $slideshow .html(settings.get('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.get('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.get('slideshow')) { $events.unbind(event_cleanup, reset); reset(); } } else { if (settings.get('slideshow') && $related[1]) { active = true; $events.one(event_cleanup, reset); if (settings.get('slideshowauto')) { start(); } else { stop(); } $slideshow.show(); } } }; }()); function launch(element) { var options; if (!closing) { options = $(element).data(colorbox); settings = new settings(element, options); getrelated(settings.get('rel')); if (!open) { open = active = true; // prevents the page-change action from queuing up if the visitor holds down the left or right keys. setclass(settings.get('classname')); // show colorbox so the sizes can be calculated in older versions of jquery $box.css({visibility:'hidden', display:'block', opacity:''}); $loaded = $tag(div, 'loadedcontent', 'width:0; height:0; overflow:hidden; visibility: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. var initialwidth = setsize(settings.get('initialwidth'), 'x'); var initialheight = setsize(settings.get('initialheight'), 'y'); var maxwidth = settings.get('maxwidth'); var maxheight = settings.get('maxheight'); settings.w = (maxwidth !== false ? math.min(initialwidth, setsize(maxwidth, 'x')) : initialwidth) - loadedwidth - interfacewidth; settings.h = (maxheight !== false ? math.min(initialheight, setsize(maxheight, 'y')) : initialheight) - loadedheight - interfaceheight; $loaded.css({width:'', height:settings.h}); publicmethod.position(); trigger(event_open); settings.get('onopen'); $groupcontrols.add($title).hide(); $box.focus(); if (settings.get('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.get('returnfocus')) { $events.one(event_closed, function () { $(settings.el).focus(); }); } } var opacity = parsefloat(settings.get('opacity')); $overlay.css({ opacity: opacity === opacity ? opacity : '', cursor: settings.get('overlayclose') ? 'pointer' : '', visibility: 'visible' }).show(); if (settings.get('closebutton')) { $close.html(settings.get('close')).appendto($content); } else { $close.appendto('
'); // replace with .detach() when dropping jquery < 1.4 } 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) { 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); } if (document.body && !$box.parent().length) { $(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.get('overlayclose')) { publicmethod.close(); } }); // key bindings $(document).bind('keydown.' + prefix, function (e) { var key = e.keycode; if (open && settings.get('esckey') && key === 27) { e.preventdefault(); publicmethod.close(); } if (open && settings.get('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 settings; var $obj = this; options = options || {}; if ($.isfunction($obj)) { // assume a call to $.colorbox $obj = $(''); options.open = true; } if (!$obj[0]) { // colorbox being applied to empty collection return $obj; } appendhtml(); if (addbindings()) { if (callback) { options.oncomplete = callback; } $obj.each(function () { var old = $.data(this, colorbox) || {}; $.data(this, colorbox, $.extend(old, options)); }).addclass(boxelement); settings = new settings($obj[0], options); if (settings.get('open')) { launch($obj[0]); } } if (settings.get("next") == "") { $("#cboxnext").remove(); } if (settings.get("prev") == "") { $("#cboxprevious").remove(); } return $obj; }; 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.get('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.get('right') !== false) { left += math.max($window.width() - settings.w - loadedwidth - interfacewidth - setsize(settings.get('right'), 'x'), 0); } else if (settings.get('left') !== false) { left += setsize(settings.get('left'), 'x'); } else { left += math.round(math.max($window.width() - settings.w - loadedwidth - interfacewidth, 0) / 2); } if (settings.get('bottom') !== false) { top += math.max(winheight() - settings.h - loadedheight - interfaceheight - setsize(settings.get('bottom'), 'y'), 0); } else if (settings.get('top') !== false) { top += setsize(settings.get('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.get('reposition')) { settimeout(function () { // small delay before binding onresize due to an ie8 bug. $window.bind('resize.' + prefix, publicmethod.position); }, 1); } if ($.isfunction(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.get('transition') === "none" ? 0 : settings.get('speed')); } }; publicmethod.prep = function (object) { if (!open) { return; } var callback, speed = settings.get('transition') === "none" ? 0 : settings.get('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.get('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'}); setclass(settings.get('classname')); callback = function () { var total = $related.length, iframe, complete; if (!open) { return; } function removefilter() { // needed for 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.get('oncomplete'); }; $title.html(settings.get('title')).show(); $loaded.show(); if (typeof settings.get('current') === "string") { $current.html(settings.get('current').replace('{current}', index + 1).replace('{total}', total)).show(); } if (total > 1) { // handle grouping $next[(settings.get('loop') || index < total - 1) ? "show" : "hide"]().html(settings.get('next')); $prev[(settings.get('loop') || index) ? "show" : "hide"]().html(settings.get('previous')); slideshow(); // preloads images within a rel group if (settings.get('preloading')) { $.each([getindex(-1), getindex(1)], function(){ var img, i = $related[this], settings = new settings(i, $.data(i, colorbox)), src = settings.get('href'); if (src && isimage(settings, src)) { src = retinaurl(settings, src); img = document.createelement('img'); img.src = src; } }); } } else { $groupcontrols.hide(); } if (settings.get('iframe')) { iframe = settings.get('createiframe'); if (!settings.get('scrolling')) { iframe.scrolling = "no"; } $(iframe) .attr({ src: settings.get('href'), 'class': prefix + 'iframe' }) .one('load', complete) .appendto($loaded); $events.one(event_purge, function () { iframe.src = "//about:blank"; }); if (settings.get('fastiframe')) { $(iframe).trigger('load'); } } else { complete(); } if (settings.get('transition') === 'fade') { $box.fadeto(speed, 1, removefilter); } else { removefilter(); } }; if (settings.get('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; trigger(event_purge); trigger(event_load); settings.get('onload'); settings.h = settings.get('height') ? setsize(settings.get('height'), 'y') - loadedheight - interfaceheight : settings.get('innerheight') && setsize(settings.get('innerheight'), 'y'); settings.w = settings.get('width') ? setsize(settings.get('width'), 'x') - loadedwidth - interfacewidth : settings.get('innerwidth') && setsize(settings.get('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.get('maxwidth')) { settings.mw = setsize(settings.get('maxwidth'), 'x') - loadedwidth - interfacewidth; settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw; } if (settings.get('maxheight')) { settings.mh = setsize(settings.get('maxheight'), 'y') - loadedheight - interfaceheight; settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh; } href = settings.get('href'); loadingtimer = settimeout(function () { $loadingoverlay.show(); }, 100); if (settings.get('inline')) { var $target = $(href); // 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 = $('