| 19 | } |
| 20 | |
| 21 | function attachEvent(element, name, f) { |
| 22 | /* Cross-browser attachEvent(). |
| 23 | * Ensures that "this" inside the function f refers to the given element . |
| 24 | */ |
| 25 | f = Function.closure(element, f); |
| 26 | if (element.addEventListener) { |
| 27 | element.addEventListener(name, f, false); |
| 28 | } else if (element.attachEvent) { |
| 29 | element.attachEvent("on"+name, f); |
| 30 | } else { |
| 31 | element["on"+name] = f; |
| 32 | } |
| 33 | element[name] = f; // So we can do element.name(), see widget(). |
| 34 | } |
| 35 | |
| 36 | Function.closure = function(parent, f) { |
| 37 | /* Returns the function f, where "this" inside the function refers to the given parent. |