From 6a354a599fe946f9f94b49ee0dc24e8c88d83ca0 Mon Sep 17 00:00:00 2001 From: Steven Truesdell Date: Sun, 11 Jun 2017 11:56:47 -0600 Subject: [PATCH] pre-release chore --- dist/retina.min.js | 2 +- dist/retina.min.js.map | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/retina.min.js b/dist/retina.min.js index 93e7b70..d5e2354 100644 --- a/dist/retina.min.js +++ b/dist/retina.min.js @@ -1,2 +1,2 @@ -(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define(b):a.retinajs=b()})(this,function(){'use strict';function a(p){return Array.prototype.slice.call(p)}function b(p){var q=parseInt(p,10);return k {\n /*\n * If we're dealing with an image tag, force it's dimensions\n * and set the source attribute. If not, go after the background-image\n * inline style.\n */\n if (imgType === 'img') {\n forceOriginalDimensions(image).setAttribute('src', retinaURL);\n } else {\n image.style.backgroundImage = `url(${retinaURL})`;\n }\n });\n\n /*\n * Attach the retina URL to our proxy image to load in the new\n * image resource.\n */\n testImage.setAttribute('src', retinaURL);\n\n /*\n * Mark our image as processed so that it won't be processed again.\n */\n image.setAttribute(processedAttr, true);\n}\n\n/**\n * Attempts to do an image url swap on a given image.\n *\n * @param {Element} image An image in the DOM.\n * @param {String} src The original image source attribute.\n * @param {String|Number} rjs The pixel density cap for images provided.\n *\n * @return {undefined}\n */\nfunction dynamicSwapImage(image, src, rjs = 1) {\n const cap = chooseCap(rjs);\n\n /*\n * Don't do anything if the cap is less than 2 or there is no src.\n */\n if (src && cap > 1) {\n const newSrc = src.replace(srcReplace, `@${cap}x$1`);\n setSourceIfAvailable(image, newSrc);\n }\n}\n\n/**\n * Performs an image url swap on a given image with a provided url.\n *\n * @param {Element} image An image in the DOM.\n * @param {String} src The original image source attribute.\n * @param {String} hdsrc The path for a 2x image.\n *\n * @return {undefined}\n */\nfunction manualSwapImage(image, src, hdsrc) {\n if (environment > 1) {\n setSourceIfAvailable(image, hdsrc);\n }\n}\n\n/**\n * Collects all images matching our selector, and converts our\n * NodeList into an Array so that Array methods will be available to it.\n *\n * @param {Iterable} images Optional. An Array, jQuery selection, or NodeList\n * of elements to affect with retina.js.\n *\n * @return {Iterable} Contains all elements matching our selector.\n */\nfunction getImages(images) {\n if (!images) {\n return typeof document !== 'undefined' ? arrayify(document.querySelectorAll(selector)) : [];\n } else {\n return typeof images.forEach === 'function' ? images : arrayify(images);\n }\n}\n\n/**\n * Converts a string like \"url(hello.png)\" into \"hello.png\".\n *\n * @param {Element} img An HTML element with a background image.\n *\n * @return {String}\n */\nfunction cleanBgImg(img) {\n return img.style.backgroundImage.replace(inlineReplace, '$2');\n}\n\n/**\n * Gets all participating images and dynamically swaps out each one for its\n * retina equivalent taking into account the environment capabilities and\n * the densities for which the user has provided images.\n *\n * @param {Iterable} images Optional. An Array, jQuery selection, or NodeList\n * of elements to affect with retina.js. If not\n * provided, retina.js will grab all images on the\n * page.\n *\n * @return {undefined}\n */\nfunction retina(images) {\n getImages(images).forEach(img => {\n if (!img.getAttribute(processedAttr)) {\n const isImg = img.nodeName.toLowerCase() === 'img';\n const src = isImg ? img.getAttribute('src') : cleanBgImg(img);\n const rjs = img.getAttribute('data-rjs');\n const rjsIsNumber = !isNaN(parseInt(rjs, 10));\n\n // do not try to load /null image!\n if (rjs === null) {\n return;\n }\n\n /*\n * If the user provided a number, dynamically swap out the image.\n * If the user provided a url, do it manually.\n */\n if (rjsIsNumber) {\n dynamicSwapImage(img, src, rjs);\n } else {\n manualSwapImage(img, src, rjs);\n }\n }\n });\n}\n\n/*\n * If this environment has `window`, activate the plugin.\n */\nif (hasWindow) {\n window.addEventListener('load', () => {\n retina();\n });\n window.retinajs = retina;\n}\n\nexport default retina;\n"],"names":["Array","prototype","slice","call","object","numericCap","parseInt","cap","environment","image","hasAttribute","offsetWidth","offsetHeight","setAttribute","naturalWidth","naturalHeight","imgType","nodeName","toLowerCase","testImage","document","createElement","addEventListener","retinaURL","style","backgroundImage","processedAttr","rjs","chooseCap","src","newSrc","replace","srcReplace","hdsrc","images","forEach","arrayify","querySelectorAll","selector","img","inlineReplace","getAttribute","isImg","cleanBgImg","rjsIsNumber","isNaN","hasWindow","window","Math","round","devicePixelRatio","retinajs","retina"],"mappings":"qLA8CA,aAA0B,OACjBA,OAAMC,SAAND,CAAgBE,KAAhBF,CAAsBG,IAAtBH,CAA2BI,CAA3BJ,EAYT,aAAwB,IAChBK,GAAaC,SAASC,CAATD,CAAc,EAAdA,EADG,MAOlBE,GAAcH,CAPI,CAQbG,CARa,CAebH,EAYX,aAAwC,OACjCI,GAAMC,YAAND,CAAmB,gBAAnBA,IACuB,CAAtBA,KAAME,WAANF,EAAkD,CAAvBA,KAAMG,gBAC7BC,aAAa,QAASJ,EAAMK,gBAC5BD,aAAa,SAAUJ,EAAMM,mBAE7BF,aAAa,QAASJ,EAAME,eAC5BE,aAAa,SAAUJ,EAAMG,gBAGhCH,EAaT,eAAgD,IACxCO,GAAUP,EAAMQ,QAANR,CAAeS,WAAfT,GAOVU,EAAYC,SAASC,aAATD,CAAuB,KAAvBA,IACRE,iBAAiB,OAAQ,UAAM,CAMvB,KAAZN,IANmC,GAObP,GAAOI,aAAa,MAAOU,EAPd,GAS/BC,MAAMC,uBAAyBF,KATzC,EAT8C,GA0BpCV,aAAa,MAAOU,EA1BgB,GA+BxCV,aAAaa,MAYrB,eAA+C,IAATC,0DAAM,EACpCpB,EAAMqB,EAAUD,CAAVC,KAKRC,GAAa,CAANtB,GAAS,IACZuB,GAASD,EAAIE,OAAJF,CAAYG,CAAZH,KAA4BtB,OAA5BsB,IACMpB,EAAOqB,IAahC,iBAA4C,CACxB,CAAdtB,EADsC,IAEnBC,EAAOwB,GAahC,aAA2B,OACpBC,EADoB,CAIU,UAA1B,QAAOA,GAAOC,OAAd,CAAuCD,CAAvC,CAAgDE,EAASF,CAATE,CAJhC,CAEI,WAApB,QAAOhB,SAAP,IAAkCgB,EAAShB,SAASiB,gBAATjB,CAA0BkB,CAA1BlB,CAATgB,EAa7C,aAAyB,OAChBG,GAAIf,KAAJe,CAAUd,eAAVc,CAA0BR,OAA1BQ,CAAkCC,CAAlCD,CAAiD,IAAjDA,EAeT,aAAwB,GACZL,GAAQC,QAAQ,WAAO,IAC3B,CAACI,EAAIE,YAAJF,CAAiBb,CAAjBa,EAAiC,IAC9BG,GAAuC,KAA/BH,KAAItB,QAAJsB,CAAarB,WAAbqB,GACRV,EAAMa,EAAQH,EAAIE,YAAJF,CAAiB,KAAjBA,CAARG,CAAkCC,EAAWJ,CAAXI,EACxChB,EAAMY,EAAIE,YAAJF,CAAiB,UAAjBA,EACNK,EAAc,CAACC,MAAMvC,SAASqB,CAATrB,CAAc,EAAdA,CAANuC,KAGT,IAARlB,YAQAiB,CAfgC,GAgBjBL,EAAKV,EAAKF,EAhBO,GAkBlBY,EAAKV,EAAKF,GAnBhC,GA7MF,GAAMmB,GAA8B,WAAlB,QAAOC,OAAzB,CAMMvC,EAAcwC,KAAKC,KAALD,CAAWF,EAAYC,OAAOG,gBAAPH,EAA2B,CAAvCD,CAA2C,CAAtDE,CANpB,CAWMhB,EAAa,2BAXnB,CAYMQ,EAAgB,+BAZtB,CAiBMF,EAAW,YAjBjB,CAsBMZ,EAAgB,oBAtBtB,OAyOIoB,YACKxB,iBAAiB,OAAQ,UAAM,IAAtC,UAGO6B,SAAWC"} \ No newline at end of file +{"version":3,"file":"retina.min.js","sources":["../src/retina.js"],"sourcesContent":["/* @flow */\n\n/**\n * --------------------------------------------------------------------------\n * Retina.js\n * Licensed under MIT (https://github.com/strues/retinajs/blob/master/LICENSE)\n *\n * Retina.js is an open source script that makes it easy to serve high-resolution\n * images to devices with retina displays.\n * --------------------------------------------------------------------------\n */\n\n/*\n * Determine whether or not `window` is available.\n */\nconst hasWindow = typeof window !== 'undefined';\n\n/*\n * Get the device pixel ratio per our environment.\n * Default to 1.\n */\nconst environment = Math.round(hasWindow ? window.devicePixelRatio || 1 : 1);\n\n/*\n * Define a pattern for capturing src url suffixes.\n */\nconst srcReplace = /(\\.[A-z]{3,4}\\/?(\\?.*)?)$/;\nconst inlineReplace = /url\\(('|\")?([^)'\"]+)('|\")?\\)/i;\n\n/*\n * Define our selectors for elements to target.\n */\nconst selector = '[data-rjs]';\n\n/*\n * Define the attribute we'll use to mark an image as having been processed.\n */\nconst processedAttr = 'data-rjs-processed';\n\n/**\n * Shortcut for turning some iterable object into an array.\n *\n * @param {Iterable} object Any iterable object.\n *\n * @return {Array}\n */\nfunction arrayify(object) {\n return Array.prototype.slice.call(object);\n}\n\n/**\n * Chooses the actual image size to fetch, (for example 2 or 3) that\n * will be used to create a suffix like \"@2x\" or \"@3x\".\n *\n * @param {String|Number} cap The number the user provided indicating that\n * they have prepared images up to this size.\n *\n * @return {Number} The number we'll be using to create a suffix.\n */\nfunction chooseCap(cap) {\n const numericCap = parseInt(cap, 10);\n\n /*\n * If the environment's device pixel ratio is less than what the user\n * provided, we'll only grab images at that size.\n */\n if (environment < numericCap) {\n return environment;\n\n /*\n * If the device pixel ratio is greater than or equal to what the\n * user provided, we'll use what the user provided.\n */\n } else {\n return numericCap;\n }\n}\n\n/**\n * Makes sure that, since we are going to swap out the source of an image,\n * the image does not change size on the page.\n *\n * @param {Element} image An image element in the DOM.\n *\n * @return {Element} The same element that was passed in.\n */\nfunction forceOriginalDimensions(image) {\n if (!image.hasAttribute('data-no-resize')) {\n if (image.offsetWidth === 0 && image.offsetHeight === 0) {\n image.setAttribute('width', image.naturalWidth);\n image.setAttribute('height', image.naturalHeight);\n } else {\n image.setAttribute('width', image.offsetWidth);\n image.setAttribute('height', image.offsetHeight);\n }\n }\n return image;\n}\n\n/**\n * Determines whether the retina image actually exists on the server.\n * If so, swaps out the retina image for the standard one. If not,\n * leaves the original image alone.\n *\n * @param {Element} image An image element in the DOM.\n * @param {String} newSrc The url to the retina image.\n *\n * @return {undefined}\n */\nfunction setSourceIfAvailable(image, retinaURL) {\n const imgType = image.nodeName.toLowerCase();\n\n /*\n * Create a new image element and give it a load listener. When the\n * load listener fires, it means the URL is correct and we will then\n * attach it to the user's image.\n */\n const testImage = document.createElement('img');\n testImage.addEventListener('load', () => {\n /*\n * If we're dealing with an image tag, force it's dimensions\n * and set the source attribute. If not, go after the background-image\n * inline style.\n */\n if (imgType === 'img') {\n forceOriginalDimensions(image).setAttribute('src', retinaURL);\n } else {\n image.style.backgroundImage = `url(${retinaURL})`;\n }\n });\n\n /*\n * Attach the retina URL to our proxy image to load in the new\n * image resource.\n */\n testImage.setAttribute('src', retinaURL);\n\n /*\n * Mark our image as processed so that it won't be processed again.\n */\n image.setAttribute(processedAttr, true);\n}\n\n/**\n * Attempts to do an image url swap on a given image.\n *\n * @param {Element} image An image in the DOM.\n * @param {String} src The original image source attribute.\n * @param {String|Number} rjs The pixel density cap for images provided.\n *\n * @return {undefined}\n */\nfunction dynamicSwapImage(image, src, rjs = 1) {\n const cap = chooseCap(rjs);\n\n /*\n * Don't do anything if the cap is less than 2 or there is no src.\n */\n if (src && cap > 1) {\n const newSrc = src.replace(srcReplace, `@${cap}x$1`);\n setSourceIfAvailable(image, newSrc);\n }\n}\n\n/**\n * Performs an image url swap on a given image with a provided url.\n *\n * @param {Element} image An image in the DOM.\n * @param {String} src The original image source attribute.\n * @param {String} hdsrc The path for a 2x image.\n *\n * @return {undefined}\n */\nfunction manualSwapImage(image, src, hdsrc) {\n if (environment > 1) {\n setSourceIfAvailable(image, hdsrc);\n }\n}\n\n/**\n * Collects all images matching our selector, and converts our\n * NodeList into an Array so that Array methods will be available to it.\n *\n * @param {Iterable} images Optional. An Array, jQuery selection, or NodeList\n * of elements to affect with retina.js.\n *\n * @return {Iterable} Contains all elements matching our selector.\n */\nfunction getImages(images) {\n if (!images) {\n return typeof document !== 'undefined' ? arrayify(document.querySelectorAll(selector)) : [];\n } else {\n return typeof images.forEach === 'function' ? images : arrayify(images);\n }\n}\n\n/**\n * Converts a string like \"url(hello.png)\" into \"hello.png\".\n *\n * @param {Element} img An HTML element with a background image.\n *\n * @return {String}\n */\nfunction cleanBgImg(img) {\n return img.style.backgroundImage.replace(inlineReplace, '$2');\n}\n\n/**\n * Gets all participating images and dynamically swaps out each one for its\n * retina equivalent taking into account the environment capabilities and\n * the densities for which the user has provided images.\n *\n * @param {Iterable} images Optional. An Array, jQuery selection, or NodeList\n * of elements to affect with retina.js. If not\n * provided, retina.js will grab all images on the\n * page.\n *\n * @return {undefined}\n */\nfunction retina(images) {\n getImages(images).forEach(img => {\n if (!img.getAttribute(processedAttr)) {\n const isImg = img.nodeName.toLowerCase() === 'img';\n const src = isImg ? img.getAttribute('src') : cleanBgImg(img);\n const rjs = img.getAttribute('data-rjs');\n const rjsIsNumber = !isNaN(parseInt(rjs, 10));\n\n // do not try to load /null image!\n if (rjs === null) {\n return;\n }\n\n /*\n * If the user provided a number, dynamically swap out the image.\n * If the user provided a url, do it manually.\n */\n if (rjsIsNumber) {\n dynamicSwapImage(img, src, rjs);\n } else {\n manualSwapImage(img, src, rjs);\n }\n }\n });\n}\n\n/*\n * If this environment has `window`, activate the plugin.\n */\nif (hasWindow) {\n window.addEventListener('load', () => {\n retina();\n });\n window.retinajs = retina;\n}\n\nexport default retina;\n"],"names":["Array","prototype","slice","call","numericCap","parseInt","environment","image","hasAttribute","offsetWidth","offsetHeight","setAttribute","naturalWidth","naturalHeight","imgType","nodeName","toLowerCase","testImage","document","createElement","addEventListener","style","backgroundImage","rjs","cap","chooseCap","src","newSrc","replace","images","forEach","arrayify","querySelectorAll","img","getAttribute","isImg","cleanBgImg","rjsIsNumber","isNaN","hasWindow","window","Math","round","devicePixelRatio","srcReplace","inlineReplace","selector","processedAttr","retinajs"],"mappings":"qLA8CA,aAA0B,OACjBA,OAAMC,SAAND,CAAgBE,KAAhBF,CAAsBG,IAAtBH,IAYT,aAAwB,IAChBI,GAAaC,WAAc,EAAdA,EADG,MAOlBC,IAPkB,KA2BxB,aAAwC,OACjCC,GAAMC,YAAND,CAAmB,gBAAnBA,IACuB,CAAtBA,KAAME,WAANF,EAAkD,C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