Line | |
---|
1 |
|
---|
2 | // attach a handler to a particular event on an element
|
---|
3 | // in a browser-independent way
|
---|
4 | function registerEventHandler (element, event, handler) {
|
---|
5 | if (element.attachEvent) {
|
---|
6 | // MS registration model
|
---|
7 | element.attachEvent('on' + event, handler);
|
---|
8 | } else if (element.addEventListener) {
|
---|
9 | // NN (W4C) regisration model
|
---|
10 | element.addEventListener(event, handler, false);
|
---|
11 | } else {
|
---|
12 | // old regisration model as fall-back
|
---|
13 | element[event] = handler;
|
---|
14 | }
|
---|
15 | }
|
---|
16 |
|
---|
17 | // get a delegate that refers to an instance method
|
---|
18 | function getInstanceDelegate (obj, methodName) {
|
---|
19 | return( function(e) {
|
---|
20 | e = e || window.event;
|
---|
21 | return obj[methodName](e);
|
---|
22 | } );
|
---|
23 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.