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 | // TypeScript Version: 2.3
|
9 | type channel = "loadstart" | "loadstop" | "loaderror" | "exit" | "message" | "customscheme";
|
10 |
|
11 | /**
|
12 | * The object returned from a call to cordova.InAppBrowser.open.
|
13 | * NOTE: The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs.
|
14 | */
|
15 | interface InAppBrowser {
|
16 |
|
17 | /**
|
18 | * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
|
19 | * @param url The URL to load.
|
20 | * @param target The target in which to load the URL, an optional parameter that defaults to _self.
|
21 | * @param options Options for the InAppBrowser. Optional, defaulting to: location=yes.
|
22 | * The options string must not contain any blank space, and each feature's
|
23 | * name/value pairs must be separated by a comma. Feature names are case insensitive.
|
24 | */
|
25 | open(url: string, target?: string, options?: string): InAppBrowser;
|
26 |
|
27 | onloadstart(type: Event): void;
|
28 | onloadstop(type: InAppBrowserEvent): void;
|
29 | onloaderror(type: InAppBrowserEvent): void;
|
30 | onexit(type: InAppBrowserEvent): void;
|
31 | // addEventListener overloads
|
32 | /**
|
33 | * Adds a listener for an event from the InAppBrowser.
|
34 | * @param type loadstart: event fires when the InAppBrowser starts to load a URL.
|
35 | * loadstop: event fires when the InAppBrowser finishes loading a URL.
|
36 | * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
|
37 | * exit: event fires when the InAppBrowser window is closed.
|
38 | * @param callback the function that executes when the event fires. The function is
|
39 | * passed an InAppBrowserEvent object as a parameter.
|
40 | */
|
41 | addEventListener(type: channel, callback: InAppBrowserEventListenerOrEventListenerObject): void;
|
42 | /**
|
43 | * Adds a listener for an event from the InAppBrowser.
|
44 | * @param type any custom event that might occur.
|
45 | * @param callback the function that executes when the event fires. The function is
|
46 | * passed an InAppBrowserEvent object as a parameter.
|
47 | */
|
48 | addEventListener(type: string, callback: InAppBrowserEventListenerOrEventListenerObject): void;
|
49 | // removeEventListener overloads
|
50 | /**
|
51 | * Removes a listener for an event from the InAppBrowser.
|
52 | * @param type The event to stop listening for.
|
53 | * loadstart: event fires when the InAppBrowser starts to load a URL.
|
54 | * loadstop: event fires when the InAppBrowser finishes loading a URL.
|
55 | * loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
|
56 | * exit: event fires when the InAppBrowser window is closed.
|
57 | * @param callback the function that executes when the event fires. The function is
|
58 | * passed an InAppBrowserEvent object as a parameter.
|
59 | */
|
60 | removeEventListener(type: channel, callback: InAppBrowserEventListenerOrEventListenerObject): void;
|
61 | /** Closes the InAppBrowser window. */
|
62 | close(): void;
|
63 | /** Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden. */
|
64 | hide(): void;
|
65 | /**
|
66 | * Displays an InAppBrowser window that was opened hidden. Calling this has no effect
|
67 | * if the InAppBrowser was already visible.
|
68 | */
|
69 | show(): void;
|
70 | /**
|
71 | * Injects JavaScript code into the InAppBrowser window.
|
72 | * @param script Details of the script to run, specifying either a file or code key.
|
73 | * @param callback The function that executes after the JavaScript code is injected.
|
74 | * If the injected script is of type code, the callback executes with
|
75 | * a single parameter, which is the return value of the script, wrapped in an Array.
|
76 | * For multi-line scripts, this is the return value of the last statement,
|
77 | * or the last expression evaluated.
|
78 | */
|
79 | executeScript(script: { code: string } | { file: string }, callback: (result: any) => void): void;
|
80 | /**
|
81 | * Injects CSS into the InAppBrowser window.
|
82 | * @param css Details of the script to run, specifying either a file or code key.
|
83 | * @param callback The function that executes after the CSS is injected.
|
84 | */
|
85 | insertCSS(css: { code: string } | { file: string }, callback: () => void): void;
|
86 | }
|
87 |
|
88 | type InAppBrowserEventListenerOrEventListenerObject = InAppBrowserEventListener | InAppBrowserEventListenerObject;
|
89 |
|
90 | type InAppBrowserEventListener = (evt: InAppBrowserEvent) => void;
|
91 |
|
92 | interface InAppBrowserEventListenerObject {
|
93 | handleEvent(evt: InAppBrowserEvent): void;
|
94 | }
|
95 |
|
96 | interface InAppBrowserEvent extends Event {
|
97 | /** the eventname, either loadstart, loadstop, loaderror, or exit. */
|
98 | type: string;
|
99 | /** the URL that was loaded. */
|
100 | url: string;
|
101 | /** the error code, only in the case of loaderror. */
|
102 | code: number;
|
103 | /** the error message, only in the case of loaderror. */
|
104 | message: string;
|
105 | }
|
106 |
|
107 | interface Cordova {
|
108 | InAppBrowser: InAppBrowser;
|
109 | }
|