· 7 years ago · Dec 11, 2018, 09:28 AM
1// commit 02b91c5313ff37d74a58f71775170afd360f4a1f
2
3// File generated at :: Wed Oct 31 2012 10:40:25 GMT-0700 (PDT)
4
5/*
6 Licensed to the Apache Software Foundation (ASF) under one
7 or more contributor license agreements. See the NOTICE file
8 distributed with this work for additional information
9 regarding copyright ownership. The ASF licenses this file
10 to you under the Apache License, Version 2.0 (the
11 "License"); you may not use this file except in compliance
12 with the License. You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing,
17 software distributed under the License is distributed on an
18 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 KIND, either express or implied. See the License for the
20 specific language governing permissions and limitations
21 under the License.
22*/
23
24;(function() {
25
26// file: lib/scripts/require.js
27
28var require,
29 define;
30
31(function () {
32 var modules = {};
33 // Stack of moduleIds currently being built.
34 var requireStack = [];
35 // Map of module ID -> index into requireStack of modules currently being built.
36 var inProgressModules = {};
37
38 function build(module) {
39 var factory = module.factory;
40 module.exports = {};
41 delete module.factory;
42 factory(require, module.exports, module);
43 return module.exports;
44 }
45
46 require = function (id) {
47 if (!modules[id]) {
48 throw "module " + id + " not found";
49 } else if (id in inProgressModules) {
50 var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
51 throw "Cycle in require graph: " + cycle;
52 }
53 if (modules[id].factory) {
54 try {
55 inProgressModules[id] = requireStack.length;
56 requireStack.push(id);
57 return build(modules[id]);
58 } finally {
59 delete inProgressModules[id];
60 requireStack.pop();
61 }
62 }
63 return modules[id].exports;
64 };
65
66 define = function (id, factory) {
67 if (modules[id]) {
68 throw "module " + id + " already defined";
69 }
70
71 modules[id] = {
72 id: id,
73 factory: factory
74 };
75 };
76
77 define.remove = function (id) {
78 delete modules[id];
79 };
80
81})();
82
83//Export for use in node
84if (typeof module === "object" && typeof require === "function") {
85 module.exports.require = require;
86 module.exports.define = define;
87}
88
89// file: lib/cordova.js
90define("cordova", function(require, exports, module) {
91
92
93var channel = require('cordova/channel');
94
95/**
96 * Listen for DOMContentLoaded and notify our channel subscribers.
97 */
98document.addEventListener('DOMContentLoaded', function() {
99 channel.onDOMContentLoaded.fire();
100}, false);
101if (document.readyState == 'complete' || document.readyState == 'interactive') {
102 channel.onDOMContentLoaded.fire();
103}
104
105/**
106 * Intercept calls to addEventListener + removeEventListener and handle deviceready,
107 * resume, and pause events.
108 */
109var m_document_addEventListener = document.addEventListener;
110var m_document_removeEventListener = document.removeEventListener;
111var m_window_addEventListener = window.addEventListener;
112var m_window_removeEventListener = window.removeEventListener;
113
114/**
115 * Houses custom event handlers to intercept on document + window event listeners.
116 */
117var documentEventHandlers = {},
118 windowEventHandlers = {};
119
120document.addEventListener = function(evt, handler, capture) {
121 var e = evt.toLowerCase();
122 if (typeof documentEventHandlers[e] != 'undefined') {
123 documentEventHandlers[e].subscribe(handler);
124 } else {
125 m_document_addEventListener.call(document, evt, handler, capture);
126 }
127};
128
129window.addEventListener = function(evt, handler, capture) {
130 var e = evt.toLowerCase();
131 if (typeof windowEventHandlers[e] != 'undefined') {
132 windowEventHandlers[e].subscribe(handler);
133 } else {
134 m_window_addEventListener.call(window, evt, handler, capture);
135 }
136};
137
138document.removeEventListener = function(evt, handler, capture) {
139 var e = evt.toLowerCase();
140 // If unsubscribing from an event that is handled by a plugin
141 if (typeof documentEventHandlers[e] != "undefined") {
142 documentEventHandlers[e].unsubscribe(handler);
143 } else {
144 m_document_removeEventListener.call(document, evt, handler, capture);
145 }
146};
147
148window.removeEventListener = function(evt, handler, capture) {
149 var e = evt.toLowerCase();
150 // If unsubscribing from an event that is handled by a plugin
151 if (typeof windowEventHandlers[e] != "undefined") {
152 windowEventHandlers[e].unsubscribe(handler);
153 } else {
154 m_window_removeEventListener.call(window, evt, handler, capture);
155 }
156};
157
158function createEvent(type, data) {
159 var event = document.createEvent('Events');
160 event.initEvent(type, false, false);
161 if (data) {
162 for (var i in data) {
163 if (data.hasOwnProperty(i)) {
164 event[i] = data[i];
165 }
166 }
167 }
168 return event;
169}
170
171if(typeof window.console === "undefined") {
172 window.console = {
173 log:function(){}
174 };
175}
176
177var cordova = {
178 define:define,
179 require:require,
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 * Retrieve original event handlers that were replaced by Cordova
200 *
201 * @return object
202 */
203 getOriginalHandlers: function() {
204 return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
205 'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
206 },
207 /**
208 * Method to fire event from native code
209 * bNoDetach is required for events which cause an exception which needs to be caught in native code
210 */
211 fireDocumentEvent: function(type, data, bNoDetach) {
212 var evt = createEvent(type, data);
213 if (typeof documentEventHandlers[type] != 'undefined') {
214 if( bNoDetach ) {
215 documentEventHandlers[type].fire(evt);
216 }
217 else {
218 setTimeout(function() {
219 documentEventHandlers[type].fire(evt);
220 }, 0);
221 }
222 } else {
223 document.dispatchEvent(evt);
224 }
225 },
226 fireWindowEvent: function(type, data) {
227 var evt = createEvent(type,data);
228 if (typeof windowEventHandlers[type] != 'undefined') {
229 setTimeout(function() {
230 windowEventHandlers[type].fire(evt);
231 }, 0);
232 } else {
233 window.dispatchEvent(evt);
234 }
235 },
236
237 /**
238 * Plugin callback mechanism.
239 */
240 // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
241 // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
242 callbackId: Math.floor(Math.random() * 2000000000),
243 callbacks: {},
244 callbackStatus: {
245 NO_RESULT: 0,
246 OK: 1,
247 CLASS_NOT_FOUND_EXCEPTION: 2,
248 ILLEGAL_ACCESS_EXCEPTION: 3,
249 INSTANTIATION_EXCEPTION: 4,
250 MALFORMED_URL_EXCEPTION: 5,
251 IO_EXCEPTION: 6,
252 INVALID_ACTION: 7,
253 JSON_EXCEPTION: 8,
254 ERROR: 9
255 },
256
257 /**
258 * Called by native code when returning successful result from an action.
259 */
260 callbackSuccess: function(callbackId, args) {
261 try {
262 cordova.callbackFromNative(callbackId, true, args.status, args.message, args.keepCallback);
263 } catch (e) {
264 console.log("Error in error callback: " + callbackId + " = "+e);
265 }
266 },
267
268 /**
269 * Called by native code when returning error result from an action.
270 */
271 callbackError: function(callbackId, args) {
272 // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
273 // Derive success from status.
274 try {
275 cordova.callbackFromNative(callbackId, false, args.status, args.message, args.keepCallback);
276 } catch (e) {
277 console.log("Error in error callback: " + callbackId + " = "+e);
278 }
279 },
280
281 /**
282 * Called by native code when returning the result from an action.
283 */
284 callbackFromNative: function(callbackId, success, status, message, keepCallback) {
285 var callback = cordova.callbacks[callbackId];
286 if (callback) {
287 if (success && status == cordova.callbackStatus.OK) {
288 callback.success && callback.success(message);
289 } else if (!success) {
290 callback.fail && callback.fail(message);
291 }
292
293 // Clear callback if not expecting any more results
294 if (!keepCallback) {
295 delete cordova.callbacks[callbackId];
296 }
297 }
298 },
299 addConstructor: function(func) {
300 channel.onCordovaReady.subscribe(function() {
301 try {
302 func();
303 } catch(e) {
304 console.log("Failed to run constructor: " + e);
305 }
306 });
307 }
308};
309
310// Register pause, resume and deviceready channels as events on document.
311channel.onPause = cordova.addDocumentEventHandler('pause');
312channel.onResume = cordova.addDocumentEventHandler('resume');
313channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
314
315module.exports = cordova;
316
317});
318
319// file: lib/common/builder.js
320define("cordova/builder", function(require, exports, module) {
321
322var utils = require('cordova/utils');
323
324function each(objects, func, context) {
325 for (var prop in objects) {
326 if (objects.hasOwnProperty(prop)) {
327 func.apply(context, [objects[prop], prop]);
328 }
329 }
330}
331
332function assignOrWrapInDeprecateGetter(obj, key, value, message) {
333 if (message) {
334 utils.defineGetter(obj, key, function() {
335 window.console && console.log(message);
336 return value;
337 });
338 } else {
339 obj[key] = value;
340 }
341}
342
343function include(parent, objects, clobber, merge) {
344 each(objects, function (obj, key) {
345 try {
346 var result = obj.path ? require(obj.path) : {};
347
348 if (clobber) {
349 // Clobber if it doesn't exist.
350 if (typeof parent[key] === 'undefined') {
351 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
352 } else if (typeof obj.path !== 'undefined') {
353 // If merging, merge properties onto parent, otherwise, clobber.
354 if (merge) {
355 recursiveMerge(parent[key], result);
356 } else {
357 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
358 }
359 }
360 result = parent[key];
361 } else {
362 // Overwrite if not currently defined.
363 if (typeof parent[key] == 'undefined') {
364 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
365 } else if (merge && typeof obj.path !== 'undefined') {
366 // If merging, merge parent onto result
367 recursiveMerge(result, parent[key]);
368 parent[key] = result;
369 } else {
370 // Set result to what already exists, so we can build children into it if they exist.
371 result = parent[key];
372 }
373 }
374
375 if (obj.children) {
376 include(result, obj.children, clobber, merge);
377 }
378 } catch(e) {
379 utils.alert('Exception building cordova JS globals: ' + e + ' for key "' + key + '"');
380 }
381 });
382}
383
384/**
385 * Merge properties from one object onto another recursively. Properties from
386 * the src object will overwrite existing target property.
387 *
388 * @param target Object to merge properties into.
389 * @param src Object to merge properties from.
390 */
391function recursiveMerge(target, src) {
392 for (var prop in src) {
393 if (src.hasOwnProperty(prop)) {
394 if (typeof target.prototype !== 'undefined' && target.prototype.constructor === target) {
395 // If the target object is a constructor override off prototype.
396 target.prototype[prop] = src[prop];
397 } else {
398 target[prop] = typeof src[prop] === 'object' ? recursiveMerge(
399 target[prop], src[prop]) : src[prop];
400 }
401 }
402 }
403 return target;
404}
405
406module.exports = {
407 build: function (objects) {
408 return {
409 intoButDoNotClobber: function (target) {
410 include(target, objects, false, false);
411 },
412 intoAndClobber: function(target) {
413 include(target, objects, true, false);
414 },
415 intoAndMerge: function(target) {
416 include(target, objects, true, true);
417 }
418 };
419 }
420};
421
422});
423
424// file: lib/common/channel.js
425define("cordova/channel", function(require, exports, module) {
426
427var utils = require('cordova/utils'),
428 nextGuid = 1;
429
430/**
431 * Custom pub-sub "channel" that can have functions subscribed to it
432 * This object is used to define and control firing of events for
433 * cordova initialization, as well as for custom events thereafter.
434 *
435 * The order of events during page load and Cordova startup is as follows:
436 *
437 * onDOMContentLoaded* Internal event that is received when the web page is loaded and parsed.
438 * onNativeReady* Internal event that indicates the Cordova native side is ready.
439 * onCordovaReady* Internal event fired when all Cordova JavaScript objects have been created.
440 * onCordovaInfoReady* Internal event fired when device properties are available.
441 * onCordovaConnectionReady* Internal event fired when the connection property has been set.
442 * onDeviceReady* User event fired to indicate that Cordova is ready
443 * onResume User event fired to indicate a start/resume lifecycle event
444 * onPause User event fired to indicate a pause lifecycle event
445 * onDestroy* Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
446 *
447 * The events marked with an * are sticky. Once they have fired, they will stay in the fired state.
448 * All listeners that subscribe after the event is fired will be executed right away.
449 *
450 * The only Cordova events that user code should register for are:
451 * deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
452 * pause App has moved to background
453 * resume App has returned to foreground
454 *
455 * Listeners can be registered as:
456 * document.addEventListener("deviceready", myDeviceReadyListener, false);
457 * document.addEventListener("resume", myResumeListener, false);
458 * document.addEventListener("pause", myPauseListener, false);
459 *
460 * The DOM lifecycle events should be used for saving and restoring state
461 * window.onload
462 * window.onunload
463 *
464 */
465
466/**
467 * Channel
468 * @constructor
469 * @param type String the channel name
470 */
471var Channel = function(type, sticky) {
472 this.type = type;
473 // Map of guid -> function.
474 this.handlers = {};
475 // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired.
476 this.state = sticky ? 1 : 0;
477 // Used in sticky mode to remember args passed to fire().
478 this.fireArgs = null;
479 // Used by onHasSubscribersChange to know if there are any listeners.
480 this.numHandlers = 0;
481 // Function that is called when the first listener is subscribed, or when
482 // the last listener is unsubscribed.
483 this.onHasSubscribersChange = null;
484},
485 channel = {
486 /**
487 * Calls the provided function only after all of the channels specified
488 * have been fired. All channels must be sticky channels.
489 */
490 join: function(h, c) {
491 var len = c.length,
492 i = len,
493 f = function() {
494 if (!(--i)) h();
495 };
496 for (var j=0; j<len; j++) {
497 if (c[j].state === 0) {
498 throw Error('Can only use join with sticky channels.');
499 }
500 c[j].subscribe(f);
501 }
502 if (!len) h();
503 },
504 create: function(type) {
505 return channel[type] = new Channel(type, false);
506 },
507 createSticky: function(type) {
508 return channel[type] = new Channel(type, true);
509 },
510
511 /**
512 * cordova Channels that must fire before "deviceready" is fired.
513 */
514 deviceReadyChannelsArray: [],
515 deviceReadyChannelsMap: {},
516
517 /**
518 * Indicate that a feature needs to be initialized before it is ready to be used.
519 * This holds up Cordova's "deviceready" event until the feature has been initialized
520 * and Cordova.initComplete(feature) is called.
521 *
522 * @param feature {String} The unique feature name
523 */
524 waitForInitialization: function(feature) {
525 if (feature) {
526 var c = channel[feature] || this.createSticky(feature);
527 this.deviceReadyChannelsMap[feature] = c;
528 this.deviceReadyChannelsArray.push(c);
529 }
530 },
531
532 /**
533 * Indicate that initialization code has completed and the feature is ready to be used.
534 *
535 * @param feature {String} The unique feature name
536 */
537 initializationComplete: function(feature) {
538 var c = this.deviceReadyChannelsMap[feature];
539 if (c) {
540 c.fire();
541 }
542 }
543 };
544
545function forceFunction(f) {
546 if (typeof f != 'function') throw "Function required as first argument!";
547}
548
549/**
550 * Subscribes the given function to the channel. Any time that
551 * Channel.fire is called so too will the function.
552 * Optionally specify an execution context for the function
553 * and a guid that can be used to stop subscribing to the channel.
554 * Returns the guid.
555 */
556Channel.prototype.subscribe = function(f, c) {
557 // need a function to call
558 forceFunction(f);
559 if (this.state == 2) {
560 f.apply(c || this, this.fireArgs);
561 return;
562 }
563
564 var func = f,
565 guid = f.observer_guid;
566 if (typeof c == "object") { func = utils.close(c, f); }
567
568 if (!guid) {
569 // first time any channel has seen this subscriber
570 guid = '' + nextGuid++;
571 }
572 func.observer_guid = guid;
573 f.observer_guid = guid;
574
575 // Don't add the same handler more than once.
576 if (!this.handlers[guid]) {
577 this.handlers[guid] = func;
578 this.numHandlers++;
579 if (this.numHandlers == 1) {
580 this.onHasSubscribersChange && this.onHasSubscribersChange();
581 }
582 }
583};
584
585/**
586 * Unsubscribes the function with the given guid from the channel.
587 */
588Channel.prototype.unsubscribe = function(f) {
589 // need a function to unsubscribe
590 forceFunction(f);
591
592 var guid = f.observer_guid,
593 handler = this.handlers[guid];
594 if (handler) {
595 delete this.handlers[guid];
596 this.numHandlers--;
597 if (this.numHandlers === 0) {
598 this.onHasSubscribersChange && this.onHasSubscribersChange();
599 }
600 }
601};
602
603/**
604 * Calls all functions subscribed to this channel.
605 */
606Channel.prototype.fire = function(e) {
607 var fail = false,
608 fireArgs = Array.prototype.slice.call(arguments);
609 // Apply stickiness.
610 if (this.state == 1) {
611 this.state = 2;
612 this.fireArgs = fireArgs;
613 }
614 if (this.numHandlers) {
615 // Copy the values first so that it is safe to modify it from within
616 // callbacks.
617 var toCall = [];
618 for (var item in this.handlers) {
619 toCall.push(this.handlers[item]);
620 }
621 for (var i = 0; i < toCall.length; ++i) {
622 toCall[i].apply(this, fireArgs);
623 }
624 if (this.state == 2 && this.numHandlers) {
625 this.numHandlers = 0;
626 this.handlers = {};
627 this.onHasSubscribersChange && this.onHasSubscribersChange();
628 }
629 }
630};
631
632
633// defining them here so they are ready super fast!
634// DOM event that is received when the web page is loaded and parsed.
635channel.createSticky('onDOMContentLoaded');
636
637// Event to indicate the Cordova native side is ready.
638channel.createSticky('onNativeReady');
639
640// Event to indicate that all Cordova JavaScript objects have been created
641// and it's time to run plugin constructors.
642channel.createSticky('onCordovaReady');
643
644// Event to indicate that device properties are available
645channel.createSticky('onCordovaInfoReady');
646
647// Event to indicate that the connection property has been set.
648channel.createSticky('onCordovaConnectionReady');
649
650// Event to indicate that Cordova is ready
651channel.createSticky('onDeviceReady');
652
653// Event to indicate a resume lifecycle event
654channel.create('onResume');
655
656// Event to indicate a pause lifecycle event
657channel.create('onPause');
658
659// Event to indicate a destroy lifecycle event
660channel.createSticky('onDestroy');
661
662// Channels that must fire before "deviceready" is fired.
663channel.waitForInitialization('onCordovaReady');
664channel.waitForInitialization('onCordovaConnectionReady');
665
666module.exports = channel;
667
668});
669
670// file: lib/common/commandProxy.js
671define("cordova/commandProxy", function(require, exports, module) {
672
673
674// internal map of proxy function
675var CommandProxyMap = {};
676
677module.exports = {
678
679 // example: cordova.commandProxy.add("Accelerometer",{getCurrentAcceleration: function(successCallback, errorCallback, options) {...},...);
680 add:function(id,proxyObj) {
681 console.log("adding proxy for " + id);
682 CommandProxyMap[id] = proxyObj;
683 return proxyObj;
684 },
685
686 // cordova.commandProxy.remove("Accelerometer");
687 remove:function(id) {
688 var proxy = CommandProxyMap[id];
689 delete CommandProxyMap[id];
690 CommandProxyMap[id] = null;
691 return proxy;
692 },
693
694 get:function(service,action) {
695 return ( CommandProxyMap[service] ? CommandProxyMap[service][action] : null );
696 }
697};
698});
699
700// file: lib/common/common.js
701define("cordova/common", function(require, exports, module) {
702
703module.exports = {
704 objects: {
705 cordova: {
706 path: 'cordova',
707 children: {
708 exec: {
709 path: 'cordova/exec'
710 },
711 logger: {
712 path: 'cordova/plugin/logger'
713 }
714 }
715 },
716 Cordova: {
717 children: {
718 exec: {
719 path: 'cordova/exec'
720 }
721 }
722 },
723 navigator: {
724 children: {
725 notification: {
726 path: 'cordova/plugin/notification'
727 },
728 accelerometer: {
729 path: 'cordova/plugin/accelerometer'
730 },
731 battery: {
732 path: 'cordova/plugin/battery'
733 },
734 camera:{
735 path: 'cordova/plugin/Camera'
736 },
737 compass:{
738 path: 'cordova/plugin/compass'
739 },
740 connection: {
741 path: 'cordova/plugin/network'
742 },
743 contacts: {
744 path: 'cordova/plugin/contacts'
745 },
746 device:{
747 children:{
748 capture: {
749 path: 'cordova/plugin/capture'
750 }
751 }
752 },
753 geolocation: {
754 path: 'cordova/plugin/geolocation'
755 },
756 globalization: {
757 path: 'cordova/plugin/globalization'
758 },
759 network: {
760 children: {
761 connection: {
762 path: 'cordova/plugin/network',
763 deprecated: 'navigator.network.connection is deprecated. Use navigator.connection instead.'
764 }
765 }
766 },
767 splashscreen: {
768 path: 'cordova/plugin/splashscreen'
769 }
770 }
771 },
772 Acceleration: {
773 path: 'cordova/plugin/Acceleration'
774 },
775 Camera:{
776 path: 'cordova/plugin/CameraConstants'
777 },
778 CameraPopoverOptions: {
779 path: 'cordova/plugin/CameraPopoverOptions'
780 },
781 CaptureError: {
782 path: 'cordova/plugin/CaptureError'
783 },
784 CaptureAudioOptions:{
785 path: 'cordova/plugin/CaptureAudioOptions'
786 },
787 CaptureImageOptions: {
788 path: 'cordova/plugin/CaptureImageOptions'
789 },
790 CaptureVideoOptions: {
791 path: 'cordova/plugin/CaptureVideoOptions'
792 },
793 CompassHeading:{
794 path: 'cordova/plugin/CompassHeading'
795 },
796 CompassError:{
797 path: 'cordova/plugin/CompassError'
798 },
799 ConfigurationData: {
800 path: 'cordova/plugin/ConfigurationData'
801 },
802 Connection: {
803 path: 'cordova/plugin/Connection'
804 },
805 Contact: {
806 path: 'cordova/plugin/Contact'
807 },
808 ContactAddress: {
809 path: 'cordova/plugin/ContactAddress'
810 },
811 ContactError: {
812 path: 'cordova/plugin/ContactError'
813 },
814 ContactField: {
815 path: 'cordova/plugin/ContactField'
816 },
817 ContactFindOptions: {
818 path: 'cordova/plugin/ContactFindOptions'
819 },
820 ContactName: {
821 path: 'cordova/plugin/ContactName'
822 },
823 ContactOrganization: {
824 path: 'cordova/plugin/ContactOrganization'
825 },
826 Coordinates: {
827 path: 'cordova/plugin/Coordinates'
828 },
829 device: {
830 path: 'cordova/plugin/device'
831 },
832 DirectoryEntry: {
833 path: 'cordova/plugin/DirectoryEntry'
834 },
835 DirectoryReader: {
836 path: 'cordova/plugin/DirectoryReader'
837 },
838 Entry: {
839 path: 'cordova/plugin/Entry'
840 },
841 File: {
842 path: 'cordova/plugin/File'
843 },
844 FileEntry: {
845 path: 'cordova/plugin/FileEntry'
846 },
847 FileError: {
848 path: 'cordova/plugin/FileError'
849 },
850 FileReader: {
851 path: 'cordova/plugin/FileReader'
852 },
853 FileSystem: {
854 path: 'cordova/plugin/FileSystem'
855 },
856 FileTransfer: {
857 path: 'cordova/plugin/FileTransfer'
858 },
859 FileTransferError: {
860 path: 'cordova/plugin/FileTransferError'
861 },
862 FileUploadOptions: {
863 path: 'cordova/plugin/FileUploadOptions'
864 },
865 FileUploadResult: {
866 path: 'cordova/plugin/FileUploadResult'
867 },
868 FileWriter: {
869 path: 'cordova/plugin/FileWriter'
870 },
871 Flags: {
872 path: 'cordova/plugin/Flags'
873 },
874 GlobalizationError: {
875 path: 'cordova/plugin/GlobalizationError'
876 },
877 LocalFileSystem: {
878 path: 'cordova/plugin/LocalFileSystem'
879 },
880 Media: {
881 path: 'cordova/plugin/Media'
882 },
883 MediaError: {
884 path: 'cordova/plugin/MediaError'
885 },
886 MediaFile: {
887 path: 'cordova/plugin/MediaFile'
888 },
889 MediaFileData:{
890 path: 'cordova/plugin/MediaFileData'
891 },
892 Metadata:{
893 path: 'cordova/plugin/Metadata'
894 },
895 Position: {
896 path: 'cordova/plugin/Position'
897 },
898 PositionError: {
899 path: 'cordova/plugin/PositionError'
900 },
901 ProgressEvent: {
902 path: 'cordova/plugin/ProgressEvent'
903 },
904 requestFileSystem:{
905 path: 'cordova/plugin/requestFileSystem'
906 },
907 resolveLocalFileSystemURI:{
908 path: 'cordova/plugin/resolveLocalFileSystemURI'
909 }
910 }
911};
912
913});
914
915// file: lib/android/exec.js
916define("cordova/exec", function(require, exports, module) {
917
918/**
919 * Execute a cordova command. It is up to the native side whether this action
920 * is synchronous or asynchronous. The native side can return:
921 * Synchronous: PluginResult object as a JSON string
922 * Asynchronous: Empty string ""
923 * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
924 * depending upon the result of the action.
925 *
926 * @param {Function} success The success callback
927 * @param {Function} fail The fail callback
928 * @param {String} service The name of the service to use
929 * @param {String} action Action to be run in cordova
930 * @param {String[]} [args] Zero or more arguments to pass to the method
931 */
932var cordova = require('cordova'),
933 nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'),
934 jsToNativeModes = {
935 PROMPT: 0,
936 JS_OBJECT: 1,
937 // This mode is currently for benchmarking purposes only. It must be enabled
938 // on the native side through the ENABLE_LOCATION_CHANGE_EXEC_MODE
939 // constant within CordovaWebViewClient.java before it will work.
940 LOCATION_CHANGE: 2
941 },
942 nativeToJsModes = {
943 // Polls for messages using the JS->Native bridge.
944 POLLING: 0,
945 // For LOAD_URL to be viable, it would need to have a work-around for
946 // the bug where the soft-keyboard gets dismissed when a message is sent.
947 LOAD_URL: 1,
948 // For the ONLINE_EVENT to be viable, it would need to intercept all event
949 // listeners (both through addEventListener and window.ononline) as well
950 // as set the navigator property itself.
951 ONLINE_EVENT: 2,
952 // Uses reflection to access private APIs of the WebView that can send JS
953 // to be executed.
954 // Requires Android 3.2.4 or above.
955 PRIVATE_API: 3
956 },
957 jsToNativeBridgeMode, // Set lazily.
958 nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
959 pollEnabled = false,
960 messagesFromNative = [];
961
962function androidExec(success, fail, service, action, args) {
963 // Set default bridge modes if they have not already been set.
964 if (jsToNativeBridgeMode === undefined) {
965 androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
966 }
967
968 var callbackId = service + cordova.callbackId++,
969 argsJson = JSON.stringify(args),
970 returnValue;
971
972 // TODO: Returning the payload of a synchronous call was deprecated in 2.2.0.
973 // Remove it after 6 months.
974 function captureReturnValue(value) {
975 returnValue = value;
976 success && success(value);
977 }
978
979 cordova.callbacks[callbackId] = {success:captureReturnValue, fail:fail};
980
981 if (jsToNativeBridgeMode == jsToNativeModes.LOCATION_CHANGE) {
982 window.location = 'http://cdv_exec/' + service + '#' + action + '#' + callbackId + '#' + argsJson;
983 } else {
984 var messages = nativeApiProvider.get().exec(service, action, callbackId, argsJson);
985 androidExec.processMessages(messages);
986 }
987 if (cordova.callbacks[callbackId]) {
988 if (success || fail) {
989 cordova.callbacks[callbackId].success = success;
990 } else {
991 delete cordova.callbacks[callbackId];
992 }
993 }
994 return returnValue;
995}
996
997function pollOnce() {
998 var msg = nativeApiProvider.get().retrieveJsMessages();
999 androidExec.processMessages(msg);
1000}
1001
1002function pollingTimerFunc() {
1003 if (pollEnabled) {
1004 pollOnce();
1005 setTimeout(pollingTimerFunc, 50);
1006 }
1007}
1008
1009function hookOnlineApis() {
1010 function proxyEvent(e) {
1011 cordova.fireWindowEvent(e.type);
1012 }
1013 // The network module takes care of firing online and offline events.
1014 // It currently fires them only on document though, so we bridge them
1015 // to window here (while first listening for exec()-releated online/offline
1016 // events).
1017 window.addEventListener('online', pollOnce, false);
1018 window.addEventListener('offline', pollOnce, false);
1019 cordova.addWindowEventHandler('online');
1020 cordova.addWindowEventHandler('offline');
1021 document.addEventListener('online', proxyEvent, false);
1022 document.addEventListener('offline', proxyEvent, false);
1023}
1024
1025hookOnlineApis();
1026
1027androidExec.jsToNativeModes = jsToNativeModes;
1028androidExec.nativeToJsModes = nativeToJsModes;
1029
1030androidExec.setJsToNativeBridgeMode = function(mode) {
1031 if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
1032 console.log('Falling back on PROMPT mode since _cordovaNative is missing.');
1033 mode = jsToNativeModes.PROMPT;
1034 }
1035 nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
1036 jsToNativeBridgeMode = mode;
1037};
1038
1039androidExec.setNativeToJsBridgeMode = function(mode) {
1040 if (mode == nativeToJsBridgeMode) {
1041 return;
1042 }
1043 if (nativeToJsBridgeMode == nativeToJsModes.POLLING) {
1044 pollEnabled = false;
1045 }
1046
1047 nativeToJsBridgeMode = mode;
1048 // Tell the native side to switch modes.
1049 nativeApiProvider.get().setNativeToJsBridgeMode(mode);
1050
1051 if (mode == nativeToJsModes.POLLING) {
1052 pollEnabled = true;
1053 setTimeout(pollingTimerFunc, 1);
1054 }
1055};
1056
1057// Processes a single message, as encoded by NativeToJsMessageQueue.java.
1058function processMessage(message) {
1059 try {
1060 var firstChar = message.charAt(0);
1061 if (firstChar == 'J') {
1062 eval(message.slice(1));
1063 } else if (firstChar == 'S' || firstChar == 'F') {
1064 var success = firstChar == 'S';
1065 var keepCallback = message.charAt(1) == '1';
1066 var spaceIdx = message.indexOf(' ', 2);
1067 var status = +message.slice(2, spaceIdx);
1068 var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
1069 var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
1070 var payloadKind = message.charAt(nextSpaceIdx + 1);
1071 var payload;
1072 if (payloadKind == 's') {
1073 payload = message.slice(nextSpaceIdx + 2);
1074 } else if (payloadKind == 't') {
1075 payload = true;
1076 } else if (payloadKind == 'f') {
1077 payload = false;
1078 } else if (payloadKind == 'N') {
1079 payload = null;
1080 } else if (payloadKind == 'n') {
1081 payload = +message.slice(nextSpaceIdx + 2);
1082 } else {
1083 payload = JSON.parse(message.slice(nextSpaceIdx + 1));
1084 }
1085 cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
1086 } else {
1087 console.log("processMessage failed: invalid message:" + message);
1088 }
1089 } catch (e) {
1090 console.log("processMessage failed: Message: " + message);
1091 console.log("processMessage failed: Error: " + e);
1092 console.log("processMessage failed: Stack: " + e.stack);
1093 }
1094}
1095
1096// This is called from the NativeToJsMessageQueue.java.
1097androidExec.processMessages = function(messages) {
1098 if (messages) {
1099 messagesFromNative.push(messages);
1100 while (messagesFromNative.length) {
1101 messages = messagesFromNative.shift();
1102 // The Java side can send a * message to indicate that it
1103 // still has messages waiting to be retrieved.
1104 // TODO(agrieve): This is currently disabled on the Java side
1105 // since it breaks returning the result in exec of synchronous
1106 // plugins. Once we remove this ability, we can remove this comment.
1107 if (messages == '*') {
1108 window.setTimeout(pollOnce, 0);
1109 continue;
1110 }
1111
1112 var spaceIdx = messages.indexOf(' ');
1113 var msgLen = +messages.slice(0, spaceIdx);
1114 var message = messages.substr(spaceIdx + 1, msgLen);
1115 messages = messages.slice(spaceIdx + msgLen + 1);
1116 // Put the remaining messages back into queue in case an exec()
1117 // is made by the callback.
1118 if (messages) {
1119 messagesFromNative.unshift(messages);
1120 }
1121
1122 if (message) {
1123 processMessage(message);
1124 }
1125 }
1126 }
1127};
1128
1129module.exports = androidExec;
1130
1131});
1132
1133// file: lib/android/platform.js
1134define("cordova/platform", function(require, exports, module) {
1135
1136module.exports = {
1137 id: "android",
1138 initialize:function() {
1139 var channel = require("cordova/channel"),
1140 cordova = require('cordova'),
1141 exec = require('cordova/exec');
1142
1143 // Inject a listener for the backbutton on the document.
1144 var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
1145 backButtonChannel.onHasSubscribersChange = function() {
1146 // If we just attached the first handler or detached the last handler,
1147 // let native know we need to override the back button.
1148 exec(null, null, "App", "overrideBackbutton", [this.numHandlers == 1]);
1149 };
1150
1151 // Add hardware MENU and SEARCH button handlers
1152 cordova.addDocumentEventHandler('menubutton');
1153 cordova.addDocumentEventHandler('searchbutton');
1154
1155 // Figure out if we need to shim-in localStorage and WebSQL
1156 // support from the native side.
1157 var storage = require('cordova/plugin/android/storage');
1158
1159 // First patch WebSQL if necessary
1160 if (typeof window.openDatabase == 'undefined') {
1161 // Not defined, create an openDatabase function for all to use!
1162 window.openDatabase = storage.openDatabase;
1163 } else {
1164 // Defined, but some Android devices will throw a SECURITY_ERR -
1165 // so we wrap the whole thing in a try-catch and shim in our own
1166 // if the device has Android bug 16175.
1167 var originalOpenDatabase = window.openDatabase;
1168 window.openDatabase = function(name, version, desc, size) {
1169 var db = null;
1170 try {
1171 db = originalOpenDatabase(name, version, desc, size);
1172 }
1173 catch (ex) {
1174 if (ex.code === 18) {
1175 db = null;
1176 } else {
1177 throw ex;
1178 }
1179 }
1180
1181 if (db === null) {
1182 return storage.openDatabase(name, version, desc, size);
1183 }
1184 else {
1185 return db;
1186 }
1187
1188 };
1189 }
1190
1191 // Patch localStorage if necessary
1192 if (typeof window.localStorage == 'undefined' || window.localStorage === null) {
1193 window.localStorage = new storage.CupcakeLocalStorage();
1194 }
1195
1196 // Let native code know we are all done on the JS side.
1197 // Native code will then un-hide the WebView.
1198 channel.join(function() {
1199 exec(null, null, "App", "show", []);
1200 }, [channel.onCordovaReady]);
1201 },
1202 objects: {
1203 navigator: {
1204 children: {
1205 app:{
1206 path: "cordova/plugin/android/app"
1207 }
1208 }
1209 },
1210 File: { // exists natively on Android WebView, override
1211 path: "cordova/plugin/File"
1212 },
1213 FileReader: { // exists natively on Android WebView, override
1214 path: "cordova/plugin/FileReader"
1215 },
1216 FileError: { //exists natively on Android WebView on Android 4.x
1217 path: "cordova/plugin/FileError"
1218 },
1219 MediaError: { // exists natively on Android WebView on Android 4.x
1220 path: "cordova/plugin/MediaError"
1221 }
1222 },
1223 merges: {
1224 device: {
1225 path: 'cordova/plugin/android/device'
1226 },
1227 navigator: {
1228 children: {
1229 notification: {
1230 path: 'cordova/plugin/android/notification'
1231 }
1232 }
1233 }
1234 }
1235};
1236
1237});
1238
1239// file: lib/common/plugin/Acceleration.js
1240define("cordova/plugin/Acceleration", function(require, exports, module) {
1241
1242var Acceleration = function(x, y, z, timestamp) {
1243 this.x = x;
1244 this.y = y;
1245 this.z = z;
1246 this.timestamp = timestamp || (new Date()).getTime();
1247};
1248
1249module.exports = Acceleration;
1250
1251});
1252
1253// file: lib/common/plugin/Camera.js
1254define("cordova/plugin/Camera", function(require, exports, module) {
1255
1256var exec = require('cordova/exec'),
1257 Camera = require('cordova/plugin/CameraConstants');
1258
1259var cameraExport = {};
1260
1261// Tack on the Camera Constants to the base camera plugin.
1262for (var key in Camera) {
1263 cameraExport[key] = Camera[key];
1264}
1265
1266/**
1267 * Gets a picture from source defined by "options.sourceType", and returns the
1268 * image as defined by the "options.destinationType" option.
1269
1270 * The defaults are sourceType=CAMERA and destinationType=FILE_URI.
1271 *
1272 * @param {Function} successCallback
1273 * @param {Function} errorCallback
1274 * @param {Object} options
1275 */
1276cameraExport.getPicture = function(successCallback, errorCallback, options) {
1277 options = options || {};
1278 // successCallback required
1279 if (typeof successCallback != "function") {
1280 console.log("Camera Error: successCallback is not a function");
1281 return;
1282 }
1283
1284 // errorCallback optional
1285 if (errorCallback && (typeof errorCallback != "function")) {
1286 console.log("Camera Error: errorCallback is not a function");
1287 return;
1288 }
1289
1290 var quality = 50;
1291 if (typeof options.quality == "number") {
1292 quality = options.quality;
1293 } else if (typeof options.quality == "string") {
1294 var qlity = parseInt(options.quality, 10);
1295 if (isNaN(qlity) === false) {
1296 quality = qlity.valueOf();
1297 }
1298 }
1299
1300 var destinationType = Camera.DestinationType.FILE_URI;
1301 if (typeof options.destinationType == "number") {
1302 destinationType = options.destinationType;
1303 }
1304
1305 var sourceType = Camera.PictureSourceType.CAMERA;
1306 if (typeof options.sourceType == "number") {
1307 sourceType = options.sourceType;
1308 }
1309
1310 var targetWidth = -1;
1311 if (typeof options.targetWidth == "number") {
1312 targetWidth = options.targetWidth;
1313 } else if (typeof options.targetWidth == "string") {
1314 var width = parseInt(options.targetWidth, 10);
1315 if (isNaN(width) === false) {
1316 targetWidth = width.valueOf();
1317 }
1318 }
1319
1320 var targetHeight = -1;
1321 if (typeof options.targetHeight == "number") {
1322 targetHeight = options.targetHeight;
1323 } else if (typeof options.targetHeight == "string") {
1324 var height = parseInt(options.targetHeight, 10);
1325 if (isNaN(height) === false) {
1326 targetHeight = height.valueOf();
1327 }
1328 }
1329
1330 var encodingType = Camera.EncodingType.JPEG;
1331 if (typeof options.encodingType == "number") {
1332 encodingType = options.encodingType;
1333 }
1334
1335 var mediaType = Camera.MediaType.PICTURE;
1336 if (typeof options.mediaType == "number") {
1337 mediaType = options.mediaType;
1338 }
1339 var allowEdit = false;
1340 if (typeof options.allowEdit == "boolean") {
1341 allowEdit = options.allowEdit;
1342 } else if (typeof options.allowEdit == "number") {
1343 allowEdit = options.allowEdit <= 0 ? false : true;
1344 }
1345 var correctOrientation = false;
1346 if (typeof options.correctOrientation == "boolean") {
1347 correctOrientation = options.correctOrientation;
1348 } else if (typeof options.correctOrientation == "number") {
1349 correctOrientation = options.correctOrientation <=0 ? false : true;
1350 }
1351 var saveToPhotoAlbum = false;
1352 if (typeof options.saveToPhotoAlbum == "boolean") {
1353 saveToPhotoAlbum = options.saveToPhotoAlbum;
1354 } else if (typeof options.saveToPhotoAlbum == "number") {
1355 saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true;
1356 }
1357 var popoverOptions = null;
1358 if (typeof options.popoverOptions == "object") {
1359 popoverOptions = options.popoverOptions;
1360 }
1361
1362 var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,
1363 mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions];
1364
1365 exec(successCallback, errorCallback, "Camera", "takePicture", args);
1366};
1367
1368cameraExport.cleanup = function(successCallback, errorCallback) {
1369 exec(successCallback, errorCallback, "Camera", "cleanup", []);
1370};
1371
1372module.exports = cameraExport;
1373
1374});
1375
1376// file: lib/common/plugin/CameraConstants.js
1377define("cordova/plugin/CameraConstants", function(require, exports, module) {
1378
1379module.exports = {
1380 DestinationType:{
1381 DATA_URL: 0, // Return base64 encoded string
1382 FILE_URI: 1 // Return file uri (content://media/external/images/media/2 for Android)
1383 },
1384 EncodingType:{
1385 JPEG: 0, // Return JPEG encoded image
1386 PNG: 1 // Return PNG encoded image
1387 },
1388 MediaType:{
1389 PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
1390 VIDEO: 1, // allow selection of video only, ONLY RETURNS URL
1391 ALLMEDIA : 2 // allow selection from all media types
1392 },
1393 PictureSourceType:{
1394 PHOTOLIBRARY : 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android)
1395 CAMERA : 1, // Take picture from camera
1396 SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android)
1397 },
1398 PopoverArrowDirection:{
1399 ARROW_UP : 1, // matches iOS UIPopoverArrowDirection constants to specify arrow location on popover
1400 ARROW_DOWN : 2,
1401 ARROW_LEFT : 4,
1402 ARROW_RIGHT : 8,
1403 ARROW_ANY : 15
1404 }
1405};
1406
1407});
1408
1409// file: lib/common/plugin/CameraPopoverOptions.js
1410define("cordova/plugin/CameraPopoverOptions", function(require, exports, module) {
1411
1412var Camera = require('cordova/plugin/CameraConstants');
1413
1414/**
1415 * Encapsulates options for iOS Popover image picker
1416 */
1417var CameraPopoverOptions = function(x,y,width,height,arrowDir){
1418 // information of rectangle that popover should be anchored to
1419 this.x = x || 0;
1420 this.y = y || 32;
1421 this.width = width || 320;
1422 this.height = height || 480;
1423 // The direction of the popover arrow
1424 this.arrowDir = arrowDir || Camera.PopoverArrowDirection.ARROW_ANY;
1425};
1426
1427module.exports = CameraPopoverOptions;
1428
1429});
1430
1431// file: lib/common/plugin/CaptureAudioOptions.js
1432define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) {
1433
1434/**
1435 * Encapsulates all audio capture operation configuration options.
1436 */
1437var CaptureAudioOptions = function(){
1438 // Upper limit of sound clips user can record. Value must be equal or greater than 1.
1439 this.limit = 1;
1440 // Maximum duration of a single sound clip in seconds.
1441 this.duration = 0;
1442 // The selected audio mode. Must match with one of the elements in supportedAudioModes array.
1443 this.mode = null;
1444};
1445
1446module.exports = CaptureAudioOptions;
1447
1448});
1449
1450// file: lib/common/plugin/CaptureError.js
1451define("cordova/plugin/CaptureError", function(require, exports, module) {
1452
1453/**
1454 * The CaptureError interface encapsulates all errors in the Capture API.
1455 */
1456var CaptureError = function(c) {
1457 this.code = c || null;
1458};
1459
1460// Camera or microphone failed to capture image or sound.
1461CaptureError.CAPTURE_INTERNAL_ERR = 0;
1462// Camera application or audio capture application is currently serving other capture request.
1463CaptureError.CAPTURE_APPLICATION_BUSY = 1;
1464// Invalid use of the API (e.g. limit parameter has value less than one).
1465CaptureError.CAPTURE_INVALID_ARGUMENT = 2;
1466// User exited camera application or audio capture application before capturing anything.
1467CaptureError.CAPTURE_NO_MEDIA_FILES = 3;
1468// The requested capture operation is not supported.
1469CaptureError.CAPTURE_NOT_SUPPORTED = 20;
1470
1471module.exports = CaptureError;
1472
1473});
1474
1475// file: lib/common/plugin/CaptureImageOptions.js
1476define("cordova/plugin/CaptureImageOptions", function(require, exports, module) {
1477
1478/**
1479 * Encapsulates all image capture operation configuration options.
1480 */
1481var CaptureImageOptions = function(){
1482 // Upper limit of images user can take. Value must be equal or greater than 1.
1483 this.limit = 1;
1484 // The selected image mode. Must match with one of the elements in supportedImageModes array.
1485 this.mode = null;
1486};
1487
1488module.exports = CaptureImageOptions;
1489
1490});
1491
1492// file: lib/common/plugin/CaptureVideoOptions.js
1493define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) {
1494
1495/**
1496 * Encapsulates all video capture operation configuration options.
1497 */
1498var CaptureVideoOptions = function(){
1499 // Upper limit of videos user can record. Value must be equal or greater than 1.
1500 this.limit = 1;
1501 // Maximum duration of a single video clip in seconds.
1502 this.duration = 0;
1503 // The selected video mode. Must match with one of the elements in supportedVideoModes array.
1504 this.mode = null;
1505};
1506
1507module.exports = CaptureVideoOptions;
1508
1509});
1510
1511// file: lib/common/plugin/CompassError.js
1512define("cordova/plugin/CompassError", function(require, exports, module) {
1513
1514/**
1515 * CompassError.
1516 * An error code assigned by an implementation when an error has occurred
1517 * @constructor
1518 */
1519var CompassError = function(err) {
1520 this.code = (err !== undefined ? err : null);
1521};
1522
1523CompassError.COMPASS_INTERNAL_ERR = 0;
1524CompassError.COMPASS_NOT_SUPPORTED = 20;
1525
1526module.exports = CompassError;
1527
1528});
1529
1530// file: lib/common/plugin/CompassHeading.js
1531define("cordova/plugin/CompassHeading", function(require, exports, module) {
1532
1533var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
1534 this.magneticHeading = (magneticHeading !== undefined ? magneticHeading : null);
1535 this.trueHeading = (trueHeading !== undefined ? trueHeading : null);
1536 this.headingAccuracy = (headingAccuracy !== undefined ? headingAccuracy : null);
1537 this.timestamp = (timestamp !== undefined ? timestamp : new Date().getTime());
1538};
1539
1540module.exports = CompassHeading;
1541
1542});
1543
1544// file: lib/common/plugin/ConfigurationData.js
1545define("cordova/plugin/ConfigurationData", function(require, exports, module) {
1546
1547/**
1548 * Encapsulates a set of parameters that the capture device supports.
1549 */
1550function ConfigurationData() {
1551 // The ASCII-encoded string in lower case representing the media type.
1552 this.type = null;
1553 // The height attribute represents height of the image or video in pixels.
1554 // In the case of a sound clip this attribute has value 0.
1555 this.height = 0;
1556 // The width attribute represents width of the image or video in pixels.
1557 // In the case of a sound clip this attribute has value 0
1558 this.width = 0;
1559}
1560
1561module.exports = ConfigurationData;
1562
1563});
1564
1565// file: lib/common/plugin/Connection.js
1566define("cordova/plugin/Connection", function(require, exports, module) {
1567
1568/**
1569 * Network status
1570 */
1571module.exports = {
1572 UNKNOWN: "unknown",
1573 ETHERNET: "ethernet",
1574 WIFI: "wifi",
1575 CELL_2G: "2g",
1576 CELL_3G: "3g",
1577 CELL_4G: "4g",
1578 NONE: "none"
1579};
1580
1581});
1582
1583// file: lib/common/plugin/Contact.js
1584define("cordova/plugin/Contact", function(require, exports, module) {
1585
1586var exec = require('cordova/exec'),
1587 ContactError = require('cordova/plugin/ContactError'),
1588 utils = require('cordova/utils');
1589
1590/**
1591* Converts primitives into Complex Object
1592* Currently only used for Date fields
1593*/
1594function convertIn(contact) {
1595 var value = contact.birthday;
1596 try {
1597 contact.birthday = new Date(parseFloat(value));
1598 } catch (exception){
1599 console.log("Cordova Contact convertIn error: exception creating date.");
1600 }
1601 return contact;
1602}
1603
1604/**
1605* Converts Complex objects into primitives
1606* Only conversion at present is for Dates.
1607**/
1608
1609function convertOut(contact) {
1610 var value = contact.birthday;
1611 if (value !== null) {
1612 // try to make it a Date object if it is not already
1613 if (!utils.isDate(value)){
1614 try {
1615 value = new Date(value);
1616 } catch(exception){
1617 value = null;
1618 }
1619 }
1620 if (utils.isDate(value)){
1621 value = value.valueOf(); // convert to milliseconds
1622 }
1623 contact.birthday = value;
1624 }
1625 return contact;
1626}
1627
1628/**
1629* Contains information about a single contact.
1630* @constructor
1631* @param {DOMString} id unique identifier
1632* @param {DOMString} displayName
1633* @param {ContactName} name
1634* @param {DOMString} nickname
1635* @param {Array.<ContactField>} phoneNumbers array of phone numbers
1636* @param {Array.<ContactField>} emails array of email addresses
1637* @param {Array.<ContactAddress>} addresses array of addresses
1638* @param {Array.<ContactField>} ims instant messaging user ids
1639* @param {Array.<ContactOrganization>} organizations
1640* @param {DOMString} birthday contact's birthday
1641* @param {DOMString} note user notes about contact
1642* @param {Array.<ContactField>} photos
1643* @param {Array.<ContactField>} categories
1644* @param {Array.<ContactField>} urls contact's web sites
1645*/
1646var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, addresses,
1647 ims, organizations, birthday, note, photos, categories, urls) {
1648 this.id = id || null;
1649 this.rawId = null;
1650 this.displayName = displayName || null;
1651 this.name = name || null; // ContactName
1652 this.nickname = nickname || null;
1653 this.phoneNumbers = phoneNumbers || null; // ContactField[]
1654 this.emails = emails || null; // ContactField[]
1655 this.addresses = addresses || null; // ContactAddress[]
1656 this.ims = ims || null; // ContactField[]
1657 this.organizations = organizations || null; // ContactOrganization[]
1658 this.birthday = birthday || null;
1659 this.note = note || null;
1660 this.photos = photos || null; // ContactField[]
1661 this.categories = categories || null; // ContactField[]
1662 this.urls = urls || null; // ContactField[]
1663};
1664
1665/**
1666* Removes contact from device storage.
1667* @param successCB success callback
1668* @param errorCB error callback
1669*/
1670Contact.prototype.remove = function(successCB, errorCB) {
1671 var fail = function(code) {
1672 errorCB(new ContactError(code));
1673 };
1674 if (this.id === null) {
1675 fail(ContactError.UNKNOWN_ERROR);
1676 }
1677 else {
1678 exec(successCB, fail, "Contacts", "remove", [this.id]);
1679 }
1680};
1681
1682/**
1683* Creates a deep copy of this Contact.
1684* With the contact ID set to null.
1685* @return copy of this Contact
1686*/
1687Contact.prototype.clone = function() {
1688 var clonedContact = utils.clone(this);
1689 var i;
1690 clonedContact.id = null;
1691 clonedContact.rawId = null;
1692 // Loop through and clear out any id's in phones, emails, etc.
1693 if (clonedContact.phoneNumbers) {
1694 for (i = 0; i < clonedContact.phoneNumbers.length; i++) {
1695 clonedContact.phoneNumbers[i].id = null;
1696 }
1697 }
1698 if (clonedContact.emails) {
1699 for (i = 0; i < clonedContact.emails.length; i++) {
1700 clonedContact.emails[i].id = null;
1701 }
1702 }
1703 if (clonedContact.addresses) {
1704 for (i = 0; i < clonedContact.addresses.length; i++) {
1705 clonedContact.addresses[i].id = null;
1706 }
1707 }
1708 if (clonedContact.ims) {
1709 for (i = 0; i < clonedContact.ims.length; i++) {
1710 clonedContact.ims[i].id = null;
1711 }
1712 }
1713 if (clonedContact.organizations) {
1714 for (i = 0; i < clonedContact.organizations.length; i++) {
1715 clonedContact.organizations[i].id = null;
1716 }
1717 }
1718 if (clonedContact.categories) {
1719 for (i = 0; i < clonedContact.categories.length; i++) {
1720 clonedContact.categories[i].id = null;
1721 }
1722 }
1723 if (clonedContact.photos) {
1724 for (i = 0; i < clonedContact.photos.length; i++) {
1725 clonedContact.photos[i].id = null;
1726 }
1727 }
1728 if (clonedContact.urls) {
1729 for (i = 0; i < clonedContact.urls.length; i++) {
1730 clonedContact.urls[i].id = null;
1731 }
1732 }
1733 return clonedContact;
1734};
1735
1736/**
1737* Persists contact to device storage.
1738* @param successCB success callback
1739* @param errorCB error callback
1740*/
1741Contact.prototype.save = function(successCB, errorCB) {
1742 var fail = function(code) {
1743 errorCB(new ContactError(code));
1744 };
1745 var success = function(result) {
1746 if (result) {
1747 if (typeof successCB === 'function') {
1748 var fullContact = require('cordova/plugin/contacts').create(result);
1749 successCB(convertIn(fullContact));
1750 }
1751 }
1752 else {
1753 // no Entry object returned
1754 fail(ContactError.UNKNOWN_ERROR);
1755 }
1756 };
1757 var dupContact = convertOut(utils.clone(this));
1758 exec(success, fail, "Contacts", "save", [dupContact]);
1759};
1760
1761
1762module.exports = Contact;
1763
1764});
1765
1766// file: lib/common/plugin/ContactAddress.js
1767define("cordova/plugin/ContactAddress", function(require, exports, module) {
1768
1769/**
1770* Contact address.
1771* @constructor
1772* @param {DOMString} id unique identifier, should only be set by native code
1773* @param formatted // NOTE: not a W3C standard
1774* @param streetAddress
1775* @param locality
1776* @param region
1777* @param postalCode
1778* @param country
1779*/
1780
1781var ContactAddress = function(pref, type, formatted, streetAddress, locality, region, postalCode, country) {
1782 this.id = null;
1783 this.pref = (typeof pref != 'undefined' ? pref : false);
1784 this.type = type || null;
1785 this.formatted = formatted || null;
1786 this.streetAddress = streetAddress || null;
1787 this.locality = locality || null;
1788 this.region = region || null;
1789 this.postalCode = postalCode || null;
1790 this.country = country || null;
1791};
1792
1793module.exports = ContactAddress;
1794
1795});
1796
1797// file: lib/common/plugin/ContactError.js
1798define("cordova/plugin/ContactError", function(require, exports, module) {
1799
1800/**
1801 * ContactError.
1802 * An error code assigned by an implementation when an error has occurred
1803 * @constructor
1804 */
1805var ContactError = function(err) {
1806 this.code = (typeof err != 'undefined' ? err : null);
1807};
1808
1809/**
1810 * Error codes
1811 */
1812ContactError.UNKNOWN_ERROR = 0;
1813ContactError.INVALID_ARGUMENT_ERROR = 1;
1814ContactError.TIMEOUT_ERROR = 2;
1815ContactError.PENDING_OPERATION_ERROR = 3;
1816ContactError.IO_ERROR = 4;
1817ContactError.NOT_SUPPORTED_ERROR = 5;
1818ContactError.PERMISSION_DENIED_ERROR = 20;
1819
1820module.exports = ContactError;
1821
1822});
1823
1824// file: lib/common/plugin/ContactField.js
1825define("cordova/plugin/ContactField", function(require, exports, module) {
1826
1827/**
1828* Generic contact field.
1829* @constructor
1830* @param {DOMString} id unique identifier, should only be set by native code // NOTE: not a W3C standard
1831* @param type
1832* @param value
1833* @param pref
1834*/
1835var ContactField = function(type, value, pref) {
1836 this.id = null;
1837 this.type = (type && type.toString()) || null;
1838 this.value = (value && value.toString()) || null;
1839 this.pref = (typeof pref != 'undefined' ? pref : false);
1840};
1841
1842module.exports = ContactField;
1843
1844});
1845
1846// file: lib/common/plugin/ContactFindOptions.js
1847define("cordova/plugin/ContactFindOptions", function(require, exports, module) {
1848
1849/**
1850 * ContactFindOptions.
1851 * @constructor
1852 * @param filter used to match contacts against
1853 * @param multiple boolean used to determine if more than one contact should be returned
1854 */
1855
1856var ContactFindOptions = function(filter, multiple) {
1857 this.filter = filter || '';
1858 this.multiple = (typeof multiple != 'undefined' ? multiple : false);
1859};
1860
1861module.exports = ContactFindOptions;
1862
1863});
1864
1865// file: lib/common/plugin/ContactName.js
1866define("cordova/plugin/ContactName", function(require, exports, module) {
1867
1868/**
1869* Contact name.
1870* @constructor
1871* @param formatted // NOTE: not part of W3C standard
1872* @param familyName
1873* @param givenName
1874* @param middle
1875* @param prefix
1876* @param suffix
1877*/
1878var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
1879 this.formatted = formatted || null;
1880 this.familyName = familyName || null;
1881 this.givenName = givenName || null;
1882 this.middleName = middle || null;
1883 this.honorificPrefix = prefix || null;
1884 this.honorificSuffix = suffix || null;
1885};
1886
1887module.exports = ContactName;
1888
1889});
1890
1891// file: lib/common/plugin/ContactOrganization.js
1892define("cordova/plugin/ContactOrganization", function(require, exports, module) {
1893
1894/**
1895* Contact organization.
1896* @constructor
1897* @param {DOMString} id unique identifier, should only be set by native code // NOTE: not a W3C standard
1898* @param name
1899* @param dept
1900* @param title
1901* @param startDate
1902* @param endDate
1903* @param location
1904* @param desc
1905*/
1906
1907var ContactOrganization = function(pref, type, name, dept, title) {
1908 this.id = null;
1909 this.pref = (typeof pref != 'undefined' ? pref : false);
1910 this.type = type || null;
1911 this.name = name || null;
1912 this.department = dept || null;
1913 this.title = title || null;
1914};
1915
1916module.exports = ContactOrganization;
1917
1918});
1919
1920// file: lib/common/plugin/Coordinates.js
1921define("cordova/plugin/Coordinates", function(require, exports, module) {
1922
1923/**
1924 * This class contains position information.
1925 * @param {Object} lat
1926 * @param {Object} lng
1927 * @param {Object} alt
1928 * @param {Object} acc
1929 * @param {Object} head
1930 * @param {Object} vel
1931 * @param {Object} altacc
1932 * @constructor
1933 */
1934var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) {
1935 /**
1936 * The latitude of the position.
1937 */
1938 this.latitude = lat;
1939 /**
1940 * The longitude of the position,
1941 */
1942 this.longitude = lng;
1943 /**
1944 * The accuracy of the position.
1945 */
1946 this.accuracy = acc;
1947 /**
1948 * The altitude of the position.
1949 */
1950 this.altitude = (alt !== undefined ? alt : null);
1951 /**
1952 * The direction the device is moving at the position.
1953 */
1954 this.heading = (head !== undefined ? head : null);
1955 /**
1956 * The velocity with which the device is moving at the position.
1957 */
1958 this.speed = (vel !== undefined ? vel : null);
1959
1960 if (this.speed === 0 || this.speed === null) {
1961 this.heading = NaN;
1962 }
1963
1964 /**
1965 * The altitude accuracy of the position.
1966 */
1967 this.altitudeAccuracy = (altacc !== undefined) ? altacc : null;
1968};
1969
1970module.exports = Coordinates;
1971
1972});
1973
1974// file: lib/common/plugin/DirectoryEntry.js
1975define("cordova/plugin/DirectoryEntry", function(require, exports, module) {
1976
1977var utils = require('cordova/utils'),
1978 exec = require('cordova/exec'),
1979 Entry = require('cordova/plugin/Entry'),
1980 FileError = require('cordova/plugin/FileError'),
1981 DirectoryReader = require('cordova/plugin/DirectoryReader');
1982
1983/**
1984 * An interface representing a directory on the file system.
1985 *
1986 * {boolean} isFile always false (readonly)
1987 * {boolean} isDirectory always true (readonly)
1988 * {DOMString} name of the directory, excluding the path leading to it (readonly)
1989 * {DOMString} fullPath the absolute full path to the directory (readonly)
1990 * TODO: implement this!!! {FileSystem} filesystem on which the directory resides (readonly)
1991 */
1992var DirectoryEntry = function(name, fullPath) {
1993 DirectoryEntry.__super__.constructor.apply(this, [false, true, name, fullPath]);
1994};
1995
1996utils.extend(DirectoryEntry, Entry);
1997
1998/**
1999 * Creates a new DirectoryReader to read entries from this directory
2000 */
2001DirectoryEntry.prototype.createReader = function() {
2002 return new DirectoryReader(this.fullPath);
2003};
2004
2005/**
2006 * Creates or looks up a directory
2007 *
2008 * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory
2009 * @param {Flags} options to create or exclusively create the directory
2010 * @param {Function} successCallback is called with the new entry
2011 * @param {Function} errorCallback is called with a FileError
2012 */
2013DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
2014 var win = typeof successCallback !== 'function' ? null : function(result) {
2015 var entry = new DirectoryEntry(result.name, result.fullPath);
2016 successCallback(entry);
2017 };
2018 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2019 errorCallback(new FileError(code));
2020 };
2021 exec(win, fail, "File", "getDirectory", [this.fullPath, path, options]);
2022};
2023
2024/**
2025 * Deletes a directory and all of it's contents
2026 *
2027 * @param {Function} successCallback is called with no parameters
2028 * @param {Function} errorCallback is called with a FileError
2029 */
2030DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
2031 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2032 errorCallback(new FileError(code));
2033 };
2034 exec(successCallback, fail, "File", "removeRecursively", [this.fullPath]);
2035};
2036
2037/**
2038 * Creates or looks up a file
2039 *
2040 * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file
2041 * @param {Flags} options to create or exclusively create the file
2042 * @param {Function} successCallback is called with the new entry
2043 * @param {Function} errorCallback is called with a FileError
2044 */
2045DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
2046 var win = typeof successCallback !== 'function' ? null : function(result) {
2047 var FileEntry = require('cordova/plugin/FileEntry');
2048 var entry = new FileEntry(result.name, result.fullPath);
2049 successCallback(entry);
2050 };
2051 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2052 errorCallback(new FileError(code));
2053 };
2054 exec(win, fail, "File", "getFile", [this.fullPath, path, options]);
2055};
2056
2057module.exports = DirectoryEntry;
2058
2059});
2060
2061// file: lib/common/plugin/DirectoryReader.js
2062define("cordova/plugin/DirectoryReader", function(require, exports, module) {
2063
2064var exec = require('cordova/exec'),
2065 FileError = require('cordova/plugin/FileError') ;
2066
2067/**
2068 * An interface that lists the files and directories in a directory.
2069 */
2070function DirectoryReader(path) {
2071 this.path = path || null;
2072}
2073
2074/**
2075 * Returns a list of entries from a directory.
2076 *
2077 * @param {Function} successCallback is called with a list of entries
2078 * @param {Function} errorCallback is called with a FileError
2079 */
2080DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
2081 var win = typeof successCallback !== 'function' ? null : function(result) {
2082 var retVal = [];
2083 for (var i=0; i<result.length; i++) {
2084 var entry = null;
2085 if (result[i].isDirectory) {
2086 entry = new (require('cordova/plugin/DirectoryEntry'))();
2087 }
2088 else if (result[i].isFile) {
2089 entry = new (require('cordova/plugin/FileEntry'))();
2090 }
2091 entry.isDirectory = result[i].isDirectory;
2092 entry.isFile = result[i].isFile;
2093 entry.name = result[i].name;
2094 entry.fullPath = result[i].fullPath;
2095 retVal.push(entry);
2096 }
2097 successCallback(retVal);
2098 };
2099 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2100 errorCallback(new FileError(code));
2101 };
2102 exec(win, fail, "File", "readEntries", [this.path]);
2103};
2104
2105module.exports = DirectoryReader;
2106
2107});
2108
2109// file: lib/common/plugin/Entry.js
2110define("cordova/plugin/Entry", function(require, exports, module) {
2111
2112var exec = require('cordova/exec'),
2113 FileError = require('cordova/plugin/FileError'),
2114 Metadata = require('cordova/plugin/Metadata');
2115
2116/**
2117 * Represents a file or directory on the local file system.
2118 *
2119 * @param isFile
2120 * {boolean} true if Entry is a file (readonly)
2121 * @param isDirectory
2122 * {boolean} true if Entry is a directory (readonly)
2123 * @param name
2124 * {DOMString} name of the file or directory, excluding the path
2125 * leading to it (readonly)
2126 * @param fullPath
2127 * {DOMString} the absolute full path to the file or directory
2128 * (readonly)
2129 */
2130function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
2131 this.isFile = (typeof isFile != 'undefined'?isFile:false);
2132 this.isDirectory = (typeof isDirectory != 'undefined'?isDirectory:false);
2133 this.name = name || '';
2134 this.fullPath = fullPath || '';
2135 this.filesystem = fileSystem || null;
2136}
2137
2138/**
2139 * Look up the metadata of the entry.
2140 *
2141 * @param successCallback
2142 * {Function} is called with a Metadata object
2143 * @param errorCallback
2144 * {Function} is called with a FileError
2145 */
2146Entry.prototype.getMetadata = function(successCallback, errorCallback) {
2147 var success = typeof successCallback !== 'function' ? null : function(lastModified) {
2148 var metadata = new Metadata(lastModified);
2149 successCallback(metadata);
2150 };
2151 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2152 errorCallback(new FileError(code));
2153 };
2154
2155 exec(success, fail, "File", "getMetadata", [this.fullPath]);
2156};
2157
2158/**
2159 * Set the metadata of the entry.
2160 *
2161 * @param successCallback
2162 * {Function} is called with a Metadata object
2163 * @param errorCallback
2164 * {Function} is called with a FileError
2165 * @param metadataObject
2166 * {Object} keys and values to set
2167 */
2168Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataObject) {
2169
2170 exec(successCallback, errorCallback, "File", "setMetadata", [this.fullPath, metadataObject]);
2171};
2172
2173/**
2174 * Move a file or directory to a new location.
2175 *
2176 * @param parent
2177 * {DirectoryEntry} the directory to which to move this entry
2178 * @param newName
2179 * {DOMString} new name of the entry, defaults to the current name
2180 * @param successCallback
2181 * {Function} called with the new DirectoryEntry object
2182 * @param errorCallback
2183 * {Function} called with a FileError
2184 */
2185Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
2186 var fail = function(code) {
2187 if (typeof errorCallback === 'function') {
2188 errorCallback(new FileError(code));
2189 }
2190 };
2191 // user must specify parent Entry
2192 if (!parent) {
2193 fail(FileError.NOT_FOUND_ERR);
2194 return;
2195 }
2196 // source path
2197 var srcPath = this.fullPath,
2198 // entry name
2199 name = newName || this.name,
2200 success = function(entry) {
2201 if (entry) {
2202 if (typeof successCallback === 'function') {
2203 // create appropriate Entry object
2204 var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
2205 try {
2206 successCallback(result);
2207 }
2208 catch (e) {
2209 console.log('Error invoking callback: ' + e);
2210 }
2211 }
2212 }
2213 else {
2214 // no Entry object returned
2215 fail(FileError.NOT_FOUND_ERR);
2216 }
2217 };
2218
2219 // copy
2220 exec(success, fail, "File", "moveTo", [srcPath, parent.fullPath, name]);
2221};
2222
2223/**
2224 * Copy a directory to a different location.
2225 *
2226 * @param parent
2227 * {DirectoryEntry} the directory to which to copy the entry
2228 * @param newName
2229 * {DOMString} new name of the entry, defaults to the current name
2230 * @param successCallback
2231 * {Function} called with the new Entry object
2232 * @param errorCallback
2233 * {Function} called with a FileError
2234 */
2235Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
2236 var fail = function(code) {
2237 if (typeof errorCallback === 'function') {
2238 errorCallback(new FileError(code));
2239 }
2240 };
2241
2242 // user must specify parent Entry
2243 if (!parent) {
2244 fail(FileError.NOT_FOUND_ERR);
2245 return;
2246 }
2247
2248 // source path
2249 var srcPath = this.fullPath,
2250 // entry name
2251 name = newName || this.name,
2252 // success callback
2253 success = function(entry) {
2254 if (entry) {
2255 if (typeof successCallback === 'function') {
2256 // create appropriate Entry object
2257 var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
2258 try {
2259 successCallback(result);
2260 }
2261 catch (e) {
2262 console.log('Error invoking callback: ' + e);
2263 }
2264 }
2265 }
2266 else {
2267 // no Entry object returned
2268 fail(FileError.NOT_FOUND_ERR);
2269 }
2270 };
2271
2272 // copy
2273 exec(success, fail, "File", "copyTo", [srcPath, parent.fullPath, name]);
2274};
2275
2276/**
2277 * Return a URL that can be used to identify this entry.
2278 */
2279Entry.prototype.toURL = function() {
2280 // fullPath attribute contains the full URL
2281 return this.fullPath;
2282};
2283
2284/**
2285 * Returns a URI that can be used to identify this entry.
2286 *
2287 * @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI.
2288 * @return uri
2289 */
2290Entry.prototype.toURI = function(mimeType) {
2291 console.log("DEPRECATED: Update your code to use 'toURL'");
2292 // fullPath attribute contains the full URI
2293 return this.toURL();
2294};
2295
2296/**
2297 * Remove a file or directory. It is an error to attempt to delete a
2298 * directory that is not empty. It is an error to attempt to delete a
2299 * root directory of a file system.
2300 *
2301 * @param successCallback {Function} called with no parameters
2302 * @param errorCallback {Function} called with a FileError
2303 */
2304Entry.prototype.remove = function(successCallback, errorCallback) {
2305 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2306 errorCallback(new FileError(code));
2307 };
2308 exec(successCallback, fail, "File", "remove", [this.fullPath]);
2309};
2310
2311/**
2312 * Look up the parent DirectoryEntry of this entry.
2313 *
2314 * @param successCallback {Function} called with the parent DirectoryEntry object
2315 * @param errorCallback {Function} called with a FileError
2316 */
2317Entry.prototype.getParent = function(successCallback, errorCallback) {
2318 var win = typeof successCallback !== 'function' ? null : function(result) {
2319 var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
2320 var entry = new DirectoryEntry(result.name, result.fullPath);
2321 successCallback(entry);
2322 };
2323 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2324 errorCallback(new FileError(code));
2325 };
2326 exec(win, fail, "File", "getParent", [this.fullPath]);
2327};
2328
2329module.exports = Entry;
2330
2331});
2332
2333// file: lib/common/plugin/File.js
2334define("cordova/plugin/File", function(require, exports, module) {
2335
2336/**
2337 * Constructor.
2338 * name {DOMString} name of the file, without path information
2339 * fullPath {DOMString} the full path of the file, including the name
2340 * type {DOMString} mime type
2341 * lastModifiedDate {Date} last modified date
2342 * size {Number} size of the file in bytes
2343 */
2344
2345var File = function(name, fullPath, type, lastModifiedDate, size){
2346 this.name = name || '';
2347 this.fullPath = fullPath || null;
2348 this.type = type || null;
2349 this.lastModifiedDate = lastModifiedDate || null;
2350 this.size = size || 0;
2351};
2352
2353module.exports = File;
2354
2355});
2356
2357// file: lib/common/plugin/FileEntry.js
2358define("cordova/plugin/FileEntry", function(require, exports, module) {
2359
2360var utils = require('cordova/utils'),
2361 exec = require('cordova/exec'),
2362 Entry = require('cordova/plugin/Entry'),
2363 FileWriter = require('cordova/plugin/FileWriter'),
2364 File = require('cordova/plugin/File'),
2365 FileError = require('cordova/plugin/FileError');
2366
2367/**
2368 * An interface representing a file on the file system.
2369 *
2370 * {boolean} isFile always true (readonly)
2371 * {boolean} isDirectory always false (readonly)
2372 * {DOMString} name of the file, excluding the path leading to it (readonly)
2373 * {DOMString} fullPath the absolute full path to the file (readonly)
2374 * {FileSystem} filesystem on which the file resides (readonly)
2375 */
2376var FileEntry = function(name, fullPath) {
2377 FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath]);
2378};
2379
2380utils.extend(FileEntry, Entry);
2381
2382/**
2383 * Creates a new FileWriter associated with the file that this FileEntry represents.
2384 *
2385 * @param {Function} successCallback is called with the new FileWriter
2386 * @param {Function} errorCallback is called with a FileError
2387 */
2388FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
2389 this.file(function(filePointer) {
2390 var writer = new FileWriter(filePointer);
2391
2392 if (writer.fileName === null || writer.fileName === "") {
2393 if (typeof errorCallback === "function") {
2394 errorCallback(new FileError(FileError.INVALID_STATE_ERR));
2395 }
2396 } else {
2397 if (typeof successCallback === "function") {
2398 successCallback(writer);
2399 }
2400 }
2401 }, errorCallback);
2402};
2403
2404/**
2405 * Returns a File that represents the current state of the file that this FileEntry represents.
2406 *
2407 * @param {Function} successCallback is called with the new File object
2408 * @param {Function} errorCallback is called with a FileError
2409 */
2410FileEntry.prototype.file = function(successCallback, errorCallback) {
2411 var win = typeof successCallback !== 'function' ? null : function(f) {
2412 var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
2413 successCallback(file);
2414 };
2415 var fail = typeof errorCallback !== 'function' ? null : function(code) {
2416 errorCallback(new FileError(code));
2417 };
2418 exec(win, fail, "File", "getFileMetadata", [this.fullPath]);
2419};
2420
2421
2422module.exports = FileEntry;
2423
2424});
2425
2426// file: lib/common/plugin/FileError.js
2427define("cordova/plugin/FileError", function(require, exports, module) {
2428
2429/**
2430 * FileError
2431 */
2432function FileError(error) {
2433 this.code = error || null;
2434}
2435
2436// File error codes
2437// Found in DOMException
2438FileError.NOT_FOUND_ERR = 1;
2439FileError.SECURITY_ERR = 2;
2440FileError.ABORT_ERR = 3;
2441
2442// Added by File API specification
2443FileError.NOT_READABLE_ERR = 4;
2444FileError.ENCODING_ERR = 5;
2445FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
2446FileError.INVALID_STATE_ERR = 7;
2447FileError.SYNTAX_ERR = 8;
2448FileError.INVALID_MODIFICATION_ERR = 9;
2449FileError.QUOTA_EXCEEDED_ERR = 10;
2450FileError.TYPE_MISMATCH_ERR = 11;
2451FileError.PATH_EXISTS_ERR = 12;
2452
2453module.exports = FileError;
2454
2455});
2456
2457// file: lib/common/plugin/FileReader.js
2458define("cordova/plugin/FileReader", function(require, exports, module) {
2459
2460var exec = require('cordova/exec'),
2461 FileError = require('cordova/plugin/FileError'),
2462 ProgressEvent = require('cordova/plugin/ProgressEvent');
2463
2464/**
2465 * This class reads the mobile device file system.
2466 *
2467 * For Android:
2468 * The root directory is the root of the file system.
2469 * To read from the SD card, the file name is "sdcard/my_file.txt"
2470 * @constructor
2471 */
2472var FileReader = function() {
2473 this.fileName = "";
2474
2475 this.readyState = 0; // FileReader.EMPTY
2476
2477 // File data
2478 this.result = null;
2479
2480 // Error
2481 this.error = null;
2482
2483 // Event handlers
2484 this.onloadstart = null; // When the read starts.
2485 this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progress.loaded/progress.total)
2486 this.onload = null; // When the read has successfully completed.
2487 this.onerror = null; // When the read has failed (see errors).
2488 this.onloadend = null; // When the request has completed (either in success or failure).
2489 this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method.
2490};
2491
2492// States
2493FileReader.EMPTY = 0;
2494FileReader.LOADING = 1;
2495FileReader.DONE = 2;
2496
2497/**
2498 * Abort reading file.
2499 */
2500FileReader.prototype.abort = function() {
2501 this.result = null;
2502
2503 if (this.readyState == FileReader.DONE || this.readyState == FileReader.EMPTY) {
2504 return;
2505 }
2506
2507 this.readyState = FileReader.DONE;
2508
2509 // If abort callback
2510 if (typeof this.onabort === 'function') {
2511 this.onabort(new ProgressEvent('abort', {target:this}));
2512 }
2513 // If load end callback
2514 if (typeof this.onloadend === 'function') {
2515 this.onloadend(new ProgressEvent('loadend', {target:this}));
2516 }
2517};
2518
2519/**
2520 * Read text file.
2521 *
2522 * @param file {File} File object containing file properties
2523 * @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
2524 */
2525FileReader.prototype.readAsText = function(file, encoding) {
2526 // Figure out pathing
2527 this.fileName = '';
2528 if (typeof file.fullPath === 'undefined') {
2529 this.fileName = file;
2530 } else {
2531 this.fileName = file.fullPath;
2532 }
2533
2534 // Already loading something
2535 if (this.readyState == FileReader.LOADING) {
2536 throw new FileError(FileError.INVALID_STATE_ERR);
2537 }
2538
2539 // LOADING state
2540 this.readyState = FileReader.LOADING;
2541
2542 // If loadstart callback
2543 if (typeof this.onloadstart === "function") {
2544 this.onloadstart(new ProgressEvent("loadstart", {target:this}));
2545 }
2546
2547 // Default encoding is UTF-8
2548 var enc = encoding ? encoding : "UTF-8";
2549
2550 var me = this;
2551
2552 // Read file
2553 exec(
2554 // Success callback
2555 function(r) {
2556 // If DONE (cancelled), then don't do anything
2557 if (me.readyState === FileReader.DONE) {
2558 return;
2559 }
2560
2561 // Save result
2562 me.result = r;
2563
2564 // If onload callback
2565 if (typeof me.onload === "function") {
2566 me.onload(new ProgressEvent("load", {target:me}));
2567 }
2568
2569 // DONE state
2570 me.readyState = FileReader.DONE;
2571
2572 // If onloadend callback
2573 if (typeof me.onloadend === "function") {
2574 me.onloadend(new ProgressEvent("loadend", {target:me}));
2575 }
2576 },
2577 // Error callback
2578 function(e) {
2579 // If DONE (cancelled), then don't do anything
2580 if (me.readyState === FileReader.DONE) {
2581 return;
2582 }
2583
2584 // DONE state
2585 me.readyState = FileReader.DONE;
2586
2587 // null result
2588 me.result = null;
2589
2590 // Save error
2591 me.error = new FileError(e);
2592
2593 // If onerror callback
2594 if (typeof me.onerror === "function") {
2595 me.onerror(new ProgressEvent("error", {target:me}));
2596 }
2597
2598 // If onloadend callback
2599 if (typeof me.onloadend === "function") {
2600 me.onloadend(new ProgressEvent("loadend", {target:me}));
2601 }
2602 }, "File", "readAsText", [this.fileName, enc]);
2603};
2604
2605
2606/**
2607 * Read file and return data as a base64 encoded data url.
2608 * A data url is of the form:
2609 * data:[<mediatype>][;base64],<data>
2610 *
2611 * @param file {File} File object containing file properties
2612 */
2613FileReader.prototype.readAsDataURL = function(file) {
2614 this.fileName = "";
2615 if (typeof file.fullPath === "undefined") {
2616 this.fileName = file;
2617 } else {
2618 this.fileName = file.fullPath;
2619 }
2620
2621 // Already loading something
2622 if (this.readyState == FileReader.LOADING) {
2623 throw new FileError(FileError.INVALID_STATE_ERR);
2624 }
2625
2626 // LOADING state
2627 this.readyState = FileReader.LOADING;
2628
2629 // If loadstart callback
2630 if (typeof this.onloadstart === "function") {
2631 this.onloadstart(new ProgressEvent("loadstart", {target:this}));
2632 }
2633
2634 var me = this;
2635
2636 // Read file
2637 exec(
2638 // Success callback
2639 function(r) {
2640 // If DONE (cancelled), then don't do anything
2641 if (me.readyState === FileReader.DONE) {
2642 return;
2643 }
2644
2645 // DONE state
2646 me.readyState = FileReader.DONE;
2647
2648 // Save result
2649 me.result = r;
2650
2651 // If onload callback
2652 if (typeof me.onload === "function") {
2653 me.onload(new ProgressEvent("load", {target:me}));
2654 }
2655
2656 // If onloadend callback
2657 if (typeof me.onloadend === "function") {
2658 me.onloadend(new ProgressEvent("loadend", {target:me}));
2659 }
2660 },
2661 // Error callback
2662 function(e) {
2663 // If DONE (cancelled), then don't do anything
2664 if (me.readyState === FileReader.DONE) {
2665 return;
2666 }
2667
2668 // DONE state
2669 me.readyState = FileReader.DONE;
2670
2671 me.result = null;
2672
2673 // Save error
2674 me.error = new FileError(e);
2675
2676 // If onerror callback
2677 if (typeof me.onerror === "function") {
2678 me.onerror(new ProgressEvent("error", {target:me}));
2679 }
2680
2681 // If onloadend callback
2682 if (typeof me.onloadend === "function") {
2683 me.onloadend(new ProgressEvent("loadend", {target:me}));
2684 }
2685 }, "File", "readAsDataURL", [this.fileName]);
2686};
2687
2688/**
2689 * Read file and return data as a binary data.
2690 *
2691 * @param file {File} File object containing file properties
2692 */
2693FileReader.prototype.readAsBinaryString = function(file) {
2694 // TODO - Can't return binary data to browser.
2695 console.log('method "readAsBinaryString" is not supported at this time.');
2696};
2697
2698/**
2699 * Read file and return data as a binary data.
2700 *
2701 * @param file {File} File object containing file properties
2702 */
2703FileReader.prototype.readAsArrayBuffer = function(file) {
2704 // TODO - Can't return binary data to browser.
2705 console.log('This method is not supported at this time.');
2706};
2707
2708module.exports = FileReader;
2709
2710});
2711
2712// file: lib/common/plugin/FileSystem.js
2713define("cordova/plugin/FileSystem", function(require, exports, module) {
2714
2715var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
2716
2717/**
2718 * An interface representing a file system
2719 *
2720 * @constructor
2721 * {DOMString} name the unique name of the file system (readonly)
2722 * {DirectoryEntry} root directory of the file system (readonly)
2723 */
2724var FileSystem = function(name, root) {
2725 this.name = name || null;
2726 if (root) {
2727 this.root = new DirectoryEntry(root.name, root.fullPath);
2728 }
2729};
2730
2731module.exports = FileSystem;
2732
2733});
2734
2735// file: lib/common/plugin/FileTransfer.js
2736define("cordova/plugin/FileTransfer", function(require, exports, module) {
2737
2738var exec = require('cordova/exec'),
2739 FileTransferError = require('cordova/plugin/FileTransferError'),
2740 ProgressEvent = require('cordova/plugin/ProgressEvent');
2741
2742function newProgressEvent(result) {
2743 var pe = new ProgressEvent();
2744 pe.lengthComputable = result.lengthComputable;
2745 pe.loaded = result.loaded;
2746 pe.total = result.total;
2747 return pe;
2748}
2749
2750var idCounter = 0;
2751
2752/**
2753 * FileTransfer uploads a file to a remote server.
2754 * @constructor
2755 */
2756var FileTransfer = function() {
2757 this._id = ++idCounter;
2758 this.onprogress = null; // optional callback
2759};
2760
2761/**
2762* Given an absolute file path, uploads a file on the device to a remote server
2763* using a multipart HTTP request.
2764* @param filePath {String} Full path of the file on the device
2765* @param server {String} URL of the server to receive the file
2766* @param successCallback (Function} Callback to be invoked when upload has completed
2767* @param errorCallback {Function} Callback to be invoked upon error
2768* @param options {FileUploadOptions} Optional parameters such as file name and mimetype
2769* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
2770*/
2771FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, trustAllHosts) {
2772 // sanity parameter checking
2773 if (!filePath || !server) throw new Error("FileTransfer.upload requires filePath and server URL parameters at the minimum.");
2774 // check for options
2775 var fileKey = null;
2776 var fileName = null;
2777 var mimeType = null;
2778 var params = null;
2779 var chunkedMode = true;
2780 var headers = null;
2781 if (options) {
2782 fileKey = options.fileKey;
2783 fileName = options.fileName;
2784 mimeType = options.mimeType;
2785 headers = options.headers;
2786 if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") {
2787 chunkedMode = options.chunkedMode;
2788 }
2789 if (options.params) {
2790 params = options.params;
2791 }
2792 else {
2793 params = {};
2794 }
2795 }
2796
2797 var fail = function(e) {
2798 var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
2799 errorCallback(error);
2800 };
2801
2802 var self = this;
2803 var win = function(result) {
2804 if (typeof result.lengthComputable != "undefined") {
2805 if (self.onprogress) {
2806 return self.onprogress(newProgressEvent(result));
2807 }
2808 } else {
2809 return successCallback(result);
2810 }
2811 };
2812 exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id]);
2813};
2814
2815/**
2816 * Downloads a file form a given URL and saves it to the specified directory.
2817 * @param source {String} URL of the server to receive the file
2818 * @param target {String} Full path of the file on the device
2819 * @param successCallback (Function} Callback to be invoked when upload has completed
2820 * @param errorCallback {Function} Callback to be invoked upon error
2821 * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
2822 */
2823FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts) {
2824 // sanity parameter checking
2825 if (!source || !target) throw new Error("FileTransfer.download requires source URI and target URI parameters at the minimum.");
2826 var self = this;
2827 var win = function(result) {
2828 if (typeof result.lengthComputable != "undefined") {
2829 if (self.onprogress) {
2830 return self.onprogress(newProgressEvent(result));
2831 }
2832 } else {
2833 var entry = null;
2834 if (result.isDirectory) {
2835 entry = new (require('cordova/plugin/DirectoryEntry'))();
2836 }
2837 else if (result.isFile) {
2838 entry = new (require('cordova/plugin/FileEntry'))();
2839 }
2840 entry.isDirectory = result.isDirectory;
2841 entry.isFile = result.isFile;
2842 entry.name = result.name;
2843 entry.fullPath = result.fullPath;
2844 successCallback(entry);
2845 }
2846 };
2847
2848 var fail = function(e) {
2849 var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
2850 errorCallback(error);
2851 };
2852
2853 exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
2854};
2855
2856/**
2857 * Aborts the ongoing file transfer on this object
2858 * @param successCallback {Function} Callback to be invoked upon success
2859 * @param errorCallback {Function} Callback to be invoked upon error
2860 */
2861FileTransfer.prototype.abort = function(successCallback, errorCallback) {
2862 exec(successCallback, errorCallback, 'FileTransfer', 'abort', [this._id]);
2863};
2864
2865module.exports = FileTransfer;
2866
2867});
2868
2869// file: lib/common/plugin/FileTransferError.js
2870define("cordova/plugin/FileTransferError", function(require, exports, module) {
2871
2872/**
2873 * FileTransferError
2874 * @constructor
2875 */
2876var FileTransferError = function(code, source, target, status) {
2877 this.code = code || null;
2878 this.source = source || null;
2879 this.target = target || null;
2880 this.http_status = status || null;
2881};
2882
2883FileTransferError.FILE_NOT_FOUND_ERR = 1;
2884FileTransferError.INVALID_URL_ERR = 2;
2885FileTransferError.CONNECTION_ERR = 3;
2886FileTransferError.ABORT_ERR = 4;
2887
2888module.exports = FileTransferError;
2889
2890});
2891
2892// file: lib/common/plugin/FileUploadOptions.js
2893define("cordova/plugin/FileUploadOptions", function(require, exports, module) {
2894
2895/**
2896 * Options to customize the HTTP request used to upload files.
2897 * @constructor
2898 * @param fileKey {String} Name of file request parameter.
2899 * @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
2900 * @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
2901 * @param params {Object} Object with key: value params to send to the server.
2902 * @param headers {Object} Keys are header names, values are header values. Multiple
2903 * headers of the same name are not supported.
2904 */
2905var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers) {
2906 this.fileKey = fileKey || null;
2907 this.fileName = fileName || null;
2908 this.mimeType = mimeType || null;
2909 this.params = params || null;
2910 this.headers = headers || null;
2911};
2912
2913module.exports = FileUploadOptions;
2914
2915});
2916
2917// file: lib/common/plugin/FileUploadResult.js
2918define("cordova/plugin/FileUploadResult", function(require, exports, module) {
2919
2920/**
2921 * FileUploadResult
2922 * @constructor
2923 */
2924var FileUploadResult = function() {
2925 this.bytesSent = 0;
2926 this.responseCode = null;
2927 this.response = null;
2928};
2929
2930module.exports = FileUploadResult;
2931
2932});
2933
2934// file: lib/common/plugin/FileWriter.js
2935define("cordova/plugin/FileWriter", function(require, exports, module) {
2936
2937var exec = require('cordova/exec'),
2938 FileError = require('cordova/plugin/FileError'),
2939 ProgressEvent = require('cordova/plugin/ProgressEvent');
2940
2941/**
2942 * This class writes to the mobile device file system.
2943 *
2944 * For Android:
2945 * The root directory is the root of the file system.
2946 * To write to the SD card, the file name is "sdcard/my_file.txt"
2947 *
2948 * @constructor
2949 * @param file {File} File object containing file properties
2950 * @param append if true write to the end of the file, otherwise overwrite the file
2951 */
2952var FileWriter = function(file) {
2953 this.fileName = "";
2954 this.length = 0;
2955 if (file) {
2956 this.fileName = file.fullPath || file;
2957 this.length = file.size || 0;
2958 }
2959 // default is to write at the beginning of the file
2960 this.position = 0;
2961
2962 this.readyState = 0; // EMPTY
2963
2964 this.result = null;
2965
2966 // Error
2967 this.error = null;
2968
2969 // Event handlers
2970 this.onwritestart = null; // When writing starts
2971 this.onprogress = null; // While writing the file, and reporting partial file data
2972 this.onwrite = null; // When the write has successfully completed.
2973 this.onwriteend = null; // When the request has completed (either in success or failure).
2974 this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
2975 this.onerror = null; // When the write has failed (see errors).
2976};
2977
2978// States
2979FileWriter.INIT = 0;
2980FileWriter.WRITING = 1;
2981FileWriter.DONE = 2;
2982
2983/**
2984 * Abort writing file.
2985 */
2986FileWriter.prototype.abort = function() {
2987 // check for invalid state
2988 if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
2989 throw new FileError(FileError.INVALID_STATE_ERR);
2990 }
2991
2992 // set error
2993 this.error = new FileError(FileError.ABORT_ERR);
2994
2995 this.readyState = FileWriter.DONE;
2996
2997 // If abort callback
2998 if (typeof this.onabort === "function") {
2999 this.onabort(new ProgressEvent("abort", {"target":this}));
3000 }
3001
3002 // If write end callback
3003 if (typeof this.onwriteend === "function") {
3004 this.onwriteend(new ProgressEvent("writeend", {"target":this}));
3005 }
3006};
3007
3008/**
3009 * Writes data to the file
3010 *
3011 * @param text to be written
3012 */
3013FileWriter.prototype.write = function(text) {
3014 // Throw an exception if we are already writing a file
3015 if (this.readyState === FileWriter.WRITING) {
3016 throw new FileError(FileError.INVALID_STATE_ERR);
3017 }
3018
3019 // WRITING state
3020 this.readyState = FileWriter.WRITING;
3021
3022 var me = this;
3023
3024 // If onwritestart callback
3025 if (typeof me.onwritestart === "function") {
3026 me.onwritestart(new ProgressEvent("writestart", {"target":me}));
3027 }
3028
3029 // Write file
3030 exec(
3031 // Success callback
3032 function(r) {
3033 // If DONE (cancelled), then don't do anything
3034 if (me.readyState === FileWriter.DONE) {
3035 return;
3036 }
3037
3038 // position always increases by bytes written because file would be extended
3039 me.position += r;
3040 // The length of the file is now where we are done writing.
3041
3042 me.length = me.position;
3043
3044 // DONE state
3045 me.readyState = FileWriter.DONE;
3046
3047 // If onwrite callback
3048 if (typeof me.onwrite === "function") {
3049 me.onwrite(new ProgressEvent("write", {"target":me}));
3050 }
3051
3052 // If onwriteend callback
3053 if (typeof me.onwriteend === "function") {
3054 me.onwriteend(new ProgressEvent("writeend", {"target":me}));
3055 }
3056 },
3057 // Error callback
3058 function(e) {
3059 // If DONE (cancelled), then don't do anything
3060 if (me.readyState === FileWriter.DONE) {
3061 return;
3062 }
3063
3064 // DONE state
3065 me.readyState = FileWriter.DONE;
3066
3067 // Save error
3068 me.error = new FileError(e);
3069
3070 // If onerror callback
3071 if (typeof me.onerror === "function") {
3072 me.onerror(new ProgressEvent("error", {"target":me}));
3073 }
3074
3075 // If onwriteend callback
3076 if (typeof me.onwriteend === "function") {
3077 me.onwriteend(new ProgressEvent("writeend", {"target":me}));
3078 }
3079 }, "File", "write", [this.fileName, text, this.position]);
3080};
3081
3082/**
3083 * Moves the file pointer to the location specified.
3084 *
3085 * If the offset is a negative number the position of the file
3086 * pointer is rewound. If the offset is greater than the file
3087 * size the position is set to the end of the file.
3088 *
3089 * @param offset is the location to move the file pointer to.
3090 */
3091FileWriter.prototype.seek = function(offset) {
3092 // Throw an exception if we are already writing a file
3093 if (this.readyState === FileWriter.WRITING) {
3094 throw new FileError(FileError.INVALID_STATE_ERR);
3095 }
3096
3097 if (!offset && offset !== 0) {
3098 return;
3099 }
3100
3101 // See back from end of file.
3102 if (offset < 0) {
3103 this.position = Math.max(offset + this.length, 0);
3104 }
3105 // Offset is bigger than file size so set position
3106 // to the end of the file.
3107 else if (offset > this.length) {
3108 this.position = this.length;
3109 }
3110 // Offset is between 0 and file size so set the position
3111 // to start writing.
3112 else {
3113 this.position = offset;
3114 }
3115};
3116
3117/**
3118 * Truncates the file to the size specified.
3119 *
3120 * @param size to chop the file at.
3121 */
3122FileWriter.prototype.truncate = function(size) {
3123 // Throw an exception if we are already writing a file
3124 if (this.readyState === FileWriter.WRITING) {
3125 throw new FileError(FileError.INVALID_STATE_ERR);
3126 }
3127
3128 // WRITING state
3129 this.readyState = FileWriter.WRITING;
3130
3131 var me = this;
3132
3133 // If onwritestart callback
3134 if (typeof me.onwritestart === "function") {
3135 me.onwritestart(new ProgressEvent("writestart", {"target":this}));
3136 }
3137
3138 // Write file
3139 exec(
3140 // Success callback
3141 function(r) {
3142 // If DONE (cancelled), then don't do anything
3143 if (me.readyState === FileWriter.DONE) {
3144 return;
3145 }
3146
3147 // DONE state
3148 me.readyState = FileWriter.DONE;
3149
3150 // Update the length of the file
3151 me.length = r;
3152 me.position = Math.min(me.position, r);
3153
3154 // If onwrite callback
3155 if (typeof me.onwrite === "function") {
3156 me.onwrite(new ProgressEvent("write", {"target":me}));
3157 }
3158
3159 // If onwriteend callback
3160 if (typeof me.onwriteend === "function") {
3161 me.onwriteend(new ProgressEvent("writeend", {"target":me}));
3162 }
3163 },
3164 // Error callback
3165 function(e) {
3166 // If DONE (cancelled), then don't do anything
3167 if (me.readyState === FileWriter.DONE) {
3168 return;
3169 }
3170
3171 // DONE state
3172 me.readyState = FileWriter.DONE;
3173
3174 // Save error
3175 me.error = new FileError(e);
3176
3177 // If onerror callback
3178 if (typeof me.onerror === "function") {
3179 me.onerror(new ProgressEvent("error", {"target":me}));
3180 }
3181
3182 // If onwriteend callback
3183 if (typeof me.onwriteend === "function") {
3184 me.onwriteend(new ProgressEvent("writeend", {"target":me}));
3185 }
3186 }, "File", "truncate", [this.fileName, size]);
3187};
3188
3189module.exports = FileWriter;
3190
3191});
3192
3193// file: lib/common/plugin/Flags.js
3194define("cordova/plugin/Flags", function(require, exports, module) {
3195
3196/**
3197 * Supplies arguments to methods that lookup or create files and directories.
3198 *
3199 * @param create
3200 * {boolean} file or directory if it doesn't exist
3201 * @param exclusive
3202 * {boolean} used with create; if true the command will fail if
3203 * target path exists
3204 */
3205function Flags(create, exclusive) {
3206 this.create = create || false;
3207 this.exclusive = exclusive || false;
3208}
3209
3210module.exports = Flags;
3211
3212});
3213
3214// file: lib/common/plugin/GlobalizationError.js
3215define("cordova/plugin/GlobalizationError", function(require, exports, module) {
3216
3217
3218/**
3219 * Globalization error object
3220 *
3221 * @constructor
3222 * @param code
3223 * @param message
3224 */
3225var GlobalizationError = function(code, message) {
3226 this.code = code || null;
3227 this.message = message || '';
3228};
3229
3230// Globalization error codes
3231GlobalizationError.UNKNOWN_ERROR = 0;
3232GlobalizationError.FORMATTING_ERROR = 1;
3233GlobalizationError.PARSING_ERROR = 2;
3234GlobalizationError.PATTERN_ERROR = 3;
3235
3236module.exports = GlobalizationError;
3237
3238});
3239
3240// file: lib/common/plugin/LocalFileSystem.js
3241define("cordova/plugin/LocalFileSystem", function(require, exports, module) {
3242
3243var exec = require('cordova/exec');
3244
3245/**
3246 * Represents a local file system.
3247 */
3248var LocalFileSystem = function() {
3249
3250};
3251
3252LocalFileSystem.TEMPORARY = 0; //temporary, with no guarantee of persistence
3253LocalFileSystem.PERSISTENT = 1; //persistent
3254
3255module.exports = LocalFileSystem;
3256
3257});
3258
3259// file: lib/common/plugin/Media.js
3260define("cordova/plugin/Media", function(require, exports, module) {
3261
3262var utils = require('cordova/utils'),
3263 exec = require('cordova/exec');
3264
3265var mediaObjects = {};
3266
3267/**
3268 * This class provides access to the device media, interfaces to both sound and video
3269 *
3270 * @constructor
3271 * @param src The file name or url to play
3272 * @param successCallback The callback to be called when the file is done playing or recording.
3273 * successCallback()
3274 * @param errorCallback The callback to be called if there is an error.
3275 * errorCallback(int errorCode) - OPTIONAL
3276 * @param statusCallback The callback to be called when media status has changed.
3277 * statusCallback(int statusCode) - OPTIONAL
3278 */
3279var Media = function(src, successCallback, errorCallback, statusCallback) {
3280
3281 // successCallback optional
3282 if (successCallback && (typeof successCallback !== "function")) {
3283 console.log("Media Error: successCallback is not a function");
3284 return;
3285 }
3286
3287 // errorCallback optional
3288 if (errorCallback && (typeof errorCallback !== "function")) {
3289 console.log("Media Error: errorCallback is not a function");
3290 return;
3291 }
3292
3293 // statusCallback optional
3294 if (statusCallback && (typeof statusCallback !== "function")) {
3295 console.log("Media Error: statusCallback is not a function");
3296 return;
3297 }
3298
3299 this.id = utils.createUUID();
3300 mediaObjects[this.id] = this;
3301 this.src = src;
3302 this.successCallback = successCallback;
3303 this.errorCallback = errorCallback;
3304 this.statusCallback = statusCallback;
3305 this._duration = -1;
3306 this._position = -1;
3307 exec(null, this.errorCallback, "Media", "create", [this.id, this.src]);
3308};
3309
3310// Media messages
3311Media.MEDIA_STATE = 1;
3312Media.MEDIA_DURATION = 2;
3313Media.MEDIA_POSITION = 3;
3314Media.MEDIA_ERROR = 9;
3315
3316// Media states
3317Media.MEDIA_NONE = 0;
3318Media.MEDIA_STARTING = 1;
3319Media.MEDIA_RUNNING = 2;
3320Media.MEDIA_PAUSED = 3;
3321Media.MEDIA_STOPPED = 4;
3322Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"];
3323
3324// "static" function to return existing objs.
3325Media.get = function(id) {
3326 return mediaObjects[id];
3327};
3328
3329/**
3330 * Start or resume playing audio file.
3331 */
3332Media.prototype.play = function(options) {
3333 exec(null, null, "Media", "startPlayingAudio", [this.id, this.src, options]);
3334};
3335
3336/**
3337 * Stop playing audio file.
3338 */
3339Media.prototype.stop = function() {
3340 var me = this;
3341 exec(function() {
3342 me._position = 0;
3343 }, this.errorCallback, "Media", "stopPlayingAudio", [this.id]);
3344};
3345
3346/**
3347 * Seek or jump to a new time in the track..
3348 */
3349Media.prototype.seekTo = function(milliseconds) {
3350 var me = this;
3351 exec(function(p) {
3352 me._position = p;
3353 }, this.errorCallback, "Media", "seekToAudio", [this.id, milliseconds]);
3354};
3355
3356/**
3357 * Pause playing audio file.
3358 */
3359Media.prototype.pause = function() {
3360 exec(null, this.errorCallback, "Media", "pausePlayingAudio", [this.id]);
3361};
3362
3363/**
3364 * Get duration of an audio file.
3365 * The duration is only set for audio that is playing, paused or stopped.
3366 *
3367 * @return duration or -1 if not known.
3368 */
3369Media.prototype.getDuration = function() {
3370 return this._duration;
3371};
3372
3373/**
3374 * Get position of audio.
3375 */
3376Media.prototype.getCurrentPosition = function(success, fail) {
3377 var me = this;
3378 exec(function(p) {
3379 me._position = p;
3380 success(p);
3381 }, fail, "Media", "getCurrentPositionAudio", [this.id]);
3382};
3383
3384/**
3385 * Start recording audio file.
3386 */
3387Media.prototype.startRecord = function() {
3388 exec(null, this.errorCallback, "Media", "startRecordingAudio", [this.id, this.src]);
3389};
3390
3391/**
3392 * Stop recording audio file.
3393 */
3394Media.prototype.stopRecord = function() {
3395 exec(null, this.errorCallback, "Media", "stopRecordingAudio", [this.id]);
3396};
3397
3398/**
3399 * Release the resources.
3400 */
3401Media.prototype.release = function() {
3402 exec(null, this.errorCallback, "Media", "release", [this.id]);
3403};
3404
3405/**
3406 * Adjust the volume.
3407 */
3408Media.prototype.setVolume = function(volume) {
3409 exec(null, null, "Media", "setVolume", [this.id, volume]);
3410};
3411
3412/**
3413 * Audio has status update.
3414 * PRIVATE
3415 *
3416 * @param id The media object id (string)
3417 * @param msgType The 'type' of update this is
3418 * @param value Use of value is determined by the msgType
3419 */
3420Media.onStatus = function(id, msgType, value) {
3421
3422 var media = mediaObjects[id];
3423
3424 if(media) {
3425 switch(msgType) {
3426 case Media.MEDIA_STATE :
3427 media.statusCallback && media.statusCallback(value);
3428 if(value == Media.MEDIA_STOPPED) {
3429 media.successCallback && media.successCallback();
3430 }
3431 break;
3432 case Media.MEDIA_DURATION :
3433 media._duration = value;
3434 break;
3435 case Media.MEDIA_ERROR :
3436 media.errorCallback && media.errorCallback(value);
3437 break;
3438 case Media.MEDIA_POSITION :
3439 media._position = Number(value);
3440 break;
3441 default :
3442 console && console.error && console.error("Unhandled Media.onStatus :: " + msgType);
3443 break;
3444 }
3445 }
3446 else {
3447 console && console.error && console.error("Received Media.onStatus callback for unknown media :: " + id);
3448 }
3449
3450};
3451
3452module.exports = Media;
3453
3454});
3455
3456// file: lib/common/plugin/MediaError.js
3457define("cordova/plugin/MediaError", function(require, exports, module) {
3458
3459/**
3460 * This class contains information about any Media errors.
3461*/
3462/*
3463 According to :: http://dev.w3.org/html5/spec-author-view/video.html#mediaerror
3464 We should never be creating these objects, we should just implement the interface
3465 which has 1 property for an instance, 'code'
3466
3467 instead of doing :
3468 errorCallbackFunction( new MediaError(3,'msg') );
3469we should simply use a literal :
3470 errorCallbackFunction( {'code':3} );
3471 */
3472
3473 var _MediaError = window.MediaError;
3474
3475
3476if(!_MediaError) {
3477 window.MediaError = _MediaError = function(code, msg) {
3478 this.code = (typeof code != 'undefined') ? code : null;
3479 this.message = msg || ""; // message is NON-standard! do not use!
3480 };
3481}
3482
3483_MediaError.MEDIA_ERR_NONE_ACTIVE = _MediaError.MEDIA_ERR_NONE_ACTIVE || 0;
3484_MediaError.MEDIA_ERR_ABORTED = _MediaError.MEDIA_ERR_ABORTED || 1;
3485_MediaError.MEDIA_ERR_NETWORK = _MediaError.MEDIA_ERR_NETWORK || 2;
3486_MediaError.MEDIA_ERR_DECODE = _MediaError.MEDIA_ERR_DECODE || 3;
3487_MediaError.MEDIA_ERR_NONE_SUPPORTED = _MediaError.MEDIA_ERR_NONE_SUPPORTED || 4;
3488// TODO: MediaError.MEDIA_ERR_NONE_SUPPORTED is legacy, the W3 spec now defines it as below.
3489// as defined by http://dev.w3.org/html5/spec-author-view/video.html#error-codes
3490_MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = _MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED || 4;
3491
3492module.exports = _MediaError;
3493
3494});
3495
3496// file: lib/common/plugin/MediaFile.js
3497define("cordova/plugin/MediaFile", function(require, exports, module) {
3498
3499var utils = require('cordova/utils'),
3500 exec = require('cordova/exec'),
3501 File = require('cordova/plugin/File'),
3502 CaptureError = require('cordova/plugin/CaptureError');
3503/**
3504 * Represents a single file.
3505 *
3506 * name {DOMString} name of the file, without path information
3507 * fullPath {DOMString} the full path of the file, including the name
3508 * type {DOMString} mime type
3509 * lastModifiedDate {Date} last modified date
3510 * size {Number} size of the file in bytes
3511 */
3512var MediaFile = function(name, fullPath, type, lastModifiedDate, size){
3513 MediaFile.__super__.constructor.apply(this, arguments);
3514};
3515
3516utils.extend(MediaFile, File);
3517
3518/**
3519 * Request capture format data for a specific file and type
3520 *
3521 * @param {Function} successCB
3522 * @param {Function} errorCB
3523 */
3524MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
3525 if (typeof this.fullPath === "undefined" || this.fullPath === null) {
3526 errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
3527 } else {
3528 exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
3529 }
3530};
3531
3532module.exports = MediaFile;
3533
3534});
3535
3536// file: lib/common/plugin/MediaFileData.js
3537define("cordova/plugin/MediaFileData", function(require, exports, module) {
3538
3539/**
3540 * MediaFileData encapsulates format information of a media file.
3541 *
3542 * @param {DOMString} codecs
3543 * @param {long} bitrate
3544 * @param {long} height
3545 * @param {long} width
3546 * @param {float} duration
3547 */
3548var MediaFileData = function(codecs, bitrate, height, width, duration){
3549 this.codecs = codecs || null;
3550 this.bitrate = bitrate || 0;
3551 this.height = height || 0;
3552 this.width = width || 0;
3553 this.duration = duration || 0;
3554};
3555
3556module.exports = MediaFileData;
3557
3558});
3559
3560// file: lib/common/plugin/Metadata.js
3561define("cordova/plugin/Metadata", function(require, exports, module) {
3562
3563/**
3564 * Information about the state of the file or directory
3565 *
3566 * {Date} modificationTime (readonly)
3567 */
3568var Metadata = function(time) {
3569 this.modificationTime = (typeof time != 'undefined'?new Date(time):null);
3570};
3571
3572module.exports = Metadata;
3573
3574});
3575
3576// file: lib/common/plugin/Position.js
3577define("cordova/plugin/Position", function(require, exports, module) {
3578
3579var Coordinates = require('cordova/plugin/Coordinates');
3580
3581var Position = function(coords, timestamp) {
3582 if (coords) {
3583 this.coords = new Coordinates(coords.latitude, coords.longitude, coords.altitude, coords.accuracy, coords.heading, coords.velocity, coords.altitudeAccuracy);
3584 } else {
3585 this.coords = new Coordinates();
3586 }
3587 this.timestamp = (timestamp !== undefined) ? timestamp : new Date();
3588};
3589
3590module.exports = Position;
3591
3592});
3593
3594// file: lib/common/plugin/PositionError.js
3595define("cordova/plugin/PositionError", function(require, exports, module) {
3596
3597/**
3598 * Position error object
3599 *
3600 * @constructor
3601 * @param code
3602 * @param message
3603 */
3604var PositionError = function(code, message) {
3605 this.code = code || null;
3606 this.message = message || '';
3607};
3608
3609PositionError.PERMISSION_DENIED = 1;
3610PositionError.POSITION_UNAVAILABLE = 2;
3611PositionError.TIMEOUT = 3;
3612
3613module.exports = PositionError;
3614
3615});
3616
3617// file: lib/common/plugin/ProgressEvent.js
3618define("cordova/plugin/ProgressEvent", function(require, exports, module) {
3619
3620// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
3621// Feature test: See if we can instantiate a native ProgressEvent;
3622// if so, use that approach,
3623// otherwise fill-in with our own implementation.
3624//
3625// NOTE: right now we always fill in with our own. Down the road would be nice if we can use whatever is native in the webview.
3626var ProgressEvent = (function() {
3627 /*
3628 var createEvent = function(data) {
3629 var event = document.createEvent('Events');
3630 event.initEvent('ProgressEvent', false, false);
3631 if (data) {
3632 for (var i in data) {
3633 if (data.hasOwnProperty(i)) {
3634 event[i] = data[i];
3635 }
3636 }
3637 if (data.target) {
3638 // TODO: cannot call <some_custom_object>.dispatchEvent
3639 // need to first figure out how to implement EventTarget
3640 }
3641 }
3642 return event;
3643 };
3644 try {
3645 var ev = createEvent({type:"abort",target:document});
3646 return function ProgressEvent(type, data) {
3647 data.type = type;
3648 return createEvent(data);
3649 };
3650 } catch(e){
3651 */
3652 return function ProgressEvent(type, dict) {
3653 this.type = type;
3654 this.bubbles = false;
3655 this.cancelBubble = false;
3656 this.cancelable = false;
3657 this.lengthComputable = false;
3658 this.loaded = dict && dict.loaded ? dict.loaded : 0;
3659 this.total = dict && dict.total ? dict.total : 0;
3660 this.target = dict && dict.target ? dict.target : null;
3661 };
3662 //}
3663})();
3664
3665module.exports = ProgressEvent;
3666
3667});
3668
3669// file: lib/common/plugin/accelerometer.js
3670define("cordova/plugin/accelerometer", function(require, exports, module) {
3671
3672/**
3673 * This class provides access to device accelerometer data.
3674 * @constructor
3675 */
3676var utils = require("cordova/utils"),
3677 exec = require("cordova/exec"),
3678 Acceleration = require('cordova/plugin/Acceleration');
3679
3680// Is the accel sensor running?
3681var running = false;
3682
3683// Keeps reference to watchAcceleration calls.
3684var timers = {};
3685
3686// Array of listeners; used to keep track of when we should call start and stop.
3687var listeners = [];
3688
3689// Last returned acceleration object from native
3690var accel = null;
3691
3692// Tells native to start.
3693function start() {
3694 exec(function(a) {
3695 var tempListeners = listeners.slice(0);
3696 accel = new Acceleration(a.x, a.y, a.z, a.timestamp);
3697 for (var i = 0, l = tempListeners.length; i < l; i++) {
3698 tempListeners[i].win(accel);
3699 }
3700 }, function(e) {
3701 var tempListeners = listeners.slice(0);
3702 for (var i = 0, l = tempListeners.length; i < l; i++) {
3703 tempListeners[i].fail(e);
3704 }
3705 }, "Accelerometer", "start", []);
3706 running = true;
3707}
3708
3709// Tells native to stop.
3710function stop() {
3711 exec(null, null, "Accelerometer", "stop", []);
3712 running = false;
3713}
3714
3715// Adds a callback pair to the listeners array
3716function createCallbackPair(win, fail) {
3717 return {win:win, fail:fail};
3718}
3719
3720// Removes a win/fail listener pair from the listeners array
3721function removeListeners(l) {
3722 var idx = listeners.indexOf(l);
3723 if (idx > -1) {
3724 listeners.splice(idx, 1);
3725 if (listeners.length === 0) {
3726 stop();
3727 }
3728 }
3729}
3730
3731var accelerometer = {
3732 /**
3733 * Asynchronously acquires the current acceleration.
3734 *
3735 * @param {Function} successCallback The function to call when the acceleration data is available
3736 * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL)
3737 * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL)
3738 */
3739 getCurrentAcceleration: function(successCallback, errorCallback, options) {
3740 // successCallback required
3741 if (typeof successCallback !== "function") {
3742 throw "getCurrentAcceleration must be called with at least a success callback function as first parameter.";
3743 }
3744
3745 var p;
3746 var win = function(a) {
3747 removeListeners(p);
3748 successCallback(a);
3749 };
3750 var fail = function(e) {
3751 removeListeners(p);
3752 errorCallback(e);
3753 };
3754
3755 p = createCallbackPair(win, fail);
3756 listeners.push(p);
3757
3758 if (!running) {
3759 start();
3760 }
3761 },
3762
3763 /**
3764 * Asynchronously acquires the acceleration repeatedly at a given interval.
3765 *
3766 * @param {Function} successCallback The function to call each time the acceleration data is available
3767 * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL)
3768 * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL)
3769 * @return String The watch id that must be passed to #clearWatch to stop watching.
3770 */
3771 watchAcceleration: function(successCallback, errorCallback, options) {
3772 // Default interval (10 sec)
3773 var frequency = (options && options.frequency && typeof options.frequency == 'number') ? options.frequency : 10000;
3774
3775 // successCallback required
3776 if (typeof successCallback !== "function") {
3777 throw "watchAcceleration must be called with at least a success callback function as first parameter.";
3778 }
3779
3780 // Keep reference to watch id, and report accel readings as often as defined in frequency
3781 var id = utils.createUUID();
3782
3783 var p = createCallbackPair(function(){}, function(e) {
3784 removeListeners(p);
3785 errorCallback(e);
3786 });
3787 listeners.push(p);
3788
3789 timers[id] = {
3790 timer:window.setInterval(function() {
3791 if (accel) {
3792 successCallback(accel);
3793 }
3794 }, frequency),
3795 listeners:p
3796 };
3797
3798 if (running) {
3799 // If we're already running then immediately invoke the success callback
3800 // but only if we have retrieved a value, sample code does not check for null ...
3801 if(accel) {
3802 successCallback(accel);
3803 }
3804 } else {
3805 start();
3806 }
3807
3808 return id;
3809 },
3810
3811 /**
3812 * Clears the specified accelerometer watch.
3813 *
3814 * @param {String} id The id of the watch returned from #watchAcceleration.
3815 */
3816 clearWatch: function(id) {
3817 // Stop javascript timer & remove from timer list
3818 if (id && timers[id]) {
3819 window.clearInterval(timers[id].timer);
3820 removeListeners(timers[id].listeners);
3821 delete timers[id];
3822 }
3823 }
3824};
3825
3826module.exports = accelerometer;
3827
3828});
3829
3830// file: lib/android/plugin/android/app.js
3831define("cordova/plugin/android/app", function(require, exports, module) {
3832
3833var exec = require('cordova/exec');
3834
3835module.exports = {
3836 /**
3837 * Clear the resource cache.
3838 */
3839 clearCache:function() {
3840 exec(null, null, "App", "clearCache", []);
3841 },
3842
3843 /**
3844 * Load the url into the webview or into new browser instance.
3845 *
3846 * @param url The URL to load
3847 * @param props Properties that can be passed in to the activity:
3848 * wait: int => wait msec before loading URL
3849 * loadingDialog: "Title,Message" => display a native loading dialog
3850 * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error
3851 * clearHistory: boolean => clear webview history (default=false)
3852 * openExternal: boolean => open in a new browser (default=false)
3853 *
3854 * Example:
3855 * navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
3856 */
3857 loadUrl:function(url, props) {
3858 exec(null, null, "App", "loadUrl", [url, props]);
3859 },
3860
3861 /**
3862 * Cancel loadUrl that is waiting to be loaded.
3863 */
3864 cancelLoadUrl:function() {
3865 exec(null, null, "App", "cancelLoadUrl", []);
3866 },
3867
3868 /**
3869 * Clear web history in this web view.
3870 * Instead of BACK button loading the previous web page, it will exit the app.
3871 */
3872 clearHistory:function() {
3873 exec(null, null, "App", "clearHistory", []);
3874 },
3875
3876 /**
3877 * Go to previous page displayed.
3878 * This is the same as pressing the backbutton on Android device.
3879 */
3880 backHistory:function() {
3881 exec(null, null, "App", "backHistory", []);
3882 },
3883
3884 /**
3885 * Override the default behavior of the Android back button.
3886 * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
3887 *
3888 * Note: The user should not have to call this method. Instead, when the user
3889 * registers for the "backbutton" event, this is automatically done.
3890 *
3891 * @param override T=override, F=cancel override
3892 */
3893 overrideBackbutton:function(override) {
3894 exec(null, null, "App", "overrideBackbutton", [override]);
3895 },
3896
3897 /**
3898 * Exit and terminate the application.
3899 */
3900 exitApp:function() {
3901 return exec(null, null, "App", "exitApp", []);
3902 }
3903};
3904
3905});
3906
3907// file: lib/android/plugin/android/device.js
3908define("cordova/plugin/android/device", function(require, exports, module) {
3909
3910var channel = require('cordova/channel'),
3911 utils = require('cordova/utils'),
3912 exec = require('cordova/exec'),
3913 app = require('cordova/plugin/android/app');
3914
3915module.exports = {
3916 /*
3917 * DEPRECATED
3918 * This is only for Android.
3919 *
3920 * You must explicitly override the back button.
3921 */
3922 overrideBackButton:function() {
3923 console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true).");
3924 app.overrideBackbutton(true);
3925 },
3926
3927 /*
3928 * DEPRECATED
3929 * This is only for Android.
3930 *
3931 * This resets the back button to the default behavior
3932 */
3933 resetBackButton:function() {
3934 console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false).");
3935 app.overrideBackbutton(false);
3936 },
3937
3938 /*
3939 * DEPRECATED
3940 * This is only for Android.
3941 *
3942 * This terminates the activity!
3943 */
3944 exitApp:function() {
3945 console.log("Device.exitApp() is deprecated. Use App.exitApp().");
3946 app.exitApp();
3947 }
3948};
3949
3950});
3951
3952// file: lib/android/plugin/android/nativeapiprovider.js
3953define("cordova/plugin/android/nativeapiprovider", function(require, exports, module) {
3954
3955var nativeApi = this._cordovaNative || require('cordova/plugin/android/promptbasednativeapi');
3956var currentApi = nativeApi;
3957
3958module.exports = {
3959 get: function() { return currentApi; },
3960 setPreferPrompt: function(value) {
3961 currentApi = value ? require('cordova/plugin/android/promptbasednativeapi') : nativeApi;
3962 },
3963 // Used only by tests.
3964 set: function(value) {
3965 currentApi = value;
3966 }
3967};
3968
3969});
3970
3971// file: lib/android/plugin/android/notification.js
3972define("cordova/plugin/android/notification", function(require, exports, module) {
3973
3974var exec = require('cordova/exec');
3975
3976/**
3977 * Provides Android enhanced notification API.
3978 */
3979module.exports = {
3980 activityStart : function(title, message) {
3981 // If title and message not specified then mimic Android behavior of
3982 // using default strings.
3983 if (typeof title === "undefined" && typeof message == "undefined") {
3984 title = "Busy";
3985 message = 'Please wait...';
3986 }
3987
3988 exec(null, null, 'Notification', 'activityStart', [ title, message ]);
3989 },
3990
3991 /**
3992 * Close an activity dialog
3993 */
3994 activityStop : function() {
3995 exec(null, null, 'Notification', 'activityStop', []);
3996 },
3997
3998 /**
3999 * Display a progress dialog with progress bar that goes from 0 to 100.
4000 *
4001 * @param {String}
4002 * title Title of the progress dialog.
4003 * @param {String}
4004 * message Message to display in the dialog.
4005 */
4006 progressStart : function(title, message) {
4007 exec(null, null, 'Notification', 'progressStart', [ title, message ]);
4008 },
4009
4010 /**
4011 * Close the progress dialog.
4012 */
4013 progressStop : function() {
4014 exec(null, null, 'Notification', 'progressStop', []);
4015 },
4016
4017 /**
4018 * Set the progress dialog value.
4019 *
4020 * @param {Number}
4021 * value 0-100
4022 */
4023 progressValue : function(value) {
4024 exec(null, null, 'Notification', 'progressValue', [ value ]);
4025 }
4026};
4027
4028});
4029
4030// file: lib/android/plugin/android/promptbasednativeapi.js
4031define("cordova/plugin/android/promptbasednativeapi", function(require, exports, module) {
4032
4033module.exports = {
4034 exec: function(service, action, callbackId, argsJson) {
4035 return prompt(argsJson, 'gap:'+JSON.stringify([service, action, callbackId]));
4036 },
4037 setNativeToJsBridgeMode: function(value) {
4038 prompt(value, 'gap_bridge_mode:');
4039 },
4040 retrieveJsMessages: function() {
4041 return prompt('', 'gap_poll:');
4042 }
4043};
4044
4045});
4046
4047// file: lib/android/plugin/android/storage.js
4048define("cordova/plugin/android/storage", function(require, exports, module) {
4049
4050var utils = require('cordova/utils'),
4051 exec = require('cordova/exec'),
4052 channel = require('cordova/channel');
4053
4054var queryQueue = {};
4055
4056/**
4057 * SQL result set object
4058 * PRIVATE METHOD
4059 * @constructor
4060 */
4061var DroidDB_Rows = function() {
4062 this.resultSet = []; // results array
4063 this.length = 0; // number of rows
4064};
4065
4066/**
4067 * Get item from SQL result set
4068 *
4069 * @param row The row number to return
4070 * @return The row object
4071 */
4072DroidDB_Rows.prototype.item = function(row) {
4073 return this.resultSet[row];
4074};
4075
4076/**
4077 * SQL result set that is returned to user.
4078 * PRIVATE METHOD
4079 * @constructor
4080 */
4081var DroidDB_Result = function() {
4082 this.rows = new DroidDB_Rows();
4083};
4084
4085/**
4086 * Callback from native code when query is complete.
4087 * PRIVATE METHOD
4088 *
4089 * @param id Query id
4090 */
4091function completeQuery(id, data) {
4092 var query = queryQueue[id];
4093 if (query) {
4094 try {
4095 delete queryQueue[id];
4096
4097 // Get transaction
4098 var tx = query.tx;
4099
4100 // If transaction hasn't failed
4101 // Note: We ignore all query results if previous query
4102 // in the same transaction failed.
4103 if (tx && tx.queryList[id]) {
4104
4105 // Save query results
4106 var r = new DroidDB_Result();
4107 r.rows.resultSet = data;
4108 r.rows.length = data.length;
4109 try {
4110 if (typeof query.successCallback === 'function') {
4111 query.successCallback(query.tx, r);
4112 }
4113 } catch (ex) {
4114 console.log("executeSql error calling user success callback: "+ex);
4115 }
4116
4117 tx.queryComplete(id);
4118 }
4119 } catch (e) {
4120 console.log("executeSql error: "+e);
4121 }
4122 }
4123}
4124
4125/**
4126 * Callback from native code when query fails
4127 * PRIVATE METHOD
4128 *
4129 * @param reason Error message
4130 * @param id Query id
4131 */
4132function failQuery(reason, id) {
4133 var query = queryQueue[id];
4134 if (query) {
4135 try {
4136 delete queryQueue[id];
4137
4138 // Get transaction
4139 var tx = query.tx;
4140
4141 // If transaction hasn't failed
4142 // Note: We ignore all query results if previous query
4143 // in the same transaction failed.
4144 if (tx && tx.queryList[id]) {
4145 tx.queryList = {};
4146
4147 try {
4148 if (typeof query.errorCallback === 'function') {
4149 query.errorCallback(query.tx, reason);
4150 }
4151 } catch (ex) {
4152 console.log("executeSql error calling user error callback: "+ex);
4153 }
4154
4155 tx.queryFailed(id, reason);
4156 }
4157
4158 } catch (e) {
4159 console.log("executeSql error: "+e);
4160 }
4161 }
4162}
4163
4164/**
4165 * SQL query object
4166 * PRIVATE METHOD
4167 *
4168 * @constructor
4169 * @param tx The transaction object that this query belongs to
4170 */
4171var DroidDB_Query = function(tx) {
4172
4173 // Set the id of the query
4174 this.id = utils.createUUID();
4175
4176 // Add this query to the queue
4177 queryQueue[this.id] = this;
4178
4179 // Init result
4180 this.resultSet = [];
4181
4182 // Set transaction that this query belongs to
4183 this.tx = tx;
4184
4185 // Add this query to transaction list
4186 this.tx.queryList[this.id] = this;
4187
4188 // Callbacks
4189 this.successCallback = null;
4190 this.errorCallback = null;
4191
4192};
4193
4194/**
4195 * Transaction object
4196 * PRIVATE METHOD
4197 * @constructor
4198 */
4199var DroidDB_Tx = function() {
4200
4201 // Set the id of the transaction
4202 this.id = utils.createUUID();
4203
4204 // Callbacks
4205 this.successCallback = null;
4206 this.errorCallback = null;
4207
4208 // Query list
4209 this.queryList = {};
4210};
4211
4212/**
4213 * Mark query in transaction as complete.
4214 * If all queries are complete, call the user's transaction success callback.
4215 *
4216 * @param id Query id
4217 */
4218DroidDB_Tx.prototype.queryComplete = function(id) {
4219 delete this.queryList[id];
4220
4221 // If no more outstanding queries, then fire transaction success
4222 if (this.successCallback) {
4223 var count = 0;
4224 var i;
4225 for (i in this.queryList) {
4226 if (this.queryList.hasOwnProperty(i)) {
4227 count++;
4228 }
4229 }
4230 if (count === 0) {
4231 try {
4232 this.successCallback();
4233 } catch(e) {
4234 console.log("Transaction error calling user success callback: " + e);
4235 }
4236 }
4237 }
4238};
4239
4240/**
4241 * Mark query in transaction as failed.
4242 *
4243 * @param id Query id
4244 * @param reason Error message
4245 */
4246DroidDB_Tx.prototype.queryFailed = function(id, reason) {
4247
4248 // The sql queries in this transaction have already been run, since
4249 // we really don't have a real transaction implemented in native code.
4250 // However, the user callbacks for the remaining sql queries in transaction
4251 // will not be called.
4252 this.queryList = {};
4253
4254 if (this.errorCallback) {
4255 try {
4256 this.errorCallback(reason);
4257 } catch(e) {
4258 console.log("Transaction error calling user error callback: " + e);
4259 }
4260 }
4261};
4262
4263/**
4264 * Execute SQL statement
4265 *
4266 * @param sql SQL statement to execute
4267 * @param params Statement parameters
4268 * @param successCallback Success callback
4269 * @param errorCallback Error callback
4270 */
4271DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCallback) {
4272
4273 // Init params array
4274 if (typeof params === 'undefined') {
4275 params = [];
4276 }
4277
4278 // Create query and add to queue
4279 var query = new DroidDB_Query(this);
4280 queryQueue[query.id] = query;
4281
4282 // Save callbacks
4283 query.successCallback = successCallback;
4284 query.errorCallback = errorCallback;
4285
4286 // Call native code
4287 exec(null, null, "Storage", "executeSql", [sql, params, query.id]);
4288};
4289
4290var DatabaseShell = function() {
4291};
4292
4293/**
4294 * Start a transaction.
4295 * Does not support rollback in event of failure.
4296 *
4297 * @param process {Function} The transaction function
4298 * @param successCallback {Function}
4299 * @param errorCallback {Function}
4300 */
4301DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) {
4302 var tx = new DroidDB_Tx();
4303 tx.successCallback = successCallback;
4304 tx.errorCallback = errorCallback;
4305 try {
4306 process(tx);
4307 } catch (e) {
4308 console.log("Transaction error: "+e);
4309 if (tx.errorCallback) {
4310 try {
4311 tx.errorCallback(e);
4312 } catch (ex) {
4313 console.log("Transaction error calling user error callback: "+e);
4314 }
4315 }
4316 }
4317};
4318
4319/**
4320 * Open database
4321 *
4322 * @param name Database name
4323 * @param version Database version
4324 * @param display_name Database display name
4325 * @param size Database size in bytes
4326 * @return Database object
4327 */
4328var DroidDB_openDatabase = function(name, version, display_name, size) {
4329 exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]);
4330 var db = new DatabaseShell();
4331 return db;
4332};
4333
4334/**
4335 * For browsers with no localStorage we emulate it with SQLite. Follows the w3c api.
4336 * TODO: Do similar for sessionStorage.
4337 * @constructor
4338 */
4339var CupcakeLocalStorage = function() {
4340 channel.waitForInitialization("cupcakeStorage");
4341
4342 try {
4343
4344 this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440);
4345 var storage = {};
4346 this.length = 0;
4347 function setLength (length) {
4348 this.length = length;
4349 localStorage.length = length;
4350 }
4351 this.db.transaction(
4352 function (transaction) {
4353 var i;
4354 transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
4355 transaction.executeSql('SELECT * FROM storage', [], function(tx, result) {
4356 for(var i = 0; i < result.rows.length; i++) {
4357 storage[result.rows.item(i).id] = result.rows.item(i).body;
4358 }
4359 setLength(result.rows.length);
4360 channel.initializationComplete("cupcakeStorage");
4361 });
4362
4363 },
4364 function (err) {
4365 utils.alert(err.message);
4366 }
4367 );
4368 this.setItem = function(key, val) {
4369 if (typeof(storage[key])=='undefined') {
4370 this.length++;
4371 }
4372 storage[key] = val;
4373 this.db.transaction(
4374 function (transaction) {
4375 transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
4376 transaction.executeSql('REPLACE INTO storage (id, body) values(?,?)', [key,val]);
4377 }
4378 );
4379 };
4380 this.getItem = function(key) {
4381 return storage[key];
4382 };
4383 this.removeItem = function(key) {
4384 delete storage[key];
4385 this.length--;
4386 this.db.transaction(
4387 function (transaction) {
4388 transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
4389 transaction.executeSql('DELETE FROM storage where id=?', [key]);
4390 }
4391 );
4392 };
4393 this.clear = function() {
4394 storage = {};
4395 this.length = 0;
4396 this.db.transaction(
4397 function (transaction) {
4398 transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
4399 transaction.executeSql('DELETE FROM storage', []);
4400 }
4401 );
4402 };
4403 this.key = function(index) {
4404 var i = 0;
4405 for (var j in storage) {
4406 if (i==index) {
4407 return j;
4408 } else {
4409 i++;
4410 }
4411 }
4412 return null;
4413 };
4414
4415 } catch(e) {
4416 utils.alert("Database error "+e+".");
4417 return;
4418 }
4419};
4420
4421module.exports = {
4422 openDatabase:DroidDB_openDatabase,
4423 CupcakeLocalStorage:CupcakeLocalStorage,
4424 failQuery:failQuery,
4425 completeQuery:completeQuery
4426};
4427
4428});
4429
4430// file: lib/common/plugin/battery.js
4431define("cordova/plugin/battery", function(require, exports, module) {
4432
4433/**
4434 * This class contains information about the current battery status.
4435 * @constructor
4436 */
4437var cordova = require('cordova'),
4438 exec = require('cordova/exec');
4439
4440function handlers() {
4441 return battery.channels.batterystatus.numHandlers +
4442 battery.channels.batterylow.numHandlers +
4443 battery.channels.batterycritical.numHandlers;
4444}
4445
4446var Battery = function() {
4447 this._level = null;
4448 this._isPlugged = null;
4449 // Create new event handlers on the window (returns a channel instance)
4450 this.channels = {
4451 batterystatus:cordova.addWindowEventHandler("batterystatus"),
4452 batterylow:cordova.addWindowEventHandler("batterylow"),
4453 batterycritical:cordova.addWindowEventHandler("batterycritical")
4454 };
4455 for (var key in this.channels) {
4456 this.channels[key].onHasSubscribersChange = Battery.onHasSubscribersChange;
4457 }
4458};
4459/**
4460 * Event handlers for when callbacks get registered for the battery.
4461 * Keep track of how many handlers we have so we can start and stop the native battery listener
4462 * appropriately (and hopefully save on battery life!).
4463 */
4464Battery.onHasSubscribersChange = function() {
4465 // If we just registered the first handler, make sure native listener is started.
4466 if (this.numHandlers === 1 && handlers() === 1) {
4467 exec(battery._status, battery._error, "Battery", "start", []);
4468 } else if (handlers() === 0) {
4469 exec(null, null, "Battery", "stop", []);
4470 }
4471};
4472
4473/**
4474 * Callback for battery status
4475 *
4476 * @param {Object} info keys: level, isPlugged
4477 */
4478Battery.prototype._status = function(info) {
4479 if (info) {
4480 var me = battery;
4481 var level = info.level;
4482 if (me._level !== level || me._isPlugged !== info.isPlugged) {
4483 // Fire batterystatus event
4484 cordova.fireWindowEvent("batterystatus", info);
4485
4486 // Fire low battery event
4487 if (level === 20 || level === 5) {
4488 if (level === 20) {
4489 cordova.fireWindowEvent("batterylow", info);
4490 }
4491 else {
4492 cordova.fireWindowEvent("batterycritical", info);
4493 }
4494 }
4495 }
4496 me._level = level;
4497 me._isPlugged = info.isPlugged;
4498 }
4499};
4500
4501/**
4502 * Error callback for battery start
4503 */
4504Battery.prototype._error = function(e) {
4505 console.log("Error initializing Battery: " + e);
4506};
4507
4508var battery = new Battery();
4509
4510module.exports = battery;
4511
4512});
4513
4514// file: lib/common/plugin/capture.js
4515define("cordova/plugin/capture", function(require, exports, module) {
4516
4517var exec = require('cordova/exec'),
4518 MediaFile = require('cordova/plugin/MediaFile');
4519
4520/**
4521 * Launches a capture of different types.
4522 *
4523 * @param (DOMString} type
4524 * @param {Function} successCB
4525 * @param {Function} errorCB
4526 * @param {CaptureVideoOptions} options
4527 */
4528function _capture(type, successCallback, errorCallback, options) {
4529 var win = function(pluginResult) {
4530 var mediaFiles = [];
4531 var i;
4532 for (i = 0; i < pluginResult.length; i++) {
4533 var mediaFile = new MediaFile();
4534 mediaFile.name = pluginResult[i].name;
4535 mediaFile.fullPath = pluginResult[i].fullPath;
4536 mediaFile.type = pluginResult[i].type;
4537 mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;
4538 mediaFile.size = pluginResult[i].size;
4539 mediaFiles.push(mediaFile);
4540 }
4541 successCallback(mediaFiles);
4542 };
4543 exec(win, errorCallback, "Capture", type, [options]);
4544}
4545/**
4546 * The Capture interface exposes an interface to the camera and microphone of the hosting device.
4547 */
4548function Capture() {
4549 this.supportedAudioModes = [];
4550 this.supportedImageModes = [];
4551 this.supportedVideoModes = [];
4552}
4553
4554/**
4555 * Launch audio recorder application for recording audio clip(s).
4556 *
4557 * @param {Function} successCB
4558 * @param {Function} errorCB
4559 * @param {CaptureAudioOptions} options
4560 */
4561Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
4562 _capture("captureAudio", successCallback, errorCallback, options);
4563};
4564
4565/**
4566 * Launch camera application for taking image(s).
4567 *
4568 * @param {Function} successCB
4569 * @param {Function} errorCB
4570 * @param {CaptureImageOptions} options
4571 */
4572Capture.prototype.captureImage = function(successCallback, errorCallback, options){
4573 _capture("captureImage", successCallback, errorCallback, options);
4574};
4575
4576/**
4577 * Launch device camera application for recording video(s).
4578 *
4579 * @param {Function} successCB
4580 * @param {Function} errorCB
4581 * @param {CaptureVideoOptions} options
4582 */
4583Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
4584 _capture("captureVideo", successCallback, errorCallback, options);
4585};
4586
4587
4588module.exports = new Capture();
4589
4590});
4591
4592// file: lib/common/plugin/compass.js
4593define("cordova/plugin/compass", function(require, exports, module) {
4594
4595var exec = require('cordova/exec'),
4596 utils = require('cordova/utils'),
4597 CompassHeading = require('cordova/plugin/CompassHeading'),
4598 CompassError = require('cordova/plugin/CompassError'),
4599 timers = {},
4600 compass = {
4601 /**
4602 * Asynchronously acquires the current heading.
4603 * @param {Function} successCallback The function to call when the heading
4604 * data is available
4605 * @param {Function} errorCallback The function to call when there is an error
4606 * getting the heading data.
4607 * @param {CompassOptions} options The options for getting the heading data (not used).
4608 */
4609 getCurrentHeading:function(successCallback, errorCallback, options) {
4610 // successCallback required
4611 if (typeof successCallback !== "function") {
4612 console.log("Compass Error: successCallback is not a function");
4613 return;
4614 }
4615
4616 // errorCallback optional
4617 if (errorCallback && (typeof errorCallback !== "function")) {
4618 console.log("Compass Error: errorCallback is not a function");
4619 return;
4620 }
4621
4622 var win = function(result) {
4623 var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
4624 successCallback(ch);
4625 };
4626 var fail = function(code) {
4627 var ce = new CompassError(code);
4628 errorCallback(ce);
4629 };
4630
4631 // Get heading
4632 exec(win, fail, "Compass", "getHeading", [options]);
4633 },
4634
4635 /**
4636 * Asynchronously acquires the heading repeatedly at a given interval.
4637 * @param {Function} successCallback The function to call each time the heading
4638 * data is available
4639 * @param {Function} errorCallback The function to call when there is an error
4640 * getting the heading data.
4641 * @param {HeadingOptions} options The options for getting the heading data
4642 * such as timeout and the frequency of the watch. For iOS, filter parameter
4643 * specifies to watch via a distance filter rather than time.
4644 */
4645 watchHeading:function(successCallback, errorCallback, options) {
4646 // Default interval (100 msec)
4647 var frequency = (options !== undefined && options.frequency !== undefined) ? options.frequency : 100;
4648 var filter = (options !== undefined && options.filter !== undefined) ? options.filter : 0;
4649
4650 // successCallback required
4651 if (typeof successCallback !== "function") {
4652 console.log("Compass Error: successCallback is not a function");
4653 return;
4654 }
4655
4656 // errorCallback optional
4657 if (errorCallback && (typeof errorCallback !== "function")) {
4658 console.log("Compass Error: errorCallback is not a function");
4659 return;
4660 }
4661
4662 var id = utils.createUUID();
4663 if (filter > 0) {
4664 // is an iOS request for watch by filter, no timer needed
4665 timers[id] = "iOS";
4666 compass.getCurrentHeading(successCallback, errorCallback, options);
4667 } else {
4668 // Start watch timer to get headings
4669 timers[id] = window.setInterval(function() {
4670 compass.getCurrentHeading(successCallback, errorCallback);
4671 }, frequency);
4672 }
4673
4674 return id;
4675 },
4676
4677 /**
4678 * Clears the specified heading watch.
4679 * @param {String} watchId The ID of the watch returned from #watchHeading.
4680 */
4681 clearWatch:function(id) {
4682 // Stop javascript timer & remove from timer list
4683 if (id && timers[id]) {
4684 if (timers[id] != "iOS") {
4685 clearInterval(timers[id]);
4686 } else {
4687 // is iOS watch by filter so call into device to stop
4688 exec(null, null, "Compass", "stopHeading", []);
4689 }
4690 delete timers[id];
4691 }
4692 }
4693 };
4694
4695module.exports = compass;
4696
4697});
4698
4699// file: lib/common/plugin/console-via-logger.js
4700define("cordova/plugin/console-via-logger", function(require, exports, module) {
4701
4702//------------------------------------------------------------------------------
4703
4704var logger = require("cordova/plugin/logger");
4705var utils = require("cordova/utils");
4706
4707//------------------------------------------------------------------------------
4708// object that we're exporting
4709//------------------------------------------------------------------------------
4710var console = module.exports;
4711
4712//------------------------------------------------------------------------------
4713// copy of the original console object
4714//------------------------------------------------------------------------------
4715var WinConsole = window.console;
4716
4717//------------------------------------------------------------------------------
4718// whether to use the logger
4719//------------------------------------------------------------------------------
4720var UseLogger = false;
4721
4722//------------------------------------------------------------------------------
4723// Timers
4724//------------------------------------------------------------------------------
4725var Timers = {};
4726
4727//------------------------------------------------------------------------------
4728// used for unimplemented methods
4729//------------------------------------------------------------------------------
4730function noop() {}
4731
4732//------------------------------------------------------------------------------
4733// used for unimplemented methods
4734//------------------------------------------------------------------------------
4735console.useLogger = function (value) {
4736 if (arguments.length) UseLogger = !!value;
4737
4738 if (UseLogger) {
4739 if (logger.useConsole()) {
4740 throw new Error("console and logger are too intertwingly");
4741 }
4742 }
4743
4744 return UseLogger;
4745};
4746
4747//------------------------------------------------------------------------------
4748console.log = function() {
4749 if (logger.useConsole()) return;
4750 logger.log.apply(logger, [].slice.call(arguments));
4751};
4752
4753//------------------------------------------------------------------------------
4754console.error = function() {
4755 if (logger.useConsole()) return;
4756 logger.error.apply(logger, [].slice.call(arguments));
4757};
4758
4759//------------------------------------------------------------------------------
4760console.warn = function() {
4761 if (logger.useConsole()) return;
4762 logger.warn.apply(logger, [].slice.call(arguments));
4763};
4764
4765//------------------------------------------------------------------------------
4766console.info = function() {
4767 if (logger.useConsole()) return;
4768 logger.info.apply(logger, [].slice.call(arguments));
4769};
4770
4771//------------------------------------------------------------------------------
4772console.debug = function() {
4773 if (logger.useConsole()) return;
4774 logger.debug.apply(logger, [].slice.call(arguments));
4775};
4776
4777//------------------------------------------------------------------------------
4778console.assert = function(expression) {
4779 if (expression) return;
4780
4781 var message = utils.vformat(arguments[1], [].slice.call(arguments, 2));
4782 console.log("ASSERT: " + message);
4783};
4784
4785//------------------------------------------------------------------------------
4786console.clear = function() {};
4787
4788//------------------------------------------------------------------------------
4789console.dir = function(object) {
4790 console.log("%o", object);
4791};
4792
4793//------------------------------------------------------------------------------
4794console.dirxml = function(node) {
4795 console.log(node.innerHTML);
4796};
4797
4798//------------------------------------------------------------------------------
4799console.trace = noop;
4800
4801//------------------------------------------------------------------------------
4802console.group = console.log;
4803
4804//------------------------------------------------------------------------------
4805console.groupCollapsed = console.log;
4806
4807//------------------------------------------------------------------------------
4808console.groupEnd = noop;
4809
4810//------------------------------------------------------------------------------
4811console.time = function(name) {
4812 Timers[name] = new Date().valueOf();
4813};
4814
4815//------------------------------------------------------------------------------
4816console.timeEnd = function(name) {
4817 var timeStart = Timers[name];
4818 if (!timeStart) {
4819 console.warn("unknown timer: " + name);
4820 return;
4821 }
4822
4823 var timeElapsed = new Date().valueOf() - timeStart;
4824 console.log(name + ": " + timeElapsed + "ms");
4825};
4826
4827//------------------------------------------------------------------------------
4828console.timeStamp = noop;
4829
4830//------------------------------------------------------------------------------
4831console.profile = noop;
4832
4833//------------------------------------------------------------------------------
4834console.profileEnd = noop;
4835
4836//------------------------------------------------------------------------------
4837console.count = noop;
4838
4839//------------------------------------------------------------------------------
4840console.exception = console.log;
4841
4842//------------------------------------------------------------------------------
4843console.table = function(data, columns) {
4844 console.log("%o", data);
4845};
4846
4847//------------------------------------------------------------------------------
4848// return a new function that calls both functions passed as args
4849//------------------------------------------------------------------------------
4850function wrappedOrigCall(orgFunc, newFunc) {
4851 return function() {
4852 var args = [].slice.call(arguments);
4853 try { orgFunc.apply(WinConsole, args); } catch (e) {}
4854 try { newFunc.apply(console, args); } catch (e) {}
4855 };
4856}
4857
4858//------------------------------------------------------------------------------
4859// For every function that exists in the original console object, that
4860// also exists in the new console object, wrap the new console method
4861// with one that calls both
4862//------------------------------------------------------------------------------
4863for (var key in console) {
4864 if (typeof WinConsole[key] == "function") {
4865 console[key] = wrappedOrigCall(WinConsole[key], console[key]);
4866 }
4867}
4868
4869});
4870
4871// file: lib/common/plugin/contacts.js
4872define("cordova/plugin/contacts", function(require, exports, module) {
4873
4874var exec = require('cordova/exec'),
4875 ContactError = require('cordova/plugin/ContactError'),
4876 utils = require('cordova/utils'),
4877 Contact = require('cordova/plugin/Contact');
4878
4879/**
4880* Represents a group of Contacts.
4881* @constructor
4882*/
4883var contacts = {
4884 /**
4885 * Returns an array of Contacts matching the search criteria.
4886 * @param fields that should be searched
4887 * @param successCB success callback
4888 * @param errorCB error callback
4889 * @param {ContactFindOptions} options that can be applied to contact searching
4890 * @return array of Contacts matching search criteria
4891 */
4892 find:function(fields, successCB, errorCB, options) {
4893 if (!successCB) {
4894 throw new TypeError("You must specify a success callback for the find command.");
4895 }
4896 if (!fields || (utils.isArray(fields) && fields.length === 0)) {
4897 if (typeof errorCB === "function") {
4898 errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
4899 }
4900 } else {
4901 var win = function(result) {
4902 var cs = [];
4903 for (var i = 0, l = result.length; i < l; i++) {
4904 cs.push(contacts.create(result[i]));
4905 }
4906 successCB(cs);
4907 };
4908 exec(win, errorCB, "Contacts", "search", [fields, options]);
4909 }
4910 },
4911
4912 /**
4913 * This function creates a new contact, but it does not persist the contact
4914 * to device storage. To persist the contact to device storage, invoke
4915 * contact.save().
4916 * @param properties an object whose properties will be examined to create a new Contact
4917 * @returns new Contact object
4918 */
4919 create:function(properties) {
4920 var i;
4921 var contact = new Contact();
4922 for (i in properties) {
4923 if (typeof contact[i] !== 'undefined' && properties.hasOwnProperty(i)) {
4924 contact[i] = properties[i];
4925 }
4926 }
4927 return contact;
4928 }
4929};
4930
4931module.exports = contacts;
4932
4933});
4934
4935// file: lib/common/plugin/device.js
4936define("cordova/plugin/device", function(require, exports, module) {
4937
4938var channel = require('cordova/channel'),
4939 utils = require('cordova/utils'),
4940 exec = require('cordova/exec');
4941
4942// Tell cordova channel to wait on the CordovaInfoReady event
4943channel.waitForInitialization('onCordovaInfoReady');
4944
4945/**
4946 * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
4947 * phone, etc.
4948 * @constructor
4949 */
4950function Device() {
4951 this.available = false;
4952 this.platform = null;
4953 this.version = null;
4954 this.name = null;
4955 this.uuid = null;
4956 this.cordova = null;
4957
4958 var me = this;
4959
4960 channel.onCordovaReady.subscribe(function() {
4961 me.getInfo(function(info) {
4962 me.available = true;
4963 me.platform = info.platform;
4964 me.version = info.version;
4965 me.name = info.name;
4966 me.uuid = info.uuid;
4967 me.cordova = info.cordova;
4968 channel.onCordovaInfoReady.fire();
4969 },function(e) {
4970 me.available = false;
4971 utils.alert("[ERROR] Error initializing Cordova: " + e);
4972 });
4973 });
4974}
4975
4976/**
4977 * Get device info
4978 *
4979 * @param {Function} successCallback The function to call when the heading data is available
4980 * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
4981 */
4982Device.prototype.getInfo = function(successCallback, errorCallback) {
4983
4984 // successCallback required
4985 if (typeof successCallback !== "function") {
4986 console.log("Device Error: successCallback is not a function");
4987 return;
4988 }
4989
4990 // errorCallback optional
4991 if (errorCallback && (typeof errorCallback !== "function")) {
4992 console.log("Device Error: errorCallback is not a function");
4993 return;
4994 }
4995
4996 // Get info
4997 exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
4998};
4999
5000module.exports = new Device();
5001
5002});
5003
5004// file: lib/common/plugin/echo.js
5005define("cordova/plugin/echo", function(require, exports, module) {
5006
5007var exec = require('cordova/exec');
5008
5009/**
5010 * Sends the given message through exec() to the Echo plugin, which sends it back to the successCallback.
5011 * @param successCallback invoked with a FileSystem object
5012 * @param errorCallback invoked if error occurs retrieving file system
5013 * @param message The string to be echoed.
5014 * @param forceAsync Whether to force an async return value (for testing native->js bridge).
5015 */
5016module.exports = function(successCallback, errorCallback, message, forceAsync) {
5017 var action = forceAsync ? 'echoAsync' : 'echo';
5018 exec(successCallback, errorCallback, "Echo", action, [message]);
5019};
5020
5021
5022});
5023
5024// file: lib/common/plugin/geolocation.js
5025define("cordova/plugin/geolocation", function(require, exports, module) {
5026
5027var utils = require('cordova/utils'),
5028 exec = require('cordova/exec'),
5029 PositionError = require('cordova/plugin/PositionError'),
5030 Position = require('cordova/plugin/Position');
5031
5032var timers = {}; // list of timers in use
5033
5034// Returns default params, overrides if provided with values
5035function parseParameters(options) {
5036 var opt = {
5037 maximumAge: 0,
5038 enableHighAccuracy: false,
5039 timeout: Infinity
5040 };
5041
5042 if (options) {
5043 if (options.maximumAge !== undefined && !isNaN(options.maximumAge) && options.maximumAge > 0) {
5044 opt.maximumAge = options.maximumAge;
5045 }
5046 if (options.enableHighAccuracy !== undefined) {
5047 opt.enableHighAccuracy = options.enableHighAccuracy;
5048 }
5049 if (options.timeout !== undefined && !isNaN(options.timeout)) {
5050 if (options.timeout < 0) {
5051 opt.timeout = 0;
5052 } else {
5053 opt.timeout = options.timeout;
5054 }
5055 }
5056 }
5057
5058 return opt;
5059}
5060
5061// Returns a timeout failure, closed over a specified timeout value and error callback.
5062function createTimeout(errorCallback, timeout) {
5063 var t = setTimeout(function() {
5064 clearTimeout(t);
5065 t = null;
5066 errorCallback({
5067 code:PositionError.TIMEOUT,
5068 message:"Position retrieval timed out."
5069 });
5070 }, timeout);
5071 return t;
5072}
5073
5074var geolocation = {
5075 lastPosition:null, // reference to last known (cached) position returned
5076 /**
5077 * Asynchronously acquires the current position.
5078 *
5079 * @param {Function} successCallback The function to call when the position data is available
5080 * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL)
5081 * @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
5082 */
5083 getCurrentPosition:function(successCallback, errorCallback, options) {
5084 if (arguments.length === 0) {
5085 throw new Error("getCurrentPosition must be called with at least one argument.");
5086 }
5087 options = parseParameters(options);
5088
5089 // Timer var that will fire an error callback if no position is retrieved from native
5090 // before the "timeout" param provided expires
5091 var timeoutTimer = {timer:null};
5092
5093 var win = function(p) {
5094 clearTimeout(timeoutTimer.timer);
5095 if (!(timeoutTimer.timer)) {
5096 // Timeout already happened, or native fired error callback for
5097 // this geo request.
5098 // Don't continue with success callback.
5099 return;
5100 }
5101 var pos = new Position(
5102 {
5103 latitude:p.latitude,
5104 longitude:p.longitude,
5105 altitude:p.altitude,
5106 accuracy:p.accuracy,
5107 heading:p.heading,
5108 velocity:p.velocity,
5109 altitudeAccuracy:p.altitudeAccuracy
5110 },
5111 (p.timestamp === undefined ? new Date() : ((p.timestamp instanceof Date) ? p.timestamp : new Date(p.timestamp)))
5112 );
5113 geolocation.lastPosition = pos;
5114 successCallback(pos);
5115 };
5116 var fail = function(e) {
5117 clearTimeout(timeoutTimer.timer);
5118 timeoutTimer.timer = null;
5119 var err = new PositionError(e.code, e.message);
5120 if (errorCallback) {
5121 errorCallback(err);
5122 }
5123 };
5124
5125 // Check our cached position, if its timestamp difference with current time is less than the maximumAge, then just
5126 // fire the success callback with the cached position.
5127 if (geolocation.lastPosition && options.maximumAge && (((new Date()).getTime() - geolocation.lastPosition.timestamp.getTime()) <= options.maximumAge)) {
5128 successCallback(geolocation.lastPosition);
5129 // If the cached position check failed and the timeout was set to 0, error out with a TIMEOUT error object.
5130 } else if (options.timeout === 0) {
5131 fail({
5132 code:PositionError.TIMEOUT,
5133 message:"timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceeds provided PositionOptions' maximumAge parameter."
5134 });
5135 // Otherwise we have to call into native to retrieve a position.
5136 } else {
5137 if (options.timeout !== Infinity) {
5138 // If the timeout value was not set to Infinity (default), then
5139 // set up a timeout function that will fire the error callback
5140 // if no successful position was retrieved before timeout expired.
5141 timeoutTimer.timer = createTimeout(fail, options.timeout);
5142 } else {
5143 // This is here so the check in the win function doesn't mess stuff up
5144 // may seem weird but this guarantees timeoutTimer is
5145 // always truthy before we call into native
5146 timeoutTimer.timer = true;
5147 }
5148 exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.maximumAge]);
5149 }
5150 return timeoutTimer;
5151 },
5152 /**
5153 * Asynchronously watches the geolocation for changes to geolocation. When a change occurs,
5154 * the successCallback is called with the new location.
5155 *
5156 * @param {Function} successCallback The function to call each time the location data is available
5157 * @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL)
5158 * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL)
5159 * @return String The watch id that must be passed to #clearWatch to stop watching.
5160 */
5161 watchPosition:function(successCallback, errorCallback, options) {
5162 if (arguments.length === 0) {
5163 throw new Error("watchPosition must be called with at least one argument.");
5164 }
5165 options = parseParameters(options);
5166
5167 var id = utils.createUUID();
5168
5169 // Tell device to get a position ASAP, and also retrieve a reference to the timeout timer generated in getCurrentPosition
5170 timers[id] = geolocation.getCurrentPosition(successCallback, errorCallback, options);
5171
5172 var fail = function(e) {
5173 clearTimeout(timers[id].timer);
5174 var err = new PositionError(e.code, e.message);
5175 if (errorCallback) {
5176 errorCallback(err);
5177 }
5178 };
5179
5180 var win = function(p) {
5181 clearTimeout(timers[id].timer);
5182 if (options.timeout !== Infinity) {
5183 timers[id].timer = createTimeout(fail, options.timeout);
5184 }
5185 var pos = new Position(
5186 {
5187 latitude:p.latitude,
5188 longitude:p.longitude,
5189 altitude:p.altitude,
5190 accuracy:p.accuracy,
5191 heading:p.heading,
5192 velocity:p.velocity,
5193 altitudeAccuracy:p.altitudeAccuracy
5194 },
5195 (p.timestamp === undefined ? new Date() : ((p.timestamp instanceof Date) ? p.timestamp : new Date(p.timestamp)))
5196 );
5197 geolocation.lastPosition = pos;
5198 successCallback(pos);
5199 };
5200
5201 exec(win, fail, "Geolocation", "addWatch", [id, options.enableHighAccuracy]);
5202
5203 return id;
5204 },
5205 /**
5206 * Clears the specified heading watch.
5207 *
5208 * @param {String} id The ID of the watch returned from #watchPosition
5209 */
5210 clearWatch:function(id) {
5211 if (id && timers[id] !== undefined) {
5212 clearTimeout(timers[id].timer);
5213 timers[id].timer = false;
5214 exec(null, null, "Geolocation", "clearWatch", [id]);
5215 }
5216 }
5217};
5218
5219module.exports = geolocation;
5220
5221});
5222
5223// file: lib/common/plugin/globalization.js
5224define("cordova/plugin/globalization", function(require, exports, module) {
5225
5226var exec = require('cordova/exec'),
5227 GlobalizationError = require('cordova/plugin/GlobalizationError');
5228
5229var globalization = {
5230
5231/**
5232* Returns the string identifier for the client's current language.
5233* It returns the language identifier string to the successCB callback with a
5234* properties object as a parameter. If there is an error getting the language,
5235* then the errorCB callback is invoked.
5236*
5237* @param {Function} successCB
5238* @param {Function} errorCB
5239*
5240* @return Object.value {String}: The language identifier
5241*
5242* @error GlobalizationError.UNKNOWN_ERROR
5243*
5244* Example
5245* globalization.getPreferredLanguage(function (language) {alert('language:' + language.value + '\n');},
5246* function () {});
5247*/
5248getPreferredLanguage:function(successCB, failureCB) {
5249 // successCallback required
5250 if (typeof successCB != "function") {
5251 console.log("Globalization.getPreferredLanguage Error: successCB is not a function");
5252 return;
5253 }
5254
5255 // errorCallback required
5256 if (typeof failureCB != "function") {
5257 console.log("Globalization.getPreferredLanguage Error: failureCB is not a function");
5258 return;
5259 }
5260
5261 exec(successCB, failureCB, "Globalization","getPreferredLanguage", []);
5262},
5263
5264/**
5265* Returns the string identifier for the client's current locale setting.
5266* It returns the locale identifier string to the successCB callback with a
5267* properties object as a parameter. If there is an error getting the locale,
5268* then the errorCB callback is invoked.
5269*
5270* @param {Function} successCB
5271* @param {Function} errorCB
5272*
5273* @return Object.value {String}: The locale identifier
5274*
5275* @error GlobalizationError.UNKNOWN_ERROR
5276*
5277* Example
5278* globalization.getLocaleName(function (locale) {alert('locale:' + locale.value + '\n');},
5279* function () {});
5280*/
5281getLocaleName:function(successCB, failureCB) {
5282 // successCallback required
5283 if (typeof successCB != "function") {
5284 console.log("Globalization.getLocaleName Error: successCB is not a function");
5285 return;
5286 }
5287
5288 // errorCallback required
5289 if (typeof failureCB != "function") {
5290 console.log("Globalization.getLocaleName Error: failureCB is not a function");
5291 return;
5292 }
5293 exec(successCB, failureCB, "Globalization","getLocaleName", []);
5294},
5295
5296
5297/**
5298* Returns a date formatted as a string according to the client's user preferences and
5299* calendar using the time zone of the client. It returns the formatted date string to the
5300* successCB callback with a properties object as a parameter. If there is an error
5301* formatting the date, then the errorCB callback is invoked.
5302*
5303* The defaults are: formatLenght="short" and selector="date and time"
5304*
5305* @param {Date} date
5306* @param {Function} successCB
5307* @param {Function} errorCB
5308* @param {Object} options {optional}
5309* formatLength {String}: 'short', 'medium', 'long', or 'full'
5310* selector {String}: 'date', 'time', or 'date and time'
5311*
5312* @return Object.value {String}: The localized date string
5313*
5314* @error GlobalizationError.FORMATTING_ERROR
5315*
5316* Example
5317* globalization.dateToString(new Date(),
5318* function (date) {alert('date:' + date.value + '\n');},
5319* function (errorCode) {alert(errorCode);},
5320* {formatLength:'short'});
5321*/
5322dateToString:function(date, successCB, failureCB, options) {
5323 // successCallback required
5324 if (typeof successCB != "function") {
5325 console.log("Globalization.dateToString Error: successCB is not a function");
5326 return;
5327 }
5328
5329 // errorCallback required
5330 if (typeof failureCB != "function") {
5331 console.log("Globalization.dateToString Error: failureCB is not a function");
5332 return;
5333 }
5334
5335
5336 if (date instanceof Date){
5337 var dateValue;
5338 dateValue = date.valueOf();
5339 exec(successCB, failureCB, "Globalization", "dateToString", [{"date": dateValue, "options": options}]);
5340 }
5341 else {
5342 console.log("Globalization.dateToString Error: date is not a Date object");
5343 }
5344},
5345
5346
5347/**
5348* Parses a date formatted as a string according to the client's user
5349* preferences and calendar using the time zone of the client and returns
5350* the corresponding date object. It returns the date to the successCB
5351* callback with a properties object as a parameter. If there is an error
5352* parsing the date string, then the errorCB callback is invoked.
5353*
5354* The defaults are: formatLength="short" and selector="date and time"
5355*
5356* @param {String} dateString
5357* @param {Function} successCB
5358* @param {Function} errorCB
5359* @param {Object} options {optional}
5360* formatLength {String}: 'short', 'medium', 'long', or 'full'
5361* selector {String}: 'date', 'time', or 'date and time'
5362*
5363* @return Object.year {Number}: The four digit year
5364* Object.month {Number}: The month from (0 - 11)
5365* Object.day {Number}: The day from (1 - 31)
5366* Object.hour {Number}: The hour from (0 - 23)
5367* Object.minute {Number}: The minute from (0 - 59)
5368* Object.second {Number}: The second from (0 - 59)
5369* Object.millisecond {Number}: The milliseconds (from 0 - 999),
5370* not available on all platforms
5371*
5372* @error GlobalizationError.PARSING_ERROR
5373*
5374* Example
5375* globalization.stringToDate('4/11/2011',
5376* function (date) { alert('Month:' + date.month + '\n' +
5377* 'Day:' + date.day + '\n' +
5378* 'Year:' + date.year + '\n');},
5379* function (errorCode) {alert(errorCode);},
5380* {selector:'date'});
5381*/
5382stringToDate:function(dateString, successCB, failureCB, options) {
5383 // successCallback required
5384 if (typeof successCB != "function") {
5385 console.log("Globalization.stringToDate Error: successCB is not a function");
5386 return;
5387 }
5388
5389 // errorCallback required
5390 if (typeof failureCB != "function") {
5391 console.log("Globalization.stringToDate Error: failureCB is not a function");
5392 return;
5393 }
5394 if (typeof dateString == "string"){
5395 exec(successCB, failureCB, "Globalization", "stringToDate", [{"dateString": dateString, "options": options}]);
5396 }
5397 else {
5398 console.log("Globalization.stringToDate Error: dateString is not a string");
5399 }
5400},
5401
5402
5403/**
5404* Returns a pattern string for formatting and parsing dates according to the client's
5405* user preferences. It returns the pattern to the successCB callback with a
5406* properties object as a parameter. If there is an error obtaining the pattern,
5407* then the errorCB callback is invoked.
5408*
5409* The defaults are: formatLength="short" and selector="date and time"
5410*
5411* @param {Function} successCB
5412* @param {Function} errorCB
5413* @param {Object} options {optional}
5414* formatLength {String}: 'short', 'medium', 'long', or 'full'
5415* selector {String}: 'date', 'time', or 'date and time'
5416*
5417* @return Object.pattern {String}: The date and time pattern for formatting and parsing dates.
5418* The patterns follow Unicode Technical Standard #35
5419* http://unicode.org/reports/tr35/tr35-4.html
5420* Object.timezone {String}: The abbreviated name of the time zone on the client
5421* Object.utc_offset {Number}: The current difference in seconds between the client's
5422* time zone and coordinated universal time.
5423* Object.dst_offset {Number}: The current daylight saving time offset in seconds
5424* between the client's non-daylight saving's time zone
5425* and the client's daylight saving's time zone.
5426*
5427* @error GlobalizationError.PATTERN_ERROR
5428*
5429* Example
5430* globalization.getDatePattern(
5431* function (date) {alert('pattern:' + date.pattern + '\n');},
5432* function () {},
5433* {formatLength:'short'});
5434*/
5435getDatePattern:function(successCB, failureCB, options) {
5436 // successCallback required
5437 if (typeof successCB != "function") {
5438 console.log("Globalization.getDatePattern Error: successCB is not a function");
5439 return;
5440 }
5441
5442 // errorCallback required
5443 if (typeof failureCB != "function") {
5444 console.log("Globalization.getDatePattern Error: failureCB is not a function");
5445 return;
5446 }
5447
5448 exec(successCB, failureCB, "Globalization", "getDatePattern", [{"options": options}]);
5449},
5450
5451
5452/**
5453* Returns an array of either the names of the months or days of the week
5454* according to the client's user preferences and calendar. It returns the array of names to the
5455* successCB callback with a properties object as a parameter. If there is an error obtaining the
5456* names, then the errorCB callback is invoked.
5457*
5458* The defaults are: type="wide" and item="months"
5459*
5460* @param {Function} successCB
5461* @param {Function} errorCB
5462* @param {Object} options {optional}
5463* type {String}: 'narrow' or 'wide'
5464* item {String}: 'months', or 'days'
5465*
5466* @return Object.value {Array{String}}: The array of names starting from either
5467* the first month in the year or the
5468* first day of the week.
5469* @error GlobalizationError.UNKNOWN_ERROR
5470*
5471* Example
5472* globalization.getDateNames(function (names) {
5473* for(var i = 0; i < names.value.length; i++) {
5474* alert('Month:' + names.value[i] + '\n');}},
5475* function () {});
5476*/
5477getDateNames:function(successCB, failureCB, options) {
5478 // successCallback required
5479 if (typeof successCB != "function") {
5480 console.log("Globalization.getDateNames Error: successCB is not a function");
5481 return;
5482 }
5483
5484 // errorCallback required
5485 if (typeof failureCB != "function") {
5486 console.log("Globalization.getDateNames Error: failureCB is not a function");
5487 return;
5488 }
5489 exec(successCB, failureCB, "Globalization", "getDateNames", [{"options": options}]);
5490},
5491
5492/**
5493* Returns whether daylight savings time is in effect for a given date using the client's
5494* time zone and calendar. It returns whether or not daylight savings time is in effect
5495* to the successCB callback with a properties object as a parameter. If there is an error
5496* reading the date, then the errorCB callback is invoked.
5497*
5498* @param {Date} date
5499* @param {Function} successCB
5500* @param {Function} errorCB
5501*
5502* @return Object.dst {Boolean}: The value "true" indicates that daylight savings time is
5503* in effect for the given date and "false" indicate that it is not.
5504*
5505* @error GlobalizationError.UNKNOWN_ERROR
5506*
5507* Example
5508* globalization.isDayLightSavingsTime(new Date(),
5509* function (date) {alert('dst:' + date.dst + '\n');}
5510* function () {});
5511*/
5512isDayLightSavingsTime:function(date, successCB, failureCB) {
5513 // successCallback required
5514 if (typeof successCB != "function") {
5515 console.log("Globalization.isDayLightSavingsTime Error: successCB is not a function");
5516 return;
5517 }
5518
5519 // errorCallback required
5520 if (typeof failureCB != "function") {
5521 console.log("Globalization.isDayLightSavingsTime Error: failureCB is not a function");
5522 return;
5523 }
5524
5525
5526 if (date instanceof Date){
5527 var dateValue;
5528 dateValue = date.valueOf();
5529 exec(successCB, failureCB, "Globalization", "isDayLightSavingsTime", [{"date": dateValue}]);
5530 }
5531 else {
5532 console.log("Globalization.isDayLightSavingsTime Error: date is not a Date object");
5533 }
5534
5535},
5536
5537/**
5538* Returns the first day of the week according to the client's user preferences and calendar.
5539* The days of the week are numbered starting from 1 where 1 is considered to be Sunday.
5540* It returns the day to the successCB callback with a properties object as a parameter.
5541* If there is an error obtaining the pattern, then the errorCB callback is invoked.
5542*
5543* @param {Function} successCB
5544* @param {Function} errorCB
5545*
5546* @return Object.value {Number}: The number of the first day of the week.
5547*
5548* @error GlobalizationError.UNKNOWN_ERROR
5549*
5550* Example
5551* globalization.getFirstDayOfWeek(function (day)
5552* { alert('Day:' + day.value + '\n');},
5553* function () {});
5554*/
5555getFirstDayOfWeek:function(successCB, failureCB) {
5556 // successCallback required
5557 if (typeof successCB != "function") {
5558 console.log("Globalization.getFirstDayOfWeek Error: successCB is not a function");
5559 return;
5560 }
5561
5562 // errorCallback required
5563 if (typeof failureCB != "function") {
5564 console.log("Globalization.getFirstDayOfWeek Error: failureCB is not a function");
5565 return;
5566 }
5567
5568 exec(successCB, failureCB, "Globalization", "getFirstDayOfWeek", []);
5569},
5570
5571
5572/**
5573* Returns a number formatted as a string according to the client's user preferences.
5574* It returns the formatted number string to the successCB callback with a properties object as a
5575* parameter. If there is an error formatting the number, then the errorCB callback is invoked.
5576*
5577* The defaults are: type="decimal"
5578*
5579* @param {Number} number
5580* @param {Function} successCB
5581* @param {Function} errorCB
5582* @param {Object} options {optional}
5583* type {String}: 'decimal', "percent", or 'currency'
5584*
5585* @return Object.value {String}: The formatted number string.
5586*
5587* @error GlobalizationError.FORMATTING_ERROR
5588*
5589* Example
5590* globalization.numberToString(3.25,
5591* function (number) {alert('number:' + number.value + '\n');},
5592* function () {},
5593* {type:'decimal'});
5594*/
5595numberToString:function(number, successCB, failureCB, options) {
5596 // successCallback required
5597 if (typeof successCB != "function") {
5598 console.log("Globalization.numberToString Error: successCB is not a function");
5599 return;
5600 }
5601
5602 // errorCallback required
5603 if (typeof failureCB != "function") {
5604 console.log("Globalization.numberToString Error: failureCB is not a function");
5605 return;
5606 }
5607
5608 if(typeof number == "number") {
5609 exec(successCB, failureCB, "Globalization", "numberToString", [{"number": number, "options": options}]);
5610 }
5611 else {
5612 console.log("Globalization.numberToString Error: number is not a number");
5613 }
5614},
5615
5616/**
5617* Parses a number formatted as a string according to the client's user preferences and
5618* returns the corresponding number. It returns the number to the successCB callback with a
5619* properties object as a parameter. If there is an error parsing the number string, then
5620* the errorCB callback is invoked.
5621*
5622* The defaults are: type="decimal"
5623*
5624* @param {String} numberString
5625* @param {Function} successCB
5626* @param {Function} errorCB
5627* @param {Object} options {optional}
5628* type {String}: 'decimal', "percent", or 'currency'
5629*
5630* @return Object.value {Number}: The parsed number.
5631*
5632* @error GlobalizationError.PARSING_ERROR
5633*
5634* Example
5635* globalization.stringToNumber('1234.56',
5636* function (number) {alert('Number:' + number.value + '\n');},
5637* function () { alert('Error parsing number');});
5638*/
5639stringToNumber:function(numberString, successCB, failureCB, options) {
5640 // successCallback required
5641 if (typeof successCB != "function") {
5642 console.log("Globalization.stringToNumber Error: successCB is not a function");
5643 return;
5644 }
5645
5646 // errorCallback required
5647 if (typeof failureCB != "function") {
5648 console.log("Globalization.stringToNumber Error: failureCB is not a function");
5649 return;
5650 }
5651
5652 if(typeof numberString == "string") {
5653 exec(successCB, failureCB, "Globalization", "stringToNumber", [{"numberString": numberString, "options": options}]);
5654 }
5655 else {
5656 console.log("Globalization.stringToNumber Error: numberString is not a string");
5657 }
5658},
5659
5660/**
5661* Returns a pattern string for formatting and parsing numbers according to the client's user
5662* preferences. It returns the pattern to the successCB callback with a properties object as a
5663* parameter. If there is an error obtaining the pattern, then the errorCB callback is invoked.
5664*
5665* The defaults are: type="decimal"
5666*
5667* @param {Function} successCB
5668* @param {Function} errorCB
5669* @param {Object} options {optional}
5670* type {String}: 'decimal', "percent", or 'currency'
5671*
5672* @return Object.pattern {String}: The number pattern for formatting and parsing numbers.
5673* The patterns follow Unicode Technical Standard #35.
5674* http://unicode.org/reports/tr35/tr35-4.html
5675* Object.symbol {String}: The symbol to be used when formatting and parsing
5676* e.g., percent or currency symbol.
5677* Object.fraction {Number}: The number of fractional digits to use when parsing and
5678* formatting numbers.
5679* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
5680* Object.positive {String}: The symbol to use for positive numbers when parsing and formatting.
5681* Object.negative: {String}: The symbol to use for negative numbers when parsing and formatting.
5682* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
5683* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
5684*
5685* @error GlobalizationError.PATTERN_ERROR
5686*
5687* Example
5688* globalization.getNumberPattern(
5689* function (pattern) {alert('Pattern:' + pattern.pattern + '\n');},
5690* function () {});
5691*/
5692getNumberPattern:function(successCB, failureCB, options) {
5693 // successCallback required
5694 if (typeof successCB != "function") {
5695 console.log("Globalization.getNumberPattern Error: successCB is not a function");
5696 return;
5697 }
5698
5699 // errorCallback required
5700 if (typeof failureCB != "function") {
5701 console.log("Globalization.getNumberPattern Error: failureCB is not a function");
5702 return;
5703 }
5704
5705 exec(successCB, failureCB, "Globalization", "getNumberPattern", [{"options": options}]);
5706},
5707
5708/**
5709* Returns a pattern string for formatting and parsing currency values according to the client's
5710* user preferences and ISO 4217 currency code. It returns the pattern to the successCB callback with a
5711* properties object as a parameter. If there is an error obtaining the pattern, then the errorCB
5712* callback is invoked.
5713*
5714* @param {String} currencyCode
5715* @param {Function} successCB
5716* @param {Function} errorCB
5717*
5718* @return Object.pattern {String}: The currency pattern for formatting and parsing currency values.
5719* The patterns follow Unicode Technical Standard #35
5720* http://unicode.org/reports/tr35/tr35-4.html
5721* Object.code {String}: The ISO 4217 currency code for the pattern.
5722* Object.fraction {Number}: The number of fractional digits to use when parsing and
5723* formatting currency.
5724* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
5725* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
5726* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
5727*
5728* @error GlobalizationError.FORMATTING_ERROR
5729*
5730* Example
5731* globalization.getCurrencyPattern('EUR',
5732* function (currency) {alert('Pattern:' + currency.pattern + '\n');}
5733* function () {});
5734*/
5735getCurrencyPattern:function(currencyCode, successCB, failureCB) {
5736 // successCallback required
5737 if (typeof successCB != "function") {
5738 console.log("Globalization.getCurrencyPattern Error: successCB is not a function");
5739 return;
5740 }
5741
5742 // errorCallback required
5743 if (typeof failureCB != "function") {
5744 console.log("Globalization.getCurrencyPattern Error: failureCB is not a function");
5745 return;
5746 }
5747
5748 if(typeof currencyCode == "string") {
5749 exec(successCB, failureCB, "Globalization", "getCurrencyPattern", [{"currencyCode": currencyCode}]);
5750 }
5751 else {
5752 console.log("Globalization.getCurrencyPattern Error: currencyCode is not a currency code");
5753 }
5754}
5755
5756};
5757
5758module.exports = globalization;
5759
5760});
5761
5762// file: lib/common/plugin/logger.js
5763define("cordova/plugin/logger", function(require, exports, module) {
5764
5765//------------------------------------------------------------------------------
5766// The logger module exports the following properties/functions:
5767//
5768// LOG - constant for the level LOG
5769// ERROR - constant for the level ERROR
5770// WARN - constant for the level WARN
5771// INFO - constant for the level INFO
5772// DEBUG - constant for the level DEBUG
5773// logLevel() - returns current log level
5774// logLevel(value) - sets and returns a new log level
5775// useConsole() - returns whether logger is using console
5776// useConsole(value) - sets and returns whether logger is using console
5777// log(message,...) - logs a message at level LOG
5778// error(message,...) - logs a message at level ERROR
5779// warn(message,...) - logs a message at level WARN
5780// info(message,...) - logs a message at level INFO
5781// debug(message,...) - logs a message at level DEBUG
5782// logLevel(level,message,...) - logs a message specified level
5783//
5784//------------------------------------------------------------------------------
5785
5786var logger = exports;
5787
5788var exec = require('cordova/exec');
5789var utils = require('cordova/utils');
5790
5791var UseConsole = true;
5792var Queued = [];
5793var DeviceReady = false;
5794var CurrentLevel;
5795
5796/**
5797 * Logging levels
5798 */
5799
5800var Levels = [
5801 "LOG",
5802 "ERROR",
5803 "WARN",
5804 "INFO",
5805 "DEBUG"
5806];
5807
5808/*
5809 * add the logging levels to the logger object and
5810 * to a separate levelsMap object for testing
5811 */
5812
5813var LevelsMap = {};
5814for (var i=0; i<Levels.length; i++) {
5815 var level = Levels[i];
5816 LevelsMap[level] = i;
5817 logger[level] = level;
5818}
5819
5820CurrentLevel = LevelsMap.WARN;
5821
5822/**
5823 * Getter/Setter for the logging level
5824 *
5825 * Returns the current logging level.
5826 *
5827 * When a value is passed, sets the logging level to that value.
5828 * The values should be one of the following constants:
5829 * logger.LOG
5830 * logger.ERROR
5831 * logger.WARN
5832 * logger.INFO
5833 * logger.DEBUG
5834 *
5835 * The value used determines which messages get printed. The logging
5836 * values above are in order, and only messages logged at the logging
5837 * level or above will actually be displayed to the user. E.g., the
5838 * default level is WARN, so only messages logged with LOG, ERROR, or
5839 * WARN will be displayed; INFO and DEBUG messages will be ignored.
5840 */
5841logger.level = function (value) {
5842 if (arguments.length) {
5843 if (LevelsMap[value] === null) {
5844 throw new Error("invalid logging level: " + value);
5845 }
5846 CurrentLevel = LevelsMap[value];
5847 }
5848
5849 return Levels[CurrentLevel];
5850};
5851
5852/**
5853 * Getter/Setter for the useConsole functionality
5854 *
5855 * When useConsole is true, the logger will log via the
5856 * browser 'console' object. Otherwise, it will use the
5857 * native Logger plugin.
5858 */
5859logger.useConsole = function (value) {
5860 if (arguments.length) UseConsole = !!value;
5861
5862 if (UseConsole) {
5863 if (typeof console == "undefined") {
5864 throw new Error("global console object is not defined");
5865 }
5866
5867 if (typeof console.log != "function") {
5868 throw new Error("global console object does not have a log function");
5869 }
5870
5871 if (typeof console.useLogger == "function") {
5872 if (console.useLogger()) {
5873 throw new Error("console and logger are too intertwingly");
5874 }
5875 }
5876 }
5877
5878 return UseConsole;
5879};
5880
5881/**
5882 * Logs a message at the LOG level.
5883 *
5884 * Parameters passed after message are used applied to
5885 * the message with utils.format()
5886 */
5887logger.log = function(message) { logWithArgs("LOG", arguments); };
5888
5889/**
5890 * Logs a message at the ERROR level.
5891 *
5892 * Parameters passed after message are used applied to
5893 * the message with utils.format()
5894 */
5895logger.error = function(message) { logWithArgs("ERROR", arguments); };
5896
5897/**
5898 * Logs a message at the WARN level.
5899 *
5900 * Parameters passed after message are used applied to
5901 * the message with utils.format()
5902 */
5903logger.warn = function(message) { logWithArgs("WARN", arguments); };
5904
5905/**
5906 * Logs a message at the INFO level.
5907 *
5908 * Parameters passed after message are used applied to
5909 * the message with utils.format()
5910 */
5911logger.info = function(message) { logWithArgs("INFO", arguments); };
5912
5913/**
5914 * Logs a message at the DEBUG level.
5915 *
5916 * Parameters passed after message are used applied to
5917 * the message with utils.format()
5918 */
5919logger.debug = function(message) { logWithArgs("DEBUG", arguments); };
5920
5921// log at the specified level with args
5922function logWithArgs(level, args) {
5923 args = [level].concat([].slice.call(args));
5924 logger.logLevel.apply(logger, args);
5925}
5926
5927/**
5928 * Logs a message at the specified level.
5929 *
5930 * Parameters passed after message are used applied to
5931 * the message with utils.format()
5932 */
5933logger.logLevel = function(level, message /* , ... */) {
5934 // format the message with the parameters
5935 var formatArgs = [].slice.call(arguments, 2);
5936 message = utils.vformat(message, formatArgs);
5937
5938 if (LevelsMap[level] === null) {
5939 throw new Error("invalid logging level: " + level);
5940 }
5941
5942 if (LevelsMap[level] > CurrentLevel) return;
5943
5944 // queue the message if not yet at deviceready
5945 if (!DeviceReady && !UseConsole) {
5946 Queued.push([level, message]);
5947 return;
5948 }
5949
5950 // if not using the console, use the native logger
5951 if (!UseConsole) {
5952 exec(null, null, "Logger", "logLevel", [level, message]);
5953 return;
5954 }
5955
5956 // make sure console is not using logger
5957 if (console.__usingCordovaLogger) {
5958 throw new Error("console and logger are too intertwingly");
5959 }
5960
5961 // log to the console
5962 switch (level) {
5963 case logger.LOG: console.log(message); break;
5964 case logger.ERROR: console.log("ERROR: " + message); break;
5965 case logger.WARN: console.log("WARN: " + message); break;
5966 case logger.INFO: console.log("INFO: " + message); break;
5967 case logger.DEBUG: console.log("DEBUG: " + message); break;
5968 }
5969};
5970
5971// when deviceready fires, log queued messages
5972logger.__onDeviceReady = function() {
5973 if (DeviceReady) return;
5974
5975 DeviceReady = true;
5976
5977 for (var i=0; i<Queued.length; i++) {
5978 var messageArgs = Queued[i];
5979 logger.logLevel(messageArgs[0], messageArgs[1]);
5980 }
5981
5982 Queued = null;
5983};
5984
5985// add a deviceready event to log queued messages
5986document.addEventListener("deviceready", logger.__onDeviceReady, false);
5987
5988});
5989
5990// file: lib/common/plugin/network.js
5991define("cordova/plugin/network", function(require, exports, module) {
5992
5993var exec = require('cordova/exec'),
5994 cordova = require('cordova'),
5995 channel = require('cordova/channel'),
5996 utils = require('cordova/utils');
5997
5998// Link the onLine property with the Cordova-supplied network info.
5999// This works because we clobber the naviagtor object with our own
6000// object in bootstrap.js.
6001if (typeof navigator != 'undefined') {
6002 utils.defineGetter(navigator, 'onLine', function() {
6003 return this.connection.type != 'none';
6004 });
6005}
6006
6007var NetworkConnection = function () {
6008 this.type = null;
6009 this._firstRun = true;
6010 this._timer = null;
6011 this.timeout = 500;
6012
6013 var me = this;
6014
6015 channel.onCordovaReady.subscribe(function() {
6016 me.getInfo(function (info) {
6017 me.type = info;
6018 if (info === "none") {
6019 // set a timer if still offline at the end of timer send the offline event
6020 me._timer = setTimeout(function(){
6021 cordova.fireDocumentEvent("offline");
6022 me._timer = null;
6023 }, me.timeout);
6024 } else {
6025 // If there is a current offline event pending clear it
6026 if (me._timer !== null) {
6027 clearTimeout(me._timer);
6028 me._timer = null;
6029 }
6030 cordova.fireDocumentEvent("online");
6031 }
6032
6033 // should only fire this once
6034 if (me._firstRun) {
6035 me._firstRun = false;
6036 channel.onCordovaConnectionReady.fire();
6037 }
6038 },
6039 function (e) {
6040 // If we can't get the network info we should still tell Cordova
6041 // to fire the deviceready event.
6042 if (me._firstRun) {
6043 me._firstRun = false;
6044 channel.onCordovaConnectionReady.fire();
6045 }
6046 console.log("Error initializing Network Connection: " + e);
6047 });
6048 });
6049};
6050
6051/**
6052 * Get connection info
6053 *
6054 * @param {Function} successCallback The function to call when the Connection data is available
6055 * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
6056 */
6057NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) {
6058 // Get info
6059 exec(successCallback, errorCallback, "NetworkStatus", "getConnectionInfo", []);
6060};
6061
6062module.exports = new NetworkConnection();
6063
6064});
6065
6066// file: lib/common/plugin/notification.js
6067define("cordova/plugin/notification", function(require, exports, module) {
6068
6069var exec = require('cordova/exec');
6070
6071/**
6072 * Provides access to notifications on the device.
6073 */
6074
6075module.exports = {
6076
6077 /**
6078 * Open a native alert dialog, with a customizable title and button text.
6079 *
6080 * @param {String} message Message to print in the body of the alert
6081 * @param {Function} completeCallback The callback that is called when user clicks on a button.
6082 * @param {String} title Title of the alert dialog (default: Alert)
6083 * @param {String} buttonLabel Label of the close button (default: OK)
6084 */
6085 alert: function(message, completeCallback, title, buttonLabel) {
6086 var _title = (title || "Alert");
6087 var _buttonLabel = (buttonLabel || "OK");
6088 exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]);
6089 },
6090
6091 /**
6092 * Open a native confirm dialog, with a customizable title and button text.
6093 * The result that the user selects is returned to the result callback.
6094 *
6095 * @param {String} message Message to print in the body of the alert
6096 * @param {Function} resultCallback The callback that is called when user clicks on a button.
6097 * @param {String} title Title of the alert dialog (default: Confirm)
6098 * @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel')
6099 */
6100 confirm: function(message, resultCallback, title, buttonLabels) {
6101 var _title = (title || "Confirm");
6102 var _buttonLabels = (buttonLabels || "OK,Cancel");
6103 exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]);
6104 },
6105
6106 /**
6107 * Causes the device to vibrate.
6108 *
6109 * @param {Integer} mills The number of milliseconds to vibrate for.
6110 */
6111 vibrate: function(mills) {
6112 exec(null, null, "Notification", "vibrate", [mills]);
6113 },
6114
6115 /**
6116 * Causes the device to beep.
6117 * On Android, the default notification ringtone is played "count" times.
6118 *
6119 * @param {Integer} count The number of beeps.
6120 */
6121 beep: function(count) {
6122 exec(null, null, "Notification", "beep", [count]);
6123 }
6124};
6125
6126});
6127
6128// file: lib/common/plugin/requestFileSystem.js
6129define("cordova/plugin/requestFileSystem", function(require, exports, module) {
6130
6131var FileError = require('cordova/plugin/FileError'),
6132 FileSystem = require('cordova/plugin/FileSystem'),
6133 exec = require('cordova/exec');
6134
6135/**
6136 * Request a file system in which to store application data.
6137 * @param type local file system type
6138 * @param size indicates how much storage space, in bytes, the application expects to need
6139 * @param successCallback invoked with a FileSystem object
6140 * @param errorCallback invoked if error occurs retrieving file system
6141 */
6142var requestFileSystem = function(type, size, successCallback, errorCallback) {
6143 var fail = function(code) {
6144 if (typeof errorCallback === 'function') {
6145 errorCallback(new FileError(code));
6146 }
6147 };
6148
6149 if (type < 0 || type > 3) {
6150 fail(FileError.SYNTAX_ERR);
6151 } else {
6152 // if successful, return a FileSystem object
6153 var success = function(file_system) {
6154 if (file_system) {
6155 if (typeof successCallback === 'function') {
6156 // grab the name and root from the file system object
6157 var result = new FileSystem(file_system.name, file_system.root);
6158 successCallback(result);
6159 }
6160 }
6161 else {
6162 // no FileSystem object returned
6163 fail(FileError.NOT_FOUND_ERR);
6164 }
6165 };
6166 exec(success, fail, "File", "requestFileSystem", [type, size]);
6167 }
6168};
6169
6170module.exports = requestFileSystem;
6171
6172});
6173
6174// file: lib/common/plugin/resolveLocalFileSystemURI.js
6175define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) {
6176
6177var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
6178 FileEntry = require('cordova/plugin/FileEntry'),
6179 FileError = require('cordova/plugin/FileError'),
6180 exec = require('cordova/exec');
6181
6182/**
6183 * Look up file system Entry referred to by local URI.
6184 * @param {DOMString} uri URI referring to a local file or directory
6185 * @param successCallback invoked with Entry object corresponding to URI
6186 * @param errorCallback invoked if error occurs retrieving file system entry
6187 */
6188module.exports = function(uri, successCallback, errorCallback) {
6189 // error callback
6190 var fail = function(error) {
6191 if (typeof errorCallback === 'function') {
6192 errorCallback(new FileError(error));
6193 }
6194 };
6195 // sanity check for 'not:valid:filename'
6196 if(!uri || uri.split(":").length > 2) {
6197 setTimeout( function() {
6198 fail(FileError.ENCODING_ERR);
6199 },0);
6200 return;
6201 }
6202 // if successful, return either a file or directory entry
6203 var success = function(entry) {
6204 var result;
6205 if (entry) {
6206 if (typeof successCallback === 'function') {
6207 // create appropriate Entry object
6208 result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath);
6209 try {
6210 successCallback(result);
6211 }
6212 catch (e) {
6213 console.log('Error invoking callback: ' + e);
6214 }
6215 }
6216 }
6217 else {
6218 // no Entry object returned
6219 fail(FileError.NOT_FOUND_ERR);
6220 }
6221 };
6222
6223 exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
6224};
6225
6226});
6227
6228// file: lib/common/plugin/splashscreen.js
6229define("cordova/plugin/splashscreen", function(require, exports, module) {
6230
6231var exec = require('cordova/exec');
6232
6233var splashscreen = {
6234 show:function() {
6235 exec(null, null, "SplashScreen", "show", []);
6236 },
6237 hide:function() {
6238 exec(null, null, "SplashScreen", "hide", []);
6239 }
6240};
6241
6242module.exports = splashscreen;
6243
6244});
6245
6246// file: lib/common/utils.js
6247define("cordova/utils", function(require, exports, module) {
6248
6249var utils = exports;
6250
6251/**
6252 * Defines a property getter for obj[key].
6253 */
6254utils.defineGetter = function(obj, key, func) {
6255 if (Object.defineProperty) {
6256 Object.defineProperty(obj, key, { get: func });
6257 } else {
6258 obj.__defineGetter__(key, func);
6259 }
6260};
6261
6262/**
6263 * Returns an indication of whether the argument is an array or not
6264 */
6265utils.isArray = function(a) {
6266 return Object.prototype.toString.call(a) == '[object Array]';
6267};
6268
6269/**
6270 * Returns an indication of whether the argument is a Date or not
6271 */
6272utils.isDate = function(d) {
6273 return Object.prototype.toString.call(d) == '[object Date]';
6274};
6275
6276/**
6277 * Does a deep clone of the object.
6278 */
6279utils.clone = function(obj) {
6280 if(!obj || typeof obj == 'function' || utils.isDate(obj) || typeof obj != 'object') {
6281 return obj;
6282 }
6283
6284 var retVal, i;
6285
6286 if(utils.isArray(obj)){
6287 retVal = [];
6288 for(i = 0; i < obj.length; ++i){
6289 retVal.push(utils.clone(obj[i]));
6290 }
6291 return retVal;
6292 }
6293
6294 retVal = {};
6295 for(i in obj){
6296 if(!(i in retVal) || retVal[i] != obj[i]) {
6297 retVal[i] = utils.clone(obj[i]);
6298 }
6299 }
6300 return retVal;
6301};
6302
6303/**
6304 * Returns a wrapped version of the function
6305 */
6306utils.close = function(context, func, params) {
6307 if (typeof params == 'undefined') {
6308 return function() {
6309 return func.apply(context, arguments);
6310 };
6311 } else {
6312 return function() {
6313 return func.apply(context, params);
6314 };
6315 }
6316};
6317
6318/**
6319 * Create a UUID
6320 */
6321utils.createUUID = function() {
6322 return UUIDcreatePart(4) + '-' +
6323 UUIDcreatePart(2) + '-' +
6324 UUIDcreatePart(2) + '-' +
6325 UUIDcreatePart(2) + '-' +
6326 UUIDcreatePart(6);
6327};
6328
6329/**
6330 * Extends a child object from a parent object using classical inheritance
6331 * pattern.
6332 */
6333utils.extend = (function() {
6334 // proxy used to establish prototype chain
6335 var F = function() {};
6336 // extend Child from Parent
6337 return function(Child, Parent) {
6338 F.prototype = Parent.prototype;
6339 Child.prototype = new F();
6340 Child.__super__ = Parent.prototype;
6341 Child.prototype.constructor = Child;
6342 };
6343}());
6344
6345/**
6346 * Alerts a message in any available way: alert or console.log.
6347 */
6348utils.alert = function(msg) {
6349 if (window.alert) {
6350 window.alert(msg);
6351 } else if (console && console.log) {
6352 console.log(msg);
6353 }
6354};
6355
6356/**
6357 * Formats a string and arguments following it ala sprintf()
6358 *
6359 * see utils.vformat() for more information
6360 */
6361utils.format = function(formatString /* ,... */) {
6362 var args = [].slice.call(arguments, 1);
6363 return utils.vformat(formatString, args);
6364};
6365
6366/**
6367 * Formats a string and arguments following it ala vsprintf()
6368 *
6369 * format chars:
6370 * %j - format arg as JSON
6371 * %o - format arg as JSON
6372 * %c - format arg as ''
6373 * %% - replace with '%'
6374 * any other char following % will format it's
6375 * arg via toString().
6376 *
6377 * for rationale, see FireBug's Console API:
6378 * http://getfirebug.com/wiki/index.php/Console_API
6379 */
6380utils.vformat = function(formatString, args) {
6381 if (formatString === null || formatString === undefined) return "";
6382 if (arguments.length == 1) return formatString.toString();
6383 if (typeof formatString != "string") return formatString.toString();
6384
6385 var pattern = /(.*?)%(.)(.*)/;
6386 var rest = formatString;
6387 var result = [];
6388
6389 while (args.length) {
6390 var arg = args.shift();
6391 var match = pattern.exec(rest);
6392
6393 if (!match) break;
6394
6395 rest = match[3];
6396
6397 result.push(match[1]);
6398
6399 if (match[2] == '%') {
6400 result.push('%');
6401 args.unshift(arg);
6402 continue;
6403 }
6404
6405 result.push(formatted(arg, match[2]));
6406 }
6407
6408 result.push(rest);
6409
6410 return result.join('');
6411};
6412
6413//------------------------------------------------------------------------------
6414function UUIDcreatePart(length) {
6415 var uuidpart = "";
6416 for (var i=0; i<length; i++) {
6417 var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
6418 if (uuidchar.length == 1) {
6419 uuidchar = "0" + uuidchar;
6420 }
6421 uuidpart += uuidchar;
6422 }
6423 return uuidpart;
6424}
6425
6426//------------------------------------------------------------------------------
6427function formatted(object, formatChar) {
6428
6429 try {
6430 switch(formatChar) {
6431 case 'j':
6432 case 'o': return JSON.stringify(object);
6433 case 'c': return '';
6434 }
6435 }
6436 catch (e) {
6437 return "error JSON.stringify()ing argument: " + e;
6438 }
6439
6440 if ((object === null) || (object === undefined)) {
6441 return Object.prototype.toString.call(object);
6442 }
6443
6444 return object.toString();
6445}
6446
6447});
6448
6449
6450window.cordova = require('cordova');
6451
6452// file: lib/scripts/bootstrap.js
6453
6454(function (context) {
6455 // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
6456 // We replace it so that properties that can't be clobbered can instead be overridden.
6457 if (typeof navigator != 'undefined') {
6458 var CordovaNavigator = function () {};
6459 CordovaNavigator.prototype = navigator;
6460 navigator = new CordovaNavigator();
6461 }
6462
6463 var channel = require("cordova/channel"),
6464 _self = {
6465 boot: function () {
6466 /**
6467 * Create all cordova objects once page has fully loaded and native side is ready.
6468 */
6469 channel.join(function() {
6470 var builder = require('cordova/builder'),
6471 base = require('cordova/common'),
6472 platform = require('cordova/platform');
6473
6474 // Drop the common globals into the window object, but be nice and don't overwrite anything.
6475 builder.build(base.objects).intoButDoNotClobber(window);
6476
6477 // Drop the platform-specific globals into the window object
6478 // and clobber any existing object.
6479 builder.build(platform.objects).intoAndClobber(window);
6480
6481 // Merge the platform-specific overrides/enhancements into
6482 // the window object.
6483 if (typeof platform.merges !== 'undefined') {
6484 builder.build(platform.merges).intoAndMerge(window);
6485 }
6486
6487 // Call the platform-specific initialization
6488 platform.initialize();
6489
6490 // Fire event to notify that all objects are created
6491 channel.onCordovaReady.fire();
6492
6493 // Fire onDeviceReady event once all constructors have run and
6494 // cordova info has been received from native side.
6495 channel.join(function() {
6496 require('cordova').fireDocumentEvent('deviceready');
6497 }, channel.deviceReadyChannelsArray);
6498
6499 }, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
6500 }
6501 };
6502
6503 // boot up once native side is ready
6504 channel.onNativeReady.subscribe(_self.boot);
6505
6506 // _nativeReady is global variable that the native side can set
6507 // to signify that the native code is ready. It is a global since
6508 // it may be called before any cordova JS is ready.
6509 if (window._nativeReady) {
6510 channel.onNativeReady.fire();
6511 }
6512
6513}(window));
6514
6515
6516})();var PhoneGap = cordova;