UNPKG

4.43 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9var Observable_1 = require('rxjs/Observable');
10/**
11 * @name InAppBrowser
12 * @description Launches in app Browser
13 * @usage
14 * ```typescript
15 * import {InAppBrowser} from 'ionic-native';
16 *
17 *
18 * ...
19 *
20 *
21 * let browser = new InAppBrowser('https://ionic.io', '_system');
22 * browser.executeScript(...);
23 * browser.insertCSS(...);
24 * browser.close();
25 * ```
26 * @interfaces
27 * InAppBrowserEvent
28 * InAppBrowserOptions
29 */
30var InAppBrowser = (function () {
31 function InAppBrowser(url, target, options) {
32 try {
33 if (options && typeof options !== 'string')
34 options = Object.keys(options).map(function (key) { return (key + "=" + options[key]); }).join(',');
35 this._objectInstance = cordova.InAppBrowser.open(url, target, options);
36 }
37 catch (e) {
38 window.open(url);
39 console.warn('Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open, all instance methods will NOT work.');
40 }
41 }
42 /**
43 * Displays an InAppBrowser window that was opened hidden. Calling this has no effect
44 * if the InAppBrowser was already visible.
45 */
46 InAppBrowser.prototype.show = function () { };
47 /**
48 * Closes the InAppBrowser window.
49 */
50 InAppBrowser.prototype.close = function () { };
51 /**
52 * Hides an InAppBrowser window that is currently shown. Calling this has no effect
53 * if the InAppBrowser was already hidden.
54 */
55 InAppBrowser.prototype.hide = function () { };
56 /**
57 * Injects JavaScript code into the InAppBrowser window.
58 * @param script {Object} Details of the script to run, specifying either a file or code key.
59 * @returns {Promise<any>}
60 */
61 InAppBrowser.prototype.executeScript = function (script) { return; };
62 /**
63 * Injects CSS into the InAppBrowser window.
64 * @param css {Object} Details of the script to run, specifying either a file or code key.
65 * @returns {Promise<any>}
66 */
67 InAppBrowser.prototype.insertCSS = function (css) { return; };
68 /**
69 * A method that allows you to listen to events happening in the browser.
70 * @param {string} name of the event
71 * @returns {Observable<InAppBrowserEvent>} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe.
72 */
73 InAppBrowser.prototype.on = function (event) {
74 var _this = this;
75 return new Observable_1.Observable(function (observer) {
76 _this._objectInstance.addEventListener(event, observer.next.bind(observer));
77 return function () { return _this._objectInstance.removeEventListener(event, observer.next.bind(observer)); };
78 });
79 };
80 __decorate([
81 plugin_1.CordovaInstance({ sync: true })
82 ], InAppBrowser.prototype, "show", null);
83 __decorate([
84 plugin_1.CordovaInstance({ sync: true })
85 ], InAppBrowser.prototype, "close", null);
86 __decorate([
87 plugin_1.CordovaInstance({ sync: true })
88 ], InAppBrowser.prototype, "hide", null);
89 __decorate([
90 plugin_1.CordovaInstance()
91 ], InAppBrowser.prototype, "executeScript", null);
92 __decorate([
93 plugin_1.CordovaInstance()
94 ], InAppBrowser.prototype, "insertCSS", null);
95 InAppBrowser = __decorate([
96 plugin_1.Plugin({
97 pluginName: 'InAppBrowser',
98 plugin: 'cordova-plugin-inappbrowser',
99 pluginRef: 'cordova.InAppBrowser',
100 repo: 'https://github.com/apache/cordova-plugin-inappbrowser'
101 })
102 ], InAppBrowser);
103 return InAppBrowser;
104}());
105exports.InAppBrowser = InAppBrowser;
106//# sourceMappingURL=inappbrowser.js.map
\No newline at end of file