mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Only allow the installation of one onEventType handler at a time.
For more, use #attach() / #detach()
This commit is contained in:
parent
7e9989c6b9
commit
41fa3b24e7
1 changed files with 9 additions and 7 deletions
|
@ -84,13 +84,12 @@ var Callback = {
|
||||||
function callHandlers() {
|
function callHandlers() {
|
||||||
for (var i in handlers) {
|
for (var i in handlers) {
|
||||||
// When the handler function returns false, prevent the default
|
// When the handler function returns false, prevent the default
|
||||||
// behaviour of the event by calling stop() on it.
|
// behaviour and stop propagation of the event by calling stop()
|
||||||
if (handlers[i].apply(that, args) === false
|
if (handlers[i].apply(that, args) === false
|
||||||
&& event && event.stop)
|
&& event && event.stop)
|
||||||
event.stop();
|
event.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See PaperScript.handleException for an explanation of the following.
|
// See PaperScript.handleException for an explanation of the following.
|
||||||
// Firefox is to blame for the necessity of this...
|
// Firefox is to blame for the necessity of this...
|
||||||
if (handleException) {
|
if (handleException) {
|
||||||
|
@ -136,16 +135,19 @@ var Callback = {
|
||||||
types[type] = isString ? {} : entry;
|
types[type] = isString ? {} : entry;
|
||||||
// Create getters and setters for the property
|
// Create getters and setters for the property
|
||||||
// with the on*-name name:
|
// with the on*-name name:
|
||||||
name = '_' + name;
|
// Use '__' as there are some _onMouse* functions
|
||||||
|
// already, e.g.g on View.
|
||||||
|
name = '__' + name;
|
||||||
src['get' + part] = function() {
|
src['get' + part] = function() {
|
||||||
return this[name];
|
return this[name];
|
||||||
};
|
};
|
||||||
src['set' + part] = function(func) {
|
src['set' + part] = function(func) {
|
||||||
if (func) {
|
// Detach the previous event, if there was one.
|
||||||
|
var prev = this[name];
|
||||||
|
if (prev)
|
||||||
|
this.detach(type, prev);
|
||||||
|
if (func)
|
||||||
this.attach(type, func);
|
this.attach(type, func);
|
||||||
} else if (this[name]) {
|
|
||||||
this.detach(type, this[name]);
|
|
||||||
}
|
|
||||||
this[name] = func;
|
this[name] = func;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue