Last active
October 9, 2020 08:55
-
-
Save fravelgue/e6e72557c1940895cb59c6a3c2b06a1f to your computer and use it in GitHub Desktop.
Include javascript (jquery) in Shopify
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
<!DOCTYPE html> | |
<!-- | |
https://shopify.dev/tutorials/include-javascript-in-shopify-themes | |
--> | |
<html> | |
<head> | |
<script> | |
var loadScript = function (url, callback) { | |
/* JavaScript that will load the jQuery library on Google's CDN. | |
We recommend this code: http://snipplr.com/view/18756/loadscript/. | |
Once the jQuery library is loaded, the function passed as argument, | |
callback, will be executed. */ | |
/* https://web.archive.org/web/20180515114829/http://snipplr.com/view/18756/loadscript */ | |
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); | |
}; | |
var myAppJavaScript = function ($) { | |
/* Your app's JavaScript here. | |
$ in this scope references the jQuery object we'll use. | |
Don't use 'jQuery', or 'jQuery191', here. Use the dollar sign | |
that was passed as argument.*/ | |
console.log('Your app is using jQuery version ' + $.fn.jquery + '.'); | |
$(document).ready(function () { | |
}); | |
}; | |
if ((typeof jQuery === 'undefined') || (parseFloat(jQuery.fn.jquery) < 1.7)) { | |
loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', function () { | |
jQuery191 = jQuery.noConflict(true); | |
myAppJavaScript(jQuery191); | |
}); | |
} else { | |
myAppJavaScript(jQuery); | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment