Extends the Element native object to include some shortcut methods.
Element.implement({
isDisplayed: function(){
return this.style.display != 'none';
},
isVisible: function(){
var w = this.offsetWidth,
h = this.offsetHeight;
return (w == 0 && h == 0) ? false : (w > 0 && h > 0) ? true : this.style.display != 'none';
},
toggle: function(){
return this[this.isDisplayed() ? 'hide' : 'show']();
},
hide: function(){
var d;
try {
IE fails here if the element is not in the dom
d = this.getStyle('display');
} catch(e){}
return this.store('element:_originalDisplay', d || '').setStyle('display', 'none');
},
show: function(display){
display = display || this.retrieve('element:_originalDisplay') || 'block';
return this.setStyle('display', (display == 'none') ? 'block' : display);
},
swapClass: function(remove, add){
return this.removeClass(remove).addClass(add);
}
});
Document.implement({
clearSelection: function(){
if (document.selection && document.selection.empty) {
document.selection.empty();
} else if (window.getSelection) {
var selection = window.getSelection();
if (selection && selection.removeAllRanges) selection.removeAllRanges();
}
}
});