Skip to content

Instantly share code, notes, and snippets.

@NKid
Created April 17, 2013 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NKid/1287b357b45cecb42cb4 to your computer and use it in GitHub Desktop.
Save NKid/1287b357b45cecb42cb4 to your computer and use it in GitHub Desktop.
jQuerifty (NK mod)
javascript: (function() {
var el = document.createElement('div'),
b = document.getElementsByTagName('body')[0],
otherlib = false,
msg = '';
el.id = 'jq-nk-mod';
el.style.position = 'fixed';
el.style.height = '30';
el.style.width = '200';
el.style.margin = '5px';
el.style.top = '0';
el.style.left = '0';
el.style.padding = '5px';
el.style.backgroundColor = '#F99';
el.style.color = '#000';
el.style.borderRadius = '5px';
el.style.zIndex = 1001;
el.innerHTML = msg;
if(typeof jQuery != 'undefined') {
msg = 'This page already using jQuery v' + jQuery.fn.jquery;
return showMsg();
} else if(typeof $ == 'function') {
otherlib = true;
}
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if(!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
getScript('http://code.jquery.com/jquery.min.js', function() {
if(typeof jQuery == 'undefined') {
msg = 'Sorry, but jQuery wasn\'t able to load';
} else {
msg = 'This page is now jQuerified with v' + jQuery.fn.jquery;
if(otherlib) {
msg += ' and noConflict(). Use $jq(), not $().';
}
}
return showMsg();
});
function showMsg() {
el.innerHTML = msg;
b.appendChild(el);
window.setTimeout(function() {
if(typeof jQuery == 'undefined') {
b.removeChild(el);
} else {
jQuery(el).fadeOut('slow', function() {
jQuery(this).remove();
});
if(otherlib) {
$jq = jQuery.noConflict();
}
}
}, 2500);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment