Created
April 6, 2020 03:22
-
-
Save marazmiki/423c39e03e427ceb6d27eb286ee5f83c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Loader = { | |
require (scripts, callback) { | |
this.loadCount = 0; | |
this.callback = callback; | |
this.totalRequired = scripts.length; | |
scripts.forEach((src) => { | |
this.writeScript(src) | |
}); | |
}, | |
loaded (evt) { | |
this.loadCount++; | |
if (this.loadCount === this.totalRequired && typeof this.callback == 'function') { | |
this.callback.call(); | |
} | |
}, | |
writeScript (src) { | |
const s = document.createElement('script'); | |
s.src = src; | |
s.addEventListener('load', (e) => { | |
this.loaded(e); | |
}, false); | |
document.querySelector('HEAD').appendChild(s); | |
} | |
}; | |
Loader.require([ | |
'{% static "admin/js/jquery.min.js" %}', | |
'{% static "admin/js/jquery.init.js" %}', | |
], () => { | |
console.log('ok, loaded jquery from admin'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment