Skip to content

Commit 28c2089

Browse files
committed
Merge branch 'release/18.0.0'
2 parents c29d621 + 9a91099 commit 28c2089

15 files changed

+61
-83
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## Version 18
4+
5+
#### 18.0.0
6+
7+
- **Dropped support for Internet Explorer 11**
8+
- Modernized code
9+
- Smaller file
10+
311
## Version 17
412

513
#### 17.9.0

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ Please note that the video poster can be lazily loaded too.
175175

176176
## 👩‍💻 Getting started - Script
177177

178-
The latest, recommended version of LazyLoad is **17.9.0**.
178+
The latest, recommended version of LazyLoad is **18.0.0**.
179+
Note that if you need to support Internet Explorer 11, you need to use version 17.9.0 or below.
179180

180181
Quickly understand how to upgrade from a previous version reading the [practical upgrade guide](UPGRADE.md).
181182

@@ -184,7 +185,7 @@ Quickly understand how to upgrade from a previous version reading the [practical
184185
The easiest way to use LazyLoad is to include the script from a CDN:
185186

186187
```html
187-
<script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.9.0/dist/lazyload.min.js"></script>
188+
<script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@18.0.0/dist/lazyload.min.js"></script>
188189
```
189190

190191
Then, in your javascript code:
@@ -225,7 +226,7 @@ Then include the script.
225226
```html
226227
<script
227228
async
228-
src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.9.0/dist/lazyload.min.js"
229+
src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@18.0.0/dist/lazyload.min.js"
229230
></script>
230231
```
231232

@@ -259,7 +260,7 @@ Then include the script.
259260
```html
260261
<script
261262
async
262-
src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.9.0/dist/lazyload.min.js"
263+
src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@18.0.0/dist/lazyload.min.js"
263264
></script>
264265
```
265266

@@ -269,8 +270,6 @@ Now you'll be able to call its methods, like:
269270
lazyLoadInstance.update();
270271
```
271272

272-
Note about Internet Explorer: because this technique uses a `CustomEvent` to trigger the `LazyLoad::Initialized` event, you might want to add [this polyfill](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill) to make it work on Internet Explorer.
273-
274273
[DEMO](https://verlok.github.io/vanilla-lazyload/demos/async.html) - [SOURCE](https://github.com/verlok/vanilla-lazyload/blob/master/demos/async.html) &larr; for a single LazyLoad instance
275274

276275
[DEMO](https://verlok.github.io/vanilla-lazyload/demos/async_multiple.html) - [SOURCE](https://github.com/verlok/vanilla-lazyload/blob/master/demos/async_multiple.html) &larr; for multiple LazyLoad instances
@@ -859,6 +858,6 @@ Using the `restoreAll()` method, you can make LazyLoad restore all DOM manipulat
859858

860859
## Tested on real browsers
861860

862-
Legacy browsers support is from IE 9 up. This script is tested in every browser before every release using [BrowserStack](http://browserstack.com/) live, thanks to the BrowserStack Open Source initiative.
861+
This script is tested in every browser before every release using [BrowserStack](http://browserstack.com/) live, thanks to the BrowserStack Open Source initiative.
863862

864863
<a href="http://browserstack.com/"><img alt="BrowserStack Logo" src="./img/browserstack-logo-600x315.png" width="300" height="158"/></a>

dist/lazyload.amd.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ define(function () { 'use strict';
1717

1818
var runningOnBrowser = typeof window !== "undefined";
1919
var isBot = runningOnBrowser && !("onscroll" in window) || typeof navigator !== "undefined" && /(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent);
20-
var supportsIntersectionObserver = runningOnBrowser && "IntersectionObserver" in window;
21-
var supportsClassList = runningOnBrowser && "classList" in document.createElement("p");
2220
var isHiDpi = runningOnBrowser && window.devicePixelRatio > 1;
2321

2422
var defaultSettings = {
@@ -167,24 +165,22 @@ define(function () { 'use strict';
167165
};
168166

169167
var addClass = function addClass(element, className) {
170-
if (className === "") {
168+
if (!runningOnBrowser) {
171169
return;
172170
}
173-
if (supportsClassList) {
174-
element.classList.add(className);
171+
if (className === "") {
175172
return;
176173
}
177-
element.className += (element.className ? " " : "") + className;
174+
element.classList.add(className);
178175
};
179176
var removeClass = function removeClass(element, className) {
180-
if (className === "") {
177+
if (!runningOnBrowser) {
181178
return;
182179
}
183-
if (supportsClassList) {
184-
element.classList.remove(className);
180+
if (className === "") {
185181
return;
186182
}
187-
element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ").replace(/^\s+/, "").replace(/\s+$/, "");
183+
element.classList.remove(className);
188184
};
189185

190186
var addTempImage = function addTempImage(element) {
@@ -669,7 +665,7 @@ define(function () { 'use strict';
669665
observeElements(observer, elementsToObserve);
670666
};
671667
var setObserver = function setObserver(settings, instance) {
672-
if (!supportsIntersectionObserver || shouldUseNative(settings)) {
668+
if (shouldUseNative(settings)) {
673669
return;
674670
}
675671
instance._observer = new IntersectionObserver(function (entries) {
@@ -733,7 +729,7 @@ define(function () { 'use strict';
733729
var settings = this._settings;
734730
var elementsToLoad = getElementsToLoad(givenNodeset, settings);
735731
setToLoadCount(this, elementsToLoad.length);
736-
if (isBot || !supportsIntersectionObserver) {
732+
if (isBot) {
737733
this.loadAll(elementsToLoad);
738734
return;
739735
}

dist/lazyload.amd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lazyload.esm.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ const isBot =
44
(runningOnBrowser && !("onscroll" in window)) ||
55
(typeof navigator !== "undefined" && /(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent));
66

7-
const supportsIntersectionObserver = runningOnBrowser && "IntersectionObserver" in window;
8-
9-
const supportsClassList = runningOnBrowser && "classList" in document.createElement("p");
10-
117
const isHiDpi = runningOnBrowser && window.devicePixelRatio > 1;
128

139
const defaultSettings = {
@@ -140,25 +136,23 @@ const safeCallback = (callback, arg1, arg2, arg3) => {
140136
};
141137

142138
const addClass = (element, className) => {
143-
if (className === "") {
139+
if (!runningOnBrowser) {
144140
return;
145141
}
146-
if (supportsClassList) {
147-
element.classList.add(className);
142+
if (className === "") {
148143
return;
149144
}
150-
element.className += (element.className ? " " : "") + className;
145+
element.classList.add(className);
151146
};
152147

153148
const removeClass = (element, className) => {
154-
if (className === "") {
149+
if (!runningOnBrowser) {
155150
return;
156151
}
157-
if (supportsClassList) {
158-
element.classList.remove(className);
152+
if (className === "") {
159153
return;
160154
}
161-
element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ").replace(/^\s+/, "").replace(/\s+$/, "");
155+
element.classList.remove(className);
162156
};
163157

164158
const addTempImage = (element) => {
@@ -676,7 +670,7 @@ const updateObserver = (observer, elementsToObserve) => {
676670
};
677671

678672
const setObserver = (settings, instance) => {
679-
if (!supportsIntersectionObserver || shouldUseNative(settings)) {
673+
if (shouldUseNative(settings)) {
680674
return;
681675
}
682676
instance._observer = new IntersectionObserver((entries) => {
@@ -738,7 +732,7 @@ LazyLoad.prototype = {
738732
const elementsToLoad = getElementsToLoad(givenNodeset, settings);
739733
setToLoadCount(this, elementsToLoad.length);
740734

741-
if (isBot || !supportsIntersectionObserver) {
735+
if (isBot) {
742736
this.loadAll(elementsToLoad);
743737
return;
744738
}

0 commit comments

Comments
 (0)