mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Add Events object as a helper for installing and removing events.
This commit is contained in:
parent
7b237ceedc
commit
b85235e1cb
2 changed files with 29 additions and 0 deletions
|
@ -48,6 +48,7 @@ this.install = function(scope) {
|
|||
|
||||
//#include "util/CanvasProvider.js"
|
||||
//#include "util/MathUtils.js"
|
||||
//#include "util/Events.js"
|
||||
//#include "util/PaperScript.js"
|
||||
|
||||
};
|
||||
|
|
28
src/util/Events.js
Normal file
28
src/util/Events.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
var Events = {
|
||||
add: function(obj, events) {
|
||||
for (var type in events) {
|
||||
var func = events[type];
|
||||
if (obj.addEventListener) {
|
||||
obj.addEventListener(type, func, false);
|
||||
} else if (obj.attachEvent) {
|
||||
// Make a bound closure that calls on the write object and
|
||||
// passes the event object.
|
||||
obj.attachEvent('on' + type, func.bound = function() {
|
||||
func.call(obj, window.event);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
remove: function(obj, events) {
|
||||
for (var type in events) {
|
||||
var func = events[type];
|
||||
if (obj.removeEventListener) {
|
||||
obj.removeEventListener(type, func, false);
|
||||
} else if (obj.detachEvent) {
|
||||
// Remove the bound function instead of func itself
|
||||
obj.detachEvent('on' + type, func.bound);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue