loading-attribute-polyfill
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -18,2 +18,25 @@ # Changelog | ||
## [2.0.1] - 2021-05-13 | ||
### Added | ||
- build: added CI/CD yaml for pull-requests 2f59306 | ||
### Changed | ||
- refactor: removed two CSS files which aren't generated any more by `microbundle` c960f13 | ||
- test: specified the browser versions within their test-browser-names cacceaf | ||
- Formatted the code with `xo` and `prettier` again | ||
- build: replaced manual versioning via `np` package 0b4f9ef | ||
- build(deps-dev): bump `xo` from 0.39.1 to 0.40.1 (#170) b4b58eb | ||
- build(deps-dev): bump `prettier` from 2.2.1 to 2.3.0 (#168) 75696fc | ||
- build(deps-dev): bump `@commitlint` dependencies ce81f5d | ||
- build(deps-dev): bump `webdriverio` dependencies | ||
- build(deps-dev): bump `html-validate` from to 4.11.0 | ||
- build(deps-dev): bump `xo` from 0.38.2 to 0.39.1 (#143) 2514fcb | ||
### Fixed | ||
- Description within the README on the correct `UMD` JavaScript files to include | ||
## [2.0.0] - 2021-04-09 | ||
@@ -20,0 +43,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e,t="loading"in HTMLImageElement.prototype,r="loading"in HTMLIFrameElement.prototype,a="onscroll"in window;function o(e){var t,r,a=[];"picture"===e.parentNode.tagName.toLowerCase()&&((r=(t=e.parentNode).querySelector("source[data-lazy-remove]"))&&t.removeChild(r),a=Array.prototype.slice.call(e.parentNode.querySelectorAll("source"))),a.push(e),a.forEach(function(e){e.hasAttribute("data-lazy-srcset")&&(e.setAttribute("srcset",e.getAttribute("data-lazy-srcset")),e.removeAttribute("data-lazy-srcset"))}),e.setAttribute("src",e.getAttribute("data-lazy-src")),e.removeAttribute("data-lazy-src")}function n(o){var n=document.createElement("div");for(n.innerHTML=function(o){var n=o.textContent||o.innerHTML,i="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 "+((n.match(/width=['"](\d+)['"]/)||!1)[1]||1)+" "+((n.match(/height=['"](\d+)['"]/)||!1)[1]||1)+"%27%3E%3C/svg%3E";return(/<img/gim.test(n)&&!t||/<iframe/gim.test(n)&&!r)&&a&&(n=void 0===e?n.replace(/(?:\r\n|\r|\n|\t| )src=/g,' lazyload="1" src='):(n=n.replace("<source",'<source srcset="'+i+'" data-lazy-remove="true"></source>\n<source')).replace(/(?:\r\n|\r|\n|\t| )srcset=/g," data-lazy-srcset=").replace(/(?:\r\n|\r|\n|\t| )src=/g,' src="'+i+'" data-lazy-src=')),n}(o);n.firstChild;){var i=n.firstChild;if(a&&void 0!==e&&i.tagName&&(("img"===i.tagName.toLowerCase()||"picture"===i.tagName.toLowerCase())&&!t||"iframe"===i.tagName.toLowerCase()&&!r)){var c="picture"===i.tagName.toLowerCase()?n.querySelector("img"):i;e.observe(c)}o.parentNode.insertBefore(i,o)}o.parentNode.removeChild(o)}window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),"IntersectionObserver"in window&&(e=new IntersectionObserver(function(e,t){e.forEach(function(e){if(0!==e.intersectionRatio){var r=e.target;t.unobserve(r),o(r)}})},{rootMargin:"0px 0px 256px 0px",threshold:.01}));let i=()=>{document.querySelectorAll("noscript.loading-lazy").forEach(e=>n(e)),void 0!==window.matchMedia&&window.matchMedia("print").addListener(function(e){e.matches&&document.querySelectorAll('img[loading="lazy"][data-lazy-src],iframe[loading="lazy"][data-lazy-src]').forEach(function(e){o(e)})})};/comp|inter/.test(document.readyState)?i():"addEventListener"in document?document.addEventListener("DOMContentLoaded",function(){i()}):document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&i()});const c={prepareElement:n};export default c; | ||
const e="loading"in HTMLImageElement.prototype,t="loading"in HTMLIFrameElement.prototype,r="onscroll"in window;let a;function o(e){let t=[];"picture"===e.parentNode.tagName.toLowerCase()&&(function(e){const t=e.querySelector("source[data-lazy-remove]");t&&e.removeChild(t)}(e.parentNode),t=Array.prototype.slice.call(e.parentNode.querySelectorAll("source"))),t.push(e),t.forEach(e=>{e.hasAttribute("data-lazy-srcset")&&(e.setAttribute("srcset",e.getAttribute("data-lazy-srcset")),e.removeAttribute("data-lazy-srcset"))}),e.setAttribute("src",e.getAttribute("data-lazy-src")),e.removeAttribute("data-lazy-src")}function n(o){const n=document.createElement("div");for(n.innerHTML=function(o){let n=o.textContent||o.innerHTML;const c="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 "+((n.match(/width=['"](\d+)['"]/)||!1)[1]||1)+" "+((n.match(/height=['"](\d+)['"]/)||!1)[1]||1)+"%27%3E%3C/svg%3E";return(/<img/gim.test(n)&&!e||/<iframe/gim.test(n)&&!t)&&r&&(void 0===a?n=n.replace(/(?:\r\n|\r|\n|\t| )src=/g,' lazyload="1" src='):(n=n.replace("<source",'<source srcset="'+c+'" data-lazy-remove="true"></source>\n<source'),n=n.replace(/(?:\r\n|\r|\n|\t| )srcset=/g," data-lazy-srcset=").replace(/(?:\r\n|\r|\n|\t| )src=/g,' src="'+c+'" data-lazy-src='))),n}(o);n.firstChild;){const c=n.firstChild;if(r&&void 0!==a&&c.tagName&&(("img"===c.tagName.toLowerCase()||"picture"===c.tagName.toLowerCase())&&!e||"iframe"===c.tagName.toLowerCase()&&!t)){const e="picture"===c.tagName.toLowerCase()?n.querySelector("img"):c;a.observe(e)}o.parentNode.insertBefore(c,o)}o.parentNode.removeChild(o)}window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),"IntersectionObserver"in window&&(a=new IntersectionObserver(function(e,t){e.forEach(e=>{if(0===e.intersectionRatio)return;const r=e.target;t.unobserve(r),o(r)})},{rootMargin:"0px 0px 256px 0px",threshold:.01}));const c=()=>{document.querySelectorAll("noscript.loading-lazy").forEach(e=>n(e)),void 0!==window.matchMedia&&window.matchMedia("print").addListener(e=>{e.matches&&document.querySelectorAll('img[loading="lazy"][data-lazy-src],iframe[loading="lazy"][data-lazy-src]').forEach(e=>{o(e)})})};/comp|inter/.test(document.readyState)?c():"addEventListener"in document?document.addEventListener("DOMContentLoaded",()=>{c()}):document.attachEvent("onreadystatechange",()=>{"complete"===document.readyState&&c()});const s={prepareElement:n};export default s; | ||
//# sourceMappingURL=loading-attribute-polyfill.modern.js.map |
{ | ||
"name": "loading-attribute-polyfill", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Fast and lightweight dependency-free vanilla JavaScript polyfill for native lazy loading / the awesome loading='lazy'-attribute.", | ||
"source": "./src/loading-attribute-polyfill.js", | ||
"main": "./dist/loading-attribute-polyfill.js", | ||
"esmodule": "./dist/loading-attribute-polyfill.modern.js", | ||
@@ -33,16 +32,17 @@ "module": "./dist/loading-attribute-polyfill.module.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "^12.1.1", | ||
"@commitlint/config-conventional": "^12.1.1", | ||
"@wdio/cli": "^7.3.1", | ||
"@wdio/dot-reporter": "^7.3.1", | ||
"@wdio/local-runner": "^7.3.1", | ||
"@wdio/mocha-framework": "^7.3.1", | ||
"@wdio/sync": "^7.3.1", | ||
"html-validate": "^4.9.0", | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-conventional": "^12.1.4", | ||
"@wdio/cli": "^7.5.7", | ||
"@wdio/dot-reporter": "^7.5.7", | ||
"@wdio/local-runner": "^7.5.7", | ||
"@wdio/mocha-framework": "^7.5.3", | ||
"@wdio/sync": "^7.5.7", | ||
"html-validate": "^4.10.1", | ||
"husky": "^6.0.0", | ||
"microbundle": "^0.13.0", | ||
"np": "^7.5.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "2.2.1", | ||
"prettier": "2.3.0", | ||
"pretty-quick": "^3.1.0", | ||
"xo": "^0.38.2" | ||
"xo": "^0.40.1" | ||
}, | ||
@@ -56,6 +56,5 @@ "scripts": { | ||
"dev": "microbundle watch", | ||
"release:minor": "npm version minor -m 'build(release): new minor version' && git push && git push --tags && npm publish", | ||
"release:patch": "npm version patch -m 'build(release): new patch version' && git push && git push --tags && npm publish", | ||
"release": "np", | ||
"prepare": "husky install" | ||
} | ||
} |
@@ -30,3 +30,3 @@ # loading="lazy" attribute polyfill | ||
- Lightweight (see the badge above) | ||
- Web standards: supports the standard `loading="lazy"` attribute on `image` and `iframe` elements | ||
- Web standards: supports the standard `loading="lazy"` attribute on `img` and `iframe` elements | ||
- Performance: it's based on highly efficient, best practice code. | ||
@@ -56,3 +56,3 @@ - SEO & crawlers: the image and iframe contents aren't being hidden from crawlers that aren't capable of scrolling. | ||
```html | ||
<script src="dist/loading-attribute-polyfill.js" async></script> | ||
<script src="dist/loading-attribute-polyfill.umd.js" async></script> | ||
<link rel="stylesheet" href="dist/loading-attribute-polyfill.css" /> | ||
@@ -59,0 +59,0 @@ ``` |
@@ -13,7 +13,5 @@ /* | ||
'use strict'; | ||
import './loading-attribute-polyfill.css'; | ||
var config = { | ||
const config = { | ||
intersectionObserver: { | ||
@@ -29,3 +27,3 @@ // Start download if the item gets within 256px in the Y axis | ||
// Device/browser capabilities object | ||
var capabilities = { | ||
const capabilities = { | ||
loading: { | ||
@@ -44,3 +42,3 @@ image: 'loading' in HTMLImageElement.prototype, | ||
// Define according to browsers support of the IntersectionObserver feature (missing e.g. on IE11 or Safari 11) | ||
var intersectionObserver; | ||
let intersectionObserver; | ||
@@ -59,3 +57,3 @@ if ('IntersectionObserver' in window) { | ||
function restoreSource(lazyItem) { | ||
var srcsetItems = []; | ||
let srcsetItems = []; | ||
@@ -74,3 +72,3 @@ // Just in case the img is the decendent of a picture element, check for source tags | ||
// Not using .dataset within those upfollowing lines of code for polyfill independent compatibility down to IE9 | ||
srcsetItems.forEach(function (item) { | ||
srcsetItems.forEach((item) => { | ||
if (item.hasAttribute('data-lazy-srcset')) { | ||
@@ -91,3 +89,3 @@ item.setAttribute('srcset', item.getAttribute('data-lazy-srcset')); | ||
function removePlaceholderSource(lazyItemPicture) { | ||
var placeholderSource = lazyItemPicture.querySelector( | ||
const placeholderSource = lazyItemPicture.querySelector( | ||
'source[data-lazy-remove]' | ||
@@ -108,3 +106,3 @@ ); | ||
function onIntersection(entries, observer) { | ||
entries.forEach(function (entry) { | ||
entries.forEach((entry) => { | ||
// Mitigation for EDGE lacking support of .isIntersecting until v15, compare to e.g. https://github.com/w3c/IntersectionObserver/issues/211#issuecomment-309144669 | ||
@@ -116,3 +114,3 @@ if (entry.intersectionRatio === 0) { | ||
// If the item is visible now, load it and stop watching it | ||
var lazyItem = entry.target; | ||
const lazyItem = entry.target; | ||
@@ -133,5 +131,5 @@ observer.unobserve(lazyItem); | ||
var mediaQueryList = window.matchMedia('print'); | ||
const mediaQueryList = window.matchMedia('print'); | ||
mediaQueryList.addListener(function (mql) { | ||
mediaQueryList.addListener((mql) => { | ||
if (mql.matches) { | ||
@@ -145,3 +143,3 @@ document | ||
) | ||
.forEach(function (lazyItem) { | ||
.forEach((lazyItem) => { | ||
restoreSource(lazyItem); | ||
@@ -160,10 +158,10 @@ }); | ||
// The contents of a <noscript> tag are treated as text to JavaScript | ||
var lazyAreaHtml = noScriptTag.textContent || noScriptTag.innerHTML; | ||
let lazyAreaHtml = noScriptTag.textContent || noScriptTag.innerHTML; | ||
var getImageWidth = lazyAreaHtml.match(/width=['"](\d+)['"]/) || false; | ||
var temporaryImageWidth = getImageWidth[1] || 1; | ||
var getImageHeight = lazyAreaHtml.match(/height=['"](\d+)['"]/) || false; | ||
var temporaryImageHeight = getImageHeight[1] || 1; | ||
const getImageWidth = lazyAreaHtml.match(/width=['"](\d+)['"]/) || false; | ||
const temporaryImageWidth = getImageWidth[1] || 1; | ||
const getImageHeight = lazyAreaHtml.match(/height=['"](\d+)['"]/) || false; | ||
const temporaryImageHeight = getImageHeight[1] || 1; | ||
var temporaryImage = | ||
const temporaryImage = | ||
'data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 ' + | ||
@@ -216,3 +214,3 @@ temporaryImageWidth + | ||
// Sticking the noscript HTML code in the innerHTML of a new <div> tag to 'load' it after creating that <div> | ||
var lazyArea = document.createElement('div'); | ||
const lazyArea = document.createElement('div'); | ||
@@ -223,3 +221,3 @@ lazyArea.innerHTML = getAndPrepareHTMLCode(noScriptTag); | ||
while (lazyArea.firstChild) { | ||
var actualChild = lazyArea.firstChild; | ||
const actualChild = lazyArea.firstChild; | ||
@@ -236,3 +234,3 @@ if ( | ||
) { | ||
var observedElement = | ||
const observedElement = | ||
actualChild.tagName.toLowerCase() === 'picture' | ||
@@ -255,4 +253,4 @@ ? lazyArea.querySelector('img') | ||
*/ | ||
let prepareElements = () => { | ||
var lazyLoadAreas = document.querySelectorAll('noscript.loading-lazy'); | ||
const prepareElements = () => { | ||
const lazyLoadAreas = document.querySelectorAll('noscript.loading-lazy'); | ||
@@ -270,7 +268,7 @@ lazyLoadAreas.forEach((element) => prepareElement(element)); | ||
} else if ('addEventListener' in document) { | ||
document.addEventListener('DOMContentLoaded', function () { | ||
document.addEventListener('DOMContentLoaded', () => { | ||
prepareElements(); | ||
}); | ||
} else { | ||
document.attachEvent('onreadystatechange', function () { | ||
document.attachEvent('onreadystatechange', () => { | ||
if (document.readyState === 'complete') { | ||
@@ -283,5 +281,5 @@ prepareElements(); | ||
const loadingAttributePolyfill = { | ||
prepareElement: prepareElement, | ||
prepareElement, | ||
}; | ||
export default loadingAttributePolyfill; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102238
15
27
296