1
- import { Document } from "./DOM/Document" ;
2
- import "./performance" ;
3
- import { HTMLImageElement } from "./DOM/HTMLImageElement" ;
4
- import { HTMLCanvasElement } from "./DOM/HTMLCanvasElement" ;
5
- import { HTMLVideoElement } from "./DOM/HTMLVideoElement" ;
6
- import { XMLDocument } from './DOM/XMLDocument' ;
7
- import { Device , fromObject , Application , View } from "@nativescript/core" ;
8
- import {
9
- CanvasRenderingContext2D ,
10
- WebGLRenderingContext ,
11
- WebGL2RenderingContext
12
- } from "@nativescript/canvas" ;
1
+ import { Document } from './DOM/Document' ;
2
+ import './performance' ;
3
+ import { HTMLImageElement } from './DOM/HTMLImageElement' ;
4
+ import { HTMLCanvasElement } from './DOM/HTMLCanvasElement' ;
13
5
import { HTMLVideoElement } from './DOM/HTMLVideoElement' ;
14
6
import { XMLDocument } from './DOM/XMLDocument' ;
15
7
import { Device , fromObject , View } from '@nativescript/core' ;
16
8
import { CanvasRenderingContext2D , WebGLRenderingContext , WebGL2RenderingContext } from '@nativescript/canvas' ;
17
9
18
- ( global as any ) . WEBGL_RENDERER = "true" ;
10
+ ( global as any ) . CANVAS_RENDERER = 'true' ;
11
+ ( global as any ) . WEBGL_RENDERER = 'true' ;
19
12
( global as any ) . window = ( global as any ) . window || {
20
13
console : console ,
21
- WEBGL_RENDERER : " true" ,
22
- CANVAS_RENDERER : " true"
14
+ WEBGL_RENDERER : ' true' ,
15
+ CANVAS_RENDERER : ' true' ,
23
16
} ;
24
- ( global as any ) . window . self = ( global as any ) . self =
25
- ( global as any ) . self || window ;
26
- ( global as any ) . window . HTMLImageElement = ( global as any ) . HTMLImageElement =
27
- ( global as any ) . HTMLImageElement || HTMLImageElement ;
28
- ( global as any ) . window . Image = ( global as any ) . Image =
29
- ( global as any ) . Image || HTMLImageElement ;
30
- ( global as any ) . window . ImageBitmap = ( global as any ) . ImageBitmap =
31
- ( global as any ) . ImageBitmap || HTMLImageElement ;
32
- ( global as any ) . window . HTMLVideoElement = ( global as any ) . HTMLVideoElement =
33
- ( global as any ) . HTMLVideoElement || HTMLVideoElement ;
34
- ( global as any ) . window . Video = ( global as any ) . Video =
35
- ( global as any ) . Video || HTMLVideoElement ;
36
- ( global as any ) . window . HTMLCanvasElement = ( global as any ) . HTMLCanvasElement =
37
- ( global as any ) . HTMLCanvasElement || HTMLCanvasElement ;
38
- ( global as any ) . window . Canvas = ( global as any ) . Canvas =
39
- ( global as any ) . Canvas || HTMLCanvasElement ;
40
- ( global as any ) . window . CanvasRenderingContext2D = ( global as any ) . CanvasRenderingContext2D =
41
- ( global as any ) . CanvasRenderingContext2D || CanvasRenderingContext2D ;
42
- ( global as any ) . window . WebGLRenderingContext = ( global as any ) . WebGLRenderingContext =
43
- ( global as any ) . WebGLRenderingContext || WebGLRenderingContext ;
44
- ( global as any ) . window . WebGL2RenderingContext = ( global as any ) . WebGL2RenderingContext =
45
- ( global as any ) . WebGL2RenderingContext || WebGL2RenderingContext ;
17
+ ( global as any ) . window . self = ( global as any ) . self = ( global as any ) . self || window ;
18
+ ( global as any ) . window . HTMLImageElement = ( global as any ) . HTMLImageElement = ( global as any ) . HTMLImageElement || HTMLImageElement ;
19
+ ( global as any ) . window . Image = ( global as any ) . Image = ( global as any ) . Image || HTMLImageElement ;
20
+ ( global as any ) . window . ImageBitmap = ( global as any ) . ImageBitmap = ( global as any ) . ImageBitmap || HTMLImageElement ;
21
+ ( global as any ) . window . HTMLVideoElement = ( global as any ) . HTMLVideoElement = ( global as any ) . HTMLVideoElement || HTMLVideoElement ;
22
+ ( global as any ) . window . Video = ( global as any ) . Video = ( global as any ) . Video || HTMLVideoElement ;
23
+ ( global as any ) . window . HTMLCanvasElement = ( global as any ) . HTMLCanvasElement = ( global as any ) . HTMLCanvasElement || HTMLCanvasElement ;
24
+ ( global as any ) . window . Canvas = ( global as any ) . Canvas = ( global as any ) . Canvas || HTMLCanvasElement ;
25
+ ( global as any ) . window . CanvasRenderingContext2D = ( global as any ) . CanvasRenderingContext2D = ( global as any ) . CanvasRenderingContext2D || CanvasRenderingContext2D ;
26
+ ( global as any ) . window . WebGLRenderingContext = ( global as any ) . WebGLRenderingContext = ( global as any ) . WebGLRenderingContext || WebGLRenderingContext ;
27
+ ( global as any ) . window . WebGL2RenderingContext = ( global as any ) . WebGL2RenderingContext = ( global as any ) . WebGL2RenderingContext || WebGL2RenderingContext ;
46
28
47
29
function checkEmitter ( ) {
48
- if (
49
- ! ( global as any ) . emitter ||
50
- ! (
51
- ( global as any ) . emitter . on ||
52
- ( global as any ) . emitter . addEventListener ||
53
- ( global as any ) . emitter . addListener
54
- )
55
- ) {
56
- ( global as any ) . window . emitter = ( global as any ) . emitter = fromObject (
57
- { }
58
- ) ;
30
+ if ( ! ( global as any ) . emitter || ! ( ( global as any ) . emitter . on || ( global as any ) . emitter . addEventListener || ( global as any ) . emitter . addListener ) ) {
31
+ ( global as any ) . window . emitter = ( global as any ) . emitter = fromObject ( { } ) ;
59
32
}
60
33
}
61
34
62
- ( global as any ) . window . scrollTo = ( global as any ) . scrollTo =
63
- ( global as any ) . scrollTo || ( ( ) => ( { } ) ) ;
35
+ ( global as any ) . window . scrollTo = ( global as any ) . scrollTo = ( global as any ) . scrollTo || ( ( ) => ( { } ) ) ;
64
36
65
- ( global as any ) . window . addEventListener = ( global as any ) . addEventListener = (
66
- eventName ,
67
- listener
68
- ) => {
37
+ ( global as any ) . window . addEventListener = ( global as any ) . addEventListener = ( eventName , listener ) => {
69
38
checkEmitter ( ) ;
70
39
const addListener = ( ) => {
71
40
if ( ( global as any ) . emitter . on ) {
@@ -79,19 +48,16 @@ function checkEmitter() {
79
48
80
49
addListener ( ) ;
81
50
82
- if ( eventName . toLowerCase ( ) === " load" ) {
51
+ if ( eventName . toLowerCase ( ) === ' load' ) {
83
52
if ( ( global as any ) . emitter && ( global as any ) . emitter . emit ) {
84
53
setTimeout ( ( ) => {
85
- ( global as any ) . emitter . emit ( " load" ) ;
54
+ ( global as any ) . emitter . emit ( ' load' ) ;
86
55
} , 1 ) ;
87
56
}
88
57
}
89
58
} ;
90
59
91
- ( global as any ) . window . removeEventListener = ( global as any ) . removeEventListener = (
92
- eventName ,
93
- listener
94
- ) => {
60
+ ( global as any ) . window . removeEventListener = ( global as any ) . removeEventListener = ( eventName , listener ) => {
95
61
checkEmitter ( ) ;
96
62
if ( ( global as any ) . emitter . off ) {
97
63
( global as any ) . emitter . off ( eventName , listener ) ;
@@ -106,43 +72,30 @@ function checkEmitter() {
106
72
107
73
( global as any ) . window . XMLDocument = ( global as any ) . XMLDocument = XMLDocument ;
108
74
109
- const agent = "chrome" ;
110
- ( global as any ) . window . navigator = ( global as any ) . navigator =
111
- ( global as any ) . navigator || { } ;
112
- ( global as any ) . window . userAgent = ( global as any ) . userAgent =
113
- ( global as any ) . userAgent || agent ;
114
- ( global as any ) . window . navigator . userAgent = ( global as any ) . navigator . userAgent =
115
- ( global as any ) . navigator . userAgent || agent ;
116
- ( global as any ) . window . navigator . product = ( global as any ) . navigator . product =
117
- "NativeScript" ;
118
- ( global as any ) . window . navigator . platform = ( global as any ) . navigator . platform =
119
- ( global as any ) . navigator . platform || [ ] ;
120
- ( global as any ) . window . navigator . appVersion = ( global as any ) . navigator . appVersion =
121
- ( global as any ) . navigator . appVersion || Device . osVersion ;
122
- ( global as any ) . window . navigator . maxTouchPoints = ( global as any ) . navigator . maxTouchPoints =
123
- ( global as any ) . navigator . maxTouchPoints || 5 ;
124
- ( global as any ) . window . navigator . standalone = ( global as any ) . navigator . standalone =
125
- ( global as any ) . navigator . standalone === null
126
- ? true
127
- : ( global as any ) . navigator . standalone ;
75
+ const agent = 'chrome' ;
76
+ ( global as any ) . window . navigator = ( global as any ) . navigator = ( global as any ) . navigator || { } ;
77
+ ( global as any ) . window . userAgent = ( global as any ) . userAgent = ( global as any ) . userAgent || agent ;
78
+ ( global as any ) . window . navigator . userAgent = ( global as any ) . navigator . userAgent = ( global as any ) . navigator . userAgent || agent ;
79
+ ( global as any ) . window . navigator . product = ( global as any ) . navigator . product = 'NativeScript' ;
80
+ ( global as any ) . window . navigator . platform = ( global as any ) . navigator . platform = ( global as any ) . navigator . platform || [ ] ;
81
+ ( global as any ) . window . navigator . appVersion = ( global as any ) . navigator . appVersion = ( global as any ) . navigator . appVersion || Device . osVersion ;
82
+ ( global as any ) . window . navigator . maxTouchPoints = ( global as any ) . navigator . maxTouchPoints = ( global as any ) . navigator . maxTouchPoints || 5 ;
83
+ ( global as any ) . window . navigator . standalone = ( global as any ) . navigator . standalone = ( global as any ) . navigator . standalone === null ? true : ( global as any ) . navigator . standalone ;
128
84
129
- ( global as any ) . window [ "chrome" ] = ( global as any ) [ "chrome" ] = ( global as any ) [
130
- "chrome"
131
- ] || {
85
+ ( global as any ) . window [ 'chrome' ] = ( global as any ) [ 'chrome' ] = ( global as any ) [ 'chrome' ] || {
132
86
extension : { } ,
133
87
} ;
134
88
/// https://www.w3schools.com/js/js_window_location.asp
135
- ( global as any ) . window . location = ( global as any ) . location = ( global as any )
136
- . location || {
137
- href : "" , // window.location.href returns the href (URL) of the current page
138
- hostname : "" , // window.location.hostname returns the domain name of the web host
139
- pathname : "" , // window.location.pathname returns the path and filename of the current page
140
- protocol : "https" , // window.location.protocol returns the web protocol used (http: or https:)
89
+ ( global as any ) . window . location = ( global as any ) . location = ( global as any ) . location || {
90
+ href : '' , // window.location.href returns the href (URL) of the current page
91
+ hostname : '' , // window.location.hostname returns the domain name of the web host
92
+ pathname : '' , // window.location.pathname returns the path and filename of the current page
93
+ protocol : 'https' , // window.location.protocol returns the web protocol used (http: or https:)
141
94
assign : null , // window.location.assign loads a new document
142
95
} ;
143
96
144
97
if ( ( global as any ) . document ) {
145
- ( global as any ) . document . readyState = " complete" ;
98
+ ( global as any ) . document . readyState = ' complete' ;
146
99
}
147
100
148
101
( global as any ) . window . setTimeout = setTimeout ;
@@ -154,7 +107,7 @@ if ((global as any).document) {
154
107
obj . getPropertyValue = function ( prop ) {
155
108
if ( element instanceof View ) {
156
109
let val = element . style . get ( prop ) ;
157
- if ( ( val !== undefined ) && typeof val . value && typeof val . unit ) {
110
+ if ( val !== undefined && typeof val . value && typeof val . unit ) {
158
111
if ( typeof val . value && typeof val . unit ) {
159
112
return `${ val . value } ${ val . unit } ` ;
160
113
}
@@ -165,4 +118,3 @@ if ((global as any).document) {
165
118
} ;
166
119
return obj ;
167
120
} ;
168
-
0 commit comments