Skip to content

Commit a0c267f

Browse files
timbru31janpio
authored andcommitted
CB-12941: update typings (#267)
### Platforms affected n/a - development with TypeScript ### What does this PR do? Updates the typings to match the latest published version on DefinitelyTyped. See DefinitelyTyped/DefinitelyTyped#17192 and https://stackoverflow.com/q/42095516/1902598 ### What testing has been done on this change? Project compiles again ;) ### Checklist - [x] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database - [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected. - n/a: Added automated test coverage as appropriate for this change. fixes #300
1 parent 0ed0bf5 commit a0c267f

File tree

1 file changed

+25
-143
lines changed

1 file changed

+25
-143
lines changed

types/index.d.ts

Lines changed: 25 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,13 @@
22
// Project: https://github.com/apache/cordova-plugin-inappbrowser
33
// Definitions by: Microsoft Open Technologies Inc <http://msopentech.com>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5-
//
5+
//
66
// Copyright (c) Microsoft Open Technologies Inc
77
// Licensed under the MIT license.
8+
// TypeScript Version: 2.3
9+
type channel = "loadstart" | "loadstop" | "loaderror" | "exit";
810

911
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;
3712
/**
3813
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
3914
* @param url The URL to load.
@@ -50,66 +25,21 @@ interface Window {
5025
* NOTE: The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs.
5126
*/
5227
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;
5732
// addEventListener overloads
5833
/**
5934
* 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.
9536
* loadstop: event fires when the InAppBrowser finishes loading a URL.
9637
* loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
9738
* exit: event fires when the InAppBrowser window is closed.
9839
* @param callback the function that executes when the event fires. The function is
9940
* passed an InAppBrowserEvent object as a parameter.
10041
*/
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;
11343
// removeEventListener overloads
11444
/**
11545
* Removes a listener for an event from the InAppBrowser.
@@ -121,51 +51,7 @@ interface InAppBrowser extends Window {
12151
* @param callback the function that executes when the event fires. The function is
12252
* passed an InAppBrowserEvent object as a parameter.
12353
*/
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;
16955
/** Closes the InAppBrowser window. */
17056
close(): void;
17157
/** Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden. */
@@ -184,29 +70,21 @@ interface InAppBrowser extends Window {
18470
* For multi-line scripts, this is the return value of the last statement,
18571
* or the last expression evaluated.
18672
*/
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;
20474
/**
20575
* Injects CSS into the InAppBrowser window.
20676
* @param css Details of the script to run, specifying either a file or code key.
20777
* @param callback The function that executes after the CSS is injected.
20878
*/
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;
21088
}
21189

21290
interface InAppBrowserEvent extends Event {
@@ -218,4 +96,8 @@ interface InAppBrowserEvent extends Event {
21896
code: number;
21997
/** the error message, only in the case of loaderror. */
22098
message: string;
221-
}
99+
}
100+
101+
interface Cordova {
102+
InAppBrowser: InAppBrowser;
103+
}

0 commit comments

Comments
 (0)