Created
November 19, 2017 20:32
-
-
Save jenyayel/d676554930c7a02904eb62188ad5a4d7 to your computer and use it in GitHub Desktop.
jQuery async loader to page
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
| function ensureJquery(readyCallback) { | |
| if (window.jQuery === undefined || parseFloat(window.jQuery.fn.jquery) < 1.9) { | |
| var js = document.createElement('script'); | |
| js.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"; | |
| if (js.readyState) | |
| js.onreadystatechange = function () { | |
| if (this.readyState == 'complete' || this.readyState == 'loaded') { | |
| jQueryLoadHandler(); | |
| } | |
| }; | |
| else | |
| js.onload = jQueryLoadHandler; | |
| (document.getElementsByTagName('head')[0] || document.documentElement).appendChild(js); | |
| } else { | |
| readyCallback(window.jQuery); | |
| } | |
| function jQueryLoadHandler() { | |
| readyCallback(window.jQuery.noConflict(true)); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@khaliullin, just noticed your comment. You call the method
ensureJqueryand provide callback, which will be called after:The callback that you specify will get an argument, which will be jQuery object in version 1.9 or higher without changing
windowglobal objectjQuery.