diff options
Diffstat (limited to 'lib/dom_utils.coffee')
| -rw-r--r-- | lib/dom_utils.coffee | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index ff5991dc..67d5a44c 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -219,7 +219,7 @@ DomUtils = node = selection.anchorNode node and @isDOMDescendant element, node else - if selection.type == "Range" and selection.isCollapsed + if DomUtils.getSelectionType(selection) == "Range" and selection.isCollapsed # The selection is inside the Shadow DOM of a node. We can check the node it registers as being # before, since this represents the node whose Shadow DOM it's inside. containerNode = selection.anchorNode.childNodes[selection.anchorOffset] @@ -344,7 +344,7 @@ DomUtils = consumeKeyup: do -> handlerId = null - (event, callback = null) -> + (event, callback = null, suppressPropagation) -> unless event.repeat handlerStack.remove handlerId if handlerId? code = event.code @@ -353,17 +353,25 @@ DomUtils = keyup: (event) -> return handlerStack.continueBubbling unless event.code == code @remove() - handlerStack.suppressEvent + if suppressPropagation + DomUtils.suppressPropagation event + else + DomUtils.suppressEvent event + handlerStack.continueBubbling # We cannot track keyup events if we lose the focus. blur: (event) -> @remove() if event.target == window handlerStack.continueBubbling callback?() - @suppressEvent event - handlerStack.suppressEvent + if suppressPropagation + DomUtils.suppressPropagation event + handlerStack.suppressPropagation + else + DomUtils.suppressEvent event + handlerStack.suppressEvent # Polyfill for selection.type (which is not available in Firefox). - getSelectionType: (selection) -> + getSelectionType: (selection = document.getSelection()) -> selection.type or do -> if selection.rangeCount == 0 "None" @@ -376,7 +384,7 @@ DomUtils = # This finds the element containing the selection focus. getElementWithFocus: (selection, backwards) -> r = t = selection.getRangeAt 0 - if selection.type == "Range" + if DomUtils.getSelectionType(selection) == "Range" r = t.cloneRange() r.collapse backwards t = r.startContainer @@ -416,5 +424,6 @@ DomUtils = style.textContent = Settings.get "userDefinedLinkHintCss" document.head.appendChild style -root = exports ? window +root = exports ? (window.root ?= {}) root.DomUtils = DomUtils +extend window, root unless exports? |
