// Function.prototype.toEvent, .bindAsEventListener( args ) REM2006 for this.js Api // Important: sends event as the first argument to your function in IE also!, // event XY [Array][x,y] is passed as last arg, your passed args are in the middle :) // example: myElement.onclick= myFunc.toEvent( myArguments ); http://richard-m.blogspot.com/ // Function.prototype.toEvent = Function.prototype.bindAsEventListener= function(){ var _method= this, r=[], len=arguments.length, i=0;//alert(len) for (i;i<len;i++){ r[i+1]=arguments[i] } return function( ev ){ r[0]= ev= ev || event; var db=document.body, dd=document.documentElement; r[r.length++]=(ev.pageX)? [ev.pageX, ev.pageY] : [ev.clientX + db.scrollLeft+ dd.scrollLeft, ev.clientY + db.scrollTop + dd.scrollTop]; return _method.apply(ev.target|| ev.srcElement, r); }; };
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Function.prototype.toEvent (alias bindAsEventListener) (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Attach Events in javascript base prototype event
» Execute Event in javascript prototype utility event
» DomReady extension for proto... in javascript dom prototype event
» Custom Ajax.Request Function in javascript ajax base prototype
» Bind Functions in javascript base prototype
» Attach Elements in javascript dom base prototype
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails