diff options
Diffstat (limited to 'lib/dom_utils.coffee')
| -rw-r--r-- | lib/dom_utils.coffee | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 690d9969..06db1b9b 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -305,15 +305,26 @@ DomUtils = event.preventDefault() @suppressPropagation(event) - # Suppress the next keyup event for Escape. - suppressKeyupAfterEscape: (handlerStack) -> - handlerStack.push - _name: "dom_utils/suppressKeyupAfterEscape" - keyup: (event) -> - return true unless KeyboardUtils.isEscape event - @remove() - false - handlerStack.suppressEvent + consumeKeyup: do -> + handlerId = null + + (event, callback = null) -> + unless event.repeat + handlerStack.remove handlerId if handlerId? + code = event.code + handlerId = handlerStack.push + _name: "dom_utils/consumeKeyup" + keyup: (event) -> + return handlerStack.continueBubbling unless event.code == code + @remove() + handlerStack.suppressEvent + # We cannot track keyup events if we lose the focus. + blur: (event) -> + @remove() if event.target == window + handlerStack.continueBubbling + callback?() + @suppressEvent event + handlerStack.suppressEvent # Adapted from: http://roysharon.com/blog/37. # This finds the element containing the selection focus. |
