Created
June 6, 2018 09:01
-
-
Save geff21st/d2e5891635131664490d1eadd148c032 to your computer and use it in GitHub Desktop.
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 characters
var cont = document.getElementsByTagName('head')[0]; | |
var jsList = [ | |
{src: '/static/inner/js/libs.js', async: true, defer: true}, | |
{src: '/local/templates/inner/assets-prog/dist/script.min.js', async: true, defer: true}, | |
{ | |
src: 'https://maps.googleapis.com/maps/api/js?libraries=places&key=YOUR_API_KEY', | |
onLoad: function () { | |
setTimeout(function () { | |
$(window).trigger('google:map:ready'); | |
}, 500); | |
} | |
}, | |
'https://apis.google.com/js/client.js?onload=initPicker', | |
{ | |
src: 'https://www.dropbox.com/static/api/2/dropins.js', | |
attributes: {'id': 'dropboxjs', 'data-app-key': 'YOUR_APP_KEY'} | |
} | |
]; | |
function loadScript(i) { | |
i = i || 0; | |
var js = document.createElement('script'); | |
if (typeof jsList[i] === 'object') { | |
js.src = jsList[i].src; | |
js.async = jsList[i].async || false; | |
js.defer = jsList[i].defer || false; | |
if (typeof jsList[i].attributes === 'object') { | |
for (var attr in jsList[i].attributes) { | |
if (jsList[i].attributes.hasOwnProperty(attr)) { | |
js.setAttribute(attr, jsList[i].attributes[attr]); | |
} | |
} | |
} | |
} else if (typeof jsList[i] === 'string') { | |
js.src = jsList[i]; | |
} else { | |
return null; | |
} | |
cont.appendChild(js); | |
js.onload = function () { | |
loadScript(i + 1); | |
if (typeof jsList[i].onLoad === 'function') { | |
jsList[i].onLoad(); | |
} | |
}; | |
} | |
loadScript(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment