nathanr


/* nathanr: Event Handler Functions - Cross Browser Functionality */

function get_event(e) {
/* call: var e = get_event(e);
uniforms event object to make scripting simpler */
if(!e) {
var e = window.event;
}
if (e.srcElement) {
e.target = e.srcElement;
}
if(e.target) {
if (e.target.nodeType == 3) {
e.target = e.target.parentNode;
}
}
if(e.clientX || e.clientY) {
if(document.documentElement) {
try {
e.pageX = e.clientX + document.documentElement.scrollLeft;
e.pageY = e.clientY + document.documentElement.scrollTop;
} catch (error) {

}
} else {
e.pageX = e.clientX + document.body.scrollLeft;
e.pageY = e.clientY + document.body.scrollTop;
}
}
return e;
}

function add_event(event_name, function_name, event_target) {
/* add_event("mousedown", myFunction, document.getElementById('elementId'));
add_event("mou

seo

 ver", myFunction, false); */
if(!event_target) {
if(document.documentElement) {
event_target = document;
} else {
event_target = document.body;
}
}
if (event_target.attachEvent) {
remove_event(event_name, function_name, event_target);
event_target.attachEvent("on" + event_name, function_name);
} else if(event_target.addEventListener) {
event_target.addEventListener(event_name, function_name, true);
} else {
alert('Your browser does not ap

pear

  to support attachEvent OR addEventListner; Please either update your current browser or use an alternative.');
}
}

function remove_event(event_name, function_name, event_target) {
/* see add_event comments */
if(!event_target) {
if(document.documentElement) {
event_target = document;
} else {
event_target = document.body;
}
}
if (event_target.detachEvent) {
event_target.detachEvent("on" + event_name, function_name);
} else if(event_target.removeEventListener){
event_target.removeEventListener(event_name, function_name, true);
} else {
alert('Your browser does not ap

pear

  to support detachEvent OR removeEventListener; Please either update your current browser or use an alternative.');
}
}

function stop_event(e) {
/* stop event propagation, cancel bubble, depending on which browser you are using
you may also want to set the event target to unselectable especially in ie when
using drag operations on A nodes
if(e.target.nodeName == "A"Applause {
e.target.setAttribute("unselectable", true);
} */
if (e.stopPropagation) {
e.stopPropagation();
if(e.preventDefault) {
e.preventDefault();
}
} else {
e.cancelBubble = true;
e.returnValue = false;
}
}


this'll save you a few hours of coding guys Applause

perkiset

quote author=nathanr link=topic=588.msg3912#msg3912 date=1193513674

this'll save you a few hours of coding guys Applause


NO LIE. This is one area that I have not written stock classes for the base JS I send out with pages and as such I almost always end up writing the hooks and vectors by hand. These look good N, gonna have to throw them into the testing mix because they'd DEFINITELY help.

Thanks!
/p

nathanr

no problem  Applause I'm afraid I'm not giving away all my secrets though! just the simple stuff you could right click and cp anyways  Applause


Perkiset's Place Home   Politics @ Perkiset's