1
- var DomUtils = {
1
+ const DomUtils = {
2
2
//
3
3
// Runs :callback if the DOM has loaded, otherwise runs it on load
4
4
//
@@ -14,12 +14,12 @@ var DomUtils = {
14
14
let callbacks = [ ] ;
15
15
if ( ! isReady ) {
16
16
let onDOMContentLoaded ;
17
- window . addEventListener (
17
+ globalThis . addEventListener (
18
18
"DOMContentLoaded" ,
19
19
onDOMContentLoaded = forTrusted ( function ( ) {
20
- window . removeEventListener ( "DOMContentLoaded" , onDOMContentLoaded , true ) ;
20
+ globalThis . removeEventListener ( "DOMContentLoaded" , onDOMContentLoaded , true ) ;
21
21
isReady = true ;
22
- for ( let callback of callbacks ) callback ( ) ;
22
+ for ( const callback of callbacks ) callback ( ) ;
23
23
callbacks = null ;
24
24
} ) ,
25
25
true ,
@@ -40,15 +40,15 @@ var DomUtils = {
40
40
let callbacks = [ ] ;
41
41
if ( ! isComplete ) {
42
42
let onLoad ;
43
- window . addEventListener (
43
+ globalThis . addEventListener (
44
44
"load" ,
45
45
onLoad = forTrusted ( function ( event ) {
46
46
// The target is ensured to be on document. See
47
47
// https://w3c.github.io/uievents/#event-type-load
48
48
if ( event . target !== document ) return ;
49
- window . removeEventListener ( "load" , onLoad , true ) ;
49
+ globalThis . removeEventListener ( "load" , onLoad , true ) ;
50
50
isComplete = true ;
51
- for ( let callback of callbacks ) callback ( ) ;
51
+ for ( const callback of callbacks ) callback ( ) ;
52
52
callbacks = null ;
53
53
} ) ,
54
54
true ,
@@ -105,7 +105,7 @@ var DomUtils = {
105
105
// Test whether the current frame is the top/main frame.
106
106
//
107
107
isTopFrame ( ) {
108
- return window . top === window . self ;
108
+ return globalThis . top === globalThis . self ;
109
109
} ,
110
110
111
111
//
@@ -115,7 +115,7 @@ var DomUtils = {
115
115
//
116
116
makeXPath ( elementArray ) {
117
117
const xpath = [ ] ;
118
- for ( let element of elementArray ) {
118
+ for ( const element of elementArray ) {
119
119
xpath . push ( ".//" + element , ".//xhtml:" + element ) ;
120
120
}
121
121
return xpath . join ( " | " ) ;
@@ -155,7 +155,7 @@ var DomUtils = {
155
155
156
156
// Inline elements with font-size: 0px; will declare a height of zero, even if a child with
157
157
// non-zero font-size contains text.
158
- var isInlineZeroHeight = function ( ) {
158
+ let isInlineZeroHeight = function ( ) {
159
159
const elementComputedStyle = window . getComputedStyle ( element , null ) ;
160
160
const isInlineZeroFontSize =
161
161
( 0 === elementComputedStyle . getPropertyValue ( "display" ) . indexOf ( "inline" ) ) &&
@@ -168,10 +168,9 @@ var DomUtils = {
168
168
for ( clientRect of clientRects ) {
169
169
// If the link has zero dimensions, it may be wrapping visible but floated elements. Check for
170
170
// this.
171
- var computedStyle ;
171
+ let computedStyle ;
172
172
if ( ( ( clientRect . width === 0 ) || ( clientRect . height === 0 ) ) && testChildren ) {
173
- for ( let child of Array . from ( element . children ) ) {
174
- var needle ;
173
+ for ( const child of Array . from ( element . children ) ) {
175
174
computedStyle = window . getComputedStyle ( child , null ) ;
176
175
// Ignore child elements which are not floated and not absolutely positioned for parent
177
176
// elements with zero width/height, as long as the case described at isInlineZeroHeight
@@ -237,7 +236,7 @@ var DomUtils = {
237
236
getClientRectsForAreas ( imgClientRect , areas ) {
238
237
const rects = [ ] ;
239
238
for ( const area of areas ) {
240
- var x1 , x2 , y1 , y2 ;
239
+ let x1 , x2 , y1 , y2 ;
241
240
const coords = area . coords . split ( "," ) . map ( ( coord ) => parseInt ( coord , 10 ) ) ;
242
241
const shape = area . shape . toLowerCase ( ) ;
243
242
if ( [ "rect" , "rectangle" ] . includes ( shape ) ) { // "rectangle" is an IE non-standard.
@@ -302,7 +301,7 @@ var DomUtils = {
302
301
303
302
// Embedded elements like Flash and quicktime players can obtain focus.
304
303
isEmbed ( element ) {
305
- let nodeName = element . nodeName != null ? element . nodeName . toLowerCase ( ) : null ;
304
+ const nodeName = element . nodeName != null ? element . nodeName . toLowerCase ( ) : null ;
306
305
return [ "embed" , "object" ] . includes ( nodeName ) ;
307
306
} ,
308
307
@@ -361,7 +360,9 @@ var DomUtils = {
361
360
if ( ( element . selectionStart === 0 ) && ( element . selectionEnd === 0 ) ) {
362
361
return element . setSelectionRange ( element . value . length , element . value . length ) ;
363
362
}
364
- } catch ( error ) { }
363
+ } catch {
364
+ // Swallow
365
+ }
365
366
}
366
367
}
367
368
} ,
@@ -370,7 +371,7 @@ var DomUtils = {
370
371
if ( modifiers == null ) modifiers = { } ;
371
372
const eventSequence = [ "mouseover" , "mousedown" , "mouseup" , "click" ] ;
372
373
const result = [ ] ;
373
- for ( let event of eventSequence ) {
374
+ for ( const event of eventSequence ) {
374
375
// In firefox prior to 96, simulating a click on an element would be blocked under some
375
376
// conditions (#2602, #2960).
376
377
// In 96+, extensions can trigger native click listeners on elements (#3985).
@@ -643,7 +644,9 @@ var DomUtils = {
643
644
text = text . slice ( 11 ) . trim ( ) ;
644
645
try {
645
646
text = decodeURIComponent ( text ) ;
646
- } catch ( error ) { }
647
+ } catch {
648
+ // Swallow
649
+ }
647
650
}
648
651
const script = document . createElement ( "script" ) ;
649
652
script . textContent = text ;
0 commit comments