Created
October 20, 2008 21:27
-
-
Save kneath/18175 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
Element.implement({ | |
getDimensions: function() { | |
return {width: this.getStyle('width', true), height: this.getStyle('height', true)}; | |
}, | |
visible: function() { | |
return this.getStyle('display') != 'none'; | |
}, | |
toggle: function() { | |
return this[this.visible() ? 'hide' : 'show'](); | |
}, | |
hide: function() { | |
this.originalDisplay = this.style.display; | |
this.style.display = 'none'; | |
return this; | |
}, | |
show: function(display) { | |
this.style.display = display || this.originalDisplay || 'block'; | |
return this; | |
}, | |
cleanWhitespace: function() { | |
$A(this.childNodes).each(function(node){ | |
if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) node.parentNode.removeChild(node); | |
}); | |
}, | |
find: function(what) { | |
var el = this; | |
while (el.nodeType != 1) el = el[what]; | |
return el; | |
}, | |
replace: function(html) { | |
if (this.outerHTML) { | |
this.outerHTML = html.stripScripts(); | |
} else { | |
var range = this.ownerDocument.createRange(); | |
range.selectNodeContents(this); | |
this.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), this); | |
} | |
setTimeout(function() {html.evalScripts()}, 10); | |
}, | |
empty: function() { | |
return this.innerHTML.match(/^\s*$/); | |
}, | |
getOffsetHeight: function(){ return this.getStyle('height'); }, | |
getOffsetWidth: function(){ return this.getStyle('width'); } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment