Last active
August 29, 2015 14:14
-
-
Save halfninja/80dcd840ce53c7598e17 to your computer and use it in GitHub Desktop.
Loads new jQuery and Bootstrap 3 if it's not detected 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
/** | |
* If jQuery 1.8 or older is detected, loads a much newer jQuery and Bootstrap 3. | |
* After adding this script you must use the usual jQuery onready stuff to | |
* contain your code, otherwise it'll run before this has finished. e.g.: | |
* jQuery(function() { | |
* // new jQuery should work here | |
* }); | |
*/ | |
(function(){ | |
var j = jQuery; | |
var loadCss = function(url) { | |
var link = document.createElement("link"); | |
link.type = "text/css"; | |
link.rel = "stylesheet"; | |
link.href = url; | |
document.getElementsByTagName("head")[0].appendChild(link); | |
}; | |
var loadScript = function(url) { | |
j.holdReady(true); | |
j.getScript( url ).always(function() { | |
j.holdReady(false); | |
}); | |
}; | |
if (!window.jQuery || (window.jQuery.fn.jquery||'').match(/1\.[5678]/)) { | |
loadCss('//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'); | |
loadScript('https://code.jquery.com/jquery-1.11.2.min.js'); | |
loadScript('//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment