// nthist_event.js
// three wrappers for events
// inspired by incompatibility between ie6 and the world
// events may be propagated up the DOM tree -- button to div to body
function nthist_stop_propagation( an_event ) {
if( window.event ) {
window.event.cancelBubble = true;
} else {
an_event.stopPropagation();
}
}
// what DOM element was the source of the event
function nthist_get_element( an_event ) {
if( window.event ) {
return window.event.srcElement;
} else {
return an_event.currentTarget;
}
}
// bind an event and handler to a DOM element
// SOME Events: click keydown keyup load resize scroll unload blur change focus
function nthist_set_event( element, event, handler, propagate )
{
// for clarity, if the user passes onclick instead of click
var evt = event.replace( /^on/, '' ).toLowerCase();
// make propagate optional, default to false
propagate = propagate || false;
if (element.addEventListener)
{
element.addEventListener( evt, handler, propagate );
}
else
{
if (element.attachEvent)
{
element.attachEvent('on' + evt, handler );
}
}
}