Skip to content

Commit bcd37e6

Browse files
authored
Formatting fixes
1 parent 30b4573 commit bcd37e6

File tree

1 file changed

+51
-70
lines changed

1 file changed

+51
-70
lines changed

dynamicpolyfill.js

Lines changed: 51 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@ function dynamicPolyfill(tocheck, scriptToPolyfill, functionToRunonLoad) {
22
var checkPromises = [];
33
if(Array.isArray(tocheck)) {
44
tocheck.forEach(
5-
function(tocheck) {
6-
checkPromises.push(checking(tocheck))
7-
}
8-
)
5+
function(tocheck) {
6+
checkPromises.push(checking(tocheck))
7+
}
8+
)
99
} else {
1010
checkPromises.push(checking(tocheck))
1111
}
12-
Promise.all(checkPromises)
13-
.then(
14-
function() {
15-
loadMyScript(scriptToPolyfill, functionToRunonLoad)
16-
}
17-
)
18-
.catch(
19-
function(error) {
20-
return error
21-
}
22-
)
12+
Promise.all(checkPromises).then(
13+
function() {
14+
loadMyScript(scriptToPolyfill, functionToRunonLoad)
15+
}
16+
).catch(function(error){return error})
2317
}
2418

2519
function checking(check) {
@@ -34,88 +28,75 @@ function checking(check) {
3428

3529
function loadPolyfill(url) {
3630
return new Promise(
37-
function(resolve, reject) {
38-
var polyfill = document.createElement('script');
39-
polyfill.src = ('https://polyfill.io/v3/polyfill.min.js?features=' + encodeURIComponent(url));
40-
document.body.appendChild(polyfill);
41-
polyfill.onerror = function(response) {
42-
return reject("Loading the polyfill(s) failed!", response)
43-
}
44-
polyfill.onload = function() {
45-
return resolve
46-
}
47-
}
48-
)
31+
function(resolve, reject) {
32+
var polyfill = document.createElement('script');
33+
polyfill.src = ('https://polyfill.io/v3/polyfill.min.js?features=' + encodeURIComponent(url));
34+
document.body.appendChild(polyfill);
35+
polyfill.onerror = function(response) {
36+
return reject("Loading the polyfill(s) failed!", response)
37+
}
38+
polyfill.onload = function() {
39+
return resolve
40+
}
41+
}
42+
)
4943
}
5044

5145
function loadMyScript(url, functionToRunonLoad) {
5246
if(Array.isArray(url)) {
5347
var promises = [];
5448
url.forEach(
55-
function(url) {
49+
function(url) {
5650
promises.push(nonblankURL(url))
5751
}
58-
);
59-
Promise.all(promises)
60-
.then(
61-
function() {
62-
initialiseMyScript(functionToRunonLoad)
63-
}
64-
)
65-
.catch(
66-
function(error) {
67-
return error
68-
}
69-
)
70-
}
71-
else if (!Array.isArray(url) && url !== null && url !== '') {
72-
nonblankURL(url)
73-
.then(
74-
function() {
75-
initialiseMyScript(functionToRunonLoad)
76-
}
77-
)
78-
.catch(
79-
function(error) {
80-
return error
81-
}
82-
)
52+
);
53+
Promise.all(promises).then(
54+
function() {
55+
initialiseMyScript(functionToRunonLoad)
56+
}
57+
).catch(function(error){return error})
58+
} else if (!Array.isArray(url) && url !== null && url !== '') {
59+
nonblankURL(url).then(
60+
function() {
61+
initialiseMyScript(functionToRunonLoad)
62+
}
63+
).catch(function(error){return error})
8364
} else {
8465
initialiseMyScript(functionToRunonLoad)
8566
}
8667
}
8768

8869
function nonblankURL(uri) {
8970
return new Promise(
90-
function(resolve, reject) {
91-
var thescript = document.createElement('script');
92-
thescript.src = encodeURI(uri);
93-
document.body.appendChild(thescript);
94-
thescript.onerror = function(response) {
95-
return reject("Loading the script failed!", response)
96-
}
97-
thescript.onload = function() {
98-
return resolve(uri)
99-
}
100-
}
101-
)
71+
function(resolve, reject) {
72+
var thescript = document.createElement('script');
73+
thescript.src = encodeURI(uri);
74+
document.body.appendChild(thescript);
75+
thescript.onerror = function(response) {
76+
return reject("Loading the script failed!", response)
77+
}
78+
thescript.onload = function() {
79+
return resolve(uri)
80+
}
81+
}
82+
)
10283
}
10384

10485
function initialiseMyScript(functionToRunonLoad) {
10586
if(Array.isArray(functionToRunonLoad)) {
10687
functionToRunonLoad.forEach(
107-
function(functionToRunonLoad) {
108-
initScript(functionToRunonLoad)
109-
}
110-
)
88+
function(functionToRunonLoad) {
89+
initScript(functionToRunonLoad)
90+
}
91+
)
11192
} else {
11293
initScript(functionToRunonLoad)
11394
}
11495
function initScript(fn) {
11596
try {
11697
window[fn]
11798
}
118-
catch (err) {
99+
catch(err) {
119100
console.error('There was an error: ', err, err.name, err.stack)
120101
}
121102
}

0 commit comments

Comments
 (0)