/** * @license Retina.js v1.3.0 Copyright 2014 Imulus, LLC Released under the MIT license Retina.js is an open source script that makes it easy to serve high-resolution images to devices with retina displays. */ 'use strict'; !function() { /** * @return {undefined} */ function Retina() { } /** * @param {string} match * @return {?} */ function suffixReplace(match) { return config.retinaImageSuffix + match; } /** * @param {string} path * @param {string} at_2x_path * @return {undefined} */ function RetinaImagePath(path, at_2x_path) { if (this.path = path || "", "undefined" != typeof at_2x_path && null !== at_2x_path) { /** @type {string} */ this.at_2x_path = at_2x_path; /** @type {boolean} */ this.perform_check = false; } else { if (void 0 !== document.createElement) { /** @type {!Element} */ var locationObject = document.createElement("a"); locationObject.href = this.path; locationObject.pathname = locationObject.pathname.replace(regexMatch, suffixReplace); this.at_2x_path = locationObject.href; } else { var parts = this.path.split("?"); parts[0] = parts[0].replace(regexMatch, suffixReplace); this.at_2x_path = parts.join("?"); } /** @type {boolean} */ this.perform_check = true; } } /** * @param {!Object} el * @return {undefined} */ function RetinaImage(el) { /** @type {!Object} */ this.el = el; this.path = new RetinaImagePath(this.el.getAttribute("src"), this.el.getAttribute("data-at2x")); var fboVelocityPP = this; this.path.check_2x_variant(function(a) { if (a) { fboVelocityPP.swap(); } }); } var root = "undefined" == typeof exports ? window : exports; var config = { retinaImageSuffix : "@2x", check_mime_type : true, force_original_dimensions : true }; /** @type {function(): undefined} */ root.Retina = Retina; /** * @param {!Object} pos * @return {undefined} */ Retina.configure = function(pos) { if (null === pos) { pos = {}; } var i; for (i in pos) { if (pos.hasOwnProperty(i)) { config[i] = pos[i]; } } }; /** * @param {!Object} a * @return {undefined} */ Retina.init = function(a) { if (null === a) { a = root; } /** @type {function(): undefined} */ var createHistoryLink = a.onload || function() { }; /** * @return {undefined} */ a.onload = function() { var i; var image; /** @type {!NodeList} */ var images = document.getElementsByTagName("img"); /** @type {!Array} */ var retinaImages = []; /** @type {number} */ i = 0; for (; i < images.length; i = i + 1) { /** @type {!Element} */ image = images[i]; if (!image.getAttributeNode("data-no-retina")) { retinaImages.push(new RetinaImage(image)); } } createHistoryLink(); }; }; /** * @return {?} */ Retina.isRetina = function() { /** @type {string} */ var query = "(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)"; return root.devicePixelRatio > 1 ? true : root.matchMedia && root.matchMedia(query).matches ? true : false; }; /** @type {!RegExp} */ var regexMatch = /\.\w+$/; /** @type {function(string, string): undefined} */ root.RetinaImagePath = RetinaImagePath; /** @type {!Array} */ RetinaImagePath.confirmed_paths = []; /** * @return {?} */ RetinaImagePath.prototype.is_external = function() { return !(!this.path.match(/^https?:/i) || this.path.match("//" + document.domain)); }; /** * @param {!Function} callback * @return {?} */ RetinaImagePath.prototype.check_2x_variant = function(callback) { var http; var that = this; return this.is_external() ? callback(false) : this.perform_check || "undefined" == typeof this.at_2x_path || null === this.at_2x_path ? this.at_2x_path in RetinaImagePath.confirmed_paths ? callback(true) : (http = new XMLHttpRequest, http.open("HEAD", this.at_2x_path), http.onreadystatechange = function() { if (4 !== http.readyState) { return callback(false); } if (http.status >= 200 && http.status <= 399) { if (config.check_mime_type) { var type = http.getResponseHeader("Content-Type"); if (null === type || !type.match(/^image/i)) { return callback(false); } } return RetinaImagePath.confirmed_paths.push(that.at_2x_path), callback(true); } return callback(false); }, http.send(), void 0) : callback(true); }; /** @type {function(!Object): undefined} */ root.RetinaImage = RetinaImage; /** * @param {string} path * @return {undefined} */ RetinaImage.prototype.swap = function(path) { /** * @return {undefined} */ function load() { if (c.el.complete) { if (config.force_original_dimensions) { c.el.setAttribute("width", c.el.offsetWidth); c.el.setAttribute("height", c.el.offsetHeight); } c.el.setAttribute("src", path); } else { setTimeout(load, 5); } } if ("undefined" == typeof path) { path = this.path.at_2x_path; } var c = this; load(); }; if (Retina.isRetina()) { Retina.init(root); } }();