Created
November 4, 2012 23:56
-
-
Save BlakeMesdag/4014436 to your computer and use it in GitHub Desktop.
Script to Inject a jQuery loader using ScriptTags for Shopify
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
(function () { | |
function loadScript(url, callback) { | |
var script = document.createElement("script") | |
script.type = "text/javascript"; | |
if (script.readyState) { //IE | |
script.onreadystatechange = function () { | |
if (script.readyState == "loaded" || script.readyState == "complete") { | |
script.onreadystatechange = null; | |
callback(); | |
} | |
}; | |
} else { //Others | |
script.onload = function () { | |
callback(); | |
}; | |
} | |
script.src = url; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
if(typeof jQuery == undefined || typeof jQuery == "undefined"){ | |
loadScript("//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js", function () { | |
jQuery.noConflict(); | |
console.log('jquery loaded'); | |
//Code to run after jQuery is loaded | |
}); | |
} else { | |
//Code to run after jQuery is loaded | |
} | |
})(); |
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
(function(){ | |
var dynamic_loader_tag = document.createElement("script"); | |
dynamic_loader_tag.src = "/path/to/jquery-loader.js"; | |
dynamic_loader_tag.type = "text/javascript"; | |
dynamic_loader_tag.async = true; | |
document.getElementsByTagName('body')[0].appendChild(dynamic_loader_tag); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment