Instead of removing the event listener, arrange for it to keep track of whether it's been called:
addOneShotListener = function(elem, eventName, fn) {
var triggered = false, handler = function(ev) {
if (triggered) return;
fn(ev);
triggered = true;
};
if(elem.addEventListener ) {
elem.addEventListener(eventName, handler, false);
} else if (elem.attachEvent) {
elem.attachEvent('on'+eventName, handler);
}
};
That variation on your original function just wraps the original handler (the "fn" passed in) with a function that only calls the handler the first time it is invoked. After that, it sets a flag and won't ever call the original handler function again.