Created
December 22, 2012 23:25
-
-
Save anonymous/4361800 to your computer and use it in GitHub Desktop.
Coffeescript version of the JS from this answers on stackoverflow: http://stackoverflow.com/a/2174733/76486 It helps you use jquery in an embedded widget without conflicting with other javascript on the page
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
main = (window, document, version, callback) -> | |
[j, d, loaded] = [null, null, false] | |
if !(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded) | |
script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"; | |
script.onload = script.onreadystatechange = () -> | |
if !loaded && (!(d = this.readyState) || d == "loaded" || d == "complete") | |
callback((j = window.jQuery).noConflict(1), loaded = true) | |
j(script).remove(); | |
document.documentElement.childNodes[0].appendChild(script) | |
main window, document, "1.7", ($, jquery_loaded) -> | |
# Widget code here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't edit it now (wasn't signed in when creating it) but I ended up changing
to
Because it was throwing errors when inserting into badly formed html (blank line at top of file).