Socket
Socket
Sign inDemoInstall

loadjs

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadjs - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

2

bower.json
{
"name": "loadjs",
"version": "3.0.0",
"version": "3.0.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "authors": [

# LoadJS Changelog
## 3.0.1 - December 9, 2016
* Added numTries option
## 3.0.0 - August 25, 2016

@@ -4,0 +8,0 @@

@@ -83,7 +83,11 @@ loadjs = (function () {

*/
function loadFile(path, callbackFn, async) {
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
maxTries = args.numTries || 1,
isCss,
e;
numTries = numTries || 0;
if (/\.css$/.test(path)) {

@@ -118,2 +122,13 @@ isCss = true;

// handle retries in case of load failure
if (result == 'e') {
// increment counter
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
}
// execute callback

@@ -133,3 +148,3 @@ callbackFn(path, result, ev.defaultPrevented);

*/
function loadFiles(paths, callbackFn, async) {
function loadFiles(paths, callbackFn, args) {
// listify paths

@@ -157,3 +172,3 @@ paths = paths.push ? paths : [paths];

// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, async);
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}

@@ -195,3 +210,3 @@

publish(bundleId, pathsNotFound);
}, args.async);
}, args);
}

@@ -198,0 +213,0 @@

@@ -1,1 +0,1 @@

loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,c,i=[],s=n.length,h=s;for(t=function(n,t){t.length&&i.push(n),h--,h||e(i)};s--;)r=n[s],o=u[r],o?t(r,o):(c=f[r]=f[r]||[],c.push(t))}function e(n,e){if(n){var t=f[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,t){var r,o,c=document;/\.css$/.test(n)?(r=!0,o=c.createElement("link"),o.rel="stylesheet",o.href=n):(o=c.createElement("script"),o.src=n,o.async=void 0===t||t),o.onload=o.onerror=o.onbeforeload=function(t){var c=t.type[0];if(r&&"hideFocus"in o)try{o.sheet.cssText.length||(c="e")}catch(n){c="e"}e(n,c,t.defaultPrevented)},c.head.appendChild(o)}function r(n,e,r){n=n.push?n:[n];var o,c,i=n.length,u=i,f=[];for(o=function(n,t,r){if("e"==t&&f.push(n),"b"==t){if(!r)return;f.push(n)}i--,i||e(f)},c=0;c<u;c++)t(n[c],o,r)}function o(n,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in i)throw new Error("LoadJS");i[u]=!0}r(n,function(n){n.length?(f.error||c)(n):(f.success||c)(),e(u,n)},f.async)}var c=function(){},i={},u={},f={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||c)(n):(t.success||c)()}),o},o.done=function(n){e(n,[])},o}();
loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,i,c=[],f=n.length,h=f;for(t=function(n,t){t.length&&c.push(n),h--,h||e(c)};f--;)r=n[f],o=u[r],o?t(r,o):(i=s[r]=s[r]||[],i.push(t))}function e(n,e){if(n){var t=s[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,r,o){var i,c,u=document,s=r.async,f=r.numTries||1;o=o||0,/\.css$/.test(n)?(i=!0,c=u.createElement("link"),c.rel="stylesheet",c.href=n):(c=u.createElement("script"),c.src=n,c.async=void 0===s||s),c.onload=c.onerror=c.onbeforeload=function(u){var s=u.type[0];if(i&&"hideFocus"in c)try{c.sheet.cssText.length||(s="e")}catch(n){s="e"}return"e"==s&&(o+=1,o<f)?t(n,e,r,o):void e(n,s,u.defaultPrevented)},u.head.appendChild(c)}function r(n,e,r){n=n.push?n:[n];var o,i,c=n.length,u=c,s=[];for(o=function(n,t,r){if("e"==t&&s.push(n),"b"==t){if(!r)return;s.push(n)}c--,c||e(s)},i=0;i<u;i++)t(n[i],o,r)}function o(n,t,o){var u,s;if(t&&t.trim&&(u=t),s=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(n,function(n){n.length?(s.error||i)(n):(s.success||i)(),e(u,n)},s)}var i=function(){},c={},u={},s={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||i)(n):(t.success||i)()}),o},o.done=function(n){e(n,[])},o}();

@@ -91,7 +91,11 @@ (function(root, factory) {

*/
function loadFile(path, callbackFn, async) {
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
maxTries = args.numTries || 1,
isCss,
e;
numTries = numTries || 0;
if (/\.css$/.test(path)) {

@@ -126,2 +130,13 @@ isCss = true;

// handle retries in case of load failure
if (result == 'e') {
// increment counter
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
}
// execute callback

@@ -141,3 +156,3 @@ callbackFn(path, result, ev.defaultPrevented);

*/
function loadFiles(paths, callbackFn, async) {
function loadFiles(paths, callbackFn, args) {
// listify paths

@@ -165,3 +180,3 @@ paths = paths.push ? paths : [paths];

// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, async);
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}

@@ -203,3 +218,3 @@

publish(bundleId, pathsNotFound);
}, args.async);
}, args);
}

@@ -206,0 +221,0 @@

@@ -83,7 +83,11 @@ loadjs = (function () {

*/
function loadFile(path, callbackFn, async) {
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
maxTries = args.numTries || 1,
isCss,
e;
numTries = numTries || 0;
if (/\.css$/.test(path)) {

@@ -118,2 +122,13 @@ isCss = true;

// handle retries in case of load failure
if (result == 'e') {
// increment counter
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
}
// execute callback

@@ -133,3 +148,3 @@ callbackFn(path, result, ev.defaultPrevented);

*/
function loadFiles(paths, callbackFn, async) {
function loadFiles(paths, callbackFn, args) {
// listify paths

@@ -157,3 +172,3 @@ paths = paths.push ? paths : [paths];

// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, async);
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}

@@ -195,3 +210,3 @@

publish(bundleId, pathsNotFound);
}, args.async);
}, args);
}

@@ -198,0 +213,0 @@

@@ -1,1 +0,1 @@

loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,c,i=[],s=n.length,h=s;for(t=function(n,t){t.length&&i.push(n),h--,h||e(i)};s--;)r=n[s],o=u[r],o?t(r,o):(c=f[r]=f[r]||[],c.push(t))}function e(n,e){if(n){var t=f[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,t){var r,o,c=document;/\.css$/.test(n)?(r=!0,o=c.createElement("link"),o.rel="stylesheet",o.href=n):(o=c.createElement("script"),o.src=n,o.async=void 0===t||t),o.onload=o.onerror=o.onbeforeload=function(t){var c=t.type[0];if(r&&"hideFocus"in o)try{o.sheet.cssText.length||(c="e")}catch(n){c="e"}e(n,c,t.defaultPrevented)},c.head.appendChild(o)}function r(n,e,r){n=n.push?n:[n];var o,c,i=n.length,u=i,f=[];for(o=function(n,t,r){if("e"==t&&f.push(n),"b"==t){if(!r)return;f.push(n)}i--,i||e(f)},c=0;c<u;c++)t(n[c],o,r)}function o(n,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in i)throw new Error("LoadJS");i[u]=!0}r(n,function(n){n.length?(f.error||c)(n):(f.success||c)(),e(u,n)},f.async)}var c=function(){},i={},u={},f={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||c)(n):(t.success||c)()}),o},o.done=function(n){e(n,[])},o}();
loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,i,c=[],f=n.length,h=f;for(t=function(n,t){t.length&&c.push(n),h--,h||e(c)};f--;)r=n[f],o=u[r],o?t(r,o):(i=s[r]=s[r]||[],i.push(t))}function e(n,e){if(n){var t=s[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,r,o){var i,c,u=document,s=r.async,f=r.numTries||1;o=o||0,/\.css$/.test(n)?(i=!0,c=u.createElement("link"),c.rel="stylesheet",c.href=n):(c=u.createElement("script"),c.src=n,c.async=void 0===s||s),c.onload=c.onerror=c.onbeforeload=function(u){var s=u.type[0];if(i&&"hideFocus"in c)try{c.sheet.cssText.length||(s="e")}catch(n){s="e"}return"e"==s&&(o+=1,o<f)?t(n,e,r,o):void e(n,s,u.defaultPrevented)},u.head.appendChild(c)}function r(n,e,r){n=n.push?n:[n];var o,i,c=n.length,u=c,s=[];for(o=function(n,t,r){if("e"==t&&s.push(n),"b"==t){if(!r)return;s.push(n)}c--,c||e(s)},i=0;i<u;i++)t(n[i],o,r)}function o(n,t,o){var u,s;if(t&&t.trim&&(u=t),s=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(n,function(n){n.length?(s.error||i)(n):(s.success||i)(),e(u,n)},s)}var i=function(){},c={},u={},s={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||i)(n):(t.success||i)()}),o},o.done=function(n){e(n,[])},o}();
{
"name": "loadjs",
"version": "3.0.0",
"version": "3.0.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Tiny async loader for modern browsers",

@@ -36,3 +36,3 @@ # LoadJS

```bash
$ npm install --save-dev loadjs
$ npm install --save loadjs
```

@@ -120,2 +120,12 @@

1. Try loading the files multiple times before calling the error callback
```javascript
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {
success: function() { /* foo.js & bar.js loaded */ },
error: function(pathsNotFound) { /* at least one path didn't load */ },
numTries: 3
});
```
1. Execute a callback after bundle finishes loading

@@ -122,0 +132,0 @@

@@ -82,7 +82,11 @@ /**

*/
function loadFile(path, callbackFn, async) {
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
maxTries = args.numTries || 1,
isCss,
e;
numTries = numTries || 0;
if (/\.css$/.test(path)) {

@@ -117,2 +121,13 @@ isCss = true;

// handle retries in case of load failure
if (result == 'e') {
// increment counter
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
}
// execute callback

@@ -132,3 +147,3 @@ callbackFn(path, result, ev.defaultPrevented);

*/
function loadFiles(paths, callbackFn, async) {
function loadFiles(paths, callbackFn, args) {
// listify paths

@@ -156,3 +171,3 @@ paths = paths.push ? paths : [paths];

// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, async);
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}

@@ -194,3 +209,3 @@

publish(bundleId, pathsNotFound);
}, args.async);
}, args);
}

@@ -197,0 +212,0 @@

@@ -83,7 +83,11 @@ loadjs = (function () {

*/
function loadFile(path, callbackFn, async) {
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
maxTries = args.numTries || 1,
isCss,
e;
numTries = numTries || 0;
if (/\.css$/.test(path)) {

@@ -118,2 +122,13 @@ isCss = true;

// handle retries in case of load failure
if (result == 'e') {
// increment counter
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
}
// execute callback

@@ -133,3 +148,3 @@ callbackFn(path, result, ev.defaultPrevented);

*/
function loadFiles(paths, callbackFn, async) {
function loadFiles(paths, callbackFn, args) {
// listify paths

@@ -157,3 +172,3 @@ paths = paths.push ? paths : [paths];

// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, async);
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}

@@ -195,3 +210,3 @@

publish(bundleId, pathsNotFound);
}, args.async);
}, args);
}

@@ -198,0 +213,0 @@

@@ -1,1 +0,1 @@

loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,c,i=[],s=n.length,h=s;for(t=function(n,t){t.length&&i.push(n),h--,h||e(i)};s--;)r=n[s],o=u[r],o?t(r,o):(c=f[r]=f[r]||[],c.push(t))}function e(n,e){if(n){var t=f[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,t){var r,o,c=document;/\.css$/.test(n)?(r=!0,o=c.createElement("link"),o.rel="stylesheet",o.href=n):(o=c.createElement("script"),o.src=n,o.async=void 0===t||t),o.onload=o.onerror=o.onbeforeload=function(t){var c=t.type[0];if(r&&"hideFocus"in o)try{o.sheet.cssText.length||(c="e")}catch(n){c="e"}e(n,c,t.defaultPrevented)},c.head.appendChild(o)}function r(n,e,r){n=n.push?n:[n];var o,c,i=n.length,u=i,f=[];for(o=function(n,t,r){if("e"==t&&f.push(n),"b"==t){if(!r)return;f.push(n)}i--,i||e(f)},c=0;c<u;c++)t(n[c],o,r)}function o(n,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in i)throw new Error("LoadJS");i[u]=!0}r(n,function(n){n.length?(f.error||c)(n):(f.success||c)(),e(u,n)},f.async)}var c=function(){},i={},u={},f={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||c)(n):(t.success||c)()}),o},o.done=function(n){e(n,[])},o}();
loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,i,c=[],f=n.length,h=f;for(t=function(n,t){t.length&&c.push(n),h--,h||e(c)};f--;)r=n[f],o=u[r],o?t(r,o):(i=s[r]=s[r]||[],i.push(t))}function e(n,e){if(n){var t=s[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,r,o){var i,c,u=document,s=r.async,f=r.numTries||1;o=o||0,/\.css$/.test(n)?(i=!0,c=u.createElement("link"),c.rel="stylesheet",c.href=n):(c=u.createElement("script"),c.src=n,c.async=void 0===s||s),c.onload=c.onerror=c.onbeforeload=function(u){var s=u.type[0];if(i&&"hideFocus"in c)try{c.sheet.cssText.length||(s="e")}catch(n){s="e"}return"e"==s&&(o+=1,o<f)?t(n,e,r,o):void e(n,s,u.defaultPrevented)},u.head.appendChild(c)}function r(n,e,r){n=n.push?n:[n];var o,i,c=n.length,u=c,s=[];for(o=function(n,t,r){if("e"==t&&s.push(n),"b"==t){if(!r)return;s.push(n)}c--,c||e(s)},i=0;i<u;i++)t(n[i],o,r)}function o(n,t,o){var u,s;if(t&&t.trim&&(u=t),s=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(n,function(n){n.length?(s.error||i)(n):(s.success||i)(),e(u,n)},s)}var i=function(){},c={},u={},s={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||i)(n):(t.success||i)()}),o},o.done=function(n){e(n,[])},o}();

@@ -37,3 +37,3 @@ /**

it('should call error callback on invalid path', function(done) {

@@ -124,2 +124,17 @@ loadjs(['assets/file-doesntexist.js'], {

it('should support multiple tries', function(done) {
var numTries = 0;
loadjs('assets/file-doesntexist-numtries.js', {
error: function() {
// check number of scripts in document
var selector = 'script[src="assets/file-doesntexist-numtries.js"]',
scripts = document.querySelectorAll(selector);
if (scripts.length === 2) done();
},
numTries: 2
});
});
// Un-'x' this for testing ad blocked scripts.

@@ -126,0 +141,0 @@ // Ghostery: Disallow "Google Adservices"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc