2
2
// Project: https://github.com/apache/cordova-plugin-inappbrowser
3
3
// Definitions by: Microsoft Open Technologies Inc <http://msopentech.com>
4
4
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
- //
5
+ //
6
6
// Copyright (c) Microsoft Open Technologies Inc
7
7
// Licensed under the MIT license.
8
+ // TypeScript Version: 2.3
9
+ type channel = "loadstart" | "loadstop" | "loaderror" | "exit" ;
8
10
9
11
interface Window {
10
- /**
11
- * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
12
- * @param url The URL to load.
13
- * @param target The target in which to load the URL, an optional parameter that defaults to _self.
14
- * @param options Options for the InAppBrowser. Optional, defaulting to: location=yes.
15
- * The options string must not contain any blank space, and each feature's
16
- * name/value pairs must be separated by a comma. Feature names are case insensitive.
17
- */
18
- open ( url : string , target ?: "_self" , options ?: string ) : InAppBrowser ;
19
- /**
20
- * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
21
- * @param url The URL to load.
22
- * @param target The target in which to load the URL, an optional parameter that defaults to _self.
23
- * @param options Options for the InAppBrowser. Optional, defaulting to: location=yes.
24
- * The options string must not contain any blank space, and each feature's
25
- * name/value pairs must be separated by a comma. Feature names are case insensitive.
26
- */
27
- open ( url : string , target ?: "_blank" , options ?: string ) : InAppBrowser ;
28
- /**
29
- * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
30
- * @param url The URL to load.
31
- * @param target The target in which to load the URL, an optional parameter that defaults to _self.
32
- * @param options Options for the InAppBrowser. Optional, defaulting to: location=yes.
33
- * The options string must not contain any blank space, and each feature's
34
- * name/value pairs must be separated by a comma. Feature names are case insensitive.
35
- */
36
- open ( url : string , target ?: "_system" , options ?: string ) : InAppBrowser ;
37
12
/**
38
13
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
39
14
* @param url The URL to load.
@@ -50,66 +25,21 @@ interface Window {
50
25
* NOTE: The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs.
51
26
*/
52
27
interface InAppBrowser extends Window {
53
- onloadstart : ( type : InAppBrowserEvent ) => void ;
54
- onloadstop : ( type : InAppBrowserEvent ) => void ;
55
- onloaderror : ( type : InAppBrowserEvent ) => void ;
56
- onexit : ( type : InAppBrowserEvent ) => void ;
28
+ onloadstart ( type : Event ) : void ;
29
+ onloadstop ( type : InAppBrowserEvent ) : void ;
30
+ onloaderror ( type : InAppBrowserEvent ) : void ;
31
+ onexit ( type : InAppBrowserEvent ) : void ;
57
32
// addEventListener overloads
58
33
/**
59
34
* Adds a listener for an event from the InAppBrowser.
60
- * @param type the event to listen for
61
- * loadstart: event fires when the InAppBrowser starts to load a URL.
62
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
63
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
64
- * exit: event fires when the InAppBrowser window is closed.
65
- * @param callback the function that executes when the event fires. The function is
66
- * passed an InAppBrowserEvent object as a parameter.
67
- */
68
- addEventListener ( type : "loadstart" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
69
- /**
70
- * Adds a listener for an event from the InAppBrowser.
71
- * @param type the event to listen for
72
- * loadstart: event fires when the InAppBrowser starts to load a URL.
73
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
74
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
75
- * exit: event fires when the InAppBrowser window is closed.
76
- * @param callback the function that executes when the event fires. The function is
77
- * passed an InAppBrowserEvent object as a parameter.
78
- */
79
- addEventListener ( type : "loadstop" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
80
- /**
81
- * Adds a listener for an event from the InAppBrowser.
82
- * @param type the event to listen for
83
- * loadstart: event fires when the InAppBrowser starts to load a URL.
84
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
85
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
86
- * exit: event fires when the InAppBrowser window is closed.
87
- * @param callback the function that executes when the event fires. The function is
88
- * passed an InAppBrowserEvent object as a parameter.
89
- */
90
- addEventListener ( type : "loaderror" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
91
- /**
92
- * Adds a listener for an event from the InAppBrowser.
93
- * @param type the event to listen for
94
- * loadstart: event fires when the InAppBrowser starts to load a URL.
35
+ * @param type loadstart: event fires when the InAppBrowser starts to load a URL.
95
36
* loadstop: event fires when the InAppBrowser finishes loading a URL.
96
37
* loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
97
38
* exit: event fires when the InAppBrowser window is closed.
98
39
* @param callback the function that executes when the event fires. The function is
99
40
* passed an InAppBrowserEvent object as a parameter.
100
41
*/
101
- addEventListener ( type : "exit" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
102
- /**
103
- * Adds a listener for an event from the InAppBrowser.
104
- * @param type the event to listen for
105
- * loadstart: event fires when the InAppBrowser starts to load a URL.
106
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
107
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
108
- * exit: event fires when the InAppBrowser window is closed.
109
- * @param callback the function that executes when the event fires. The function is
110
- * passed an Event object as a parameter.
111
- */
112
- addEventListener ( type : string , callback : ( event : Event ) => void ) : void ;
42
+ addEventListener ( type : channel , callback : InAppBrowserEventListenerOrEventListenerObject ) : void ;
113
43
// removeEventListener overloads
114
44
/**
115
45
* Removes a listener for an event from the InAppBrowser.
@@ -121,51 +51,7 @@ interface InAppBrowser extends Window {
121
51
* @param callback the function that executes when the event fires. The function is
122
52
* passed an InAppBrowserEvent object as a parameter.
123
53
*/
124
- removeEventListener ( type : "loadstart" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
125
- /**
126
- * Removes a listener for an event from the InAppBrowser.
127
- * @param type The event to stop listening for.
128
- * loadstart: event fires when the InAppBrowser starts to load a URL.
129
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
130
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
131
- * exit: event fires when the InAppBrowser window is closed.
132
- * @param callback the function that executes when the event fires. The function is
133
- * passed an InAppBrowserEvent object as a parameter.
134
- */
135
- removeEventListener ( type : "loadstop" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
136
- /**
137
- * Removes a listener for an event from the InAppBrowser.
138
- * @param type The event to stop listening for.
139
- * loadstart: event fires when the InAppBrowser starts to load a URL.
140
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
141
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
142
- * exit: event fires when the InAppBrowser window is closed.
143
- * @param callback the function that executes when the event fires. The function is
144
- * passed an InAppBrowserEvent object as a parameter.
145
- */
146
- removeEventListener ( type : "loaderror" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
147
- /**
148
- * Removes a listener for an event from the InAppBrowser.
149
- * @param type The event to stop listening for.
150
- * loadstart: event fires when the InAppBrowser starts to load a URL.
151
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
152
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
153
- * exit: event fires when the InAppBrowser window is closed.
154
- * @param callback the function that executes when the event fires. The function is
155
- * passed an InAppBrowserEvent object as a parameter.
156
- */
157
- removeEventListener ( type : "exit" , callback : ( event : InAppBrowserEvent ) => void ) : void ;
158
- /**
159
- * Removes a listener for an event from the InAppBrowser.
160
- * @param type The event to stop listening for.
161
- * loadstart: event fires when the InAppBrowser starts to load a URL.
162
- * loadstop: event fires when the InAppBrowser finishes loading a URL.
163
- * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
164
- * exit: event fires when the InAppBrowser window is closed.
165
- * @param callback the function that executes when the event fires. The function is
166
- * passed an Event object as a parameter.
167
- */
168
- removeEventListener ( type : string , callback : ( event : Event ) => void ) : void ;
54
+ removeEventListener ( type : channel , callback : InAppBrowserEventListenerOrEventListenerObject ) : void ;
169
55
/** Closes the InAppBrowser window. */
170
56
close ( ) : void ;
171
57
/** Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden. */
@@ -184,29 +70,21 @@ interface InAppBrowser extends Window {
184
70
* For multi-line scripts, this is the return value of the last statement,
185
71
* or the last expression evaluated.
186
72
*/
187
- executeScript ( script : { code : string } , callback : ( result : any ) => void ) : void ;
188
- /**
189
- * Injects JavaScript code into the InAppBrowser window.
190
- * @param script Details of the script to run, specifying either a file or code key.
191
- * @param callback The function that executes after the JavaScript code is injected.
192
- * If the injected script is of type code, the callback executes with
193
- * a single parameter, which is the return value of the script, wrapped in an Array.
194
- * For multi-line scripts, this is the return value of the last statement,
195
- * or the last expression evaluated.
196
- */
197
- executeScript ( script : { file : string } , callback : ( result : any ) => void ) : void ;
198
- /**
199
- * Injects CSS into the InAppBrowser window.
200
- * @param css Details of the script to run, specifying either a file or code key.
201
- * @param callback The function that executes after the CSS is injected.
202
- */
203
- insertCSS ( css : { code : string } , callback : ( ) => void ) : void ;
73
+ executeScript ( script : { code : string } | { file : string } , callback : ( result : any ) => void ) : void ;
204
74
/**
205
75
* Injects CSS into the InAppBrowser window.
206
76
* @param css Details of the script to run, specifying either a file or code key.
207
77
* @param callback The function that executes after the CSS is injected.
208
78
*/
209
- insertCSS ( css : { file : string } , callback : ( ) => void ) : void ;
79
+ insertCSS ( css : { code : string } | { file : string } , callback : ( ) => void ) : void ;
80
+ }
81
+
82
+ type InAppBrowserEventListenerOrEventListenerObject = InAppBrowserEventListener | InAppBrowserEventListenerObject ;
83
+
84
+ type InAppBrowserEventListener = ( evt : InAppBrowserEvent ) => void ;
85
+
86
+ interface InAppBrowserEventListenerObject {
87
+ handleEvent ( evt : InAppBrowserEvent ) : void ;
210
88
}
211
89
212
90
interface InAppBrowserEvent extends Event {
@@ -218,4 +96,8 @@ interface InAppBrowserEvent extends Event {
218
96
code : number ;
219
97
/** the error message, only in the case of loaderror. */
220
98
message : string ;
221
- }
99
+ }
100
+
101
+ interface Cordova {
102
+ InAppBrowser : InAppBrowser ;
103
+ }
0 commit comments