From de56360a94e71aac9591d2c8adedebc365300067 Mon Sep 17 00:00:00 2001 From: verlok Date: Sun, 10 Apr 2022 12:55:14 +0200 Subject: [PATCH 1/5] Updated caniuse-lite --- package-lock.json | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2686626..fcf2969 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vanilla-lazyload", - "version": "17.5.0", + "version": "17.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vanilla-lazyload", - "version": "17.5.0", + "version": "17.6.1", "license": "MIT", "devDependencies": { "@babel/core": "^7.13.14", @@ -2937,14 +2937,20 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001259", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001259.tgz", - "integrity": "sha512-V7mQTFhjITxuk9zBpI6nYsiTXhcPe05l+364nZjK7MFK/E7ibvYBSAXr4YcA6oPR8j3ZLM/LN+lUqUVAQEUZFg==", - "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "version": "1.0.30001327", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001327.tgz", + "integrity": "sha512-1/Cg4jlD9qjZzhbzkzEaAC2JHsP0WrOc8Rd/3a3LuajGzGWR/hD7TVyvq99VqmTy99eVh8Zkmdq213OgvgXx7w==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + } + ] }, "node_modules/chalk": { "version": "2.4.2", @@ -9255,9 +9261,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001259", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001259.tgz", - "integrity": "sha512-V7mQTFhjITxuk9zBpI6nYsiTXhcPe05l+364nZjK7MFK/E7ibvYBSAXr4YcA6oPR8j3ZLM/LN+lUqUVAQEUZFg==", + "version": "1.0.30001327", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001327.tgz", + "integrity": "sha512-1/Cg4jlD9qjZzhbzkzEaAC2JHsP0WrOc8Rd/3a3LuajGzGWR/hD7TVyvq99VqmTy99eVh8Zkmdq213OgvgXx7w==", "dev": true }, "chalk": { From 4ffd5bfc621eba090104b54fdb1db1e6fe237931 Mon Sep 17 00:00:00 2001 From: verlok Date: Sun, 10 Apr 2022 12:55:59 +0200 Subject: [PATCH 2/5] Added demos to test error cases Testing with and without restore original --- demos/error_no_restore.html | 493 +++++++++++++++++++++++++++++++++ demos/error_restore.html | 531 ++++++++++++++++++++++++++++++++++++ 2 files changed, 1024 insertions(+) create mode 100644 demos/error_no_restore.html create mode 100644 demos/error_restore.html diff --git a/demos/error_no_restore.html b/demos/error_no_restore.html new file mode 100644 index 0000000..17363ee --- /dev/null +++ b/demos/error_no_restore.html @@ -0,0 +1,493 @@ + + + + + + Error, no restore - Lazyload demos + + + + + + +

Error, no restore

+
+
    +
  • + Stivaletti +
  • +
  • + Open toe +
  • +
  • + Sneakers & Tennis +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Sneakers & Tennis shoes alte +
  • +
  • + Sneakers & Tennis shoes alte +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Stivali +
  • +
  • + Stivali +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Stivali +
  • +
  • + Stivaletti +
  • +
  • + Décolleté +
  • +
  • + Mocassini +
  • +
  • + Stivaletti +
  • +
  • + Décolleté +
  • +
  • + Décolleté +
  • +
  • + Francesine +
  • +
  • + Stivaletti +
  • +
  • + Décolleté +
  • +
  • + Mocassini +
  • +
  • + Mocassini +
  • +
  • + Stivali +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Mocassini +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Cuissardes +
  • +
  • + Décolleté +
  • +
  • + Stivaletti +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Mocassini +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Mocassini +
  • +
  • + Mocassini +
  • +
+
+ + + + diff --git a/demos/error_restore.html b/demos/error_restore.html new file mode 100644 index 0000000..c01bc22 --- /dev/null +++ b/demos/error_restore.html @@ -0,0 +1,531 @@ + + + + + + Error, restore - Lazyload demos + + + + + + +

Error, restore original attribute

+
+
    +
  • + Stivaletti +
  • +
  • + Open toe +
  • +
  • + Sneakers & Tennis +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Sneakers & Tennis shoes alte +
  • +
  • + Sneakers & Tennis shoes alte +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Stivali +
  • +
  • + Stivali +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Stivali +
  • +
  • + Stivaletti +
  • +
  • + Décolleté +
  • +
  • + Mocassini +
  • +
  • + Stivaletti +
  • +
  • + Décolleté +
  • +
  • + Décolleté +
  • +
  • + Francesine +
  • +
  • + Stivaletti +
  • +
  • + Décolleté +
  • +
  • + Mocassini +
  • +
  • + Mocassini +
  • +
  • + Stivali +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Mocassini +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Stivaletti +
  • +
  • + Cuissardes +
  • +
  • + Décolleté +
  • +
  • + Stivaletti +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Mocassini +
  • +
  • + Sneakers & Tennis shoes basse +
  • +
  • + Mocassini +
  • +
  • + Mocassini +
  • +
+
+ + + + From 1f2b4da4b509a088a7d3d9e287ce0e2d068941f5 Mon Sep 17 00:00:00 2001 From: verlok Date: Sun, 10 Apr 2022 12:56:41 +0200 Subject: [PATCH 3/5] Implemented restore_on_error --- src/defaults.js | 3 ++- src/event.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/defaults.js b/src/defaults.js index d04f3a7..a12eac7 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -30,7 +30,8 @@ const defaultSettings = { callback_error: null, callback_finish: null, callback_cancel: null, - use_native: false + use_native: false, + restore_on_error: false, }; export const getExtendedSettings = (customSettings) => { diff --git a/src/event.js b/src/event.js index e10844b..1213f6f 100644 --- a/src/event.js +++ b/src/event.js @@ -10,6 +10,7 @@ import { haveElementsToLoad, isSomethingLoading } from "./counters"; +import { attrsSrcSrcsetSizes, restoreOriginalAttrs } from "./originalAttributes"; const elementsWithLoadEvent = ["IMG", "IFRAME", "VIDEO", "OBJECT"]; export const hasLoadEvent = (element) => elementsWithLoadEvent.indexOf(element.tagName) > -1; @@ -77,6 +78,7 @@ export const errorHandler = (event, element, settings, instance) => { addClass(element, settings.class_error); setStatus(element, statusError); safeCallback(settings.callback_error, element, instance); + if (settings.restore_on_error) restoreOriginalAttrs(element, attrsSrcSrcsetSizes); if (!goingNative) checkFinish(settings, instance); }; From 15d392db756ad2059cf2d23644372c743e613320 Mon Sep 17 00:00:00 2001 From: verlok Date: Sun, 10 Apr 2022 12:59:34 +0200 Subject: [PATCH 4/5] Error without restore sets to new fallback image --- demos/error_no_restore.html | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/error_no_restore.html b/demos/error_no_restore.html index 17363ee..8affff4 100644 --- a/demos/error_no_restore.html +++ b/demos/error_no_restore.html @@ -463,6 +463,7 @@

Error, no restore

}; var callback_error = function (element) { logElementEvent("💀 ERROR", element); + element.src = "https://via.placeholder.com/440x560/?text=Error"; }; var callback_finish = function () { logElementEvent("✔️ FINISHED", document.documentElement); From 551125aa1b94a3c8866ded1ef45eb3a5d33d332b Mon Sep 17 00:00:00 2001 From: verlok Date: Sun, 10 Apr 2022 13:05:44 +0200 Subject: [PATCH 5/5] Releasing 17.7.0 --- CHANGELOG.md | 4 ++++ README.md | 11 +++++++---- dist/lazyload.amd.js | 4 +++- dist/lazyload.amd.min.js | 2 +- dist/lazyload.esm.js | 4 +++- dist/lazyload.esm.min.js | 2 +- dist/lazyload.iife.js | 4 +++- dist/lazyload.iife.min.js | 2 +- dist/lazyload.js | 4 +++- dist/lazyload.min.js | 2 +- package.json | 2 +- 11 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bf13fc..0388b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Version 17 +#### 17.7.0 + +- Added the new option `restore_on_error` to restore original attributes on error. + #### 17.6.1 - Removed nasty "debugger" from code (sorry about that rookie mistake!) diff --git a/README.md b/README.md index ca4b174..c906127 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Please note that the video poster can be lazily loaded too. ## 👩‍💻 Getting started - Script -The latest, recommended version of LazyLoad is **17.6.1**. +The latest, recommended version of LazyLoad is **17.7.0**. Quickly understand how to upgrade from a previous version reading the [practical upgrade guide](UPGRADE.md). @@ -168,7 +168,7 @@ Quickly understand how to upgrade from a previous version reading the [practical The easiest way to use LazyLoad is to include the script from a CDN: ```html - + ``` Then, in your javascript code: @@ -209,7 +209,7 @@ Then include the script. ```html ``` @@ -243,7 +243,7 @@ Then include the script. ```html ``` @@ -600,6 +600,8 @@ The [demos](https://github.com/verlok/vanilla-lazyload/tree/master/demos) folder | Loading | Asynchronous loading LazyLoad + InterserctionObserver with requireJS | [Code](demos/amd_polyfill.html) | [Live](https://www.andreaverlicchi.eu/vanilla-lazyload/demos/amd_polyfill.html) | | Loading | Asynchronous loading LazyLoad with `