-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
603 lines (590 loc) · 21.6 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var rxjs = require('rxjs');
function checkReady() {
if (typeof process === 'undefined') {
var win_1 = typeof window !== 'undefined' ? window : {};
var DEVICE_READY_TIMEOUT_1 = 5000;
// To help developers using cordova, we listen for the device ready event and
// log an error if it didn't fire in a reasonable amount of time. Generally,
// when this happens, developers should remove and reinstall plugins, since
// an inconsistent plugin is often the culprit.
var before_1 = Date.now();
var didFireReady_1 = false;
win_1.document.addEventListener('deviceready', function () {
console.log("Ionic Native: deviceready event fired after " + (Date.now() - before_1) + " ms");
didFireReady_1 = true;
});
setTimeout(function () {
if (!didFireReady_1 && win_1.cordova) {
console.warn("Ionic Native: deviceready did not fire within " + DEVICE_READY_TIMEOUT_1 + "ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.");
}
}, DEVICE_READY_TIMEOUT_1);
}
}
var ERR_CORDOVA_NOT_AVAILABLE = { error: 'cordova_not_available' };
var ERR_PLUGIN_NOT_INSTALLED = { error: 'plugin_not_installed' };
function getPromise(callback) {
var tryNativePromise = function () {
if (Promise) {
return new Promise(function (resolve, reject) {
callback(resolve, reject);
});
}
else {
console.error('No Promise support or polyfill found. To enable Ionic Native support, please add the es6-promise polyfill before this script, or run with a library like Angular or on a recent browser.');
}
};
if (typeof window !== 'undefined' && window.angular) {
var doc = window.document;
var injector = window.angular.element(doc.querySelector('[ng-app]') || doc.body).injector();
if (injector) {
var $q = injector.get('$q');
return $q(function (resolve, reject) {
callback(resolve, reject);
});
}
console.warn("Angular 1 was detected but $q couldn't be retrieved. This is usually when the app is not bootstrapped on the html or body tag. Falling back to native promises which won't trigger an automatic digest when promises resolve.");
}
return tryNativePromise();
}
function wrapPromise(pluginObj, methodName, args, opts) {
if (opts === void 0) { opts = {}; }
var pluginResult, rej;
var p = getPromise(function (resolve, reject) {
if (opts.destruct) {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return resolve(args);
}, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return reject(args);
});
}
else {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject);
}
rej = reject;
});
// Angular throws an error on unhandled rejection, but in this case we have already printed
// a warning that Cordova is undefined or the plugin is uninstalled, so there is no reason
// to error
if (pluginResult && pluginResult.error) {
p.catch(function () { });
typeof rej === 'function' && rej(pluginResult.error);
}
return p;
}
function wrapOtherPromise(pluginObj, methodName, args, opts) {
if (opts === void 0) { opts = {}; }
return getPromise(function (resolve, reject) {
var pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts);
if (pluginResult) {
if (pluginResult.error) {
reject(pluginResult.error);
}
else if (pluginResult.then) {
pluginResult.then(resolve).catch(reject);
}
}
else {
reject({ error: 'unexpected_error' });
}
});
}
function wrapObservable(pluginObj, methodName, args, opts) {
if (opts === void 0) { opts = {}; }
return new rxjs.Observable(function (observer) {
var pluginResult;
if (opts.destruct) {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return observer.next(args);
}, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return observer.error(args);
});
}
else {
pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, observer.next.bind(observer), observer.error.bind(observer));
}
if (pluginResult && pluginResult.error) {
observer.error(pluginResult.error);
observer.complete();
}
return function () {
try {
if (opts.clearFunction) {
if (opts.clearWithArgs) {
return callCordovaPlugin(pluginObj, opts.clearFunction, args, opts, observer.next.bind(observer), observer.error.bind(observer));
}
return callCordovaPlugin(pluginObj, opts.clearFunction, []);
}
}
catch (e) {
console.warn('Unable to clear the previous observable watch for', pluginObj.constructor.getPluginName(), methodName);
console.warn(e);
}
};
});
}
/**
* Wrap the event with an observable
* @private
* @param event event name
* @param element The element to attach the event listener to
* @returns {Observable}
*/
function wrapEventObservable(event, element) {
element =
typeof window !== 'undefined' && element
? get$1(window, element)
: element || (typeof window !== 'undefined' ? window : {});
return rxjs.fromEvent(element, event);
}
function checkAvailability(plugin, methodName, pluginName) {
var pluginRef, pluginInstance, pluginPackage;
if (typeof plugin === 'string') {
pluginRef = plugin;
}
else {
pluginRef = plugin.constructor.getPluginRef();
pluginName = plugin.constructor.getPluginName();
pluginPackage = plugin.constructor.getPluginInstallName();
}
pluginInstance = getPlugin(pluginRef);
if (!pluginInstance || (!!methodName && typeof pluginInstance[methodName] === 'undefined')) {
if (typeof window === 'undefined' || !window.cordova) {
cordovaWarn(pluginName, methodName);
return ERR_CORDOVA_NOT_AVAILABLE;
}
pluginWarn(pluginName, pluginPackage, methodName);
return ERR_PLUGIN_NOT_INSTALLED;
}
return true;
}
/**
* Checks if _objectInstance exists and has the method/property
* @private
*/
function instanceAvailability(pluginObj, methodName) {
return pluginObj._objectInstance && (!methodName || typeof pluginObj._objectInstance[methodName] !== 'undefined');
}
function setIndex(args, opts, resolve, reject) {
if (opts === void 0) { opts = {}; }
// ignore resolve and reject in case sync
if (opts.sync) {
return args;
}
// If the plugin method expects myMethod(success, err, options)
if (opts.callbackOrder === 'reverse') {
// Get those arguments in the order [resolve, reject, ...restOfArgs]
args.unshift(reject);
args.unshift(resolve);
}
else if (opts.callbackStyle === 'node') {
args.push(function (err, result) {
if (err) {
reject(err);
}
else {
resolve(result);
}
});
}
else if (opts.callbackStyle === 'object' && opts.successName && opts.errorName) {
var obj = {};
obj[opts.successName] = resolve;
obj[opts.errorName] = reject;
args.push(obj);
}
else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
var setSuccessIndex = function () {
// If we've specified a success/error index
if (opts.successIndex > args.length) {
args[opts.successIndex] = resolve;
}
else {
args.splice(opts.successIndex, 0, resolve);
}
};
var setErrorIndex = function () {
// We don't want that the reject cb gets spliced into the position of an optional argument that has not been
// defined and thus causing non expected behavior.
if (opts.errorIndex > args.length) {
args[opts.errorIndex] = reject; // insert the reject fn at the correct specific index
}
else {
args.splice(opts.errorIndex, 0, reject); // otherwise just splice it into the array
}
};
if (opts.successIndex > opts.errorIndex) {
setErrorIndex();
setSuccessIndex();
}
else {
setSuccessIndex();
setErrorIndex();
}
}
else {
// Otherwise, let's tack them on to the end of the argument list
// which is 90% of cases
args.push(resolve);
args.push(reject);
}
return args;
}
function callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject) {
if (opts === void 0) { opts = {}; }
// Try to figure out where the success/error callbacks need to be bound
// to our promise resolve/reject handlers.
args = setIndex(args, opts, resolve, reject);
var availabilityCheck = checkAvailability(pluginObj, methodName);
if (availabilityCheck === true) {
var pluginInstance = getPlugin(pluginObj.constructor.getPluginRef());
return pluginInstance[methodName].apply(pluginInstance, args);
}
else {
return availabilityCheck;
}
}
function callInstance(pluginObj, methodName, args, opts, resolve, reject) {
if (opts === void 0) { opts = {}; }
args = setIndex(args, opts, resolve, reject);
if (instanceAvailability(pluginObj, methodName)) {
return pluginObj._objectInstance[methodName].apply(pluginObj._objectInstance, args);
}
}
function getPlugin(pluginRef) {
if (typeof window !== 'undefined') {
return get$1(window, pluginRef);
}
return null;
}
function get$1(element, path) {
var paths = path.split('.');
var obj = element;
for (var i = 0; i < paths.length; i++) {
if (!obj) {
return null;
}
obj = obj[paths[i]];
}
return obj;
}
function pluginWarn(pluginName, plugin, method) {
if (method) {
console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
}
else {
console.warn("Native: tried accessing the " + pluginName + " plugin but it's not installed.");
}
if (plugin) {
console.warn("Install the " + pluginName + " plugin: 'ionic cordova plugin add " + plugin + "'");
}
}
/**
* @private
* @param pluginName
* @param method
*/
function cordovaWarn(pluginName, method) {
if (typeof process === 'undefined') {
if (method) {
console.warn('Native: tried calling ' +
pluginName +
'.' +
method +
', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
}
else {
console.warn('Native: tried accessing the ' +
pluginName +
' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
}
}
}
/**
* @private
*/
var wrap = function (pluginObj, methodName, opts) {
if (opts === void 0) { opts = {}; }
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (opts.sync) {
// Sync doesn't wrap the plugin with a promise or observable, it returns the result as-is
return callCordovaPlugin(pluginObj, methodName, args, opts);
}
else if (opts.observable) {
return wrapObservable(pluginObj, methodName, args, opts);
}
else if (opts.eventObservable && opts.event) {
return wrapEventObservable(opts.event, opts.element);
}
else if (opts.otherPromise) {
return wrapOtherPromise(pluginObj, methodName, args, opts);
}
else {
return wrapPromise(pluginObj, methodName, args, opts);
}
};
};
/**
* @private
*/
function wrapInstance(pluginObj, methodName, opts) {
if (opts === void 0) { opts = {}; }
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (opts.sync) {
return callInstance(pluginObj, methodName, args, opts);
}
else if (opts.observable) {
return new rxjs.Observable(function (observer) {
var pluginResult;
if (opts.destruct) {
pluginResult = callInstance(pluginObj, methodName, args, opts, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return observer.next(args);
}, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return observer.error(args);
});
}
else {
pluginResult = callInstance(pluginObj, methodName, args, opts, observer.next.bind(observer), observer.error.bind(observer));
}
if (pluginResult && pluginResult.error) {
observer.error(pluginResult.error);
}
return function () {
try {
if (opts.clearWithArgs) {
return callInstance(pluginObj, opts.clearFunction, args, opts, observer.next.bind(observer), observer.error.bind(observer));
}
return callInstance(pluginObj, opts.clearFunction, []);
}
catch (e) {
console.warn('Unable to clear the previous observable watch for', pluginObj.constructor.getPluginName(), methodName);
console.warn(e);
}
};
});
}
else if (opts.otherPromise) {
return getPromise(function (resolve, reject) {
var result;
if (opts.destruct) {
result = callInstance(pluginObj, methodName, args, opts, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return resolve(args);
}, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return reject(args);
});
}
else {
result = callInstance(pluginObj, methodName, args, opts, resolve, reject);
}
if (result && result.then) {
result.then(resolve, reject);
}
else {
reject();
}
});
}
else {
var pluginResult_1, rej_1;
var p = getPromise(function (resolve, reject) {
if (opts.destruct) {
pluginResult_1 = callInstance(pluginObj, methodName, args, opts, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return resolve(args);
}, function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return reject(args);
});
}
else {
pluginResult_1 = callInstance(pluginObj, methodName, args, opts, resolve, reject);
}
rej_1 = reject;
});
// Angular throws an error on unhandled rejection, but in this case we have already printed
// a warning that Cordova is undefined or the plugin is uninstalled, so there is no reason
// to error
if (pluginResult_1 && pluginResult_1.error) {
p.catch(function () { });
typeof rej_1 === 'function' && rej_1(pluginResult_1.error);
}
return p;
}
};
}
/**
* @private
*/
function get(element, path) {
var paths = path.split('.');
var obj = element;
for (var i = 0; i < paths.length; i++) {
if (!obj) {
return null;
}
obj = obj[paths[i]];
}
return obj;
}
var IonicNativePlugin = /** @class */ (function () {
function IonicNativePlugin() {
}
/**
* Returns a boolean that indicates whether the plugin is installed
* @return {boolean}
*/
IonicNativePlugin.installed = function () {
var isAvailable = checkAvailability(this.pluginRef) === true;
return isAvailable;
};
/**
* Returns the original plugin object
*/
IonicNativePlugin.getPlugin = function () {
if (typeof window !== 'undefined') {
return get(window, this.pluginRef);
}
return null;
};
/**
* Returns the plugin's name
*/
IonicNativePlugin.getPluginName = function () {
var pluginName = this.pluginName;
return pluginName;
};
/**
* Returns the plugin's reference
*/
IonicNativePlugin.getPluginRef = function () {
var pluginRef = this.pluginRef;
return pluginRef;
};
/**
* Returns the plugin's install name
*/
IonicNativePlugin.getPluginInstallName = function () {
var plugin = this.plugin;
return plugin;
};
/**
* Returns the plugin's supported platforms
*/
IonicNativePlugin.getSupportedPlatforms = function () {
var platform = this.platforms;
return platform;
};
IonicNativePlugin.pluginName = '';
IonicNativePlugin.pluginRef = '';
IonicNativePlugin.plugin = '';
IonicNativePlugin.repo = '';
IonicNativePlugin.platforms = [];
IonicNativePlugin.install = '';
return IonicNativePlugin;
}());
function cordova(pluginObj, methodName, config, args) {
return wrap(pluginObj, methodName, config).apply(this, args);
}
function overrideFunction(pluginObj, methodName) {
return new rxjs.Observable(function (observer) {
var availabilityCheck = checkAvailability(pluginObj, methodName);
if (availabilityCheck === true) {
var pluginInstance_1 = getPlugin(pluginObj.constructor.getPluginRef());
pluginInstance_1[methodName] = observer.next.bind(observer);
return function () { return (pluginInstance_1[methodName] = function () { }); };
}
else {
observer.error(availabilityCheck);
observer.complete();
}
});
}
function cordovaFunctionOverride(pluginObj, methodName, args) {
return overrideFunction(pluginObj, methodName);
}
function cordovaInstance(pluginObj, methodName, config, args) {
args = Array.from(args);
return wrapInstance(pluginObj, methodName, config).apply(this, args);
}
function cordovaPropertyGet(pluginObj, key) {
if (checkAvailability(pluginObj, key) === true) {
return getPlugin(pluginObj.constructor.getPluginRef())[key];
}
return null;
}
function cordovaPropertySet(pluginObj, key, value) {
if (checkAvailability(pluginObj, key) === true) {
getPlugin(pluginObj.constructor.getPluginRef())[key] = value;
}
}
function instancePropertyGet(pluginObj, key) {
if (pluginObj._objectInstance && pluginObj._objectInstance[key]) {
return pluginObj._objectInstance[key];
}
return null;
}
function instancePropertySet(pluginObj, key, value) {
if (pluginObj._objectInstance) {
pluginObj._objectInstance[key] = value;
}
}
checkReady();
exports.IonicNativePlugin = IonicNativePlugin;
exports.checkAvailability = checkAvailability;
exports.cordova = cordova;
exports.cordovaFunctionOverride = cordovaFunctionOverride;
exports.cordovaInstance = cordovaInstance;
exports.cordovaPropertyGet = cordovaPropertyGet;
exports.cordovaPropertySet = cordovaPropertySet;
exports.getPromise = getPromise;
exports.instanceAvailability = instanceAvailability;
exports.instancePropertyGet = instancePropertyGet;
exports.instancePropertySet = instancePropertySet;
exports.wrap = wrap;