Last active
December 26, 2015 03:59
-
-
Save pjaspers/7090260 to your computer and use it in GitHub Desktop.
Bob & Franz bookmarklet Bookmarklet to instantly display Bob & Franz.
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
// Bob & Franz bookmarklet | |
// | |
// Bookmarklet to instantly display Bob & Franz. | |
// | |
// Using the Google Closure Compiler to minify the JS: | |
// | |
// curl -O -XPOST -d compilation_level=SIMPLE_OPTIMIZATIONS -d output_info=compiled_code -d output_format=text --data-urlencode "[email protected]" http://closure-compiler.appspot.com/compile | |
// | |
// Cats should have their own namespace | |
window.BobFranz = {}; | |
var bf = { | |
elName: "bobfranz", | |
imgURL: "http://f.cl.ly/items/423L1x1E1E291Z2T3c03/bobenfranz.png", | |
view: "<a href='#' onclick='window.BobFranz.{function}()'><img src='{url}'/></a>", | |
el: function() {return document.getElementById(this.elName)}, | |
tpl: function() { | |
return this.view.replace("{function}", "disappear"). | |
replace("{url}", this.imgURL); | |
}, | |
jq: function() { | |
if (typeof jQuery === 'undefined') return false; | |
return true; | |
}, | |
appear: function() { | |
if(!(this.el())) this.appendEl(); | |
if(this.jq()) { | |
$(this.el()).fadeIn(); | |
} else { | |
this.el().style.display = "block"; | |
} | |
}, | |
disappear: function() { | |
if(this.jq()) { | |
$(this.el()).fadeOut(); | |
} else { | |
this.el().style.display = "none"; | |
} | |
}, | |
appendEl: function() { | |
if(this.el()) return; | |
var bob_franz = document.createElement('div'); | |
bob_franz.innerHTML= this.tpl(); | |
bob_franz.setAttribute("style", "position:fixed; z-index:1000;bottom: 0px;right:0px;"); | |
bob_franz.id = this.elName; | |
document.getElementsByTagName("body")[0].appendChild(bob_franz); | |
} | |
}; | |
window.BobFranz = bf; | |
bf.appear(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment