UNPKG

13.5 kBTypeScriptView Raw
1// Type definitions for Apache Cordova InAppBrowser plugin
2// Project: https://github.com/apache/cordova-plugin-inappbrowser
3// Definitions by: Microsoft Open Technologies Inc <http://msopentech.com>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5//
6// Copyright (c) Microsoft Open Technologies Inc
7// Licensed under the MIT license.
8
9interface 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 /**
38 * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
39 * @param url The URL to load.
40 * @param target The target in which to load the URL, an optional parameter that defaults to _self.
41 * @param options Options for the InAppBrowser. Optional, defaulting to: location=yes.
42 * The options string must not contain any blank space, and each feature's
43 * name/value pairs must be separated by a comma. Feature names are case insensitive.
44 */
45 open(url: string, target?: string, options?: string, replace?: boolean): InAppBrowser;
46}
47
48/**
49 * The object returned from a call to window.open.
50 * NOTE: The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs.
51 */
52interface InAppBrowser extends Window {
53 onloadstart: (type: InAppBrowserEvent) => void;
54 onloadstop: (type: InAppBrowserEvent) => void;
55 onloaderror: (type: InAppBrowserEvent) => void;
56 onexit: (type: InAppBrowserEvent) => void;
57 // addEventListener overloads
58 /**
59 * 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.
95 * loadstop: event fires when the InAppBrowser finishes loading a URL.
96 * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
97 * exit: event fires when the InAppBrowser window is closed.
98 * @param callback the function that executes when the event fires. The function is
99 * passed an InAppBrowserEvent object as a parameter.
100 */
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;
113 // removeEventListener overloads
114 /**
115 * Removes a listener for an event from the InAppBrowser.
116 * @param type The event to stop listening for.
117 * loadstart: event fires when the InAppBrowser starts to load a URL.
118 * loadstop: event fires when the InAppBrowser finishes loading a URL.
119 * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
120 * exit: event fires when the InAppBrowser window is closed.
121 * @param callback the function that executes when the event fires. The function is
122 * passed an InAppBrowserEvent object as a parameter.
123 */
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;
169 /** Closes the InAppBrowser window. */
170 close(): void;
171 /**
172 * Displays an InAppBrowser window that was opened hidden. Calling this has no effect
173 * if the InAppBrowser was already visible.
174 */
175 show(): void;
176 /**
177 * Injects JavaScript code into the InAppBrowser window.
178 * @param script Details of the script to run, specifying either a file or code key.
179 * @param callback The function that executes after the JavaScript code is injected.
180 * If the injected script is of type code, the callback executes with
181 * a single parameter, which is the return value of the script, wrapped in an Array.
182 * For multi-line scripts, this is the return value of the last statement,
183 * or the last expression evaluated.
184 */
185 executeScript(script: { code: string }, callback: (result: any) => void): void;
186 /**
187 * Injects JavaScript code into the InAppBrowser window.
188 * @param script Details of the script to run, specifying either a file or code key.
189 * @param callback The function that executes after the JavaScript code is injected.
190 * If the injected script is of type code, the callback executes with
191 * a single parameter, which is the return value of the script, wrapped in an Array.
192 * For multi-line scripts, this is the return value of the last statement,
193 * or the last expression evaluated.
194 */
195 executeScript(script: { file: string }, callback: (result: any) => void): void;
196 /**
197 * Injects CSS into the InAppBrowser window.
198 * @param css Details of the script to run, specifying either a file or code key.
199 * @param callback The function that executes after the CSS is injected.
200 */
201 insertCSS(css: { code: string }, callback: () => void): void;
202 /**
203 * Injects CSS into the InAppBrowser window.
204 * @param css Details of the script to run, specifying either a file or code key.
205 * @param callback The function that executes after the CSS is injected.
206 */
207 insertCSS(css: { file: string }, callback: () => void): void;
208}
209
210interface InAppBrowserEvent extends Event {
211 /** the eventname, either loadstart, loadstop, loaderror, or exit. */
212 type: string;
213 /** the URL that was loaded. */
214 url: string;
215 /** the error code, only in the case of loaderror. */
216 code: number;
217 /** the error message, only in the case of loaderror. */
218 message: string;
219}
\No newline at end of file