Im creating a bookmarklet that requires jquery and jquery ui and am having trouble getting a robust/flexible version working (have trawled S.O and various blogs) but they either seem to only check one file is loaded (e.g. jQuery) or just load jQuery and other files in order without checking if they are loaded first.
I really like this one:
(function(){
// the minimum version of jQuery we want
var v = "1.8.2";
// check prior inclusion and version
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initMyBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
initMyBookmarklet();
}
function initMyBookmarklet() {
(window.myBookmarklet = function() {
$('body').append('hello world');
})();
}
})();
Which sets a minimum version for jQuery and only loads if needed. But how do I wrap this up with jQuery UI as well? e.g. setting a min version and only loading it if needed AND making sure they load in the correct order.
Any pointers would be greatly appreciated,