Created
January 26, 2010 15:03
-
-
Save roccogalluzzo/286900 to your computer and use it in GitHub Desktop.
This file contains 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
var Element = { | |
visible: function() {return (!this.hasClassName('toggle'));}, | |
toggle: function() {if (this.visible()) { this.hide();} else {this.show();}}, | |
hide: function() {this.addClassName('toggle'); return this;}, | |
show: function() { this.removeClassName('toggle'); return this;}, | |
remove: function() { this.getParentNode().removeChild(this);return null;}, | |
empty: function() {while (this.getLastChild()) { this.removeChild(this.getLastChild());}}, | |
bind: function(event, fn){ console.log(event, fn)} | |
} | |
function $(element) { | |
if (typeof element == "string"){ | |
element = document.getElementById(element); | |
if (element){ extend(element,Element);return element;}} | |
} | |
//common functions | |
function extend(instance,fn) { | |
for (var name in fn) { | |
instance[name] = fn[name]; | |
} | |
} | |
$('div').hide(); | |
$('div').show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment