Created
May 15, 2012 21:02
-
-
Save fideloper/2705119 to your computer and use it in GitHub Desktop.
Bookmarklet Skeleton JS
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() { | |
| 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); | |
| })(); |
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
| <!-- 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