X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=library%2Fcolorbox%2Fjquery.colorbox.js;h=7ce92f1c8bdee7904663ee5183c77afcf6cbce51;hb=7e6598f2c01dc25b9420309dac1ec84160f21a03;hp=5b9aecdc2f3846d4ac3c23e4d57bb98a18a9864f;hpb=f1a0aeb480542255fd2aae261382a756779b3d98;p=friendica.git diff --git a/library/colorbox/jquery.colorbox.js b/library/colorbox/jquery.colorbox.js index 5b9aecdc2f..7ce92f1c8b 100644 --- a/library/colorbox/jquery.colorbox.js +++ b/library/colorbox/jquery.colorbox.js @@ -1,15 +1,23 @@ -/* - jQuery ColorBox v1.3.32 - 2013-01-31 - (c) 2013 Jack Moore - jacklmoore.com/colorbox - license: http://www.opensource.org/licenses/mit-license.php +/*! + Colorbox 1.6.3 + 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: "elastic", speed: 300, + fadeOut: 300, width: false, initialWidth: "600", innerWidth: false, @@ -20,18 +28,36 @@ 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, 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: "previous", next: "next", @@ -39,36 +65,67 @@ xhrError: "This content failed to load.", imgError: "This image failed to load.", - open: false, + // accessbility returnFocus: true, - reposition: true, - loop: true, - slideshow: false, - slideshowAuto: true, - slideshowSpeed: 2500, - slideshowStart: "start slideshow", - slideshowStop: "stop slideshow", + trapFocus: true, + + // callbacks 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 + + 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', @@ -76,11 +133,6 @@ event_cleanup = prefix + '_cleanup', event_closed = prefix + '_closed', event_purge = prefix + '_purge', - - // Special Handling for IE - isIE = !$.support.leadingWhitespace, // IE6 to IE8 - isIE6 = isIE && !window.XMLHttpRequest, // IE6 - event_ie6 = prefix + '_IE6', // Cached jQuery Object Variables $overlay, @@ -103,15 +155,14 @@ $prev, $close, $groupControls, - $events = $({}), - + $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, @@ -120,14 +171,15 @@ loadingTimer, publicMethod, div = "div", - className, + requests = 0, + previousCSS = {}, init; // **************** // HELPER FUNCTIONS // **************** - - // Convience function for creating new jQuery objects + + // Convenience function for creating new jQuery objects function $tag(tag, id, css) { var element = document.createElement(tag); @@ -142,235 +194,303 @@ 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() : $window.height()) / 100) : 1) * parseInt(size, 10)); + 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 this regex. - function isImage(url) { - return settings.photo || /\.(gif|png|jp(e|g|eg)|bmp|ico)((#|\?).*)?$/i.test(url); + // 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); } - // 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); + 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(); } - - 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); - } + } + + function setClass(str) { + if (setClass.str !== str) { + $box.add($overlay).removeClass(setClass.str).addClass(str); + setClass.str = str; } - - 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 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, callback) { + function trigger(event) { // for external use $(document).trigger(event); - // for internal use - $events.trigger(event); + $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); } - } - // Slideshow functionality - function slideshow() { - var - timeOut, - className = prefix + "Slideshow_", - click = "click." + prefix, - clear, - set, - start, - stop; - - if (settings.slideshow && $related[1]) { - clear = function () { - clearTimeout(timeOut); - }; + function set() { + if (settings.get('loop') || $related[index + 1]) { + clear(); + timeOut = setTimeout(publicMethod.next, settings.get('slideshowSpeed')); + } + } - set = function () { - if (settings.loop || $related[index + 1]) { - timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); - } - }; + function start() { + $slideshow + .html(settings.get('slideshowStop')) + .unbind(click) + .one(click, stop); - start = function () { - $slideshow - .html(settings.slideshowStop) - .unbind(click) - .one(click, stop); + $events + .bind(event_complete, set) + .bind(event_load, clear); - $events - .bind(event_complete, set) - .bind(event_load, clear) - .bind(event_cleanup, stop); + $box.removeClass(className + "off").addClass(className + "on"); + } - $box.removeClass(className + "off").addClass(className + "on"); - }; - - stop = function () { - clear(); - - $events - .unbind(event_complete, set) - .unbind(event_load, clear) - .unbind(event_cleanup, stop); - - $slideshow - .html(settings.slideshowStart) - .unbind(click) - .one(click, function () { - publicMethod.next(); - start(); - }); + function stop() { + clear(); - $box.removeClass(className + "on").addClass(className + "off"); - }; - - if (settings.slideshowAuto) { - start(); - } else { - stop(); - } - } else { + $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"); } - } - 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 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(); } - - return (relRelated === settings.rel); - }); - index = $related.index(element); - - // Check direct calls to ColorBox. - if (index === -1) { - $related = $related.add(element); - index = $related.length - 1; + $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'}); - - $loaded = $tag(div, 'LoadedContent', 'width:0; height:0; overflow:hidden').appendTo($content); + $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();//Subtraction needed for IE6 + 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); - if (settings.returnFocus) { - $(element).blur(); + // 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 = Math.max((maxWidth !== false ? Math.min(initialWidth, setSize(maxWidth, 'x')) : initialWidth) - loadedWidth - interfaceWidth, 0); + settings.h = Math.max((maxHeight !== false ? Math.min(initialHeight, setSize(maxHeight, 'y')) : initialHeight) - loadedHeight - interfaceHeight, 0); + + $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 () { - $(element).focus(); + $(settings.el).focus(); }); } - - $overlay.css({ - opacity: parseFloat(settings.opacity), - cursor: settings.overlayClose ? "pointer" : "auto", - visibility: 'visible' - }).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); - } - - slideshow(); + var opacity = parseFloat(settings.get('opacity')); + $overlay.css({ + opacity: opacity === opacity ? opacity : '', + cursor: settings.get('overlayClose') ? 'pointer' : '', + visibility: 'visible' + }).show(); - trigger(event_open, settings.onOpen); - - $groupControls.add($title).hide(); - - $close.html(settings.close).show(); + if (settings.get('closeButton')) { + $close.html(settings.get('close')).appendTo($content); + } else { + $close.appendTo('
'); // replace with .detach() when dropping jQuery < 1.4 } - - publicMethod.load(true); + + load(); } } - // ColorBox's markup needs to be added to the DOM prior to being called + // 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) { + if (!$box) { init = false; - $window = $(window); - $box = $tag(div).attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''}).hide(); - $overlay = $tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide(); - $loadingOverlay = $tag(div, "LoadingOverlay").add($tag(div, "LoadingGraphic")); + $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"), - $next = $tag(div, "Next"), - $prev = $tag(div, "Previous"), - $slideshow = $tag(div, "Slideshow"), - $close = $tag(div, "Close") + $prev = $('