mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Add #toString() to Event#modifiers.
This commit is contained in:
parent
585e3b6254
commit
e79d890432
5 changed files with 23 additions and 7 deletions
14
src/paper.js
14
src/paper.js
|
@ -124,8 +124,22 @@ Base.inject({
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Utility function for rendering numbers to strings at a precision of up
|
||||
* to 5 fractional digits.
|
||||
*/
|
||||
formatNumber: function(num) {
|
||||
return (Math.round(num * 100000) / 100000).toString();
|
||||
},
|
||||
|
||||
/**
|
||||
* Utility function for rendering objects to strings, in object literal
|
||||
* notation.
|
||||
*/
|
||||
formatObject: function(obj) {
|
||||
return '{ ' + Base.each(obj, function(value, key) {
|
||||
this.push(key + ': ' + value);
|
||||
}, []).join(', ') + ' }';
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ var ToolEvent = this.ToolEvent = Base.extend({
|
|||
return '{ type: ' + this.type
|
||||
+ ', point: ' + this.point
|
||||
+ ', count: ' + this.count
|
||||
+ ', modifiers: ' + this.getModifiers(true)
|
||||
+ ', modifiers: ' + this.getModifiers()
|
||||
+ ' }';
|
||||
}
|
||||
});
|
||||
|
|
|
@ -35,9 +35,7 @@ var Event = this.Event = Base.extend({
|
|||
this.preventDefault();
|
||||
},
|
||||
|
||||
getModifiers: function(asString) {
|
||||
return asString ? '{ ' + Base.each(Key.modifiers, function(value, key) {
|
||||
this.push(key + ': ' + value);
|
||||
}, []).join(', ') + ' }' : Key.modifiers;
|
||||
getModifiers: function() {
|
||||
return Key.modifiers;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -44,7 +44,11 @@ var Key = this.Key = new function() {
|
|||
control: false,
|
||||
option: false,
|
||||
command: false,
|
||||
capsLock: false
|
||||
capsLock: false,
|
||||
|
||||
toString: function() {
|
||||
return Base.formatObject(this);
|
||||
}
|
||||
},
|
||||
|
||||
// Since only keypress gets proper keyCodes that are actually representing
|
||||
|
|
|
@ -27,7 +27,7 @@ var KeyEvent = this.KeyEvent = Event.extend(new function() {
|
|||
return '{ type: ' + this.type
|
||||
+ ', key: ' + this.key
|
||||
+ ', character: ' + this.character
|
||||
+ ', modifiers: ' + this.getModifiers(true)
|
||||
+ ', modifiers: ' + this.getModifiers()
|
||||
+ ' }';
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue