Add / Remove Javascript Functions


// Modular Script Library – $E
// copyright Stephen Chapman, 18th June 2010
// you may copy this script but please keep the copyright notice as well
// you may substitute your own value for $E if that clashes with other scripts

$E = {o: function(o) {return (o.obj)?o.obj:o;}, add: function() {}, remove:function() {}}; if ( window.addEventListener ) {$E.add = function(ob, type, fn ) {this.o(ob).addEventListener(type, fn, false );}; $E.remove = function(ob, type, fn ) {this.o(ob).removeEventListener(type, fn, false );};} else if (document.attachEvent) {$E.add = function(ob, type, fn ) {var eProp = type + fn; var o = this.o(ob);  o[‘e’+eProp] = fn; o[eProp] = function(){o[‘e’+eProp]( window.event );}; o.attachEvent( ‘on’+type, o[eProp]);}; $E.remove = function(ob, type, fn ) {var eProp = type + fn; var o = this.o(ob); o.detachEvent( ‘on’+type, o[eProp]); o[eProp] = null; o[“e”+eProp] = null;};}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s