@@ -81,6 +81,20 @@ function getSelection(node) {
8181 }
8282}
8383
84+ /**
85+ * Get document associated with the event target.
86+ *
87+ * @param {object } nativeEventTarget
88+ * @return {Document }
89+ */
90+ function getEventTargetDocument ( eventTarget ) {
91+ return eventTarget . window === eventTarget
92+ ? eventTarget . document
93+ : eventTarget . nodeType === DOCUMENT_NODE
94+ ? eventTarget
95+ : eventTarget . ownerDocument ;
96+ }
97+
8498/**
8599 * Poll selection to see whether it's changed.
86100 *
@@ -93,10 +107,7 @@ function constructSelectEvent(nativeEvent, nativeEventTarget) {
93107 // selection (this matches native `select` event behavior). In HTML5, select
94108 // fires only on input and textarea thus if there's no focused element we
95109 // won't dispatch.
96- var doc =
97- nativeEventTarget . ownerDocument ||
98- nativeEventTarget . document ||
99- nativeEventTarget ;
110+ var doc = getEventTargetDocument ( nativeEventTarget ) ;
100111
101112 if (
102113 mouseDown ||
@@ -152,12 +163,7 @@ var SelectEventPlugin = {
152163 nativeEvent ,
153164 nativeEventTarget ,
154165 ) {
155- var doc =
156- nativeEventTarget . window === nativeEventTarget
157- ? nativeEventTarget . document
158- : nativeEventTarget . nodeType === DOCUMENT_NODE
159- ? nativeEventTarget
160- : nativeEventTarget . ownerDocument ;
166+ var doc = getEventTargetDocument ( nativeEventTarget ) ;
161167 // Track whether all listeners exists for this plugin. If none exist, we do
162168 // not extract events. See #3639.
163169 if ( ! doc || ! isListeningToAllDependencies ( 'onSelect' , doc ) ) {
0 commit comments