0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Make event.preventDefault() cancel default key actions.

Fixes #107
This commit is contained in:
Neil Jenkins 2015-07-13 09:25:44 +07:00
parent 579cad7ff9
commit a8fcd55cf4
4 changed files with 17 additions and 7 deletions

View file

@ -1158,6 +1158,10 @@ var onKey = function ( event ) {
modifiers = '',
range = this.getSelection();
if ( event.defaultPrevented ) {
return;
}
if ( !key ) {
key = String.fromCharCode( code ).toLowerCase();
// Only reliable for letters and numbers
@ -2292,7 +2296,7 @@ var customEvents = {
proto.fireEvent = function ( type, event ) {
var handlers = this._events[ type ],
i, l, obj;
l, obj;
if ( handlers ) {
if ( !event ) {
event = {};
@ -2302,8 +2306,9 @@ proto.fireEvent = function ( type, event ) {
}
// Clone handlers array, so any handlers added/removed do not affect it.
handlers = handlers.slice();
for ( i = 0, l = handlers.length; i < l; i += 1 ) {
obj = handlers[i];
l = handlers.length;
while ( l-- ) {
obj = handlers[l];
try {
if ( obj.handleEvent ) {
obj.handleEvent( event );

File diff suppressed because one or more lines are too long

View file

@ -191,7 +191,7 @@ var customEvents = {
proto.fireEvent = function ( type, event ) {
var handlers = this._events[ type ],
i, l, obj;
l, obj;
if ( handlers ) {
if ( !event ) {
event = {};
@ -201,8 +201,9 @@ proto.fireEvent = function ( type, event ) {
}
// Clone handlers array, so any handlers added/removed do not affect it.
handlers = handlers.slice();
for ( i = 0, l = handlers.length; i < l; i += 1 ) {
obj = handlers[i];
l = handlers.length;
while ( l-- ) {
obj = handlers[l];
try {
if ( obj.handleEvent ) {
obj.handleEvent( event );

View file

@ -21,6 +21,10 @@ var onKey = function ( event ) {
modifiers = '',
range = this.getSelection();
if ( event.defaultPrevented ) {
return;
}
if ( !key ) {
key = String.fromCharCode( code ).toLowerCase();
// Only reliable for letters and numbers