@@ -5,7 +5,7 @@ import { HTMLCanvasElement } from './HTMLCanvasElement';
55import { HTMLDivElement } from './HTMLDivElement' ;
66import { Text } from './Text' ;
77import { Canvas , FontFaceSet } from '@nativescript/canvas' ;
8- import { ContentView , Frame , StackLayout , eachDescendant , knownFolders } from '@nativescript/core' ;
8+ import { ContentView , Frame , StackLayout , knownFolders } from '@nativescript/core' ;
99import { Node } from './Node' ;
1010import { Element , parseChildren } from './Element' ;
1111import { SVGSVGElement } from './svg/SVGSVGElement' ;
@@ -15,96 +15,7 @@ import { HTMLCollection } from './HTMLCollection';
1515import { HTMLHtmlElement } from './HTMLHtmlElement' ;
1616import { HTMLHeadElement } from './HTMLHeadElement' ;
1717import { HTMLBodyElement } from './HTMLBodyElement' ;
18-
19- function getElementsByClassName ( v , clsName ) {
20- var retVal = [ ] ;
21- if ( ! v ) {
22- return retVal ;
23- }
24-
25- if ( v . classList . contains ( clsName ) ) {
26- retVal . push ( v ) ;
27- }
28-
29- const classNameCallback = function ( child ) {
30- if ( child . classList . contains ( clsName ) ) {
31- retVal . push ( child ) ;
32- }
33-
34- // Android patch for ListView
35- if ( child . _realizedItems && child . _realizedItems . size !== child . _childrenCount ) {
36- for ( var key in child . _realizedItems ) {
37- if ( child . _realizedItems . hasOwnProperty ( key ) ) {
38- classNameCallback ( child . _realizedItems [ key ] ) ;
39- }
40- }
41- }
42-
43- return true ;
44- } ;
45-
46- eachDescendant ( v , classNameCallback ) ;
47-
48- // Android patch for ListView
49- if ( v . _realizedItems && v . _realizedItems . size !== v . _childrenCount ) {
50- for ( var key in v . _realizedItems ) {
51- if ( v . _realizedItems . hasOwnProperty ( key ) ) {
52- classNameCallback ( v . _realizedItems [ key ] ) ;
53- }
54- }
55- }
56-
57- return retVal ;
58- }
59-
60- function getElementsByTagName ( v , tagName ) {
61- // TagName is case-Insensitive
62- var tagNameLC = tagName . toLowerCase ( ) ;
63-
64- var retVal = [ ] ,
65- allTags = false ;
66- if ( ! v ) {
67- return retVal ;
68- }
69-
70- if ( tagName === '*' ) {
71- allTags = true ;
72- }
73-
74- if ( ( v . typeName && v . typeName . toLowerCase ( ) === tagNameLC ) || allTags ) {
75- retVal . push ( v ) ;
76- }
77-
78- const tagNameCallback = function ( child ) {
79- if ( ( child . typeName && child . typeName . toLowerCase ( ) === tagNameLC ) || allTags ) {
80- retVal . push ( child ) ;
81- }
82-
83- // Android patch for ListView
84- if ( child . _realizedItems && child . _realizedItems . size !== child . _childrenCount ) {
85- for ( var key in child . _realizedItems ) {
86- if ( child . _realizedItems . hasOwnProperty ( key ) ) {
87- tagNameCallback ( child . _realizedItems [ key ] ) ;
88- }
89- }
90- }
91-
92- return true ;
93- } ;
94-
95- eachDescendant ( v , tagNameCallback ) ;
96-
97- // Android patch for ListView
98- if ( v . _realizedItems && v . _realizedItems . size !== v . _childrenCount ) {
99- for ( var key in v . _realizedItems ) {
100- if ( v . _realizedItems . hasOwnProperty ( key ) ) {
101- tagNameCallback ( v . _realizedItems [ key ] ) ;
102- }
103- }
104- }
105-
106- return retVal ;
107- }
18+ import { domGetElementsByClassName , domGetElementsByTagName } from './domUtils' ;
10819
10920export class Document extends Node {
11021 readonly body : Element = null ;
@@ -239,10 +150,10 @@ export class Document extends Node {
239150 const topmost = Frame . topmost ( ) ;
240151 if ( topmost ) {
241152 let nativeElement ;
242- if ( topmost . currentPage && topmost . currentPage . modal ) {
243- nativeElement = topmost . getViewById ( id ) ;
244- } else {
153+ if ( topmost . currentPage ?. modal ) {
245154 nativeElement = topmost . currentPage . modal . getViewById ( id ) ;
155+ } else {
156+ nativeElement = topmost . currentPage ?. getViewById ( id ) ?? topmost . getViewById ( id ) ;
246157 }
247158
248159 if ( nativeElement ) {
@@ -269,15 +180,8 @@ export class Document extends Node {
269180 }
270181 const topmost = Frame . topmost ( ) ;
271182 if ( topmost ) {
272- let view ;
273- if ( topmost . currentPage && topmost . currentPage . modal ) {
274- view = topmost ;
275- } else {
276- view = topmost . currentPage . modal ;
277- }
278- const elements = getElementsByTagName ( view , tagname ) ;
279-
280- return elements ;
183+ const view = topmost . currentPage ?. modal ?? topmost . currentPage ?? topmost ;
184+ return domGetElementsByTagName ( view , tagname ) ;
281185 }
282186 return [ ] ;
283187 }
@@ -288,15 +192,8 @@ export class Document extends Node {
288192 }
289193 const topmost = Frame . topmost ( ) ;
290194 if ( topmost ) {
291- let view ;
292- if ( topmost . currentPage && topmost . currentPage . modal ) {
293- view = topmost ;
294- } else {
295- view = topmost . currentPage . modal ;
296- }
297- const elements = getElementsByClassName ( view , className ) ;
298-
299- return elements ;
195+ const view = topmost . currentPage ?. modal ?? topmost . currentPage ?? topmost ;
196+ return domGetElementsByClassName ( view , className ) ;
300197 }
301198 return [ ] ;
302199 }
0 commit comments