Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created May 15, 2012 21:02
Show Gist options
  • Select an option

  • Save fideloper/2705119 to your computer and use it in GitHub Desktop.

Select an option

Save fideloper/2705119 to your computer and use it in GitHub Desktop.
Bookmarklet Skeleton JS
(function() {
var Namespace = function() {
//Private
_init = function(jq) {
if(!jq) {
_getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', _run);
return;
}
_run();
}
_run = function() {
}
// Paul Irish getScript method http://pastie.org/462639
_getScript = function(url, success) {
var head = document.getElementsByTagName('head')[0],
done = false,
script = document.createElement('script');
script.src = url;
script.onload = script.onreadystatechange = function(){
if(!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
success();
}
};
head.appendChild(script);
};
//Public
return {
init: _init
};
}();
// check for jQuery, if not present pass reference
var jq = true;
if(!window.jQuery) {
jq = false;
}
//Run app
Namespace.init(jq);
})();
<!-- Linters might make this multiline. Add in semi-colons on those and then combine to one line for anchor tags -->
<a href="javascript:(function(){var Namespace=function(){_init=function(jq){if(!jq){_getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',_run);return;};_run();};_run=function(){};_getScript=function(url,success){var head=document.getElementsByTagName('head')[0],done=false,script=document.createElement('script');script.src=url;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){done=true;success();}};head.appendChild(script);};return{init:_init};}();var jq=true;if(!window.jQuery){jq=false;};Namespace.init(jq);})();">click this</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment