UNPKG

66.9 kBJavaScriptView Raw
1// Platform: ios
2// 538a985db128858c0a0eb4dd40fb9c8e5433fc94
3/*
4 Licensed to the Apache Software Foundation (ASF) under one
5 or more contributor license agreements. See the NOTICE file
6 distributed with this work for additional information
7 regarding copyright ownership. The ASF licenses this file
8 to you under the Apache License, Version 2.0 (the
9 "License"); you may not use this file except in compliance
10 with the License. You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing,
15 software distributed under the License is distributed on an
16 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 KIND, either express or implied. See the License for the
18 specific language governing permissions and limitations
19 under the License.
20*/
21;(function() {
22var PLATFORM_VERSION_BUILD_LABEL = '6.1.1';
23// file: src/scripts/require.js
24var require;
25var define;
26
27(function () {
28 var modules = {};
29 // Stack of moduleIds currently being built.
30 var requireStack = [];
31 // Map of module ID -> index into requireStack of modules currently being built.
32 var inProgressModules = {};
33 var SEPARATOR = '.';
34
35 function build (module) {
36 var factory = module.factory;
37 var localRequire = function (id) {
38 var resultantId = id;
39 // Its a relative path, so lop off the last portion and add the id (minus "./")
40 if (id.charAt(0) === '.') {
41 resultantId = module.id.slice(0, module.id.lastIndexOf(SEPARATOR)) + SEPARATOR + id.slice(2);
42 }
43 return require(resultantId);
44 };
45 module.exports = {};
46 delete module.factory;
47 factory(localRequire, module.exports, module);
48 return module.exports;
49 }
50
51 require = function (id) {
52 if (!modules[id]) {
53 throw new Error('module ' + id + ' not found');
54 } else if (id in inProgressModules) {
55 var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
56 throw new Error('Cycle in require graph: ' + cycle);
57 }
58 if (modules[id].factory) {
59 try {
60 inProgressModules[id] = requireStack.length;
61 requireStack.push(id);
62 return build(modules[id]);
63 } finally {
64 delete inProgressModules[id];
65 requireStack.pop();
66 }
67 }
68 return modules[id].exports;
69 };
70
71 define = function (id, factory) {
72 if (Object.prototype.hasOwnProperty.call(modules, id)) {
73 throw new Error('module ' + id + ' already defined');
74 }
75
76 modules[id] = {
77 id: id,
78 factory: factory
79 };
80 };
81
82 define.remove = function (id) {
83 delete modules[id];
84 };
85
86 define.moduleMap = modules;
87})();
88
89// Export for use in node
90if (typeof module === 'object' && typeof require === 'function') {
91 module.exports.require = require;
92 module.exports.define = define;
93}
94
95// file: src/cordova.js
96define("cordova", function(require, exports, module) {
97
98// Workaround for Windows 10 in hosted environment case
99// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
100if (window.cordova && !(window.cordova instanceof HTMLElement)) {
101 throw new Error('cordova already defined');
102}
103
104var channel = require('cordova/channel');
105var platform = require('cordova/platform');
106
107/**
108 * Intercept calls to addEventListener + removeEventListener and handle deviceready,
109 * resume, and pause events.
110 */
111var m_document_addEventListener = document.addEventListener;
112var m_document_removeEventListener = document.removeEventListener;
113var m_window_addEventListener = window.addEventListener;
114var m_window_removeEventListener = window.removeEventListener;
115
116/**
117 * Houses custom event handlers to intercept on document + window event listeners.
118 */
119var documentEventHandlers = {};
120var windowEventHandlers = {};
121
122document.addEventListener = function (evt, handler, capture) {
123 var e = evt.toLowerCase();
124 if (typeof documentEventHandlers[e] !== 'undefined') {
125 documentEventHandlers[e].subscribe(handler);
126 } else {
127 m_document_addEventListener.call(document, evt, handler, capture);
128 }
129};
130
131window.addEventListener = function (evt, handler, capture) {
132 var e = evt.toLowerCase();
133 if (typeof windowEventHandlers[e] !== 'undefined') {
134 windowEventHandlers[e].subscribe(handler);
135 } else {
136 m_window_addEventListener.call(window, evt, handler, capture);
137 }
138};
139
140document.removeEventListener = function (evt, handler, capture) {
141 var e = evt.toLowerCase();
142 // If unsubscribing from an event that is handled by a plugin
143 if (typeof documentEventHandlers[e] !== 'undefined') {
144 documentEventHandlers[e].unsubscribe(handler);
145 } else {
146 m_document_removeEventListener.call(document, evt, handler, capture);
147 }
148};
149
150window.removeEventListener = function (evt, handler, capture) {
151 var e = evt.toLowerCase();
152 // If unsubscribing from an event that is handled by a plugin
153 if (typeof windowEventHandlers[e] !== 'undefined') {
154 windowEventHandlers[e].unsubscribe(handler);
155 } else {
156 m_window_removeEventListener.call(window, evt, handler, capture);
157 }
158};
159
160function createEvent (type, data) {
161 var event = document.createEvent('Events');
162 event.initEvent(type, false, false);
163 if (data) {
164 for (var i in data) {
165 if (Object.prototype.hasOwnProperty.call(data, i)) {
166 event[i] = data[i];
167 }
168 }
169 }
170 return event;
171}
172
173var cordova = {
174 define: define,
175 require: require,
176 version: PLATFORM_VERSION_BUILD_LABEL,
177 platformVersion: PLATFORM_VERSION_BUILD_LABEL,
178 platformId: platform.id,
179
180 /**
181 * Methods to add/remove your own addEventListener hijacking on document + window.
182 */
183 addWindowEventHandler: function (event) {
184 return (windowEventHandlers[event] = channel.create(event));
185 },
186 addStickyDocumentEventHandler: function (event) {
187 return (documentEventHandlers[event] = channel.createSticky(event));
188 },
189 addDocumentEventHandler: function (event) {
190 return (documentEventHandlers[event] = channel.create(event));
191 },
192 removeWindowEventHandler: function (event) {
193 delete windowEventHandlers[event];
194 },
195 removeDocumentEventHandler: function (event) {
196 delete documentEventHandlers[event];
197 },
198
199 /**
200 * Retrieve original event handlers that were replaced by Cordova
201 *
202 * @return object
203 */
204 getOriginalHandlers: function () {
205 return {
206 document: {
207 addEventListener: m_document_addEventListener,
208 removeEventListener: m_document_removeEventListener
209 },
210 window: {
211 addEventListener: m_window_addEventListener,
212 removeEventListener: m_window_removeEventListener
213 }
214 };
215 },
216
217 /**
218 * Method to fire event from native code
219 * bNoDetach is required for events which cause an exception which needs to be caught in native code
220 */
221 fireDocumentEvent: function (type, data, bNoDetach) {
222 var evt = createEvent(type, data);
223 if (typeof documentEventHandlers[type] !== 'undefined') {
224 if (bNoDetach) {
225 documentEventHandlers[type].fire(evt);
226 } else {
227 setTimeout(function () {
228 // Fire deviceready on listeners that were registered before cordova.js was loaded.
229 if (type === 'deviceready') {
230 document.dispatchEvent(evt);
231 }
232 documentEventHandlers[type].fire(evt);
233 }, 0);
234 }
235 } else {
236 document.dispatchEvent(evt);
237 }
238 },
239
240 fireWindowEvent: function (type, data) {
241 var evt = createEvent(type, data);
242 if (typeof windowEventHandlers[type] !== 'undefined') {
243 setTimeout(function () {
244 windowEventHandlers[type].fire(evt);
245 }, 0);
246 } else {
247 window.dispatchEvent(evt);
248 }
249 },
250
251 /**
252 * Plugin callback mechanism.
253 */
254 // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
255 // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
256 callbackId: Math.floor(Math.random() * 2000000000),
257 callbacks: {},
258 callbackStatus: {
259 NO_RESULT: 0,
260 OK: 1,
261 CLASS_NOT_FOUND_EXCEPTION: 2,
262 ILLEGAL_ACCESS_EXCEPTION: 3,
263 INSTANTIATION_EXCEPTION: 4,
264 MALFORMED_URL_EXCEPTION: 5,
265 IO_EXCEPTION: 6,
266 INVALID_ACTION: 7,
267 JSON_EXCEPTION: 8,
268 ERROR: 9
269 },
270
271 /**
272 * Called by native code when returning successful result from an action.
273 */
274 callbackSuccess: function (callbackId, args) {
275 cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
276 },
277
278 /**
279 * Called by native code when returning error result from an action.
280 */
281 callbackError: function (callbackId, args) {
282 // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
283 // Derive success from status.
284 cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
285 },
286
287 /**
288 * Called by native code when returning the result from an action.
289 */
290 callbackFromNative: function (callbackId, isSuccess, status, args, keepCallback) {
291 try {
292 var callback = cordova.callbacks[callbackId];
293 if (callback) {
294 if (isSuccess && status === cordova.callbackStatus.OK) {
295 callback.success && callback.success.apply(null, args);
296 } else if (!isSuccess) {
297 callback.fail && callback.fail.apply(null, args);
298 }
299 /*
300 else
301 Note, this case is intentionally not caught.
302 this can happen if isSuccess is true, but callbackStatus is NO_RESULT
303 which is used to remove a callback from the list without calling the callbacks
304 typically keepCallback is false in this case
305 */
306 // Clear callback if not expecting any more results
307 if (!keepCallback) {
308 delete cordova.callbacks[callbackId];
309 }
310 }
311 } catch (err) {
312 var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
313 cordova.fireWindowEvent('cordovacallbackerror', { message: msg, error: err });
314 throw err;
315 }
316 },
317
318 addConstructor: function (func) {
319 channel.onCordovaReady.subscribe(function () {
320 try {
321 func();
322 } catch (e) {
323 console.log('Failed to run constructor: ' + e);
324 }
325 });
326 }
327};
328
329module.exports = cordova;
330
331});
332
333// file: src/common/argscheck.js
334define("cordova/argscheck", function(require, exports, module) {
335
336var utils = require('cordova/utils');
337
338var moduleExports = module.exports;
339
340var typeMap = {
341 A: 'Array',
342 D: 'Date',
343 N: 'Number',
344 S: 'String',
345 F: 'Function',
346 O: 'Object'
347};
348
349function extractParamName (callee, argIndex) {
350 return (/\(\s*([^)]*?)\s*\)/).exec(callee)[1].split(/\s*,\s*/)[argIndex];
351}
352
353/**
354 * Checks the given arguments' types and throws if they are not as expected.
355 *
356 * `spec` is a string where each character stands for the required type of the
357 * argument at the same position. In other words: the character at `spec[i]`
358 * specifies the required type for `args[i]`. The characters in `spec` are the
359 * first letter of the required type's name. The supported types are:
360 *
361 * Array, Date, Number, String, Function, Object
362 *
363 * Lowercase characters specify arguments that must not be `null` or `undefined`
364 * while uppercase characters allow those values to be passed.
365 *
366 * Finally, `*` can be used to allow any type at the corresponding position.
367 *
368 * @example
369 * function foo (arr, opts) {
370 * // require `arr` to be an Array and `opts` an Object, null or undefined
371 * checkArgs('aO', 'my.package.foo', arguments);
372 * // ...
373 * }
374 * @param {String} spec - the type specification for `args` as described above
375 * @param {String} functionName - full name of the callee.
376 * Used in the error message
377 * @param {Array|arguments} args - the arguments to be checked against `spec`
378 * @param {Function} [opt_callee=args.callee] - the recipient of `args`.
379 * Used to extract parameter names for the error message
380 * @throws {TypeError} if args do not satisfy spec
381 */
382function checkArgs (spec, functionName, args, opt_callee) {
383 if (!moduleExports.enableChecks) {
384 return;
385 }
386 var errMsg = null;
387 var typeName;
388 for (var i = 0; i < spec.length; ++i) {
389 var c = spec.charAt(i);
390 var cUpper = c.toUpperCase();
391 var arg = args[i];
392 // Asterix means allow anything.
393 if (c === '*') {
394 continue;
395 }
396 typeName = utils.typeName(arg);
397 if ((arg === null || arg === undefined) && c === cUpper) {
398 continue;
399 }
400 if (typeName !== typeMap[cUpper]) {
401 errMsg = 'Expected ' + typeMap[cUpper];
402 break;
403 }
404 }
405 if (errMsg) {
406 errMsg += ', but got ' + typeName + '.';
407 errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
408 // Don't log when running unit tests.
409 if (typeof jasmine === 'undefined') {
410 console.error(errMsg);
411 }
412 throw TypeError(errMsg);
413 }
414}
415
416function getValue (value, defaultValue) {
417 return value === undefined ? defaultValue : value;
418}
419
420moduleExports.checkArgs = checkArgs;
421moduleExports.getValue = getValue;
422moduleExports.enableChecks = true;
423
424});
425
426// file: src/common/base64.js
427define("cordova/base64", function(require, exports, module) {
428
429var base64 = exports;
430
431base64.fromArrayBuffer = function (arrayBuffer) {
432 var array = new Uint8Array(arrayBuffer);
433 return uint8ToBase64(array);
434};
435
436base64.toArrayBuffer = function (str) {
437 var decodedStr = atob(str);
438 var arrayBuffer = new ArrayBuffer(decodedStr.length);
439 var array = new Uint8Array(arrayBuffer);
440 for (var i = 0, len = decodedStr.length; i < len; i++) {
441 array[i] = decodedStr.charCodeAt(i);
442 }
443 return arrayBuffer;
444};
445
446// ------------------------------------------------------------------------------
447
448/* This code is based on the performance tests at http://jsperf.com/b64tests
449 * This 12-bit-at-a-time algorithm was the best performing version on all
450 * platforms tested.
451 */
452
453var b64_6bit = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
454var b64_12bit;
455
456var b64_12bitTable = function () {
457 b64_12bit = [];
458 for (var i = 0; i < 64; i++) {
459 for (var j = 0; j < 64; j++) {
460 b64_12bit[i * 64 + j] = b64_6bit[i] + b64_6bit[j];
461 }
462 }
463 b64_12bitTable = function () { return b64_12bit; };
464 return b64_12bit;
465};
466
467function uint8ToBase64 (rawData) {
468 var numBytes = rawData.byteLength;
469 var output = '';
470 var segment;
471 var table = b64_12bitTable();
472 for (var i = 0; i < numBytes - 2; i += 3) {
473 segment = (rawData[i] << 16) + (rawData[i + 1] << 8) + rawData[i + 2];
474 output += table[segment >> 12];
475 output += table[segment & 0xfff];
476 }
477 if (numBytes - i === 2) {
478 segment = (rawData[i] << 16) + (rawData[i + 1] << 8);
479 output += table[segment >> 12];
480 output += b64_6bit[(segment & 0xfff) >> 6];
481 output += '=';
482 } else if (numBytes - i === 1) {
483 segment = (rawData[i] << 16);
484 output += table[segment >> 12];
485 output += '==';
486 }
487 return output;
488}
489
490});
491
492// file: src/common/builder.js
493define("cordova/builder", function(require, exports, module) {
494
495var utils = require('cordova/utils');
496
497function each (objects, func, context) {
498 for (var prop in objects) {
499 if (Object.prototype.hasOwnProperty.call(objects, prop)) {
500 func.apply(context, [objects[prop], prop]);
501 }
502 }
503}
504
505function clobber (obj, key, value) {
506 var needsProperty = false;
507 try {
508 obj[key] = value;
509 } catch (e) {
510 needsProperty = true;
511 }
512 // Getters can only be overridden by getters.
513 if (needsProperty || obj[key] !== value) {
514 utils.defineGetter(obj, key, function () {
515 return value;
516 });
517 }
518}
519
520function assignOrWrapInDeprecateGetter (obj, key, value, message) {
521 if (message) {
522 utils.defineGetter(obj, key, function () {
523 console.log(message);
524 delete obj[key];
525 clobber(obj, key, value);
526 return value;
527 });
528 } else {
529 clobber(obj, key, value);
530 }
531}
532
533function include (parent, objects, clobber, merge) {
534 each(objects, function (obj, key) {
535 try {
536 var result = obj.path ? require(obj.path) : {};
537
538 if (clobber) {
539 // Clobber if it doesn't exist.
540 if (typeof parent[key] === 'undefined') {
541 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
542 } else if (typeof obj.path !== 'undefined') {
543 // If merging, merge properties onto parent, otherwise, clobber.
544 if (merge) {
545 recursiveMerge(parent[key], result);
546 } else {
547 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
548 }
549 }
550 result = parent[key];
551 } else {
552 // Overwrite if not currently defined.
553 if (typeof parent[key] === 'undefined') {
554 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
555 } else {
556 // Set result to what already exists, so we can build children into it if they exist.
557 result = parent[key];
558 }
559 }
560
561 if (obj.children) {
562 include(result, obj.children, clobber, merge);
563 }
564 } catch (e) {
565 utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"');
566 }
567 });
568}
569
570/**
571 * Merge properties from one object onto another recursively. Properties from
572 * the src object will overwrite existing target property.
573 *
574 * @param target Object to merge properties into.
575 * @param src Object to merge properties from.
576 */
577function recursiveMerge (target, src) {
578 for (var prop in src) {
579 if (Object.prototype.hasOwnProperty.call(src, prop)) {
580 if (target.prototype && target.prototype.constructor === target) {
581 // If the target object is a constructor override off prototype.
582 clobber(target.prototype, prop, src[prop]);
583 } else {
584 if (typeof src[prop] === 'object' && typeof target[prop] === 'object') {
585 recursiveMerge(target[prop], src[prop]);
586 } else {
587 clobber(target, prop, src[prop]);
588 }
589 }
590 }
591 }
592}
593
594exports.buildIntoButDoNotClobber = function (objects, target) {
595 include(target, objects, false, false);
596};
597exports.buildIntoAndClobber = function (objects, target) {
598 include(target, objects, true, false);
599};
600exports.buildIntoAndMerge = function (objects, target) {
601 include(target, objects, true, true);
602};
603exports.recursiveMerge = recursiveMerge;
604exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
605
606});
607
608// file: src/common/channel.js
609define("cordova/channel", function(require, exports, module) {
610
611var utils = require('cordova/utils');
612var nextGuid = 1;
613
614/**
615 * Custom pub-sub "channel" that can have functions subscribed to it
616 * This object is used to define and control firing of events for
617 * cordova initialization, as well as for custom events thereafter.
618 *
619 * The order of events during page load and Cordova startup is as follows:
620 *
621 * onDOMContentLoaded* Internal event that is received when the web page is loaded and parsed.
622 * onNativeReady* Internal event that indicates the Cordova native side is ready.
623 * onCordovaReady* Internal event fired when all Cordova JavaScript objects have been created.
624 * onDeviceReady* User event fired to indicate that Cordova is ready
625 * onResume User event fired to indicate a start/resume lifecycle event
626 * onPause User event fired to indicate a pause lifecycle event
627 *
628 * The events marked with an * are sticky. Once they have fired, they will stay in the fired state.
629 * All listeners that subscribe after the event is fired will be executed right away.
630 *
631 * The only Cordova events that user code should register for are:
632 * deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
633 * pause App has moved to background
634 * resume App has returned to foreground
635 *
636 * Listeners can be registered as:
637 * document.addEventListener("deviceready", myDeviceReadyListener, false);
638 * document.addEventListener("resume", myResumeListener, false);
639 * document.addEventListener("pause", myPauseListener, false);
640 *
641 * The DOM lifecycle events should be used for saving and restoring state
642 * window.onload
643 * window.onunload
644 *
645 */
646
647/**
648 * Channel
649 * @constructor
650 * @param type String the channel name
651 */
652var Channel = function (type, sticky) {
653 this.type = type;
654 // Map of guid -> function.
655 this.handlers = {};
656 // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired.
657 this.state = sticky ? 1 : 0;
658 // Used in sticky mode to remember args passed to fire().
659 this.fireArgs = null;
660 // Used by onHasSubscribersChange to know if there are any listeners.
661 this.numHandlers = 0;
662 // Function that is called when the first listener is subscribed, or when
663 // the last listener is unsubscribed.
664 this.onHasSubscribersChange = null;
665};
666var channel = {
667 /**
668 * Calls the provided function only after all of the channels specified
669 * have been fired. All channels must be sticky channels.
670 */
671 join: function (h, c) {
672 var len = c.length;
673 var i = len;
674 var f = function () {
675 if (!(--i)) h();
676 };
677 for (var j = 0; j < len; j++) {
678 if (c[j].state === 0) {
679 throw Error('Can only use join with sticky channels.');
680 }
681 c[j].subscribe(f);
682 }
683 if (!len) h();
684 },
685
686 create: function (type) {
687 return (channel[type] = new Channel(type, false));
688 },
689 createSticky: function (type) {
690 return (channel[type] = new Channel(type, true));
691 },
692
693 /**
694 * cordova Channels that must fire before "deviceready" is fired.
695 */
696 deviceReadyChannelsArray: [],
697 deviceReadyChannelsMap: {},
698
699 /**
700 * Indicate that a feature needs to be initialized before it is ready to be used.
701 * This holds up Cordova's "deviceready" event until the feature has been initialized
702 * and Cordova.initComplete(feature) is called.
703 *
704 * @param feature {String} The unique feature name
705 */
706 waitForInitialization: function (feature) {
707 if (feature) {
708 var c = channel[feature] || this.createSticky(feature);
709 this.deviceReadyChannelsMap[feature] = c;
710 this.deviceReadyChannelsArray.push(c);
711 }
712 },
713
714 /**
715 * Indicate that initialization code has completed and the feature is ready to be used.
716 *
717 * @param feature {String} The unique feature name
718 */
719 initializationComplete: function (feature) {
720 var c = this.deviceReadyChannelsMap[feature];
721 if (c) {
722 c.fire();
723 }
724 }
725};
726
727function checkSubscriptionArgument (argument) {
728 if (typeof argument !== 'function' && typeof argument.handleEvent !== 'function') {
729 throw new Error(
730 'Must provide a function or an EventListener object ' +
731 'implementing the handleEvent interface.'
732 );
733 }
734}
735
736/**
737 * Subscribes the given function to the channel. Any time that
738 * Channel.fire is called so too will the function.
739 * Optionally specify an execution context for the function
740 * and a guid that can be used to stop subscribing to the channel.
741 * Returns the guid.
742 */
743Channel.prototype.subscribe = function (eventListenerOrFunction, eventListener) {
744 checkSubscriptionArgument(eventListenerOrFunction);
745 var handleEvent, guid;
746
747 if (eventListenerOrFunction && typeof eventListenerOrFunction === 'object') {
748 // Received an EventListener object implementing the handleEvent interface
749 handleEvent = eventListenerOrFunction.handleEvent;
750 eventListener = eventListenerOrFunction;
751 } else {
752 // Received a function to handle event
753 handleEvent = eventListenerOrFunction;
754 }
755
756 if (this.state === 2) {
757 handleEvent.apply(eventListener || this, this.fireArgs);
758 return;
759 }
760
761 guid = eventListenerOrFunction.observer_guid;
762 if (typeof eventListener === 'object') {
763 handleEvent = utils.close(eventListener, handleEvent);
764 }
765
766 if (!guid) {
767 // First time any channel has seen this subscriber
768 guid = '' + nextGuid++;
769 }
770 handleEvent.observer_guid = guid;
771 eventListenerOrFunction.observer_guid = guid;
772
773 // Don't add the same handler more than once.
774 if (!this.handlers[guid]) {
775 this.handlers[guid] = handleEvent;
776 this.numHandlers++;
777 if (this.numHandlers === 1) {
778 this.onHasSubscribersChange && this.onHasSubscribersChange();
779 }
780 }
781};
782
783/**
784 * Unsubscribes the function with the given guid from the channel.
785 */
786Channel.prototype.unsubscribe = function (eventListenerOrFunction) {
787 checkSubscriptionArgument(eventListenerOrFunction);
788 var handleEvent, guid, handler;
789
790 if (eventListenerOrFunction && typeof eventListenerOrFunction === 'object') {
791 // Received an EventListener object implementing the handleEvent interface
792 handleEvent = eventListenerOrFunction.handleEvent;
793 } else {
794 // Received a function to handle event
795 handleEvent = eventListenerOrFunction;
796 }
797
798 guid = handleEvent.observer_guid;
799 handler = this.handlers[guid];
800 if (handler) {
801 delete this.handlers[guid];
802 this.numHandlers--;
803 if (this.numHandlers === 0) {
804 this.onHasSubscribersChange && this.onHasSubscribersChange();
805 }
806 }
807};
808
809/**
810 * Calls all functions subscribed to this channel.
811 */
812Channel.prototype.fire = function (e) {
813 var fireArgs = Array.prototype.slice.call(arguments);
814 // Apply stickiness.
815 if (this.state === 1) {
816 this.state = 2;
817 this.fireArgs = fireArgs;
818 }
819 if (this.numHandlers) {
820 // Copy the values first so that it is safe to modify it from within
821 // callbacks.
822 var toCall = [];
823 for (var item in this.handlers) {
824 toCall.push(this.handlers[item]);
825 }
826 for (var i = 0; i < toCall.length; ++i) {
827 toCall[i].apply(this, fireArgs);
828 }
829 if (this.state === 2 && this.numHandlers) {
830 this.numHandlers = 0;
831 this.handlers = {};
832 this.onHasSubscribersChange && this.onHasSubscribersChange();
833 }
834 }
835};
836
837// defining them here so they are ready super fast!
838// DOM event that is received when the web page is loaded and parsed.
839channel.createSticky('onDOMContentLoaded');
840
841// Event to indicate the Cordova native side is ready.
842channel.createSticky('onNativeReady');
843
844// Event to indicate that all Cordova JavaScript objects have been created
845// and it's time to run plugin constructors.
846channel.createSticky('onCordovaReady');
847
848// Event to indicate that all automatically loaded JS plugins are loaded and ready.
849// FIXME remove this
850channel.createSticky('onPluginsReady');
851
852// Event to indicate that Cordova is ready
853channel.createSticky('onDeviceReady');
854
855// Event to indicate a resume lifecycle event
856channel.create('onResume');
857
858// Event to indicate a pause lifecycle event
859channel.create('onPause');
860
861// Channels that must fire before "deviceready" is fired.
862channel.waitForInitialization('onCordovaReady');
863channel.waitForInitialization('onDOMContentLoaded');
864
865module.exports = channel;
866
867});
868
869// file: ../cordova-ios/cordova-js-src/exec.js
870define("cordova/exec", function(require, exports, module) {
871
872/**
873 * Creates the exec bridge used to notify the native code of
874 * commands.
875 */
876var cordova = require('cordova');
877var utils = require('cordova/utils');
878var base64 = require('cordova/base64');
879
880function massageArgsJsToNative (args) {
881 if (!args || utils.typeName(args) !== 'Array') {
882 return args;
883 }
884 var ret = [];
885 args.forEach(function (arg, i) {
886 if (utils.typeName(arg) === 'ArrayBuffer') {
887 ret.push({
888 CDVType: 'ArrayBuffer',
889 data: base64.fromArrayBuffer(arg)
890 });
891 } else {
892 ret.push(arg);
893 }
894 });
895 return ret;
896}
897
898function massageMessageNativeToJs (message) {
899 if (message.CDVType === 'ArrayBuffer') {
900 var stringToArrayBuffer = function (str) {
901 var ret = new Uint8Array(str.length);
902 for (var i = 0; i < str.length; i++) {
903 ret[i] = str.charCodeAt(i);
904 }
905 return ret.buffer;
906 };
907 var base64ToArrayBuffer = function (b64) {
908 return stringToArrayBuffer(atob(b64)); // eslint-disable-line no-undef
909 };
910 message = base64ToArrayBuffer(message.data);
911 }
912 return message;
913}
914
915function convertMessageToArgsNativeToJs (message) {
916 var args = [];
917 if (!message || !Object.prototype.hasOwnProperty.call(message, 'CDVType')) {
918 args.push(message);
919 } else if (message.CDVType === 'MultiPart') {
920 message.messages.forEach(function (e) {
921 args.push(massageMessageNativeToJs(e));
922 });
923 } else {
924 args.push(massageMessageNativeToJs(message));
925 }
926 return args;
927}
928
929var iOSExec = function () {
930 var successCallback, failCallback, service, action, actionArgs;
931 var callbackId = null;
932 if (typeof arguments[0] !== 'string') {
933 // FORMAT ONE
934 successCallback = arguments[0];
935 failCallback = arguments[1];
936 service = arguments[2];
937 action = arguments[3];
938 actionArgs = arguments[4];
939
940 // Since we need to maintain backwards compatibility, we have to pass
941 // an invalid callbackId even if no callback was provided since plugins
942 // will be expecting it. The Cordova.exec() implementation allocates
943 // an invalid callbackId and passes it even if no callbacks were given.
944 callbackId = 'INVALID';
945 } else {
946 throw new Error('The old format of this exec call has been removed (deprecated since 2.1). Change to: ' + // eslint-disable-line
947 'cordova.exec(null, null, \'Service\', \'action\', [ arg1, arg2 ]);');
948 }
949
950 // If actionArgs is not provided, default to an empty array
951 actionArgs = actionArgs || [];
952
953 // Register the callbacks and add the callbackId to the positional
954 // arguments if given.
955 if (successCallback || failCallback) {
956 callbackId = service + cordova.callbackId++;
957 cordova.callbacks[callbackId] =
958 { success: successCallback, fail: failCallback };
959 }
960
961 actionArgs = massageArgsJsToNative(actionArgs);
962
963 // CB-10133 DataClone DOM Exception 25 guard (fast function remover)
964 var command = [callbackId, service, action, JSON.parse(JSON.stringify(actionArgs))];
965 window.webkit.messageHandlers.cordova.postMessage(command);
966};
967
968iOSExec.nativeCallback = function (callbackId, status, message, keepCallback, debug) {
969 var success = status === 0 || status === 1;
970 var args = convertMessageToArgsNativeToJs(message);
971 Promise.resolve().then(function () {
972 cordova.callbackFromNative(callbackId, success, status, args, keepCallback); // eslint-disable-line
973 });
974};
975
976// for backwards compatibility
977iOSExec.nativeEvalAndFetch = function (func) {
978 try {
979 func();
980 } catch (e) {
981 console.log(e);
982 }
983};
984
985// Proxy the exec for bridge changes. See CB-10106
986
987function cordovaExec () {
988 var cexec = require('cordova/exec');
989 var cexec_valid = (typeof cexec.nativeFetchMessages === 'function') && (typeof cexec.nativeEvalAndFetch === 'function') && (typeof cexec.nativeCallback === 'function');
990 return (cexec_valid && execProxy !== cexec) ? cexec : iOSExec;
991}
992
993function execProxy () {
994 cordovaExec().apply(null, arguments);
995}
996
997execProxy.nativeFetchMessages = function () {
998 return cordovaExec().nativeFetchMessages.apply(null, arguments);
999};
1000
1001execProxy.nativeEvalAndFetch = function () {
1002 return cordovaExec().nativeEvalAndFetch.apply(null, arguments);
1003};
1004
1005execProxy.nativeCallback = function () {
1006 return cordovaExec().nativeCallback.apply(null, arguments);
1007};
1008
1009module.exports = execProxy;
1010
1011});
1012
1013// file: src/common/exec/proxy.js
1014define("cordova/exec/proxy", function(require, exports, module) {
1015
1016// internal map of proxy function
1017var CommandProxyMap = {};
1018
1019module.exports = {
1020
1021 // example: cordova.commandProxy.add("Accelerometer",{getCurrentAcceleration: function(successCallback, errorCallback, options) {...},...);
1022 add: function (id, proxyObj) {
1023 console.log('adding proxy for ' + id);
1024 CommandProxyMap[id] = proxyObj;
1025 return proxyObj;
1026 },
1027
1028 // cordova.commandProxy.remove("Accelerometer");
1029 remove: function (id) {
1030 var proxy = CommandProxyMap[id];
1031 delete CommandProxyMap[id];
1032 CommandProxyMap[id] = null;
1033 return proxy;
1034 },
1035
1036 get: function (service, action) {
1037 return (CommandProxyMap[service] ? CommandProxyMap[service][action] : null);
1038 }
1039};
1040
1041});
1042
1043// file: src/common/init.js
1044define("cordova/init", function(require, exports, module) {
1045
1046var channel = require('cordova/channel');
1047var cordova = require('cordova');
1048var modulemapper = require('cordova/modulemapper');
1049var platform = require('cordova/platform');
1050var pluginloader = require('cordova/pluginloader');
1051
1052var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
1053
1054function logUnfiredChannels (arr) {
1055 for (var i = 0; i < arr.length; ++i) {
1056 if (arr[i].state !== 2) {
1057 console.log('Channel not fired: ' + arr[i].type);
1058 }
1059 }
1060}
1061
1062window.setTimeout(function () {
1063 if (channel.onDeviceReady.state !== 2) {
1064 console.log('deviceready has not fired after 5 seconds.');
1065 logUnfiredChannels(platformInitChannelsArray);
1066 logUnfiredChannels(channel.deviceReadyChannelsArray);
1067 }
1068}, 5000);
1069
1070if (!window.console) {
1071 window.console = {
1072 log: function () {}
1073 };
1074}
1075if (!window.console.warn) {
1076 window.console.warn = function (msg) {
1077 this.log('warn: ' + msg);
1078 };
1079}
1080
1081// Register pause, resume and deviceready channels as events on document.
1082channel.onPause = cordova.addDocumentEventHandler('pause');
1083channel.onResume = cordova.addDocumentEventHandler('resume');
1084channel.onActivated = cordova.addDocumentEventHandler('activated');
1085channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
1086
1087// Listen for DOMContentLoaded and notify our channel subscribers.
1088if (document.readyState === 'complete' || document.readyState === 'interactive') {
1089 channel.onDOMContentLoaded.fire();
1090} else {
1091 document.addEventListener('DOMContentLoaded', function () {
1092 channel.onDOMContentLoaded.fire();
1093 }, false);
1094}
1095
1096// _nativeReady is global variable that the native side can set
1097// to signify that the native code is ready. It is a global since
1098// it may be called before any cordova JS is ready.
1099if (window._nativeReady) {
1100 channel.onNativeReady.fire();
1101}
1102
1103modulemapper.clobbers('cordova', 'cordova');
1104modulemapper.clobbers('cordova/exec', 'cordova.exec');
1105modulemapper.clobbers('cordova/exec', 'Cordova.exec');
1106
1107// Call the platform-specific initialization.
1108platform.bootstrap && platform.bootstrap();
1109
1110// Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
1111// The delay allows the attached modules to be defined before the plugin loader looks for them.
1112setTimeout(function () {
1113 pluginloader.load(function () {
1114 channel.onPluginsReady.fire();
1115 });
1116}, 0);
1117
1118/**
1119 * Create all cordova objects once native side is ready.
1120 */
1121channel.join(function () {
1122 modulemapper.mapModules(window);
1123
1124 platform.initialize && platform.initialize();
1125
1126 // Fire event to notify that all objects are created
1127 channel.onCordovaReady.fire();
1128
1129 // Fire onDeviceReady event once page has fully loaded, all
1130 // constructors have run and cordova info has been received from native
1131 // side.
1132 channel.join(function () {
1133 require('cordova').fireDocumentEvent('deviceready');
1134 }, channel.deviceReadyChannelsArray);
1135}, platformInitChannelsArray);
1136
1137});
1138
1139// file: src/common/modulemapper.js
1140define("cordova/modulemapper", function(require, exports, module) {
1141
1142var builder = require('cordova/builder');
1143var moduleMap = define.moduleMap;
1144var symbolList;
1145var deprecationMap;
1146
1147exports.reset = function () {
1148 symbolList = [];
1149 deprecationMap = {};
1150};
1151
1152function addEntry (strategy, moduleName, symbolPath, opt_deprecationMessage) {
1153 if (!(moduleName in moduleMap)) {
1154 throw new Error('Module ' + moduleName + ' does not exist.');
1155 }
1156 symbolList.push(strategy, moduleName, symbolPath);
1157 if (opt_deprecationMessage) {
1158 deprecationMap[symbolPath] = opt_deprecationMessage;
1159 }
1160}
1161
1162// Note: Android 2.3 does have Function.bind().
1163exports.clobbers = function (moduleName, symbolPath, opt_deprecationMessage) {
1164 addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
1165};
1166
1167exports.merges = function (moduleName, symbolPath, opt_deprecationMessage) {
1168 addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
1169};
1170
1171exports.defaults = function (moduleName, symbolPath, opt_deprecationMessage) {
1172 addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
1173};
1174
1175exports.runs = function (moduleName) {
1176 addEntry('r', moduleName, null);
1177};
1178
1179function prepareNamespace (symbolPath, context) {
1180 if (!symbolPath) {
1181 return context;
1182 }
1183 return symbolPath.split('.').reduce(function (cur, part) {
1184 return (cur[part] = cur[part] || {});
1185 }, context);
1186}
1187
1188exports.mapModules = function (context) {
1189 var origSymbols = {};
1190 context.CDV_origSymbols = origSymbols;
1191 for (var i = 0, len = symbolList.length; i < len; i += 3) {
1192 var strategy = symbolList[i];
1193 var moduleName = symbolList[i + 1];
1194 var module = require(moduleName);
1195 // <runs/>
1196 if (strategy === 'r') {
1197 continue;
1198 }
1199 var symbolPath = symbolList[i + 2];
1200 var lastDot = symbolPath.lastIndexOf('.');
1201 var namespace = symbolPath.substr(0, lastDot);
1202 var lastName = symbolPath.substr(lastDot + 1);
1203
1204 var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
1205 var parentObj = prepareNamespace(namespace, context);
1206 var target = parentObj[lastName];
1207
1208 if (strategy === 'm' && target) {
1209 builder.recursiveMerge(target, module);
1210 } else if ((strategy === 'd' && !target) || (strategy !== 'd')) {
1211 if (!(symbolPath in origSymbols)) {
1212 origSymbols[symbolPath] = target;
1213 }
1214 builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
1215 }
1216 }
1217};
1218
1219exports.getOriginalSymbol = function (context, symbolPath) {
1220 var origSymbols = context.CDV_origSymbols;
1221 if (origSymbols && (symbolPath in origSymbols)) {
1222 return origSymbols[symbolPath];
1223 }
1224 var parts = symbolPath.split('.');
1225 var obj = context;
1226 for (var i = 0; i < parts.length; ++i) {
1227 obj = obj && obj[parts[i]];
1228 }
1229 return obj;
1230};
1231
1232exports.reset();
1233
1234});
1235
1236// file: ../cordova-ios/cordova-js-src/platform.js
1237define("cordova/platform", function(require, exports, module) {
1238
1239module.exports = {
1240 id: 'ios',
1241 bootstrap: function () {
1242 // Attach the console polyfill that is iOS-only to window.console
1243 // see the file under plugin/ios/console.js
1244 require('cordova/modulemapper').clobbers('cordova/plugin/ios/console', 'window.console');
1245
1246 // Attach the wkwebkit utility to window.WkWebView
1247 // see the file under plugin/ios/wkwebkit.js
1248 require('cordova/modulemapper').clobbers('cordova/plugin/ios/wkwebkit', 'window.WkWebView');
1249
1250 // Attach the splashscreen utility to window.navigator.splashscreen
1251 // see the file under plugin/ios/launchscreen.js
1252 require('cordova/modulemapper').clobbers('cordova/plugin/ios/launchscreen', 'navigator.splashscreen');
1253
1254 require('cordova/channel').onNativeReady.fire();
1255 }
1256};
1257
1258});
1259
1260// file: ../cordova-ios/cordova-js-src/plugin/ios/console.js
1261define("cordova/plugin/ios/console", function(require, exports, module) {
1262
1263// ------------------------------------------------------------------------------
1264
1265var logger = require('cordova/plugin/ios/logger');
1266
1267// ------------------------------------------------------------------------------
1268// object that we're exporting
1269// ------------------------------------------------------------------------------
1270var console = module.exports;
1271
1272// ------------------------------------------------------------------------------
1273// copy of the original console object
1274// ------------------------------------------------------------------------------
1275var WinConsole = window.console;
1276
1277// ------------------------------------------------------------------------------
1278// whether to use the logger
1279// ------------------------------------------------------------------------------
1280var UseLogger = false;
1281
1282// ------------------------------------------------------------------------------
1283// Timers
1284// ------------------------------------------------------------------------------
1285var Timers = {};
1286
1287// ------------------------------------------------------------------------------
1288// used for unimplemented methods
1289// ------------------------------------------------------------------------------
1290function noop () {}
1291
1292// ------------------------------------------------------------------------------
1293// used for unimplemented methods
1294// ------------------------------------------------------------------------------
1295console.useLogger = function (value) {
1296 if (arguments.length) UseLogger = !!value;
1297
1298 if (UseLogger) {
1299 if (logger.useConsole()) {
1300 throw new Error('console and logger are too intertwingly');
1301 }
1302 }
1303
1304 return UseLogger;
1305};
1306
1307// ------------------------------------------------------------------------------
1308console.log = function () {
1309 if (logger.useConsole()) return;
1310 logger.log.apply(logger, [].slice.call(arguments));
1311};
1312
1313// ------------------------------------------------------------------------------
1314console.error = function () {
1315 if (logger.useConsole()) return;
1316 logger.error.apply(logger, [].slice.call(arguments));
1317};
1318
1319// ------------------------------------------------------------------------------
1320console.warn = function () {
1321 if (logger.useConsole()) return;
1322 logger.warn.apply(logger, [].slice.call(arguments));
1323};
1324
1325// ------------------------------------------------------------------------------
1326console.info = function () {
1327 if (logger.useConsole()) return;
1328 logger.info.apply(logger, [].slice.call(arguments));
1329};
1330
1331// ------------------------------------------------------------------------------
1332console.debug = function () {
1333 if (logger.useConsole()) return;
1334 logger.debug.apply(logger, [].slice.call(arguments));
1335};
1336
1337// ------------------------------------------------------------------------------
1338console.assert = function (expression) {
1339 if (expression) return;
1340
1341 var message = logger.format.apply(logger.format, [].slice.call(arguments, 1));
1342 console.log('ASSERT: ' + message);
1343};
1344
1345// ------------------------------------------------------------------------------
1346console.clear = function () {};
1347
1348// ------------------------------------------------------------------------------
1349console.dir = function (object) {
1350 console.log('%o', object);
1351};
1352
1353// ------------------------------------------------------------------------------
1354console.dirxml = function (node) {
1355 console.log(node.innerHTML);
1356};
1357
1358// ------------------------------------------------------------------------------
1359console.trace = noop;
1360
1361// ------------------------------------------------------------------------------
1362console.group = console.log;
1363
1364// ------------------------------------------------------------------------------
1365console.groupCollapsed = console.log;
1366
1367// ------------------------------------------------------------------------------
1368console.groupEnd = noop;
1369
1370// ------------------------------------------------------------------------------
1371console.time = function (name) {
1372 Timers[name] = new Date().valueOf();
1373};
1374
1375// ------------------------------------------------------------------------------
1376console.timeEnd = function (name) {
1377 var timeStart = Timers[name];
1378 if (!timeStart) {
1379 console.warn('unknown timer: ' + name);
1380 return;
1381 }
1382
1383 var timeElapsed = new Date().valueOf() - timeStart;
1384 console.log(name + ': ' + timeElapsed + 'ms');
1385};
1386
1387// ------------------------------------------------------------------------------
1388console.timeStamp = noop;
1389
1390// ------------------------------------------------------------------------------
1391console.profile = noop;
1392
1393// ------------------------------------------------------------------------------
1394console.profileEnd = noop;
1395
1396// ------------------------------------------------------------------------------
1397console.count = noop;
1398
1399// ------------------------------------------------------------------------------
1400console.exception = console.log;
1401
1402// ------------------------------------------------------------------------------
1403console.table = function (data, columns) {
1404 console.log('%o', data);
1405};
1406
1407// ------------------------------------------------------------------------------
1408// return a new function that calls both functions passed as args
1409// ------------------------------------------------------------------------------
1410function wrappedOrigCall (orgFunc, newFunc) {
1411 return function () {
1412 var args = [].slice.call(arguments);
1413 try { orgFunc.apply(WinConsole, args); } catch (e) {}
1414 try { newFunc.apply(console, args); } catch (e) {}
1415 };
1416}
1417
1418// ------------------------------------------------------------------------------
1419// For every function that exists in the original console object, that
1420// also exists in the new console object, wrap the new console method
1421// with one that calls both
1422// ------------------------------------------------------------------------------
1423for (var key in console) {
1424 if (typeof WinConsole[key] === 'function') {
1425 console[key] = wrappedOrigCall(WinConsole[key], console[key]);
1426 }
1427}
1428
1429});
1430
1431// file: ../cordova-ios/cordova-js-src/plugin/ios/launchscreen.js
1432define("cordova/plugin/ios/launchscreen", function(require, exports, module) {
1433
1434var exec = require('cordova/exec');
1435
1436var launchscreen = {
1437 show: function () {
1438 exec(null, null, 'LaunchScreen', 'show', []);
1439 },
1440 hide: function () {
1441 exec(null, null, 'LaunchScreen', 'hide', []);
1442 }
1443};
1444
1445module.exports = launchscreen;
1446
1447});
1448
1449// file: ../cordova-ios/cordova-js-src/plugin/ios/logger.js
1450define("cordova/plugin/ios/logger", function(require, exports, module) {
1451
1452// ------------------------------------------------------------------------------
1453// The logger module exports the following properties/functions:
1454//
1455// LOG - constant for the level LOG
1456// ERROR - constant for the level ERROR
1457// WARN - constant for the level WARN
1458// INFO - constant for the level INFO
1459// DEBUG - constant for the level DEBUG
1460// logLevel() - returns current log level
1461// logLevel(value) - sets and returns a new log level
1462// useConsole() - returns whether logger is using console
1463// useConsole(value) - sets and returns whether logger is using console
1464// log(message,...) - logs a message at level LOG
1465// error(message,...) - logs a message at level ERROR
1466// warn(message,...) - logs a message at level WARN
1467// info(message,...) - logs a message at level INFO
1468// debug(message,...) - logs a message at level DEBUG
1469// logLevel(level,message,...) - logs a message specified level
1470//
1471// ------------------------------------------------------------------------------
1472
1473var logger = exports;
1474
1475var exec = require('cordova/exec');
1476
1477var UseConsole = false;
1478var UseLogger = true;
1479var Queued = [];
1480var DeviceReady = false;
1481var CurrentLevel;
1482
1483var originalConsole = console;
1484
1485/**
1486 * Logging levels
1487 */
1488
1489var Levels = [
1490 'LOG',
1491 'ERROR',
1492 'WARN',
1493 'INFO',
1494 'DEBUG'
1495];
1496
1497/*
1498 * add the logging levels to the logger object and
1499 * to a separate levelsMap object for testing
1500 */
1501
1502var LevelsMap = {};
1503for (var i = 0; i < Levels.length; i++) {
1504 var level = Levels[i];
1505 LevelsMap[level] = i;
1506 logger[level] = level;
1507}
1508
1509CurrentLevel = LevelsMap.WARN;
1510
1511/**
1512 * Getter/Setter for the logging level
1513 *
1514 * Returns the current logging level.
1515 *
1516 * When a value is passed, sets the logging level to that value.
1517 * The values should be one of the following constants:
1518 * logger.LOG
1519 * logger.ERROR
1520 * logger.WARN
1521 * logger.INFO
1522 * logger.DEBUG
1523 *
1524 * The value used determines which messages get printed. The logging
1525 * values above are in order, and only messages logged at the logging
1526 * level or above will actually be displayed to the user. E.g., the
1527 * default level is WARN, so only messages logged with LOG, ERROR, or
1528 * WARN will be displayed; INFO and DEBUG messages will be ignored.
1529 */
1530logger.level = function (value) {
1531 if (arguments.length) {
1532 if (LevelsMap[value] === null) {
1533 throw new Error('invalid logging level: ' + value);
1534 }
1535 CurrentLevel = LevelsMap[value];
1536 }
1537
1538 return Levels[CurrentLevel];
1539};
1540
1541/**
1542 * Getter/Setter for the useConsole functionality
1543 *
1544 * When useConsole is true, the logger will log via the
1545 * browser 'console' object.
1546 */
1547logger.useConsole = function (value) {
1548 if (arguments.length) UseConsole = !!value;
1549
1550 if (UseConsole) {
1551 if (typeof console === 'undefined') {
1552 throw new Error('global console object is not defined');
1553 }
1554
1555 if (typeof console.log !== 'function') {
1556 throw new Error('global console object does not have a log function');
1557 }
1558
1559 if (typeof console.useLogger === 'function') {
1560 if (console.useLogger()) {
1561 throw new Error('console and logger are too intertwingly');
1562 }
1563 }
1564 }
1565
1566 return UseConsole;
1567};
1568
1569/**
1570 * Getter/Setter for the useLogger functionality
1571 *
1572 * When useLogger is true, the logger will log via the
1573 * native Logger plugin.
1574 */
1575logger.useLogger = function (value) {
1576 // Enforce boolean
1577 if (arguments.length) UseLogger = !!value;
1578 return UseLogger;
1579};
1580
1581/**
1582 * Logs a message at the LOG level.
1583 *
1584 * Parameters passed after message are used applied to
1585 * the message with utils.format()
1586 */
1587logger.log = function (message) { logWithArgs('LOG', arguments); };
1588
1589/**
1590 * Logs a message at the ERROR level.
1591 *
1592 * Parameters passed after message are used applied to
1593 * the message with utils.format()
1594 */
1595logger.error = function (message) { logWithArgs('ERROR', arguments); };
1596
1597/**
1598 * Logs a message at the WARN level.
1599 *
1600 * Parameters passed after message are used applied to
1601 * the message with utils.format()
1602 */
1603logger.warn = function (message) { logWithArgs('WARN', arguments); };
1604
1605/**
1606 * Logs a message at the INFO level.
1607 *
1608 * Parameters passed after message are used applied to
1609 * the message with utils.format()
1610 */
1611logger.info = function (message) { logWithArgs('INFO', arguments); };
1612
1613/**
1614 * Logs a message at the DEBUG level.
1615 *
1616 * Parameters passed after message are used applied to
1617 * the message with utils.format()
1618 */
1619logger.debug = function (message) { logWithArgs('DEBUG', arguments); };
1620
1621// log at the specified level with args
1622function logWithArgs (level, args) {
1623 args = [level].concat([].slice.call(args));
1624 logger.logLevel.apply(logger, args);
1625}
1626
1627// return the correct formatString for an object
1628function formatStringForMessage (message) {
1629 return (typeof message === 'string') ? '' : '%o';
1630}
1631
1632/**
1633 * Logs a message at the specified level.
1634 *
1635 * Parameters passed after message are used applied to
1636 * the message with utils.format()
1637 */
1638logger.logLevel = function (level /* , ... */) {
1639 // format the message with the parameters
1640 var formatArgs = [].slice.call(arguments, 1);
1641 var fmtString = formatStringForMessage(formatArgs[0]);
1642 if (fmtString.length > 0) {
1643 formatArgs.unshift(fmtString); // add formatString
1644 }
1645
1646 var message = logger.format.apply(logger.format, formatArgs);
1647
1648 if (LevelsMap[level] === null) {
1649 throw new Error('invalid logging level: ' + level);
1650 }
1651
1652 if (LevelsMap[level] > CurrentLevel) return;
1653
1654 // queue the message if not yet at deviceready
1655 if (!DeviceReady && !UseConsole) {
1656 Queued.push([level, message]);
1657 return;
1658 }
1659
1660 // Log using the native logger if that is enabled
1661 if (UseLogger) {
1662 exec(null, null, 'Console', 'logLevel', [level, message]);
1663 }
1664
1665 // Log using the console if that is enabled
1666 if (UseConsole) {
1667 // make sure console is not using logger
1668 if (console.useLogger()) {
1669 throw new Error('console and logger are too intertwingly');
1670 }
1671
1672 // log to the console
1673 switch (level) {
1674 case logger.LOG: originalConsole.log(message); break;
1675 case logger.ERROR: originalConsole.log('ERROR: ' + message); break;
1676 case logger.WARN: originalConsole.log('WARN: ' + message); break;
1677 case logger.INFO: originalConsole.log('INFO: ' + message); break;
1678 case logger.DEBUG: originalConsole.log('DEBUG: ' + message); break;
1679 }
1680 }
1681};
1682
1683/**
1684 * Formats a string and arguments following it ala console.log()
1685 *
1686 * Any remaining arguments will be appended to the formatted string.
1687 *
1688 * for rationale, see FireBug's Console API:
1689 * http://getfirebug.com/wiki/index.php/Console_API
1690 */
1691logger.format = function (formatString, args) {
1692 return __format(arguments[0], [].slice.call(arguments, 1)).join(' ');
1693};
1694
1695// ------------------------------------------------------------------------------
1696/**
1697 * Formats a string and arguments following it ala vsprintf()
1698 *
1699 * format chars:
1700 * %j - format arg as JSON
1701 * %o - format arg as JSON
1702 * %c - format arg as ''
1703 * %% - replace with '%'
1704 * any other char following % will format it's
1705 * arg via toString().
1706 *
1707 * Returns an array containing the formatted string and any remaining
1708 * arguments.
1709 */
1710function __format (formatString, args) {
1711 if (formatString === null || formatString === undefined) return [''];
1712 if (arguments.length === 1) return [formatString.toString()];
1713
1714 if (typeof formatString !== 'string') { formatString = formatString.toString(); }
1715
1716 var pattern = /(.*?)%(.)(.*)/;
1717 var rest = formatString;
1718 var result = [];
1719
1720 while (args.length) {
1721 var match = pattern.exec(rest);
1722 if (!match) break;
1723
1724 var arg = args.shift();
1725 rest = match[3];
1726 result.push(match[1]);
1727
1728 if (match[2] === '%') {
1729 result.push('%');
1730 args.unshift(arg);
1731 continue;
1732 }
1733
1734 result.push(__formatted(arg, match[2]));
1735 }
1736
1737 result.push(rest);
1738
1739 var remainingArgs = [].slice.call(args);
1740 remainingArgs.unshift(result.join(''));
1741 return remainingArgs;
1742}
1743
1744function __formatted (object, formatChar) {
1745 try {
1746 switch (formatChar) {
1747 case 'j':
1748 case 'o': return JSON.stringify(object);
1749 case 'c': return '';
1750 }
1751 } catch (e) {
1752 return 'error JSON.stringify()ing argument: ' + e;
1753 }
1754
1755 if ((object === null) || (object === undefined)) {
1756 return Object.prototype.toString.call(object);
1757 }
1758
1759 return object.toString();
1760}
1761
1762// ------------------------------------------------------------------------------
1763// when deviceready fires, log queued messages
1764logger.__onDeviceReady = function () {
1765 if (DeviceReady) return;
1766
1767 DeviceReady = true;
1768
1769 for (var i = 0; i < Queued.length; i++) {
1770 var messageArgs = Queued[i];
1771 logger.logLevel(messageArgs[0], messageArgs[1]);
1772 }
1773
1774 Queued = null;
1775};
1776
1777// add a deviceready event to log queued messages
1778document.addEventListener('deviceready', logger.__onDeviceReady, false);
1779
1780});
1781
1782// file: ../cordova-ios/cordova-js-src/plugin/ios/wkwebkit.js
1783define("cordova/plugin/ios/wkwebkit", function(require, exports, module) {
1784
1785var exec = require('cordova/exec');
1786
1787var WkWebKit = {
1788 allowsBackForwardNavigationGestures: function (allow) {
1789 exec(null, null, 'CDVWebViewEngine', 'allowsBackForwardNavigationGestures', [allow]);
1790 },
1791 convertFilePath: function (path) {
1792 if (!path || !window.CDV_ASSETS_URL) {
1793 return path;
1794 }
1795 if (path.startsWith('/')) {
1796 return window.CDV_ASSETS_URL + '/_app_file_' + path;
1797 }
1798 if (path.startsWith('file://')) {
1799 return window.CDV_ASSETS_URL + path.replace('file://', '/_app_file_');
1800 }
1801 return path;
1802 }
1803};
1804
1805module.exports = WkWebKit;
1806
1807});
1808
1809// file: src/common/pluginloader.js
1810define("cordova/pluginloader", function(require, exports, module) {
1811
1812var modulemapper = require('cordova/modulemapper');
1813
1814// Helper function to inject a <script> tag.
1815// Exported for testing.
1816exports.injectScript = function (url, onload, onerror) {
1817 var script = document.createElement('script');
1818 // onload fires even when script fails loads with an error.
1819 script.onload = onload;
1820 // onerror fires for malformed URLs.
1821 script.onerror = onerror;
1822 script.src = url;
1823 document.head.appendChild(script);
1824};
1825
1826function injectIfNecessary (id, url, onload, onerror) {
1827 onerror = onerror || onload;
1828 if (id in define.moduleMap) {
1829 onload();
1830 } else {
1831 exports.injectScript(url, function () {
1832 if (id in define.moduleMap) {
1833 onload();
1834 } else {
1835 onerror();
1836 }
1837 }, onerror);
1838 }
1839}
1840
1841function onScriptLoadingComplete (moduleList, finishPluginLoading) {
1842 // Loop through all the plugins and then through their clobbers and merges.
1843 for (var i = 0, module; (module = moduleList[i]); i++) {
1844 if (module.clobbers && module.clobbers.length) {
1845 for (var j = 0; j < module.clobbers.length; j++) {
1846 modulemapper.clobbers(module.id, module.clobbers[j]);
1847 }
1848 }
1849
1850 if (module.merges && module.merges.length) {
1851 for (var k = 0; k < module.merges.length; k++) {
1852 modulemapper.merges(module.id, module.merges[k]);
1853 }
1854 }
1855
1856 // Finally, if runs is truthy we want to simply require() the module.
1857 if (module.runs) {
1858 modulemapper.runs(module.id);
1859 }
1860 }
1861
1862 finishPluginLoading();
1863}
1864
1865// Handler for the cordova_plugins.js content.
1866// See plugman's plugin_loader.js for the details of this object.
1867// This function is only called if the really is a plugins array that isn't empty.
1868// Otherwise the onerror response handler will just call finishPluginLoading().
1869function handlePluginsObject (path, moduleList, finishPluginLoading) {
1870 // Now inject the scripts.
1871 var scriptCounter = moduleList.length;
1872
1873 if (!scriptCounter) {
1874 finishPluginLoading();
1875 return;
1876 }
1877 function scriptLoadedCallback () {
1878 if (!--scriptCounter) {
1879 onScriptLoadingComplete(moduleList, finishPluginLoading);
1880 }
1881 }
1882
1883 for (var i = 0; i < moduleList.length; i++) {
1884 injectIfNecessary(moduleList[i].id, path + moduleList[i].file, scriptLoadedCallback);
1885 }
1886}
1887
1888function findCordovaPath () {
1889 var path = null;
1890 var scripts = document.getElementsByTagName('script');
1891 var term = '/cordova.js';
1892 for (var n = scripts.length - 1; n > -1; n--) {
1893 var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
1894 if (src.indexOf(term) === (src.length - term.length)) {
1895 path = src.substring(0, src.length - term.length) + '/';
1896 break;
1897 }
1898 }
1899 return path;
1900}
1901
1902// Tries to load all plugins' js-modules.
1903// This is an async process, but onDeviceReady is blocked on onPluginsReady.
1904// onPluginsReady is fired when there are no plugins to load, or they are all done.
1905exports.load = function (callback) {
1906 var pathPrefix = findCordovaPath();
1907 if (pathPrefix === null) {
1908 console.log('Could not find cordova.js script tag. Plugin loading may fail.');
1909 pathPrefix = '';
1910 }
1911 injectIfNecessary('cordova/plugin_list', pathPrefix + 'cordova_plugins.js', function () {
1912 var moduleList = require('cordova/plugin_list');
1913 handlePluginsObject(pathPrefix, moduleList, callback);
1914 }, callback);
1915};
1916
1917});
1918
1919// file: src/common/urlutil.js
1920define("cordova/urlutil", function(require, exports, module) {
1921
1922/**
1923 * For already absolute URLs, returns what is passed in.
1924 * For relative URLs, converts them to absolute ones.
1925 */
1926exports.makeAbsolute = function makeAbsolute (url) {
1927 var anchorEl = document.createElement('a');
1928 anchorEl.href = url;
1929 return anchorEl.href;
1930};
1931
1932});
1933
1934// file: src/common/utils.js
1935define("cordova/utils", function(require, exports, module) {
1936
1937var utils = exports;
1938
1939/**
1940 * Defines a property getter / setter for obj[key].
1941 */
1942utils.defineGetterSetter = function (obj, key, getFunc, opt_setFunc) {
1943 if (Object.defineProperty) {
1944 var desc = {
1945 get: getFunc,
1946 configurable: true
1947 };
1948 if (opt_setFunc) {
1949 desc.set = opt_setFunc;
1950 }
1951 Object.defineProperty(obj, key, desc);
1952 } else {
1953 obj.__defineGetter__(key, getFunc);
1954 if (opt_setFunc) {
1955 obj.__defineSetter__(key, opt_setFunc);
1956 }
1957 }
1958};
1959
1960/**
1961 * Defines a property getter for obj[key].
1962 */
1963utils.defineGetter = utils.defineGetterSetter;
1964
1965utils.arrayIndexOf = function (a, item) {
1966 if (a.indexOf) {
1967 return a.indexOf(item);
1968 }
1969 var len = a.length;
1970 for (var i = 0; i < len; ++i) {
1971 if (a[i] === item) {
1972 return i;
1973 }
1974 }
1975 return -1;
1976};
1977
1978/**
1979 * Returns whether the item was found in the array.
1980 */
1981utils.arrayRemove = function (a, item) {
1982 var index = utils.arrayIndexOf(a, item);
1983 if (index !== -1) {
1984 a.splice(index, 1);
1985 }
1986 return index !== -1;
1987};
1988
1989utils.typeName = function (val) {
1990 return Object.prototype.toString.call(val).slice(8, -1);
1991};
1992
1993/**
1994 * Returns an indication of whether the argument is an array or not
1995 */
1996utils.isArray = Array.isArray ||
1997 function (a) { return utils.typeName(a) === 'Array'; };
1998
1999/**
2000 * Returns an indication of whether the argument is a Date or not
2001 */
2002utils.isDate = function (d) {
2003 return (d instanceof Date);
2004};
2005
2006/**
2007 * Does a deep clone of the object.
2008 */
2009utils.clone = function (obj) {
2010 if (!obj || typeof obj === 'function' || utils.isDate(obj) || typeof obj !== 'object') {
2011 return obj;
2012 }
2013
2014 var retVal, i;
2015
2016 if (utils.isArray(obj)) {
2017 retVal = [];
2018 for (i = 0; i < obj.length; ++i) {
2019 retVal.push(utils.clone(obj[i]));
2020 }
2021 return retVal;
2022 }
2023
2024 retVal = {};
2025 for (i in obj) {
2026 // 'unknown' type may be returned in custom protocol activation case on
2027 // Windows Phone 8.1 causing "No such interface supported" exception on
2028 // cloning (https://issues.apache.org/jira/browse/CB-11522)
2029 // eslint-disable-next-line valid-typeof
2030 if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') {
2031 retVal[i] = utils.clone(obj[i]);
2032 }
2033 }
2034 return retVal;
2035};
2036
2037/**
2038 * Returns a wrapped version of the function
2039 */
2040utils.close = function (context, func, params) {
2041 return function () {
2042 var args = params || arguments;
2043 return func.apply(context, args);
2044 };
2045};
2046
2047// ------------------------------------------------------------------------------
2048function UUIDcreatePart (length) {
2049 var uuidpart = '';
2050 for (var i = 0; i < length; i++) {
2051 var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
2052 if (uuidchar.length === 1) {
2053 uuidchar = '0' + uuidchar;
2054 }
2055 uuidpart += uuidchar;
2056 }
2057 return uuidpart;
2058}
2059
2060/**
2061 * Create a UUID
2062 */
2063utils.createUUID = function () {
2064 return UUIDcreatePart(4) + '-' +
2065 UUIDcreatePart(2) + '-' +
2066 UUIDcreatePart(2) + '-' +
2067 UUIDcreatePart(2) + '-' +
2068 UUIDcreatePart(6);
2069};
2070
2071/**
2072 * Extends a child object from a parent object using classical inheritance
2073 * pattern.
2074 */
2075utils.extend = (function () {
2076 // proxy used to establish prototype chain
2077 var F = function () {};
2078 // extend Child from Parent
2079 return function (Child, Parent) {
2080 F.prototype = Parent.prototype;
2081 Child.prototype = new F();
2082 Child.__super__ = Parent.prototype;
2083 Child.prototype.constructor = Child;
2084 };
2085}());
2086
2087/**
2088 * Alerts a message in any available way: alert or console.log.
2089 */
2090utils.alert = function (msg) {
2091 if (window.alert) {
2092 window.alert(msg);
2093 } else if (console && console.log) {
2094 console.log(msg);
2095 }
2096};
2097
2098});
2099
2100window.cordova = require('cordova');
2101// file: src/scripts/bootstrap.js
2102require('cordova/init');
2103
2104})();