Skip to content

Commit 19a72be

Browse files
committed
refactor(code-formatting): run xo --fix
1 parent cf8b827 commit 19a72be

9 files changed

+48
-50
lines changed

demo/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import loadingAttributePolyfill from '../dist/loading-attribute-polyfill.module.js';
22

33
// Test for dynamically inserted images
4-
let addImage = (event) => {
5-
let divElement = document.createElement('div'),
6-
noscriptElement = document.createElement('noscript'),
7-
imageElement = document.createElement('img');
4+
const addImage = (event) => {
5+
const divElement = document.createElement('div');
6+
const noscriptElement = document.createElement('noscript');
7+
const imageElement = document.createElement('img');
88

99
noscriptElement.classList.add('loading-lazy');
1010

@@ -14,9 +14,9 @@ let addImage = (event) => {
1414
imageElement.setAttribute('width', '250');
1515
imageElement.setAttribute('height', '150');
1616

17-
noscriptElement.appendChild(imageElement);
17+
noscriptElement.append(imageElement);
1818

19-
divElement.appendChild(noscriptElement);
19+
divElement.append(noscriptElement);
2020

2121
document.querySelector('main').insertAdjacentElement('beforeend', divElement);
2222

dist/loading-attribute-polyfill.js.map

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/loading-attribute-polyfill.modern.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/loading-attribute-polyfill.modern.js.map

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/loading-attribute-polyfill.module.js.map

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/loading-attribute-polyfill.umd.js.map

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

src/loading-attribute-polyfill.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
* Use an IntersectionObserver polyfill in case of IE11 support necessary.
1111
*/
1212

13-
'use strict';
14-
1513
import './loading-attribute-polyfill.css';
1614

17-
var config = {
15+
const config = {
1816
intersectionObserver: {
1917
// Start download if the item gets within 256px in the Y axis
2018
rootMargin: '0px 0px 256px 0px',
@@ -25,7 +23,7 @@ var config = {
2523
};
2624

2725
// Device/browser capabilities object
28-
var capabilities = {
26+
const capabilities = {
2927
loading: {
3028
image: 'loading' in HTMLImageElement.prototype,
3129
iframe: 'loading' in HTMLIFrameElement.prototype,
@@ -39,7 +37,7 @@ if (window.NodeList && !NodeList.prototype.forEach) {
3937
}
4038

4139
// Define according to browsers support of the IntersectionObserver feature (missing e.g. on IE11 or Safari 11)
42-
var intersectionObserver;
40+
let intersectionObserver;
4341

4442
if ('IntersectionObserver' in window) {
4543
intersectionObserver = new IntersectionObserver(
@@ -53,7 +51,7 @@ if ('IntersectionObserver' in window) {
5351
* @param {Object} lazyItem Current item to be restored after lazy loading.
5452
*/
5553
function restoreSource(lazyItem) {
56-
var srcsetItems = [];
54+
let srcsetItems = [];
5755

5856
// Just in case the img is the decendent of a picture element, check for source tags
5957
if (lazyItem.parentNode.tagName.toLowerCase() === 'picture') {
@@ -67,7 +65,7 @@ function restoreSource(lazyItem) {
6765
srcsetItems.push(lazyItem);
6866

6967
// Not using .dataset within those upfollowing lines of code for polyfill independent compatibility down to IE9
70-
srcsetItems.forEach(function (item) {
68+
srcsetItems.forEach((item) => {
7169
if (item.hasAttribute('data-lazy-srcset')) {
7270
item.setAttribute('srcset', item.getAttribute('data-lazy-srcset'));
7371
item.removeAttribute('data-lazy-srcset'); // Not using delete .dataset here for compatibility down to IE9
@@ -83,7 +81,7 @@ function restoreSource(lazyItem) {
8381
* @param {Object} lazyItemPicture Current <picture> item to be restored after lazy loading.
8482
*/
8583
function removePlaceholderSource(lazyItemPicture) {
86-
var placeholderSource = lazyItemPicture.querySelector(
84+
const placeholderSource = lazyItemPicture.querySelector(
8785
'source[data-lazy-remove]'
8886
);
8987

@@ -99,14 +97,14 @@ function removePlaceholderSource(lazyItemPicture) {
9997
* @param {Object} observer IntersectionObserver instance reference
10098
*/
10199
function onIntersection(entries, observer) {
102-
entries.forEach(function (entry) {
100+
entries.forEach((entry) => {
103101
// Mitigation for EDGE lacking support of .isIntersecting until v15, compare to e.g. https://github.com/w3c/IntersectionObserver/issues/211#issuecomment-309144669
104102
if (entry.intersectionRatio === 0) {
105103
return;
106104
}
107105

108106
// If the item is visible now, load it and stop watching it
109-
var lazyItem = entry.target;
107+
const lazyItem = entry.target;
110108

111109
observer.unobserve(lazyItem);
112110

@@ -122,9 +120,9 @@ function onPrinting() {
122120
return;
123121
}
124122

125-
var mediaQueryList = window.matchMedia('print');
123+
const mediaQueryList = window.matchMedia('print');
126124

127-
mediaQueryList.addListener(function (mql) {
125+
mediaQueryList.addListener((mql) => {
128126
if (mql.matches) {
129127
document
130128
.querySelectorAll(
@@ -133,7 +131,7 @@ function onPrinting() {
133131
config.lazyIframe +
134132
'[data-lazy-src]'
135133
)
136-
.forEach(function (lazyItem) {
134+
.forEach((lazyItem) => {
137135
restoreSource(lazyItem);
138136
});
139137
}
@@ -147,14 +145,14 @@ function onPrinting() {
147145
*/
148146
function getAndPrepareHTMLCode(noScriptTag) {
149147
// The contents of a <noscript> tag are treated as text to JavaScript
150-
var lazyAreaHtml = noScriptTag.textContent || noScriptTag.innerHTML;
148+
let lazyAreaHtml = noScriptTag.textContent || noScriptTag.innerHTML;
151149

152-
var getImageWidth = lazyAreaHtml.match(/width=['"](\d+)['"]/) || false;
153-
var temporaryImageWidth = getImageWidth[1] || 1;
154-
var getImageHeight = lazyAreaHtml.match(/height=['"](\d+)['"]/) || false;
155-
var temporaryImageHeight = getImageHeight[1] || 1;
150+
const getImageWidth = lazyAreaHtml.match(/width=['"](\d+)['"]/) || false;
151+
const temporaryImageWidth = getImageWidth[1] || 1;
152+
const getImageHeight = lazyAreaHtml.match(/height=['"](\d+)['"]/) || false;
153+
const temporaryImageHeight = getImageHeight[1] || 1;
156154

157-
var temporaryImage =
155+
const temporaryImage =
158156
'data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 ' +
159157
temporaryImageWidth +
160158
' ' +
@@ -202,13 +200,13 @@ function getAndPrepareHTMLCode(noScriptTag) {
202200
*/
203201
function prepareElement(noScriptTag) {
204202
// Sticking the noscript HTML code in the innerHTML of a new <div> tag to 'load' it after creating that <div>
205-
var lazyArea = document.createElement('div');
203+
const lazyArea = document.createElement('div');
206204

207205
lazyArea.innerHTML = getAndPrepareHTMLCode(noScriptTag);
208206

209207
// Move all children out of the element
210208
while (lazyArea.firstChild) {
211-
var actualChild = lazyArea.firstChild;
209+
const actualChild = lazyArea.firstChild;
212210

213211
if (
214212
capabilities.scrolling &&
@@ -220,7 +218,7 @@ function prepareElement(noScriptTag) {
220218
(actualChild.tagName.toLowerCase() === 'iframe' &&
221219
!capabilities.loading.iframe))
222220
) {
223-
var observedElement =
221+
const observedElement =
224222
actualChild.tagName.toLowerCase() === 'picture'
225223
? lazyArea.querySelector('img')
226224
: actualChild;
@@ -238,8 +236,8 @@ function prepareElement(noScriptTag) {
238236
/**
239237
* Get all the <noscript> tags on the page, prepare each and any one of them and setup the printing
240238
*/
241-
let prepareElements = () => {
242-
var lazyLoadAreas = document.querySelectorAll('noscript.loading-lazy');
239+
const prepareElements = () => {
240+
const lazyLoadAreas = document.querySelectorAll('noscript.loading-lazy');
243241

244242
lazyLoadAreas.forEach((element) => prepareElement(element));
245243

@@ -252,19 +250,19 @@ let prepareElements = () => {
252250
if (/comp|inter/.test(document.readyState)) {
253251
prepareElements();
254252
} else if ('addEventListener' in document) {
255-
document.addEventListener('DOMContentLoaded', function () {
253+
document.addEventListener('DOMContentLoaded', () => {
256254
prepareElements();
257255
});
258256
} else {
259-
document.attachEvent('onreadystatechange', function () {
257+
document.attachEvent('onreadystatechange', () => {
260258
if (document.readyState === 'complete') {
261259
prepareElements();
262260
}
263261
});
264262
}
265263

266264
const loadingAttributePolyfill = {
267-
prepareElement: prepareElement,
265+
prepareElement,
268266
};
269267

270268
export default loadingAttributePolyfill;

webdriverio-tests/basic.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('demo page - img', () => {
1313
element.waitForExist();
1414

1515
assert.strictEqual(
16-
element.getAttribute('src').substr(0, 8),
16+
element.getAttribute('src').slice(0, 8),
1717
// Differentiate by feature detection / the loading capability in between the two different expected values
1818
element.getProperty('loading') ? 'https://' : 'data:ima'
1919
);
@@ -26,7 +26,7 @@ describe('demo page - img', () => {
2626
// Let's use .getProperty('currentSrc') as soon as this feature is implemented
2727
assert.strictEqual(
2828
// We'd like to use the currentSrc property preferably, as it shows the correct image source usage
29-
(element.getProperty('currentSrc') || element.getAttribute('src')).substr(
29+
(element.getProperty('currentSrc') || element.getAttribute('src')).slice(
3030
0,
3131
8
3232
),
@@ -42,7 +42,7 @@ describe('demo page - img', () => {
4242
// Let's use .getProperty('currentSrc') as soon as this feature is implemented
4343
assert.strictEqual(
4444
// We'd like to use the currentSrc property preferably, as it shows the correct image source usage
45-
(element.getProperty('currentSrc') || element.getAttribute('src')).substr(
45+
(element.getProperty('currentSrc') || element.getAttribute('src')).slice(
4646
0,
4747
8
4848
),
@@ -61,7 +61,7 @@ describe('demo page - iframe', () => {
6161
element.waitForExist();
6262

6363
assert.strictEqual(
64-
element.getAttribute('src').substr(0, 8),
64+
element.getAttribute('src').slice(0, 8),
6565
// Differentiate by feature detection / the loading capability in between the two different expected values
6666
element.getProperty('loading') ? 'https://' : 'data:ima'
6767
);
@@ -80,7 +80,7 @@ describe('demo page - scrolled - img', () => {
8080

8181
element.scrollIntoView();
8282

83-
assert.strictEqual(element.getAttribute('src').substr(0, 8), 'https://');
83+
assert.strictEqual(element.getAttribute('src').slice(0, 8), 'https://');
8484
});
8585
it('should be loaded if scrolled below the fold (nested in picture)', () => {
8686
const element = $('main picture img[loading="lazy"]');
@@ -92,7 +92,7 @@ describe('demo page - scrolled - img', () => {
9292
// Let's use .getProperty('currentSrc') as soon as this feature is implemented
9393
assert.strictEqual(
9494
// We'd like to use the currentSrc property preferably, as it shows the correct image source usage
95-
(element.getProperty('currentSrc') || element.getAttribute('src')).substr(
95+
(element.getProperty('currentSrc') || element.getAttribute('src')).slice(
9696
0,
9797
8
9898
),
@@ -109,7 +109,7 @@ describe('demo page - scrolled - img', () => {
109109
// Let's use .getProperty('currentSrc') as soon as this feature is implemented
110110
assert.strictEqual(
111111
// We'd like to use the currentSrc property preferably, as it shows the correct image source usage
112-
(element.getProperty('currentSrc') || element.getAttribute('src')).substr(
112+
(element.getProperty('currentSrc') || element.getAttribute('src')).slice(
113113
0,
114114
8
115115
),
@@ -127,6 +127,6 @@ describe('demo page - scrolled - iframe', () => {
127127

128128
element.scrollIntoView();
129129

130-
assert.strictEqual(element.getAttribute('src').substr(0, 8), 'https://');
130+
assert.strictEqual(element.getAttribute('src').slice(0, 8), 'https://');
131131
});
132132
});

webdriverio-tests/wdio.conf-crossbrowsertesting.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ exports.config = {
205205
baseUrl: 'https://mfranzke.github.io/loading-attribute-polyfill/demo/',
206206
//
207207
// Default timeout for all waitFor* commands.
208-
waitforTimeout: 10000,
208+
waitforTimeout: 10_000,
209209
//
210210
// Default timeout in milliseconds for request
211211
// if Selenium Grid doesn't send response
212-
connectionRetryTimeout: 90000,
212+
connectionRetryTimeout: 90_000,
213213
//
214214
// Default request retries count
215215
connectionRetryCount: 3,
@@ -240,7 +240,7 @@ exports.config = {
240240
// See the full list at http://mochajs.org/
241241
mochaOpts: {
242242
ui: 'bdd',
243-
timeout: 60000,
243+
timeout: 60_000,
244244
},
245245
//
246246
// =====
@@ -361,5 +361,5 @@ exports.config = {
361361
*/
362362
// onReload: function(oldSessionId, newSessionId) {
363363
// }
364-
cbtTunnel: false, //set to true if a local connection is needed
364+
cbtTunnel: false, // Set to true if a local connection is needed
365365
};

0 commit comments

Comments
 (0)