Created
April 6, 2020 03:22
-
-
Save marazmiki/423c39e03e427ceb6d27eb286ee5f83c to your computer and use it in GitHub Desktop.
Revisions
-
marazmiki created this gist
Apr 6, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ 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'); })