mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Make new events work properly for key handlers.
This commit is contained in:
parent
e238dea3ac
commit
78d1ce1540
2 changed files with 11 additions and 12 deletions
|
@ -64,19 +64,23 @@ var Callback = {
|
|||
return this;
|
||||
},
|
||||
|
||||
fire: function(type, param) {
|
||||
fire: function(type, event) {
|
||||
// Returns true if fired, false otherwise
|
||||
var handlers = this._handlers && this._handlers[type];
|
||||
if (!handlers)
|
||||
return false;
|
||||
Base.each(handlers, function(func) {
|
||||
func.call(this, param);
|
||||
// When the handler function returns false, prevent the default
|
||||
// behaviour of the event by calling stop() on it
|
||||
// PORT: Add to Sg
|
||||
if (func.call(this, event) === false && event && event.stop)
|
||||
event.stop();
|
||||
}, this);
|
||||
return true;
|
||||
},
|
||||
|
||||
responds: function(type) {
|
||||
return this._handlers && this._handlers[type];
|
||||
return !!(this._handlers && this._handlers[type]);
|
||||
},
|
||||
|
||||
statics: {
|
||||
|
@ -106,7 +110,7 @@ var Callback = {
|
|||
src['set' + part] = function(func) {
|
||||
if (func) {
|
||||
this.attach(type, func);
|
||||
} else {
|
||||
} else if (this[name]) {
|
||||
this.detach(type, this[name]);
|
||||
}
|
||||
this[name] = func;
|
||||
|
|
|
@ -67,19 +67,14 @@ var Key = this.Key = new function() {
|
|||
function handleKey(down, keyCode, charCode, event) {
|
||||
var character = String.fromCharCode(charCode),
|
||||
key = keys[keyCode] || character.toLowerCase(),
|
||||
handler = down ? 'onKeyDown' : 'onKeyUp',
|
||||
type = down ? 'keydown' : 'keyup',
|
||||
view = View._focused,
|
||||
scope = view && view.isVisible() && view._scope,
|
||||
tool = scope && scope.tool;
|
||||
keyMap[key] = down;
|
||||
if (tool && tool[handler]) {
|
||||
if (tool && tool.responds(type)) {
|
||||
// Call the onKeyDown or onKeyUp handler if present
|
||||
// When the handler function returns false, prevent the
|
||||
// default behaviour of the key event:
|
||||
// PORT: Add to Sg
|
||||
var keyEvent = new KeyEvent(down, key, character, event);
|
||||
if (tool[handler](keyEvent) === false)
|
||||
keyEvent.preventDefault();
|
||||
tool.fire(type, new KeyEvent(down, key, character, event));
|
||||
if (view)
|
||||
view.draw(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue