Created
August 12, 2009 12:24
-
-
Save blatyo/166477 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.addMethods({ | |
isVisible: function(element){ | |
return !$(element).getStyle('visibility').match('hidden'); | |
}, | |
makeVisible: function(element){ | |
//IE doesn't work with others, so we don't handle them | |
return $(element).setStyle({visibility: 'visible'}); | |
}, | |
makeInvisible: function(element){ | |
return $(element).setStyle({visibility: 'hidden'}); | |
}, | |
toggleVisibility: function(element){ | |
element = $(element); | |
if(element.isVisible()){ | |
return element.makeInvisible(); | |
} | |
return element.makeVisible() | |
}, | |
cumulativeOffset: Element.Methods.cumulativeOffset.wrap( | |
function(originalCumulativeOffset, element){ | |
element = $(element); | |
var offset = originalCumulativeOffset(element); | |
var dimensions = element.getDimensions(); | |
offset.right = offset.left + dimensions.width; | |
offset.bottom = offset.top + dimensions.height; | |
offset[2] = offset.right; | |
offset[3] = offset.bottom; | |
return offset; | |
} | |
), | |
isOverlapping: function(element, other){ | |
element = $(element); | |
other = $(other); | |
var elementOffset = element.cumulativeOffset(); | |
var otherOffset = other.cumulativeOffset(); | |
return !(elementOffset.top > otherOffset.bottom | |
|| elementOffset.bottom < otherOffset.top | |
|| elementOffset.left > otherOffset.right | |
|| elementOffset.right < otherOffset.left); | |
}, | |
observeAll: function(element, eventHandlers){ | |
$H(eventHandlers).each(function(handler){ | |
Event.observe(element, handler.key, handler.value); | |
}); | |
}, | |
stopObservingAll: function(element, eventHandlers){ | |
$H(eventHandlers).each(function(handler){ | |
Event.stopObserving(element, handler.key, handler.value); | |
}); | |
} | |
}); | |
Object.extend(document, { | |
observeAll: Element.Methods.observeAll.methodize(), | |
stopObservingAll: Element.Methods.stopObservingAll.methodize() | |
}); | |
Object.extend(Array.prototype, { | |
toHash: function(){ | |
var newHash = $H(); | |
this.each(function(value, i){ | |
newHash.set(i, value); | |
}); | |
return newHash; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment