|
1 // commit 114cf5304a74ff8f7c9ff1d21cf5652298af04b0 |
|
2 |
|
3 // File generated at :: Wed Jul 18 2012 16:47: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 var require, |
|
28 define; |
|
29 |
|
30 (function () { |
|
31 var modules = {}; |
|
32 |
|
33 function build(module) { |
|
34 var factory = module.factory; |
|
35 module.exports = {}; |
|
36 delete module.factory; |
|
37 factory(require, module.exports, module); |
|
38 return module.exports; |
|
39 } |
|
40 |
|
41 require = function (id) { |
|
42 if (!modules[id]) { |
|
43 throw "module " + id + " not found"; |
|
44 } |
|
45 return modules[id].factory ? build(modules[id]) : modules[id].exports; |
|
46 }; |
|
47 |
|
48 define = function (id, factory) { |
|
49 if (modules[id]) { |
|
50 throw "module " + id + " already defined"; |
|
51 } |
|
52 |
|
53 modules[id] = { |
|
54 id: id, |
|
55 factory: factory |
|
56 }; |
|
57 }; |
|
58 |
|
59 define.remove = function (id) { |
|
60 delete modules[id]; |
|
61 }; |
|
62 |
|
63 })(); |
|
64 |
|
65 //Export for use in node |
|
66 if (typeof module === "object" && typeof require === "function") { |
|
67 module.exports.require = require; |
|
68 module.exports.define = define; |
|
69 } |
|
70 // file: lib/cordova.js |
|
71 define("cordova", function(require, exports, module) { |
|
72 var channel = require('cordova/channel'); |
|
73 |
|
74 /** |
|
75 * Listen for DOMContentLoaded and notify our channel subscribers. |
|
76 */ |
|
77 document.addEventListener('DOMContentLoaded', function() { |
|
78 channel.onDOMContentLoaded.fire(); |
|
79 }, false); |
|
80 if (document.readyState == 'complete' || document.readyState == 'interactive') { |
|
81 channel.onDOMContentLoaded.fire(); |
|
82 } |
|
83 |
|
84 /** |
|
85 * Intercept calls to addEventListener + removeEventListener and handle deviceready, |
|
86 * resume, and pause events. |
|
87 */ |
|
88 var m_document_addEventListener = document.addEventListener; |
|
89 var m_document_removeEventListener = document.removeEventListener; |
|
90 var m_window_addEventListener = window.addEventListener; |
|
91 var m_window_removeEventListener = window.removeEventListener; |
|
92 |
|
93 /** |
|
94 * Houses custom event handlers to intercept on document + window event listeners. |
|
95 */ |
|
96 var documentEventHandlers = {}, |
|
97 windowEventHandlers = {}; |
|
98 |
|
99 document.addEventListener = function(evt, handler, capture) { |
|
100 var e = evt.toLowerCase(); |
|
101 if (typeof documentEventHandlers[e] != 'undefined') { |
|
102 if (evt === 'deviceready') { |
|
103 documentEventHandlers[e].subscribeOnce(handler); |
|
104 } else { |
|
105 documentEventHandlers[e].subscribe(handler); |
|
106 } |
|
107 } else { |
|
108 m_document_addEventListener.call(document, evt, handler, capture); |
|
109 } |
|
110 }; |
|
111 |
|
112 window.addEventListener = function(evt, handler, capture) { |
|
113 var e = evt.toLowerCase(); |
|
114 if (typeof windowEventHandlers[e] != 'undefined') { |
|
115 windowEventHandlers[e].subscribe(handler); |
|
116 } else { |
|
117 m_window_addEventListener.call(window, evt, handler, capture); |
|
118 } |
|
119 }; |
|
120 |
|
121 document.removeEventListener = function(evt, handler, capture) { |
|
122 var e = evt.toLowerCase(); |
|
123 // If unsubcribing from an event that is handled by a plugin |
|
124 if (typeof documentEventHandlers[e] != "undefined") { |
|
125 documentEventHandlers[e].unsubscribe(handler); |
|
126 } else { |
|
127 m_document_removeEventListener.call(document, evt, handler, capture); |
|
128 } |
|
129 }; |
|
130 |
|
131 window.removeEventListener = function(evt, handler, capture) { |
|
132 var e = evt.toLowerCase(); |
|
133 // If unsubcribing from an event that is handled by a plugin |
|
134 if (typeof windowEventHandlers[e] != "undefined") { |
|
135 windowEventHandlers[e].unsubscribe(handler); |
|
136 } else { |
|
137 m_window_removeEventListener.call(window, evt, handler, capture); |
|
138 } |
|
139 }; |
|
140 |
|
141 function createEvent(type, data) { |
|
142 var event = document.createEvent('Events'); |
|
143 event.initEvent(type, false, false); |
|
144 if (data) { |
|
145 for (var i in data) { |
|
146 if (data.hasOwnProperty(i)) { |
|
147 event[i] = data[i]; |
|
148 } |
|
149 } |
|
150 } |
|
151 return event; |
|
152 } |
|
153 |
|
154 if(typeof window.console === "undefined") { |
|
155 window.console = { |
|
156 log:function(){} |
|
157 }; |
|
158 } |
|
159 |
|
160 var cordova = { |
|
161 define:define, |
|
162 require:require, |
|
163 /** |
|
164 * Methods to add/remove your own addEventListener hijacking on document + window. |
|
165 */ |
|
166 addWindowEventHandler:function(event, opts) { |
|
167 return (windowEventHandlers[event] = channel.create(event, opts)); |
|
168 }, |
|
169 addDocumentEventHandler:function(event, opts) { |
|
170 return (documentEventHandlers[event] = channel.create(event, opts)); |
|
171 }, |
|
172 removeWindowEventHandler:function(event) { |
|
173 delete windowEventHandlers[event]; |
|
174 }, |
|
175 removeDocumentEventHandler:function(event) { |
|
176 delete documentEventHandlers[event]; |
|
177 }, |
|
178 /** |
|
179 * Retreive original event handlers that were replaced by Cordova |
|
180 * |
|
181 * @return object |
|
182 */ |
|
183 getOriginalHandlers: function() { |
|
184 return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener}, |
|
185 'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}}; |
|
186 }, |
|
187 /** |
|
188 * Method to fire event from native code |
|
189 */ |
|
190 fireDocumentEvent: function(type, data) { |
|
191 var evt = createEvent(type, data); |
|
192 if (typeof documentEventHandlers[type] != 'undefined') { |
|
193 setTimeout(function() { |
|
194 documentEventHandlers[type].fire(evt); |
|
195 }, 0); |
|
196 } else { |
|
197 document.dispatchEvent(evt); |
|
198 } |
|
199 }, |
|
200 fireWindowEvent: function(type, data) { |
|
201 var evt = createEvent(type,data); |
|
202 if (typeof windowEventHandlers[type] != 'undefined') { |
|
203 setTimeout(function() { |
|
204 windowEventHandlers[type].fire(evt); |
|
205 }, 0); |
|
206 } else { |
|
207 window.dispatchEvent(evt); |
|
208 } |
|
209 }, |
|
210 // TODO: this is Android only; think about how to do this better |
|
211 shuttingDown:false, |
|
212 UsePolling:false, |
|
213 // END TODO |
|
214 |
|
215 // TODO: iOS only |
|
216 // This queue holds the currently executing command and all pending |
|
217 // commands executed with cordova.exec(). |
|
218 commandQueue:[], |
|
219 // Indicates if we're currently in the middle of flushing the command |
|
220 // queue on the native side. |
|
221 commandQueueFlushing:false, |
|
222 // END TODO |
|
223 /** |
|
224 * Plugin callback mechanism. |
|
225 */ |
|
226 callbackId: 0, |
|
227 callbacks: {}, |
|
228 callbackStatus: { |
|
229 NO_RESULT: 0, |
|
230 OK: 1, |
|
231 CLASS_NOT_FOUND_EXCEPTION: 2, |
|
232 ILLEGAL_ACCESS_EXCEPTION: 3, |
|
233 INSTANTIATION_EXCEPTION: 4, |
|
234 MALFORMED_URL_EXCEPTION: 5, |
|
235 IO_EXCEPTION: 6, |
|
236 INVALID_ACTION: 7, |
|
237 JSON_EXCEPTION: 8, |
|
238 ERROR: 9 |
|
239 }, |
|
240 |
|
241 /** |
|
242 * Called by native code when returning successful result from an action. |
|
243 * |
|
244 * @param callbackId |
|
245 * @param args |
|
246 */ |
|
247 callbackSuccess: function(callbackId, args) { |
|
248 if (cordova.callbacks[callbackId]) { |
|
249 |
|
250 // If result is to be sent to callback |
|
251 if (args.status == cordova.callbackStatus.OK) { |
|
252 try { |
|
253 if (cordova.callbacks[callbackId].success) { |
|
254 cordova.callbacks[callbackId].success(args.message); |
|
255 } |
|
256 } |
|
257 catch (e) { |
|
258 console.log("Error in success callback: "+callbackId+" = "+e); |
|
259 } |
|
260 } |
|
261 |
|
262 // Clear callback if not expecting any more results |
|
263 if (!args.keepCallback) { |
|
264 delete cordova.callbacks[callbackId]; |
|
265 } |
|
266 } |
|
267 }, |
|
268 |
|
269 /** |
|
270 * Called by native code when returning error result from an action. |
|
271 * |
|
272 * @param callbackId |
|
273 * @param args |
|
274 */ |
|
275 callbackError: function(callbackId, args) { |
|
276 if (cordova.callbacks[callbackId]) { |
|
277 try { |
|
278 if (cordova.callbacks[callbackId].fail) { |
|
279 cordova.callbacks[callbackId].fail(args.message); |
|
280 } |
|
281 } |
|
282 catch (e) { |
|
283 console.log("Error in error callback: "+callbackId+" = "+e); |
|
284 } |
|
285 |
|
286 // Clear callback if not expecting any more results |
|
287 if (!args.keepCallback) { |
|
288 delete cordova.callbacks[callbackId]; |
|
289 } |
|
290 } |
|
291 }, |
|
292 addConstructor: function(func) { |
|
293 channel.onCordovaReady.subscribeOnce(function() { |
|
294 try { |
|
295 func(); |
|
296 } catch(e) { |
|
297 console.log("Failed to run constructor: " + e); |
|
298 } |
|
299 }); |
|
300 } |
|
301 }; |
|
302 |
|
303 // Register pause, resume and deviceready channels as events on document. |
|
304 channel.onPause = cordova.addDocumentEventHandler('pause'); |
|
305 channel.onResume = cordova.addDocumentEventHandler('resume'); |
|
306 channel.onDeviceReady = cordova.addDocumentEventHandler('deviceready'); |
|
307 |
|
308 module.exports = cordova; |
|
309 |
|
310 }); |
|
311 |
|
312 // file: lib/common/builder.js |
|
313 define("cordova/builder", function(require, exports, module) { |
|
314 var utils = require('cordova/utils'); |
|
315 |
|
316 function each(objects, func, context) { |
|
317 for (var prop in objects) { |
|
318 if (objects.hasOwnProperty(prop)) { |
|
319 func.apply(context, [objects[prop], prop]); |
|
320 } |
|
321 } |
|
322 } |
|
323 |
|
324 function include(parent, objects, clobber, merge) { |
|
325 each(objects, function (obj, key) { |
|
326 try { |
|
327 var result = obj.path ? require(obj.path) : {}; |
|
328 |
|
329 if (clobber) { |
|
330 // Clobber if it doesn't exist. |
|
331 if (typeof parent[key] === 'undefined') { |
|
332 parent[key] = result; |
|
333 } else if (typeof obj.path !== 'undefined') { |
|
334 // If merging, merge properties onto parent, otherwise, clobber. |
|
335 if (merge) { |
|
336 recursiveMerge(parent[key], result); |
|
337 } else { |
|
338 parent[key] = result; |
|
339 } |
|
340 } |
|
341 result = parent[key]; |
|
342 } else { |
|
343 // Overwrite if not currently defined. |
|
344 if (typeof parent[key] == 'undefined') { |
|
345 parent[key] = result; |
|
346 } else if (merge && typeof obj.path !== 'undefined') { |
|
347 // If merging, merge parent onto result |
|
348 recursiveMerge(result, parent[key]); |
|
349 parent[key] = result; |
|
350 } else { |
|
351 // Set result to what already exists, so we can build children into it if they exist. |
|
352 result = parent[key]; |
|
353 } |
|
354 } |
|
355 |
|
356 if (obj.children) { |
|
357 include(result, obj.children, clobber, merge); |
|
358 } |
|
359 } catch(e) { |
|
360 utils.alert('Exception building cordova JS globals: ' + e + ' for key "' + key + '"'); |
|
361 } |
|
362 }); |
|
363 } |
|
364 |
|
365 /** |
|
366 * Merge properties from one object onto another recursively. Properties from |
|
367 * the src object will overwrite existing target property. |
|
368 * |
|
369 * @param target Object to merge properties into. |
|
370 * @param src Object to merge properties from. |
|
371 */ |
|
372 function recursiveMerge(target, src) { |
|
373 for (var prop in src) { |
|
374 if (src.hasOwnProperty(prop)) { |
|
375 if (typeof target.prototype !== 'undefined' && target.prototype.constructor === target) { |
|
376 // If the target object is a constructor override off prototype. |
|
377 target.prototype[prop] = src[prop]; |
|
378 } else { |
|
379 target[prop] = typeof src[prop] === 'object' ? recursiveMerge( |
|
380 target[prop], src[prop]) : src[prop]; |
|
381 } |
|
382 } |
|
383 } |
|
384 return target; |
|
385 } |
|
386 |
|
387 module.exports = { |
|
388 build: function (objects) { |
|
389 return { |
|
390 intoButDontClobber: function (target) { |
|
391 include(target, objects, false, false); |
|
392 }, |
|
393 intoAndClobber: function(target) { |
|
394 include(target, objects, true, false); |
|
395 }, |
|
396 intoAndMerge: function(target) { |
|
397 include(target, objects, true, true); |
|
398 } |
|
399 }; |
|
400 } |
|
401 }; |
|
402 |
|
403 }); |
|
404 |
|
405 // file: lib/common/channel.js |
|
406 define("cordova/channel", function(require, exports, module) { |
|
407 var utils = require('cordova/utils'); |
|
408 |
|
409 /** |
|
410 * Custom pub-sub "channel" that can have functions subscribed to it |
|
411 * This object is used to define and control firing of events for |
|
412 * cordova initialization. |
|
413 * |
|
414 * The order of events during page load and Cordova startup is as follows: |
|
415 * |
|
416 * onDOMContentLoaded Internal event that is received when the web page is loaded and parsed. |
|
417 * onNativeReady Internal event that indicates the Cordova native side is ready. |
|
418 * onCordovaReady Internal event fired when all Cordova JavaScript objects have been created. |
|
419 * onCordovaInfoReady Internal event fired when device properties are available. |
|
420 * onCordovaConnectionReady Internal event fired when the connection property has been set. |
|
421 * onDeviceReady User event fired to indicate that Cordova is ready |
|
422 * onResume User event fired to indicate a start/resume lifecycle event |
|
423 * onPause User event fired to indicate a pause lifecycle event |
|
424 * onDestroy Internal event fired when app is being destroyed (User should use window.onunload event, not this one). |
|
425 * |
|
426 * The only Cordova events that user code should register for are: |
|
427 * deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript |
|
428 * pause App has moved to background |
|
429 * resume App has returned to foreground |
|
430 * |
|
431 * Listeners can be registered as: |
|
432 * document.addEventListener("deviceready", myDeviceReadyListener, false); |
|
433 * document.addEventListener("resume", myResumeListener, false); |
|
434 * document.addEventListener("pause", myPauseListener, false); |
|
435 * |
|
436 * The DOM lifecycle events should be used for saving and restoring state |
|
437 * window.onload |
|
438 * window.onunload |
|
439 * |
|
440 */ |
|
441 |
|
442 /** |
|
443 * Channel |
|
444 * @constructor |
|
445 * @param type String the channel name |
|
446 * @param opts Object options to pass into the channel, currently |
|
447 * supports: |
|
448 * onSubscribe: callback that fires when |
|
449 * something subscribes to the Channel. Sets |
|
450 * context to the Channel. |
|
451 * onUnsubscribe: callback that fires when |
|
452 * something unsubscribes to the Channel. Sets |
|
453 * context to the Channel. |
|
454 */ |
|
455 var Channel = function(type, opts) { |
|
456 this.type = type; |
|
457 this.handlers = {}; |
|
458 this.numHandlers = 0; |
|
459 this.guid = 1; |
|
460 this.fired = false; |
|
461 this.enabled = true; |
|
462 this.events = { |
|
463 onSubscribe:null, |
|
464 onUnsubscribe:null |
|
465 }; |
|
466 if (opts) { |
|
467 if (opts.onSubscribe) this.events.onSubscribe = opts.onSubscribe; |
|
468 if (opts.onUnsubscribe) this.events.onUnsubscribe = opts.onUnsubscribe; |
|
469 } |
|
470 }, |
|
471 channel = { |
|
472 /** |
|
473 * Calls the provided function only after all of the channels specified |
|
474 * have been fired. |
|
475 */ |
|
476 join: function (h, c) { |
|
477 var i = c.length; |
|
478 var len = i; |
|
479 var f = function() { |
|
480 if (!(--i)) h(); |
|
481 }; |
|
482 for (var j=0; j<len; j++) { |
|
483 !c[j].fired?c[j].subscribeOnce(f):i--; |
|
484 } |
|
485 if (!i) h(); |
|
486 }, |
|
487 create: function (type, opts) { |
|
488 channel[type] = new Channel(type, opts); |
|
489 return channel[type]; |
|
490 }, |
|
491 |
|
492 /** |
|
493 * cordova Channels that must fire before "deviceready" is fired. |
|
494 */ |
|
495 deviceReadyChannelsArray: [], |
|
496 deviceReadyChannelsMap: {}, |
|
497 |
|
498 /** |
|
499 * Indicate that a feature needs to be initialized before it is ready to be used. |
|
500 * This holds up Cordova's "deviceready" event until the feature has been initialized |
|
501 * and Cordova.initComplete(feature) is called. |
|
502 * |
|
503 * @param feature {String} The unique feature name |
|
504 */ |
|
505 waitForInitialization: function(feature) { |
|
506 if (feature) { |
|
507 var c = null; |
|
508 if (this[feature]) { |
|
509 c = this[feature]; |
|
510 } |
|
511 else { |
|
512 c = this.create(feature); |
|
513 } |
|
514 this.deviceReadyChannelsMap[feature] = c; |
|
515 this.deviceReadyChannelsArray.push(c); |
|
516 } |
|
517 }, |
|
518 |
|
519 /** |
|
520 * Indicate that initialization code has completed and the feature is ready to be used. |
|
521 * |
|
522 * @param feature {String} The unique feature name |
|
523 */ |
|
524 initializationComplete: function(feature) { |
|
525 var c = this.deviceReadyChannelsMap[feature]; |
|
526 if (c) { |
|
527 c.fire(); |
|
528 } |
|
529 } |
|
530 }; |
|
531 |
|
532 function forceFunction(f) { |
|
533 if (f === null || f === undefined || typeof f != 'function') throw "Function required as first argument!"; |
|
534 } |
|
535 |
|
536 /** |
|
537 * Subscribes the given function to the channel. Any time that |
|
538 * Channel.fire is called so too will the function. |
|
539 * Optionally specify an execution context for the function |
|
540 * and a guid that can be used to stop subscribing to the channel. |
|
541 * Returns the guid. |
|
542 */ |
|
543 Channel.prototype.subscribe = function(f, c, g) { |
|
544 // need a function to call |
|
545 forceFunction(f); |
|
546 |
|
547 var func = f; |
|
548 if (typeof c == "object") { func = utils.close(c, f); } |
|
549 |
|
550 g = g || func.observer_guid || f.observer_guid; |
|
551 if (!g) { |
|
552 // first time we've seen this subscriber |
|
553 g = this.guid++; |
|
554 } |
|
555 else { |
|
556 // subscriber already handled; dont set it twice |
|
557 return g; |
|
558 } |
|
559 func.observer_guid = g; |
|
560 f.observer_guid = g; |
|
561 this.handlers[g] = func; |
|
562 this.numHandlers++; |
|
563 if (this.events.onSubscribe) this.events.onSubscribe.call(this); |
|
564 if (this.fired) func.call(this); |
|
565 return g; |
|
566 }; |
|
567 |
|
568 /** |
|
569 * Like subscribe but the function is only called once and then it |
|
570 * auto-unsubscribes itself. |
|
571 */ |
|
572 Channel.prototype.subscribeOnce = function(f, c) { |
|
573 // need a function to call |
|
574 forceFunction(f); |
|
575 |
|
576 var g = null; |
|
577 var _this = this; |
|
578 var m = function() { |
|
579 f.apply(c || null, arguments); |
|
580 _this.unsubscribe(g); |
|
581 }; |
|
582 if (this.fired) { |
|
583 if (typeof c == "object") { f = utils.close(c, f); } |
|
584 f.apply(this, this.fireArgs); |
|
585 } else { |
|
586 g = this.subscribe(m); |
|
587 } |
|
588 return g; |
|
589 }; |
|
590 |
|
591 /** |
|
592 * Unsubscribes the function with the given guid from the channel. |
|
593 */ |
|
594 Channel.prototype.unsubscribe = function(g) { |
|
595 // need a function to unsubscribe |
|
596 if (g === null || g === undefined) { throw "You must pass _something_ into Channel.unsubscribe"; } |
|
597 |
|
598 if (typeof g == 'function') { g = g.observer_guid; } |
|
599 var handler = this.handlers[g]; |
|
600 if (handler) { |
|
601 if (handler.observer_guid) handler.observer_guid=null; |
|
602 this.handlers[g] = null; |
|
603 delete this.handlers[g]; |
|
604 this.numHandlers--; |
|
605 if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); |
|
606 } |
|
607 }; |
|
608 |
|
609 /** |
|
610 * Calls all functions subscribed to this channel. |
|
611 */ |
|
612 Channel.prototype.fire = function(e) { |
|
613 if (this.enabled) { |
|
614 var fail = false; |
|
615 this.fired = true; |
|
616 for (var item in this.handlers) { |
|
617 var handler = this.handlers[item]; |
|
618 if (typeof handler == 'function') { |
|
619 var rv = (handler.apply(this, arguments)===false); |
|
620 fail = fail || rv; |
|
621 } |
|
622 } |
|
623 this.fireArgs = arguments; |
|
624 return !fail; |
|
625 } |
|
626 return true; |
|
627 }; |
|
628 |
|
629 // defining them here so they are ready super fast! |
|
630 // DOM event that is received when the web page is loaded and parsed. |
|
631 channel.create('onDOMContentLoaded'); |
|
632 |
|
633 // Event to indicate the Cordova native side is ready. |
|
634 channel.create('onNativeReady'); |
|
635 |
|
636 // Event to indicate that all Cordova JavaScript objects have been created |
|
637 // and it's time to run plugin constructors. |
|
638 channel.create('onCordovaReady'); |
|
639 |
|
640 // Event to indicate that device properties are available |
|
641 channel.create('onCordovaInfoReady'); |
|
642 |
|
643 // Event to indicate that the connection property has been set. |
|
644 channel.create('onCordovaConnectionReady'); |
|
645 |
|
646 // Event to indicate that Cordova is ready |
|
647 channel.create('onDeviceReady'); |
|
648 |
|
649 // Event to indicate a resume lifecycle event |
|
650 channel.create('onResume'); |
|
651 |
|
652 // Event to indicate a pause lifecycle event |
|
653 channel.create('onPause'); |
|
654 |
|
655 // Event to indicate a destroy lifecycle event |
|
656 channel.create('onDestroy'); |
|
657 |
|
658 // Channels that must fire before "deviceready" is fired. |
|
659 channel.waitForInitialization('onCordovaReady'); |
|
660 channel.waitForInitialization('onCordovaConnectionReady'); |
|
661 |
|
662 module.exports = channel; |
|
663 |
|
664 }); |
|
665 |
|
666 // file: lib/common/common.js |
|
667 define("cordova/common", function(require, exports, module) { |
|
668 module.exports = { |
|
669 objects: { |
|
670 cordova: { |
|
671 path: 'cordova', |
|
672 children: { |
|
673 exec: { |
|
674 path: 'cordova/exec' |
|
675 }, |
|
676 logger: { |
|
677 path: 'cordova/plugin/logger' |
|
678 } |
|
679 } |
|
680 }, |
|
681 Cordova: { |
|
682 children: { |
|
683 exec: { |
|
684 path: 'cordova/exec' |
|
685 } |
|
686 } |
|
687 }, |
|
688 PhoneGap:{ |
|
689 children: { |
|
690 exec: { |
|
691 path: 'cordova/exec' |
|
692 } |
|
693 } |
|
694 }, |
|
695 navigator: { |
|
696 children: { |
|
697 notification: { |
|
698 path: 'cordova/plugin/notification' |
|
699 }, |
|
700 accelerometer: { |
|
701 path: 'cordova/plugin/accelerometer' |
|
702 }, |
|
703 battery: { |
|
704 path: 'cordova/plugin/battery' |
|
705 }, |
|
706 camera:{ |
|
707 path: 'cordova/plugin/Camera' |
|
708 }, |
|
709 compass:{ |
|
710 path: 'cordova/plugin/compass' |
|
711 }, |
|
712 contacts: { |
|
713 path: 'cordova/plugin/contacts' |
|
714 }, |
|
715 device:{ |
|
716 children:{ |
|
717 capture: { |
|
718 path: 'cordova/plugin/capture' |
|
719 } |
|
720 } |
|
721 }, |
|
722 geolocation: { |
|
723 path: 'cordova/plugin/geolocation' |
|
724 }, |
|
725 network: { |
|
726 children: { |
|
727 connection: { |
|
728 path: 'cordova/plugin/network' |
|
729 } |
|
730 } |
|
731 }, |
|
732 splashscreen: { |
|
733 path: 'cordova/plugin/splashscreen' |
|
734 } |
|
735 } |
|
736 }, |
|
737 Acceleration: { |
|
738 path: 'cordova/plugin/Acceleration' |
|
739 }, |
|
740 Camera:{ |
|
741 path: 'cordova/plugin/CameraConstants' |
|
742 }, |
|
743 CameraPopoverOptions: { |
|
744 path: 'cordova/plugin/CameraPopoverOptions' |
|
745 }, |
|
746 CaptureError: { |
|
747 path: 'cordova/plugin/CaptureError' |
|
748 }, |
|
749 CaptureAudioOptions:{ |
|
750 path: 'cordova/plugin/CaptureAudioOptions' |
|
751 }, |
|
752 CaptureImageOptions: { |
|
753 path: 'cordova/plugin/CaptureImageOptions' |
|
754 }, |
|
755 CaptureVideoOptions: { |
|
756 path: 'cordova/plugin/CaptureVideoOptions' |
|
757 }, |
|
758 CompassHeading:{ |
|
759 path: 'cordova/plugin/CompassHeading' |
|
760 }, |
|
761 CompassError:{ |
|
762 path: 'cordova/plugin/CompassError' |
|
763 }, |
|
764 ConfigurationData: { |
|
765 path: 'cordova/plugin/ConfigurationData' |
|
766 }, |
|
767 Connection: { |
|
768 path: 'cordova/plugin/Connection' |
|
769 }, |
|
770 Contact: { |
|
771 path: 'cordova/plugin/Contact' |
|
772 }, |
|
773 ContactAddress: { |
|
774 path: 'cordova/plugin/ContactAddress' |
|
775 }, |
|
776 ContactError: { |
|
777 path: 'cordova/plugin/ContactError' |
|
778 }, |
|
779 ContactField: { |
|
780 path: 'cordova/plugin/ContactField' |
|
781 }, |
|
782 ContactFindOptions: { |
|
783 path: 'cordova/plugin/ContactFindOptions' |
|
784 }, |
|
785 ContactName: { |
|
786 path: 'cordova/plugin/ContactName' |
|
787 }, |
|
788 ContactOrganization: { |
|
789 path: 'cordova/plugin/ContactOrganization' |
|
790 }, |
|
791 Coordinates: { |
|
792 path: 'cordova/plugin/Coordinates' |
|
793 }, |
|
794 device: { |
|
795 path: 'cordova/plugin/device' |
|
796 }, |
|
797 DirectoryEntry: { |
|
798 path: 'cordova/plugin/DirectoryEntry' |
|
799 }, |
|
800 DirectoryReader: { |
|
801 path: 'cordova/plugin/DirectoryReader' |
|
802 }, |
|
803 Entry: { |
|
804 path: 'cordova/plugin/Entry' |
|
805 }, |
|
806 File: { |
|
807 path: 'cordova/plugin/File' |
|
808 }, |
|
809 FileEntry: { |
|
810 path: 'cordova/plugin/FileEntry' |
|
811 }, |
|
812 FileError: { |
|
813 path: 'cordova/plugin/FileError' |
|
814 }, |
|
815 FileReader: { |
|
816 path: 'cordova/plugin/FileReader' |
|
817 }, |
|
818 FileSystem: { |
|
819 path: 'cordova/plugin/FileSystem' |
|
820 }, |
|
821 FileTransfer: { |
|
822 path: 'cordova/plugin/FileTransfer' |
|
823 }, |
|
824 FileTransferError: { |
|
825 path: 'cordova/plugin/FileTransferError' |
|
826 }, |
|
827 FileUploadOptions: { |
|
828 path: 'cordova/plugin/FileUploadOptions' |
|
829 }, |
|
830 FileUploadResult: { |
|
831 path: 'cordova/plugin/FileUploadResult' |
|
832 }, |
|
833 FileWriter: { |
|
834 path: 'cordova/plugin/FileWriter' |
|
835 }, |
|
836 Flags: { |
|
837 path: 'cordova/plugin/Flags' |
|
838 }, |
|
839 LocalFileSystem: { |
|
840 path: 'cordova/plugin/LocalFileSystem' |
|
841 }, |
|
842 Media: { |
|
843 path: 'cordova/plugin/Media' |
|
844 }, |
|
845 MediaError: { |
|
846 path: 'cordova/plugin/MediaError' |
|
847 }, |
|
848 MediaFile: { |
|
849 path: 'cordova/plugin/MediaFile' |
|
850 }, |
|
851 MediaFileData:{ |
|
852 path: 'cordova/plugin/MediaFileData' |
|
853 }, |
|
854 Metadata:{ |
|
855 path: 'cordova/plugin/Metadata' |
|
856 }, |
|
857 Position: { |
|
858 path: 'cordova/plugin/Position' |
|
859 }, |
|
860 PositionError: { |
|
861 path: 'cordova/plugin/PositionError' |
|
862 }, |
|
863 ProgressEvent: { |
|
864 path: 'cordova/plugin/ProgressEvent' |
|
865 }, |
|
866 requestFileSystem:{ |
|
867 path: 'cordova/plugin/requestFileSystem' |
|
868 }, |
|
869 resolveLocalFileSystemURI:{ |
|
870 path: 'cordova/plugin/resolveLocalFileSystemURI' |
|
871 } |
|
872 } |
|
873 }; |
|
874 |
|
875 }); |
|
876 |
|
877 // file: lib/ios/exec.js |
|
878 define("cordova/exec", function(require, exports, module) { |
|
879 /** |
|
880 * Creates a gap bridge iframe used to notify the native code about queued |
|
881 * commands. |
|
882 * |
|
883 * @private |
|
884 */ |
|
885 var cordova = require('cordova'), |
|
886 utils = require('cordova/utils'), |
|
887 gapBridge, |
|
888 createGapBridge = function() { |
|
889 |
|
890 gapBridge = document.createElement("iframe"); |
|
891 gapBridge.setAttribute("style", "display:none;"); |
|
892 gapBridge.setAttribute("height","0px"); |
|
893 gapBridge.setAttribute("width","0px"); |
|
894 gapBridge.setAttribute("frameborder","0"); |
|
895 document.documentElement.appendChild(gapBridge); |
|
896 }, |
|
897 channel = require('cordova/channel'); |
|
898 |
|
899 module.exports = function() { |
|
900 if (!channel.onCordovaReady.fired) { |
|
901 utils.alert("ERROR: Attempting to call cordova.exec()" + |
|
902 " before 'deviceready'. Ignoring."); |
|
903 return; |
|
904 } |
|
905 |
|
906 var successCallback, failCallback, service, action, actionArgs, splitCommand; |
|
907 var callbackId = null; |
|
908 if (typeof arguments[0] !== "string") { |
|
909 // FORMAT ONE |
|
910 successCallback = arguments[0]; |
|
911 failCallback = arguments[1]; |
|
912 service = arguments[2]; |
|
913 action = arguments[3]; |
|
914 actionArgs = arguments[4]; |
|
915 |
|
916 // Since we need to maintain backwards compatibility, we have to pass |
|
917 // an invalid callbackId even if no callback was provided since plugins |
|
918 // will be expecting it. The Cordova.exec() implementation allocates |
|
919 // an invalid callbackId and passes it even if no callbacks were given. |
|
920 callbackId = 'INVALID'; |
|
921 } else { |
|
922 // FORMAT TWO |
|
923 splitCommand = arguments[0].split("."); |
|
924 action = splitCommand.pop(); |
|
925 service = splitCommand.join("."); |
|
926 actionArgs = Array.prototype.splice.call(arguments, 1); |
|
927 } |
|
928 |
|
929 // Start building the command object. |
|
930 var command = { |
|
931 className: service, |
|
932 methodName: action, |
|
933 "arguments": [] |
|
934 }; |
|
935 |
|
936 // Register the callbacks and add the callbackId to the positional |
|
937 // arguments if given. |
|
938 if (successCallback || failCallback) { |
|
939 callbackId = service + cordova.callbackId++; |
|
940 cordova.callbacks[callbackId] = |
|
941 {success:successCallback, fail:failCallback}; |
|
942 } |
|
943 if (callbackId !== null) { |
|
944 command["arguments"].push(callbackId); |
|
945 } |
|
946 |
|
947 for (var i = 0; i < actionArgs.length; ++i) { |
|
948 var arg = actionArgs[i]; |
|
949 if (arg === undefined || arg === null) { // nulls are pushed to the args now (becomes NSNull) |
|
950 command["arguments"].push(arg); |
|
951 } else if (typeof(arg) == 'object' && !(utils.isArray(arg))) { |
|
952 command.options = arg; |
|
953 } else { |
|
954 command["arguments"].push(arg); |
|
955 } |
|
956 } |
|
957 |
|
958 // Stringify and queue the command. We stringify to command now to |
|
959 // effectively clone the command arguments in case they are mutated before |
|
960 // the command is executed. |
|
961 cordova.commandQueue.push(JSON.stringify(command)); |
|
962 |
|
963 // If the queue length is 1, then that means it was empty before we queued |
|
964 // the given command, so let the native side know that we have some |
|
965 // commands to execute, unless the queue is currently being flushed, in |
|
966 // which case the command will be picked up without notification. |
|
967 if (cordova.commandQueue.length == 1 && !cordova.commandQueueFlushing) { |
|
968 if (!gapBridge) { |
|
969 createGapBridge(); |
|
970 } |
|
971 gapBridge.src = "gap://ready"; |
|
972 } |
|
973 }; |
|
974 |
|
975 }); |
|
976 |
|
977 // file: lib/ios/platform.js |
|
978 define("cordova/platform", function(require, exports, module) { |
|
979 module.exports = { |
|
980 id: "ios", |
|
981 initialize:function() { |
|
982 // iOS doesn't allow reassigning / overriding navigator.geolocation object. |
|
983 // So clobber its methods here instead :) |
|
984 var geo = require('cordova/plugin/geolocation'); |
|
985 |
|
986 navigator.geolocation.getCurrentPosition = geo.getCurrentPosition; |
|
987 navigator.geolocation.watchPosition = geo.watchPosition; |
|
988 navigator.geolocation.clearWatch = geo.clearWatch; |
|
989 }, |
|
990 objects: { |
|
991 File: { // exists natively, override |
|
992 path: "cordova/plugin/File" |
|
993 }, |
|
994 MediaError: { // exists natively, override |
|
995 path: "cordova/plugin/MediaError" |
|
996 }, |
|
997 console: { |
|
998 path: 'cordova/plugin/ios/console' |
|
999 } |
|
1000 }, |
|
1001 merges:{ |
|
1002 Contact:{ |
|
1003 path: "cordova/plugin/ios/Contact" |
|
1004 }, |
|
1005 Entry:{ |
|
1006 path: "cordova/plugin/ios/Entry" |
|
1007 }, |
|
1008 FileReader:{ |
|
1009 path: "cordova/plugin/ios/FileReader" |
|
1010 }, |
|
1011 navigator:{ |
|
1012 children:{ |
|
1013 notification:{ |
|
1014 path:"cordova/plugin/ios/notification" |
|
1015 }, |
|
1016 contacts:{ |
|
1017 path:"cordova/plugin/ios/contacts" |
|
1018 } |
|
1019 } |
|
1020 } |
|
1021 } |
|
1022 }; |
|
1023 |
|
1024 // use the native logger |
|
1025 var logger = require("cordova/plugin/logger"); |
|
1026 logger.useConsole(false); |
|
1027 |
|
1028 }); |
|
1029 |
|
1030 // file: lib/common/plugin/Acceleration.js |
|
1031 define("cordova/plugin/Acceleration", function(require, exports, module) { |
|
1032 var Acceleration = function(x, y, z, timestamp) { |
|
1033 this.x = x; |
|
1034 this.y = y; |
|
1035 this.z = z; |
|
1036 this.timestamp = timestamp || (new Date()).getTime(); |
|
1037 }; |
|
1038 |
|
1039 module.exports = Acceleration; |
|
1040 |
|
1041 }); |
|
1042 |
|
1043 // file: lib/common/plugin/Camera.js |
|
1044 define("cordova/plugin/Camera", function(require, exports, module) { |
|
1045 var exec = require('cordova/exec'), |
|
1046 Camera = require('cordova/plugin/CameraConstants'); |
|
1047 |
|
1048 var cameraExport = {}; |
|
1049 |
|
1050 // Tack on the Camera Constants to the base camera plugin. |
|
1051 for (var key in Camera) { |
|
1052 cameraExport[key] = Camera[key]; |
|
1053 } |
|
1054 |
|
1055 /** |
|
1056 * Gets a picture from source defined by "options.sourceType", and returns the |
|
1057 * image as defined by the "options.destinationType" option. |
|
1058 |
|
1059 * The defaults are sourceType=CAMERA and destinationType=FILE_URI. |
|
1060 * |
|
1061 * @param {Function} successCallback |
|
1062 * @param {Function} errorCallback |
|
1063 * @param {Object} options |
|
1064 */ |
|
1065 cameraExport.getPicture = function(successCallback, errorCallback, options) { |
|
1066 // successCallback required |
|
1067 if (typeof successCallback != "function") { |
|
1068 console.log("Camera Error: successCallback is not a function"); |
|
1069 return; |
|
1070 } |
|
1071 |
|
1072 // errorCallback optional |
|
1073 if (errorCallback && (typeof errorCallback != "function")) { |
|
1074 console.log("Camera Error: errorCallback is not a function"); |
|
1075 return; |
|
1076 } |
|
1077 |
|
1078 var quality = 50; |
|
1079 if (options && typeof options.quality == "number") { |
|
1080 quality = options.quality; |
|
1081 } else if (options && typeof options.quality == "string") { |
|
1082 var qlity = parseInt(options.quality, 10); |
|
1083 if (isNaN(qlity) === false) { |
|
1084 quality = qlity.valueOf(); |
|
1085 } |
|
1086 } |
|
1087 |
|
1088 var destinationType = Camera.DestinationType.FILE_URI; |
|
1089 if (typeof options.destinationType == "number") { |
|
1090 destinationType = options.destinationType; |
|
1091 } |
|
1092 |
|
1093 var sourceType = Camera.PictureSourceType.CAMERA; |
|
1094 if (typeof options.sourceType == "number") { |
|
1095 sourceType = options.sourceType; |
|
1096 } |
|
1097 |
|
1098 var targetWidth = -1; |
|
1099 if (typeof options.targetWidth == "number") { |
|
1100 targetWidth = options.targetWidth; |
|
1101 } else if (typeof options.targetWidth == "string") { |
|
1102 var width = parseInt(options.targetWidth, 10); |
|
1103 if (isNaN(width) === false) { |
|
1104 targetWidth = width.valueOf(); |
|
1105 } |
|
1106 } |
|
1107 |
|
1108 var targetHeight = -1; |
|
1109 if (typeof options.targetHeight == "number") { |
|
1110 targetHeight = options.targetHeight; |
|
1111 } else if (typeof options.targetHeight == "string") { |
|
1112 var height = parseInt(options.targetHeight, 10); |
|
1113 if (isNaN(height) === false) { |
|
1114 targetHeight = height.valueOf(); |
|
1115 } |
|
1116 } |
|
1117 |
|
1118 var encodingType = Camera.EncodingType.JPEG; |
|
1119 if (typeof options.encodingType == "number") { |
|
1120 encodingType = options.encodingType; |
|
1121 } |
|
1122 |
|
1123 var mediaType = Camera.MediaType.PICTURE; |
|
1124 if (typeof options.mediaType == "number") { |
|
1125 mediaType = options.mediaType; |
|
1126 } |
|
1127 var allowEdit = false; |
|
1128 if (typeof options.allowEdit == "boolean") { |
|
1129 allowEdit = options.allowEdit; |
|
1130 } else if (typeof options.allowEdit == "number") { |
|
1131 allowEdit = options.allowEdit <= 0 ? false : true; |
|
1132 } |
|
1133 var correctOrientation = false; |
|
1134 if (typeof options.correctOrientation == "boolean") { |
|
1135 correctOrientation = options.correctOrientation; |
|
1136 } else if (typeof options.correctOrientation == "number") { |
|
1137 correctOrientation = options.correctOrientation <=0 ? false : true; |
|
1138 } |
|
1139 var saveToPhotoAlbum = false; |
|
1140 if (typeof options.saveToPhotoAlbum == "boolean") { |
|
1141 saveToPhotoAlbum = options.saveToPhotoAlbum; |
|
1142 } else if (typeof options.saveToPhotoAlbum == "number") { |
|
1143 saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; |
|
1144 } |
|
1145 var popoverOptions = null; |
|
1146 if (typeof options.popoverOptions == "object") { |
|
1147 popoverOptions = options.popoverOptions; |
|
1148 } |
|
1149 |
|
1150 var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, |
|
1151 mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions]; |
|
1152 |
|
1153 exec(successCallback, errorCallback, "Camera", "takePicture", args); |
|
1154 }; |
|
1155 |
|
1156 cameraExport.cleanup = function(successCallback, errorCallback) { |
|
1157 exec(successCallback, errorCallback, "Camera", "cleanup", []); |
|
1158 }; |
|
1159 |
|
1160 module.exports = cameraExport; |
|
1161 }); |
|
1162 |
|
1163 // file: lib/common/plugin/CameraConstants.js |
|
1164 define("cordova/plugin/CameraConstants", function(require, exports, module) { |
|
1165 module.exports = { |
|
1166 DestinationType:{ |
|
1167 DATA_URL: 0, // Return base64 encoded string |
|
1168 FILE_URI: 1 // Return file uri (content://media/external/images/media/2 for Android) |
|
1169 }, |
|
1170 EncodingType:{ |
|
1171 JPEG: 0, // Return JPEG encoded image |
|
1172 PNG: 1 // Return PNG encoded image |
|
1173 }, |
|
1174 MediaType:{ |
|
1175 PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType |
|
1176 VIDEO: 1, // allow selection of video only, ONLY RETURNS URL |
|
1177 ALLMEDIA : 2 // allow selection from all media types |
|
1178 }, |
|
1179 PictureSourceType:{ |
|
1180 PHOTOLIBRARY : 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android) |
|
1181 CAMERA : 1, // Take picture from camera |
|
1182 SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) |
|
1183 }, |
|
1184 PopoverArrowDirection:{ |
|
1185 ARROW_UP : 1, // matches iOS UIPopoverArrowDirection constants to specify arrow location on popover |
|
1186 ARROW_DOWN : 2, |
|
1187 ARROW_LEFT : 4, |
|
1188 ARROW_RIGHT : 8, |
|
1189 ARROW_ANY : 15 |
|
1190 } |
|
1191 }; |
|
1192 }); |
|
1193 |
|
1194 // file: lib/common/plugin/CameraPopoverOptions.js |
|
1195 define("cordova/plugin/CameraPopoverOptions", function(require, exports, module) { |
|
1196 var Camera = require('cordova/plugin/CameraConstants'); |
|
1197 |
|
1198 /** |
|
1199 * Encapsulates options for iOS Popover image picker |
|
1200 */ |
|
1201 var CameraPopoverOptions = function(x,y,width,height,arrowDir){ |
|
1202 // information of rectangle that popover should be anchored to |
|
1203 this.x = x || 0; |
|
1204 this.y = y || 32; |
|
1205 this.width = width || 320; |
|
1206 this.height = height || 480; |
|
1207 // The direction of the popover arrow |
|
1208 this.arrowDir = arrowDir || Camera.PopoverArrowDirection.ARROW_ANY; |
|
1209 }; |
|
1210 |
|
1211 module.exports = CameraPopoverOptions; |
|
1212 }); |
|
1213 |
|
1214 // file: lib/common/plugin/CaptureAudioOptions.js |
|
1215 define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) { |
|
1216 /** |
|
1217 * Encapsulates all audio capture operation configuration options. |
|
1218 */ |
|
1219 var CaptureAudioOptions = function(){ |
|
1220 // Upper limit of sound clips user can record. Value must be equal or greater than 1. |
|
1221 this.limit = 1; |
|
1222 // Maximum duration of a single sound clip in seconds. |
|
1223 this.duration = 0; |
|
1224 // The selected audio mode. Must match with one of the elements in supportedAudioModes array. |
|
1225 this.mode = null; |
|
1226 }; |
|
1227 |
|
1228 module.exports = CaptureAudioOptions; |
|
1229 }); |
|
1230 |
|
1231 // file: lib/common/plugin/CaptureError.js |
|
1232 define("cordova/plugin/CaptureError", function(require, exports, module) { |
|
1233 /** |
|
1234 * The CaptureError interface encapsulates all errors in the Capture API. |
|
1235 */ |
|
1236 var CaptureError = function(c) { |
|
1237 this.code = c || null; |
|
1238 }; |
|
1239 |
|
1240 // Camera or microphone failed to capture image or sound. |
|
1241 CaptureError.CAPTURE_INTERNAL_ERR = 0; |
|
1242 // Camera application or audio capture application is currently serving other capture request. |
|
1243 CaptureError.CAPTURE_APPLICATION_BUSY = 1; |
|
1244 // Invalid use of the API (e.g. limit parameter has value less than one). |
|
1245 CaptureError.CAPTURE_INVALID_ARGUMENT = 2; |
|
1246 // User exited camera application or audio capture application before capturing anything. |
|
1247 CaptureError.CAPTURE_NO_MEDIA_FILES = 3; |
|
1248 // The requested capture operation is not supported. |
|
1249 CaptureError.CAPTURE_NOT_SUPPORTED = 20; |
|
1250 |
|
1251 module.exports = CaptureError; |
|
1252 }); |
|
1253 |
|
1254 // file: lib/common/plugin/CaptureImageOptions.js |
|
1255 define("cordova/plugin/CaptureImageOptions", function(require, exports, module) { |
|
1256 /** |
|
1257 * Encapsulates all image capture operation configuration options. |
|
1258 */ |
|
1259 var CaptureImageOptions = function(){ |
|
1260 // Upper limit of images user can take. Value must be equal or greater than 1. |
|
1261 this.limit = 1; |
|
1262 // The selected image mode. Must match with one of the elements in supportedImageModes array. |
|
1263 this.mode = null; |
|
1264 }; |
|
1265 |
|
1266 module.exports = CaptureImageOptions; |
|
1267 }); |
|
1268 |
|
1269 // file: lib/common/plugin/CaptureVideoOptions.js |
|
1270 define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) { |
|
1271 /** |
|
1272 * Encapsulates all video capture operation configuration options. |
|
1273 */ |
|
1274 var CaptureVideoOptions = function(){ |
|
1275 // Upper limit of videos user can record. Value must be equal or greater than 1. |
|
1276 this.limit = 1; |
|
1277 // Maximum duration of a single video clip in seconds. |
|
1278 this.duration = 0; |
|
1279 // The selected video mode. Must match with one of the elements in supportedVideoModes array. |
|
1280 this.mode = null; |
|
1281 }; |
|
1282 |
|
1283 module.exports = CaptureVideoOptions; |
|
1284 }); |
|
1285 |
|
1286 // file: lib/common/plugin/CompassError.js |
|
1287 define("cordova/plugin/CompassError", function(require, exports, module) { |
|
1288 /** |
|
1289 * CompassError. |
|
1290 * An error code assigned by an implementation when an error has occured |
|
1291 * @constructor |
|
1292 */ |
|
1293 var CompassError = function(err) { |
|
1294 this.code = (err !== undefined ? err : null); |
|
1295 }; |
|
1296 |
|
1297 CompassError.COMPASS_INTERNAL_ERR = 0; |
|
1298 CompassError.COMPASS_NOT_SUPPORTED = 20; |
|
1299 |
|
1300 module.exports = CompassError; |
|
1301 }); |
|
1302 |
|
1303 // file: lib/common/plugin/CompassHeading.js |
|
1304 define("cordova/plugin/CompassHeading", function(require, exports, module) { |
|
1305 var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) { |
|
1306 this.magneticHeading = (magneticHeading !== undefined ? magneticHeading : null); |
|
1307 this.trueHeading = (trueHeading !== undefined ? trueHeading : null); |
|
1308 this.headingAccuracy = (headingAccuracy !== undefined ? headingAccuracy : null); |
|
1309 this.timestamp = (timestamp !== undefined ? timestamp : new Date().getTime()); |
|
1310 }; |
|
1311 |
|
1312 module.exports = CompassHeading; |
|
1313 }); |
|
1314 |
|
1315 // file: lib/common/plugin/ConfigurationData.js |
|
1316 define("cordova/plugin/ConfigurationData", function(require, exports, module) { |
|
1317 /** |
|
1318 * Encapsulates a set of parameters that the capture device supports. |
|
1319 */ |
|
1320 function ConfigurationData() { |
|
1321 // The ASCII-encoded string in lower case representing the media type. |
|
1322 this.type = null; |
|
1323 // The height attribute represents height of the image or video in pixels. |
|
1324 // In the case of a sound clip this attribute has value 0. |
|
1325 this.height = 0; |
|
1326 // The width attribute represents width of the image or video in pixels. |
|
1327 // In the case of a sound clip this attribute has value 0 |
|
1328 this.width = 0; |
|
1329 } |
|
1330 |
|
1331 module.exports = ConfigurationData; |
|
1332 }); |
|
1333 |
|
1334 // file: lib/common/plugin/Connection.js |
|
1335 define("cordova/plugin/Connection", function(require, exports, module) { |
|
1336 /** |
|
1337 * Network status |
|
1338 */ |
|
1339 module.exports = { |
|
1340 UNKNOWN: "unknown", |
|
1341 ETHERNET: "ethernet", |
|
1342 WIFI: "wifi", |
|
1343 CELL_2G: "2g", |
|
1344 CELL_3G: "3g", |
|
1345 CELL_4G: "4g", |
|
1346 NONE: "none" |
|
1347 }; |
|
1348 }); |
|
1349 |
|
1350 // file: lib/common/plugin/Contact.js |
|
1351 define("cordova/plugin/Contact", function(require, exports, module) { |
|
1352 var exec = require('cordova/exec'), |
|
1353 ContactError = require('cordova/plugin/ContactError'), |
|
1354 utils = require('cordova/utils'); |
|
1355 |
|
1356 /** |
|
1357 * Converts primitives into Complex Object |
|
1358 * Currently only used for Date fields |
|
1359 */ |
|
1360 function convertIn(contact) { |
|
1361 var value = contact.birthday; |
|
1362 try { |
|
1363 contact.birthday = new Date(parseFloat(value)); |
|
1364 } catch (exception){ |
|
1365 console.log("Cordova Contact convertIn error: exception creating date."); |
|
1366 } |
|
1367 return contact; |
|
1368 } |
|
1369 |
|
1370 /** |
|
1371 * Converts Complex objects into primitives |
|
1372 * Only conversion at present is for Dates. |
|
1373 **/ |
|
1374 |
|
1375 function convertOut(contact) { |
|
1376 var value = contact.birthday; |
|
1377 if (value !== null) { |
|
1378 // try to make it a Date object if it is not already |
|
1379 if (!utils.isDate(value)){ |
|
1380 try { |
|
1381 value = new Date(value); |
|
1382 } catch(exception){ |
|
1383 value = null; |
|
1384 } |
|
1385 } |
|
1386 if (utils.isDate(value)){ |
|
1387 value = value.valueOf(); // convert to milliseconds |
|
1388 } |
|
1389 contact.birthday = value; |
|
1390 } |
|
1391 return contact; |
|
1392 } |
|
1393 |
|
1394 /** |
|
1395 * Contains information about a single contact. |
|
1396 * @constructor |
|
1397 * @param {DOMString} id unique identifier |
|
1398 * @param {DOMString} displayName |
|
1399 * @param {ContactName} name |
|
1400 * @param {DOMString} nickname |
|
1401 * @param {Array.<ContactField>} phoneNumbers array of phone numbers |
|
1402 * @param {Array.<ContactField>} emails array of email addresses |
|
1403 * @param {Array.<ContactAddress>} addresses array of addresses |
|
1404 * @param {Array.<ContactField>} ims instant messaging user ids |
|
1405 * @param {Array.<ContactOrganization>} organizations |
|
1406 * @param {DOMString} birthday contact's birthday |
|
1407 * @param {DOMString} note user notes about contact |
|
1408 * @param {Array.<ContactField>} photos |
|
1409 * @param {Array.<ContactField>} categories |
|
1410 * @param {Array.<ContactField>} urls contact's web sites |
|
1411 */ |
|
1412 var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, addresses, |
|
1413 ims, organizations, birthday, note, photos, categories, urls) { |
|
1414 this.id = id || null; |
|
1415 this.rawId = null; |
|
1416 this.displayName = displayName || null; |
|
1417 this.name = name || null; // ContactName |
|
1418 this.nickname = nickname || null; |
|
1419 this.phoneNumbers = phoneNumbers || null; // ContactField[] |
|
1420 this.emails = emails || null; // ContactField[] |
|
1421 this.addresses = addresses || null; // ContactAddress[] |
|
1422 this.ims = ims || null; // ContactField[] |
|
1423 this.organizations = organizations || null; // ContactOrganization[] |
|
1424 this.birthday = birthday || null; |
|
1425 this.note = note || null; |
|
1426 this.photos = photos || null; // ContactField[] |
|
1427 this.categories = categories || null; // ContactField[] |
|
1428 this.urls = urls || null; // ContactField[] |
|
1429 }; |
|
1430 |
|
1431 /** |
|
1432 * Removes contact from device storage. |
|
1433 * @param successCB success callback |
|
1434 * @param errorCB error callback |
|
1435 */ |
|
1436 Contact.prototype.remove = function(successCB, errorCB) { |
|
1437 var fail = function(code) { |
|
1438 errorCB(new ContactError(code)); |
|
1439 }; |
|
1440 if (this.id === null) { |
|
1441 fail(ContactError.UNKNOWN_ERROR); |
|
1442 } |
|
1443 else { |
|
1444 exec(successCB, fail, "Contacts", "remove", [this.id]); |
|
1445 } |
|
1446 }; |
|
1447 |
|
1448 /** |
|
1449 * Creates a deep copy of this Contact. |
|
1450 * With the contact ID set to null. |
|
1451 * @return copy of this Contact |
|
1452 */ |
|
1453 Contact.prototype.clone = function() { |
|
1454 var clonedContact = utils.clone(this); |
|
1455 var i; |
|
1456 clonedContact.id = null; |
|
1457 clonedContact.rawId = null; |
|
1458 // Loop through and clear out any id's in phones, emails, etc. |
|
1459 if (clonedContact.phoneNumbers) { |
|
1460 for (i = 0; i < clonedContact.phoneNumbers.length; i++) { |
|
1461 clonedContact.phoneNumbers[i].id = null; |
|
1462 } |
|
1463 } |
|
1464 if (clonedContact.emails) { |
|
1465 for (i = 0; i < clonedContact.emails.length; i++) { |
|
1466 clonedContact.emails[i].id = null; |
|
1467 } |
|
1468 } |
|
1469 if (clonedContact.addresses) { |
|
1470 for (i = 0; i < clonedContact.addresses.length; i++) { |
|
1471 clonedContact.addresses[i].id = null; |
|
1472 } |
|
1473 } |
|
1474 if (clonedContact.ims) { |
|
1475 for (i = 0; i < clonedContact.ims.length; i++) { |
|
1476 clonedContact.ims[i].id = null; |
|
1477 } |
|
1478 } |
|
1479 if (clonedContact.organizations) { |
|
1480 for (i = 0; i < clonedContact.organizations.length; i++) { |
|
1481 clonedContact.organizations[i].id = null; |
|
1482 } |
|
1483 } |
|
1484 if (clonedContact.categories) { |
|
1485 for (i = 0; i < clonedContact.categories.length; i++) { |
|
1486 clonedContact.categories[i].id = null; |
|
1487 } |
|
1488 } |
|
1489 if (clonedContact.photos) { |
|
1490 for (i = 0; i < clonedContact.photos.length; i++) { |
|
1491 clonedContact.photos[i].id = null; |
|
1492 } |
|
1493 } |
|
1494 if (clonedContact.urls) { |
|
1495 for (i = 0; i < clonedContact.urls.length; i++) { |
|
1496 clonedContact.urls[i].id = null; |
|
1497 } |
|
1498 } |
|
1499 return clonedContact; |
|
1500 }; |
|
1501 |
|
1502 /** |
|
1503 * Persists contact to device storage. |
|
1504 * @param successCB success callback |
|
1505 * @param errorCB error callback |
|
1506 */ |
|
1507 Contact.prototype.save = function(successCB, errorCB) { |
|
1508 var fail = function(code) { |
|
1509 errorCB(new ContactError(code)); |
|
1510 }; |
|
1511 var success = function(result) { |
|
1512 if (result) { |
|
1513 if (typeof successCB === 'function') { |
|
1514 var fullContact = require('cordova/plugin/contacts').create(result); |
|
1515 successCB(convertIn(fullContact)); |
|
1516 } |
|
1517 } |
|
1518 else { |
|
1519 // no Entry object returned |
|
1520 fail(ContactError.UNKNOWN_ERROR); |
|
1521 } |
|
1522 }; |
|
1523 var dupContact = convertOut(utils.clone(this)); |
|
1524 exec(success, fail, "Contacts", "save", [dupContact]); |
|
1525 }; |
|
1526 |
|
1527 |
|
1528 module.exports = Contact; |
|
1529 |
|
1530 }); |
|
1531 |
|
1532 // file: lib/common/plugin/ContactAddress.js |
|
1533 define("cordova/plugin/ContactAddress", function(require, exports, module) { |
|
1534 /** |
|
1535 * Contact address. |
|
1536 * @constructor |
|
1537 * @param {DOMString} id unique identifier, should only be set by native code |
|
1538 * @param formatted // NOTE: not a W3C standard |
|
1539 * @param streetAddress |
|
1540 * @param locality |
|
1541 * @param region |
|
1542 * @param postalCode |
|
1543 * @param country |
|
1544 */ |
|
1545 |
|
1546 var ContactAddress = function(pref, type, formatted, streetAddress, locality, region, postalCode, country) { |
|
1547 this.id = null; |
|
1548 this.pref = (typeof pref != 'undefined' ? pref : false); |
|
1549 this.type = type || null; |
|
1550 this.formatted = formatted || null; |
|
1551 this.streetAddress = streetAddress || null; |
|
1552 this.locality = locality || null; |
|
1553 this.region = region || null; |
|
1554 this.postalCode = postalCode || null; |
|
1555 this.country = country || null; |
|
1556 }; |
|
1557 |
|
1558 module.exports = ContactAddress; |
|
1559 }); |
|
1560 |
|
1561 // file: lib/common/plugin/ContactError.js |
|
1562 define("cordova/plugin/ContactError", function(require, exports, module) { |
|
1563 /** |
|
1564 * ContactError. |
|
1565 * An error code assigned by an implementation when an error has occured |
|
1566 * @constructor |
|
1567 */ |
|
1568 var ContactError = function(err) { |
|
1569 this.code = (typeof err != 'undefined' ? err : null); |
|
1570 }; |
|
1571 |
|
1572 /** |
|
1573 * Error codes |
|
1574 */ |
|
1575 ContactError.UNKNOWN_ERROR = 0; |
|
1576 ContactError.INVALID_ARGUMENT_ERROR = 1; |
|
1577 ContactError.TIMEOUT_ERROR = 2; |
|
1578 ContactError.PENDING_OPERATION_ERROR = 3; |
|
1579 ContactError.IO_ERROR = 4; |
|
1580 ContactError.NOT_SUPPORTED_ERROR = 5; |
|
1581 ContactError.PERMISSION_DENIED_ERROR = 20; |
|
1582 |
|
1583 module.exports = ContactError; |
|
1584 }); |
|
1585 |
|
1586 // file: lib/common/plugin/ContactField.js |
|
1587 define("cordova/plugin/ContactField", function(require, exports, module) { |
|
1588 /** |
|
1589 * Generic contact field. |
|
1590 * @constructor |
|
1591 * @param {DOMString} id unique identifier, should only be set by native code // NOTE: not a W3C standard |
|
1592 * @param type |
|
1593 * @param value |
|
1594 * @param pref |
|
1595 */ |
|
1596 var ContactField = function(type, value, pref) { |
|
1597 this.id = null; |
|
1598 this.type = (type && type.toString()) || null; |
|
1599 this.value = (value && value.toString()) || null; |
|
1600 this.pref = (typeof pref != 'undefined' ? pref : false); |
|
1601 }; |
|
1602 |
|
1603 module.exports = ContactField; |
|
1604 }); |
|
1605 |
|
1606 // file: lib/common/plugin/ContactFindOptions.js |
|
1607 define("cordova/plugin/ContactFindOptions", function(require, exports, module) { |
|
1608 /** |
|
1609 * ContactFindOptions. |
|
1610 * @constructor |
|
1611 * @param filter used to match contacts against |
|
1612 * @param multiple boolean used to determine if more than one contact should be returned |
|
1613 */ |
|
1614 |
|
1615 var ContactFindOptions = function(filter, multiple) { |
|
1616 this.filter = filter || ''; |
|
1617 this.multiple = (typeof multiple != 'undefined' ? multiple : false); |
|
1618 }; |
|
1619 |
|
1620 module.exports = ContactFindOptions; |
|
1621 }); |
|
1622 |
|
1623 // file: lib/common/plugin/ContactName.js |
|
1624 define("cordova/plugin/ContactName", function(require, exports, module) { |
|
1625 /** |
|
1626 * Contact name. |
|
1627 * @constructor |
|
1628 * @param formatted // NOTE: not part of W3C standard |
|
1629 * @param familyName |
|
1630 * @param givenName |
|
1631 * @param middle |
|
1632 * @param prefix |
|
1633 * @param suffix |
|
1634 */ |
|
1635 var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) { |
|
1636 this.formatted = formatted || null; |
|
1637 this.familyName = familyName || null; |
|
1638 this.givenName = givenName || null; |
|
1639 this.middleName = middle || null; |
|
1640 this.honorificPrefix = prefix || null; |
|
1641 this.honorificSuffix = suffix || null; |
|
1642 }; |
|
1643 |
|
1644 module.exports = ContactName; |
|
1645 }); |
|
1646 |
|
1647 // file: lib/common/plugin/ContactOrganization.js |
|
1648 define("cordova/plugin/ContactOrganization", function(require, exports, module) { |
|
1649 /** |
|
1650 * Contact organization. |
|
1651 * @constructor |
|
1652 * @param {DOMString} id unique identifier, should only be set by native code // NOTE: not a W3C standard |
|
1653 * @param name |
|
1654 * @param dept |
|
1655 * @param title |
|
1656 * @param startDate |
|
1657 * @param endDate |
|
1658 * @param location |
|
1659 * @param desc |
|
1660 */ |
|
1661 |
|
1662 var ContactOrganization = function(pref, type, name, dept, title) { |
|
1663 this.id = null; |
|
1664 this.pref = (typeof pref != 'undefined' ? pref : false); |
|
1665 this.type = type || null; |
|
1666 this.name = name || null; |
|
1667 this.department = dept || null; |
|
1668 this.title = title || null; |
|
1669 }; |
|
1670 |
|
1671 module.exports = ContactOrganization; |
|
1672 }); |
|
1673 |
|
1674 // file: lib/common/plugin/Coordinates.js |
|
1675 define("cordova/plugin/Coordinates", function(require, exports, module) { |
|
1676 /** |
|
1677 * This class contains position information. |
|
1678 * @param {Object} lat |
|
1679 * @param {Object} lng |
|
1680 * @param {Object} alt |
|
1681 * @param {Object} acc |
|
1682 * @param {Object} head |
|
1683 * @param {Object} vel |
|
1684 * @param {Object} altacc |
|
1685 * @constructor |
|
1686 */ |
|
1687 var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { |
|
1688 /** |
|
1689 * The latitude of the position. |
|
1690 */ |
|
1691 this.latitude = lat; |
|
1692 /** |
|
1693 * The longitude of the position, |
|
1694 */ |
|
1695 this.longitude = lng; |
|
1696 /** |
|
1697 * The accuracy of the position. |
|
1698 */ |
|
1699 this.accuracy = acc; |
|
1700 /** |
|
1701 * The altitude of the position. |
|
1702 */ |
|
1703 this.altitude = (alt !== undefined ? alt : null); |
|
1704 /** |
|
1705 * The direction the device is moving at the position. |
|
1706 */ |
|
1707 this.heading = (head !== undefined ? head : null); |
|
1708 /** |
|
1709 * The velocity with which the device is moving at the position. |
|
1710 */ |
|
1711 this.speed = (vel !== undefined ? vel : null); |
|
1712 |
|
1713 if (this.speed === 0 || this.speed === null) { |
|
1714 this.heading = NaN; |
|
1715 } |
|
1716 |
|
1717 /** |
|
1718 * The altitude accuracy of the position. |
|
1719 */ |
|
1720 this.altitudeAccuracy = (altacc !== undefined) ? altacc : null; |
|
1721 }; |
|
1722 |
|
1723 module.exports = Coordinates; |
|
1724 |
|
1725 }); |
|
1726 |
|
1727 // file: lib/common/plugin/DirectoryEntry.js |
|
1728 define("cordova/plugin/DirectoryEntry", function(require, exports, module) { |
|
1729 var utils = require('cordova/utils'), |
|
1730 exec = require('cordova/exec'), |
|
1731 Entry = require('cordova/plugin/Entry'), |
|
1732 FileError = require('cordova/plugin/FileError'), |
|
1733 DirectoryReader = require('cordova/plugin/DirectoryReader'); |
|
1734 |
|
1735 /** |
|
1736 * An interface representing a directory on the file system. |
|
1737 * |
|
1738 * {boolean} isFile always false (readonly) |
|
1739 * {boolean} isDirectory always true (readonly) |
|
1740 * {DOMString} name of the directory, excluding the path leading to it (readonly) |
|
1741 * {DOMString} fullPath the absolute full path to the directory (readonly) |
|
1742 * TODO: implement this!!! {FileSystem} filesystem on which the directory resides (readonly) |
|
1743 */ |
|
1744 var DirectoryEntry = function(name, fullPath) { |
|
1745 DirectoryEntry.__super__.constructor.apply(this, [false, true, name, fullPath]); |
|
1746 }; |
|
1747 |
|
1748 utils.extend(DirectoryEntry, Entry); |
|
1749 |
|
1750 /** |
|
1751 * Creates a new DirectoryReader to read entries from this directory |
|
1752 */ |
|
1753 DirectoryEntry.prototype.createReader = function() { |
|
1754 return new DirectoryReader(this.fullPath); |
|
1755 }; |
|
1756 |
|
1757 /** |
|
1758 * Creates or looks up a directory |
|
1759 * |
|
1760 * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory |
|
1761 * @param {Flags} options to create or excluively create the directory |
|
1762 * @param {Function} successCallback is called with the new entry |
|
1763 * @param {Function} errorCallback is called with a FileError |
|
1764 */ |
|
1765 DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) { |
|
1766 var win = typeof successCallback !== 'function' ? null : function(result) { |
|
1767 var entry = new DirectoryEntry(result.name, result.fullPath); |
|
1768 successCallback(entry); |
|
1769 }; |
|
1770 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
1771 errorCallback(new FileError(code)); |
|
1772 }; |
|
1773 exec(win, fail, "File", "getDirectory", [this.fullPath, path, options]); |
|
1774 }; |
|
1775 |
|
1776 /** |
|
1777 * Deletes a directory and all of it's contents |
|
1778 * |
|
1779 * @param {Function} successCallback is called with no parameters |
|
1780 * @param {Function} errorCallback is called with a FileError |
|
1781 */ |
|
1782 DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) { |
|
1783 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
1784 errorCallback(new FileError(code)); |
|
1785 }; |
|
1786 exec(successCallback, fail, "File", "removeRecursively", [this.fullPath]); |
|
1787 }; |
|
1788 |
|
1789 /** |
|
1790 * Creates or looks up a file |
|
1791 * |
|
1792 * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file |
|
1793 * @param {Flags} options to create or excluively create the file |
|
1794 * @param {Function} successCallback is called with the new entry |
|
1795 * @param {Function} errorCallback is called with a FileError |
|
1796 */ |
|
1797 DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) { |
|
1798 var win = typeof successCallback !== 'function' ? null : function(result) { |
|
1799 var FileEntry = require('cordova/plugin/FileEntry'); |
|
1800 var entry = new FileEntry(result.name, result.fullPath); |
|
1801 successCallback(entry); |
|
1802 }; |
|
1803 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
1804 errorCallback(new FileError(code)); |
|
1805 }; |
|
1806 exec(win, fail, "File", "getFile", [this.fullPath, path, options]); |
|
1807 }; |
|
1808 |
|
1809 module.exports = DirectoryEntry; |
|
1810 |
|
1811 }); |
|
1812 |
|
1813 // file: lib/common/plugin/DirectoryReader.js |
|
1814 define("cordova/plugin/DirectoryReader", function(require, exports, module) { |
|
1815 var exec = require('cordova/exec'), |
|
1816 FileError = require('cordova/plugin/FileError') ; |
|
1817 |
|
1818 /** |
|
1819 * An interface that lists the files and directories in a directory. |
|
1820 */ |
|
1821 function DirectoryReader(path) { |
|
1822 this.path = path || null; |
|
1823 } |
|
1824 |
|
1825 /** |
|
1826 * Returns a list of entries from a directory. |
|
1827 * |
|
1828 * @param {Function} successCallback is called with a list of entries |
|
1829 * @param {Function} errorCallback is called with a FileError |
|
1830 */ |
|
1831 DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) { |
|
1832 var win = typeof successCallback !== 'function' ? null : function(result) { |
|
1833 var retVal = []; |
|
1834 for (var i=0; i<result.length; i++) { |
|
1835 var entry = null; |
|
1836 if (result[i].isDirectory) { |
|
1837 entry = new (require('cordova/plugin/DirectoryEntry'))(); |
|
1838 } |
|
1839 else if (result[i].isFile) { |
|
1840 entry = new (require('cordova/plugin/FileEntry'))(); |
|
1841 } |
|
1842 entry.isDirectory = result[i].isDirectory; |
|
1843 entry.isFile = result[i].isFile; |
|
1844 entry.name = result[i].name; |
|
1845 entry.fullPath = result[i].fullPath; |
|
1846 retVal.push(entry); |
|
1847 } |
|
1848 successCallback(retVal); |
|
1849 }; |
|
1850 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
1851 errorCallback(new FileError(code)); |
|
1852 }; |
|
1853 exec(win, fail, "File", "readEntries", [this.path]); |
|
1854 }; |
|
1855 |
|
1856 module.exports = DirectoryReader; |
|
1857 |
|
1858 }); |
|
1859 |
|
1860 // file: lib/common/plugin/Entry.js |
|
1861 define("cordova/plugin/Entry", function(require, exports, module) { |
|
1862 var exec = require('cordova/exec'), |
|
1863 FileError = require('cordova/plugin/FileError'), |
|
1864 Metadata = require('cordova/plugin/Metadata'); |
|
1865 |
|
1866 /** |
|
1867 * Represents a file or directory on the local file system. |
|
1868 * |
|
1869 * @param isFile |
|
1870 * {boolean} true if Entry is a file (readonly) |
|
1871 * @param isDirectory |
|
1872 * {boolean} true if Entry is a directory (readonly) |
|
1873 * @param name |
|
1874 * {DOMString} name of the file or directory, excluding the path |
|
1875 * leading to it (readonly) |
|
1876 * @param fullPath |
|
1877 * {DOMString} the absolute full path to the file or directory |
|
1878 * (readonly) |
|
1879 */ |
|
1880 function Entry(isFile, isDirectory, name, fullPath, fileSystem) { |
|
1881 this.isFile = (typeof isFile != 'undefined'?isFile:false); |
|
1882 this.isDirectory = (typeof isDirectory != 'undefined'?isDirectory:false); |
|
1883 this.name = name || ''; |
|
1884 this.fullPath = fullPath || ''; |
|
1885 this.filesystem = fileSystem || null; |
|
1886 } |
|
1887 |
|
1888 /** |
|
1889 * Look up the metadata of the entry. |
|
1890 * |
|
1891 * @param successCallback |
|
1892 * {Function} is called with a Metadata object |
|
1893 * @param errorCallback |
|
1894 * {Function} is called with a FileError |
|
1895 */ |
|
1896 Entry.prototype.getMetadata = function(successCallback, errorCallback) { |
|
1897 var success = typeof successCallback !== 'function' ? null : function(lastModified) { |
|
1898 var metadata = new Metadata(lastModified); |
|
1899 successCallback(metadata); |
|
1900 }; |
|
1901 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
1902 errorCallback(new FileError(code)); |
|
1903 }; |
|
1904 |
|
1905 exec(success, fail, "File", "getMetadata", [this.fullPath]); |
|
1906 }; |
|
1907 |
|
1908 /** |
|
1909 * Set the metadata of the entry. |
|
1910 * |
|
1911 * @param successCallback |
|
1912 * {Function} is called with a Metadata object |
|
1913 * @param errorCallback |
|
1914 * {Function} is called with a FileError |
|
1915 * @param metadataObject |
|
1916 * {Object} keys and values to set |
|
1917 */ |
|
1918 Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataObject) { |
|
1919 |
|
1920 exec(successCallback, errorCallback, "File", "setMetadata", [this.fullPath, metadataObject]); |
|
1921 }; |
|
1922 |
|
1923 /** |
|
1924 * Move a file or directory to a new location. |
|
1925 * |
|
1926 * @param parent |
|
1927 * {DirectoryEntry} the directory to which to move this entry |
|
1928 * @param newName |
|
1929 * {DOMString} new name of the entry, defaults to the current name |
|
1930 * @param successCallback |
|
1931 * {Function} called with the new DirectoryEntry object |
|
1932 * @param errorCallback |
|
1933 * {Function} called with a FileError |
|
1934 */ |
|
1935 Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) { |
|
1936 var fail = function(code) { |
|
1937 if (typeof errorCallback === 'function') { |
|
1938 errorCallback(new FileError(code)); |
|
1939 } |
|
1940 }; |
|
1941 // user must specify parent Entry |
|
1942 if (!parent) { |
|
1943 fail(FileError.NOT_FOUND_ERR); |
|
1944 return; |
|
1945 } |
|
1946 // source path |
|
1947 var srcPath = this.fullPath, |
|
1948 // entry name |
|
1949 name = newName || this.name, |
|
1950 success = function(entry) { |
|
1951 if (entry) { |
|
1952 if (typeof successCallback === 'function') { |
|
1953 // create appropriate Entry object |
|
1954 var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath); |
|
1955 try { |
|
1956 successCallback(result); |
|
1957 } |
|
1958 catch (e) { |
|
1959 console.log('Error invoking callback: ' + e); |
|
1960 } |
|
1961 } |
|
1962 } |
|
1963 else { |
|
1964 // no Entry object returned |
|
1965 fail(FileError.NOT_FOUND_ERR); |
|
1966 } |
|
1967 }; |
|
1968 |
|
1969 // copy |
|
1970 exec(success, fail, "File", "moveTo", [srcPath, parent.fullPath, name]); |
|
1971 }; |
|
1972 |
|
1973 /** |
|
1974 * Copy a directory to a different location. |
|
1975 * |
|
1976 * @param parent |
|
1977 * {DirectoryEntry} the directory to which to copy the entry |
|
1978 * @param newName |
|
1979 * {DOMString} new name of the entry, defaults to the current name |
|
1980 * @param successCallback |
|
1981 * {Function} called with the new Entry object |
|
1982 * @param errorCallback |
|
1983 * {Function} called with a FileError |
|
1984 */ |
|
1985 Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) { |
|
1986 var fail = function(code) { |
|
1987 if (typeof errorCallback === 'function') { |
|
1988 errorCallback(new FileError(code)); |
|
1989 } |
|
1990 }; |
|
1991 |
|
1992 // user must specify parent Entry |
|
1993 if (!parent) { |
|
1994 fail(FileError.NOT_FOUND_ERR); |
|
1995 return; |
|
1996 } |
|
1997 |
|
1998 // source path |
|
1999 var srcPath = this.fullPath, |
|
2000 // entry name |
|
2001 name = newName || this.name, |
|
2002 // success callback |
|
2003 success = function(entry) { |
|
2004 if (entry) { |
|
2005 if (typeof successCallback === 'function') { |
|
2006 // create appropriate Entry object |
|
2007 var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath); |
|
2008 try { |
|
2009 successCallback(result); |
|
2010 } |
|
2011 catch (e) { |
|
2012 console.log('Error invoking callback: ' + e); |
|
2013 } |
|
2014 } |
|
2015 } |
|
2016 else { |
|
2017 // no Entry object returned |
|
2018 fail(FileError.NOT_FOUND_ERR); |
|
2019 } |
|
2020 }; |
|
2021 |
|
2022 // copy |
|
2023 exec(success, fail, "File", "copyTo", [srcPath, parent.fullPath, name]); |
|
2024 }; |
|
2025 |
|
2026 /** |
|
2027 * Return a URL that can be used to identify this entry. |
|
2028 */ |
|
2029 Entry.prototype.toURL = function() { |
|
2030 // fullPath attribute contains the full URL |
|
2031 return this.fullPath; |
|
2032 }; |
|
2033 |
|
2034 /** |
|
2035 * Returns a URI that can be used to identify this entry. |
|
2036 * |
|
2037 * @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI. |
|
2038 * @return uri |
|
2039 */ |
|
2040 Entry.prototype.toURI = function(mimeType) { |
|
2041 console.log("DEPRECATED: Update your code to use 'toURL'"); |
|
2042 // fullPath attribute contains the full URI |
|
2043 return this.toURL(); |
|
2044 }; |
|
2045 |
|
2046 /** |
|
2047 * Remove a file or directory. It is an error to attempt to delete a |
|
2048 * directory that is not empty. It is an error to attempt to delete a |
|
2049 * root directory of a file system. |
|
2050 * |
|
2051 * @param successCallback {Function} called with no parameters |
|
2052 * @param errorCallback {Function} called with a FileError |
|
2053 */ |
|
2054 Entry.prototype.remove = function(successCallback, errorCallback) { |
|
2055 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
2056 errorCallback(new FileError(code)); |
|
2057 }; |
|
2058 exec(successCallback, fail, "File", "remove", [this.fullPath]); |
|
2059 }; |
|
2060 |
|
2061 /** |
|
2062 * Look up the parent DirectoryEntry of this entry. |
|
2063 * |
|
2064 * @param successCallback {Function} called with the parent DirectoryEntry object |
|
2065 * @param errorCallback {Function} called with a FileError |
|
2066 */ |
|
2067 Entry.prototype.getParent = function(successCallback, errorCallback) { |
|
2068 var win = typeof successCallback !== 'function' ? null : function(result) { |
|
2069 var DirectoryEntry = require('cordova/plugin/DirectoryEntry'); |
|
2070 var entry = new DirectoryEntry(result.name, result.fullPath); |
|
2071 successCallback(entry); |
|
2072 }; |
|
2073 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
2074 errorCallback(new FileError(code)); |
|
2075 }; |
|
2076 exec(win, fail, "File", "getParent", [this.fullPath]); |
|
2077 }; |
|
2078 |
|
2079 module.exports = Entry; |
|
2080 }); |
|
2081 |
|
2082 // file: lib/common/plugin/File.js |
|
2083 define("cordova/plugin/File", function(require, exports, module) { |
|
2084 /** |
|
2085 * Constructor. |
|
2086 * name {DOMString} name of the file, without path information |
|
2087 * fullPath {DOMString} the full path of the file, including the name |
|
2088 * type {DOMString} mime type |
|
2089 * lastModifiedDate {Date} last modified date |
|
2090 * size {Number} size of the file in bytes |
|
2091 */ |
|
2092 |
|
2093 var File = function(name, fullPath, type, lastModifiedDate, size){ |
|
2094 this.name = name || ''; |
|
2095 this.fullPath = fullPath || null; |
|
2096 this.type = type || null; |
|
2097 this.lastModifiedDate = lastModifiedDate || null; |
|
2098 this.size = size || 0; |
|
2099 }; |
|
2100 |
|
2101 module.exports = File; |
|
2102 }); |
|
2103 |
|
2104 // file: lib/common/plugin/FileEntry.js |
|
2105 define("cordova/plugin/FileEntry", function(require, exports, module) { |
|
2106 var utils = require('cordova/utils'), |
|
2107 exec = require('cordova/exec'), |
|
2108 Entry = require('cordova/plugin/Entry'), |
|
2109 FileWriter = require('cordova/plugin/FileWriter'), |
|
2110 File = require('cordova/plugin/File'), |
|
2111 FileError = require('cordova/plugin/FileError'); |
|
2112 |
|
2113 /** |
|
2114 * An interface representing a file on the file system. |
|
2115 * |
|
2116 * {boolean} isFile always true (readonly) |
|
2117 * {boolean} isDirectory always false (readonly) |
|
2118 * {DOMString} name of the file, excluding the path leading to it (readonly) |
|
2119 * {DOMString} fullPath the absolute full path to the file (readonly) |
|
2120 * {FileSystem} filesystem on which the file resides (readonly) |
|
2121 */ |
|
2122 var FileEntry = function(name, fullPath) { |
|
2123 FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath]); |
|
2124 }; |
|
2125 |
|
2126 utils.extend(FileEntry, Entry); |
|
2127 |
|
2128 /** |
|
2129 * Creates a new FileWriter associated with the file that this FileEntry represents. |
|
2130 * |
|
2131 * @param {Function} successCallback is called with the new FileWriter |
|
2132 * @param {Function} errorCallback is called with a FileError |
|
2133 */ |
|
2134 FileEntry.prototype.createWriter = function(successCallback, errorCallback) { |
|
2135 this.file(function(filePointer) { |
|
2136 var writer = new FileWriter(filePointer); |
|
2137 |
|
2138 if (writer.fileName === null || writer.fileName === "") { |
|
2139 if (typeof errorCallback === "function") { |
|
2140 errorCallback(new FileError(FileError.INVALID_STATE_ERR)); |
|
2141 } |
|
2142 } else { |
|
2143 if (typeof successCallback === "function") { |
|
2144 successCallback(writer); |
|
2145 } |
|
2146 } |
|
2147 }, errorCallback); |
|
2148 }; |
|
2149 |
|
2150 /** |
|
2151 * Returns a File that represents the current state of the file that this FileEntry represents. |
|
2152 * |
|
2153 * @param {Function} successCallback is called with the new File object |
|
2154 * @param {Function} errorCallback is called with a FileError |
|
2155 */ |
|
2156 FileEntry.prototype.file = function(successCallback, errorCallback) { |
|
2157 var win = typeof successCallback !== 'function' ? null : function(f) { |
|
2158 var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size); |
|
2159 successCallback(file); |
|
2160 }; |
|
2161 var fail = typeof errorCallback !== 'function' ? null : function(code) { |
|
2162 errorCallback(new FileError(code)); |
|
2163 }; |
|
2164 exec(win, fail, "File", "getFileMetadata", [this.fullPath]); |
|
2165 }; |
|
2166 |
|
2167 |
|
2168 module.exports = FileEntry; |
|
2169 }); |
|
2170 |
|
2171 // file: lib/common/plugin/FileError.js |
|
2172 define("cordova/plugin/FileError", function(require, exports, module) { |
|
2173 /** |
|
2174 * FileError |
|
2175 */ |
|
2176 function FileError(error) { |
|
2177 this.code = error || null; |
|
2178 } |
|
2179 |
|
2180 // File error codes |
|
2181 // Found in DOMException |
|
2182 FileError.NOT_FOUND_ERR = 1; |
|
2183 FileError.SECURITY_ERR = 2; |
|
2184 FileError.ABORT_ERR = 3; |
|
2185 |
|
2186 // Added by File API specification |
|
2187 FileError.NOT_READABLE_ERR = 4; |
|
2188 FileError.ENCODING_ERR = 5; |
|
2189 FileError.NO_MODIFICATION_ALLOWED_ERR = 6; |
|
2190 FileError.INVALID_STATE_ERR = 7; |
|
2191 FileError.SYNTAX_ERR = 8; |
|
2192 FileError.INVALID_MODIFICATION_ERR = 9; |
|
2193 FileError.QUOTA_EXCEEDED_ERR = 10; |
|
2194 FileError.TYPE_MISMATCH_ERR = 11; |
|
2195 FileError.PATH_EXISTS_ERR = 12; |
|
2196 |
|
2197 module.exports = FileError; |
|
2198 }); |
|
2199 |
|
2200 // file: lib/common/plugin/FileReader.js |
|
2201 define("cordova/plugin/FileReader", function(require, exports, module) { |
|
2202 var exec = require('cordova/exec'), |
|
2203 FileError = require('cordova/plugin/FileError'), |
|
2204 ProgressEvent = require('cordova/plugin/ProgressEvent'); |
|
2205 |
|
2206 /** |
|
2207 * This class reads the mobile device file system. |
|
2208 * |
|
2209 * For Android: |
|
2210 * The root directory is the root of the file system. |
|
2211 * To read from the SD card, the file name is "sdcard/my_file.txt" |
|
2212 * @constructor |
|
2213 */ |
|
2214 var FileReader = function() { |
|
2215 this.fileName = ""; |
|
2216 |
|
2217 this.readyState = 0; // FileReader.EMPTY |
|
2218 |
|
2219 // File data |
|
2220 this.result = null; |
|
2221 |
|
2222 // Error |
|
2223 this.error = null; |
|
2224 |
|
2225 // Event handlers |
|
2226 this.onloadstart = null; // When the read starts. |
|
2227 this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progess.loaded/progress.total) |
|
2228 this.onload = null; // When the read has successfully completed. |
|
2229 this.onerror = null; // When the read has failed (see errors). |
|
2230 this.onloadend = null; // When the request has completed (either in success or failure). |
|
2231 this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method. |
|
2232 }; |
|
2233 |
|
2234 // States |
|
2235 FileReader.EMPTY = 0; |
|
2236 FileReader.LOADING = 1; |
|
2237 FileReader.DONE = 2; |
|
2238 |
|
2239 /** |
|
2240 * Abort reading file. |
|
2241 */ |
|
2242 FileReader.prototype.abort = function() { |
|
2243 this.result = null; |
|
2244 |
|
2245 if (this.readyState == FileReader.DONE || this.readyState == FileReader.EMPTY) { |
|
2246 return; |
|
2247 } |
|
2248 |
|
2249 this.readyState = FileReader.DONE; |
|
2250 |
|
2251 // If abort callback |
|
2252 if (typeof this.onabort === 'function') { |
|
2253 this.onabort(new ProgressEvent('abort', {target:this})); |
|
2254 } |
|
2255 // If load end callback |
|
2256 if (typeof this.onloadend === 'function') { |
|
2257 this.onloadend(new ProgressEvent('loadend', {target:this})); |
|
2258 } |
|
2259 }; |
|
2260 |
|
2261 /** |
|
2262 * Read text file. |
|
2263 * |
|
2264 * @param file {File} File object containing file properties |
|
2265 * @param encoding [Optional] (see http://www.iana.org/assignments/character-sets) |
|
2266 */ |
|
2267 FileReader.prototype.readAsText = function(file, encoding) { |
|
2268 // Figure out pathing |
|
2269 this.fileName = ''; |
|
2270 if (typeof file.fullPath === 'undefined') { |
|
2271 this.fileName = file; |
|
2272 } else { |
|
2273 this.fileName = file.fullPath; |
|
2274 } |
|
2275 |
|
2276 // Already loading something |
|
2277 if (this.readyState == FileReader.LOADING) { |
|
2278 throw new FileError(FileError.INVALID_STATE_ERR); |
|
2279 } |
|
2280 |
|
2281 // LOADING state |
|
2282 this.readyState = FileReader.LOADING; |
|
2283 |
|
2284 // If loadstart callback |
|
2285 if (typeof this.onloadstart === "function") { |
|
2286 this.onloadstart(new ProgressEvent("loadstart", {target:this})); |
|
2287 } |
|
2288 |
|
2289 // Default encoding is UTF-8 |
|
2290 var enc = encoding ? encoding : "UTF-8"; |
|
2291 |
|
2292 var me = this; |
|
2293 |
|
2294 // Read file |
|
2295 exec( |
|
2296 // Success callback |
|
2297 function(r) { |
|
2298 // If DONE (cancelled), then don't do anything |
|
2299 if (me.readyState === FileReader.DONE) { |
|
2300 return; |
|
2301 } |
|
2302 |
|
2303 // Save result |
|
2304 me.result = r; |
|
2305 |
|
2306 // If onload callback |
|
2307 if (typeof me.onload === "function") { |
|
2308 me.onload(new ProgressEvent("load", {target:me})); |
|
2309 } |
|
2310 |
|
2311 // DONE state |
|
2312 me.readyState = FileReader.DONE; |
|
2313 |
|
2314 // If onloadend callback |
|
2315 if (typeof me.onloadend === "function") { |
|
2316 me.onloadend(new ProgressEvent("loadend", {target:me})); |
|
2317 } |
|
2318 }, |
|
2319 // Error callback |
|
2320 function(e) { |
|
2321 // If DONE (cancelled), then don't do anything |
|
2322 if (me.readyState === FileReader.DONE) { |
|
2323 return; |
|
2324 } |
|
2325 |
|
2326 // DONE state |
|
2327 me.readyState = FileReader.DONE; |
|
2328 |
|
2329 // null result |
|
2330 me.result = null; |
|
2331 |
|
2332 // Save error |
|
2333 me.error = new FileError(e); |
|
2334 |
|
2335 // If onerror callback |
|
2336 if (typeof me.onerror === "function") { |
|
2337 me.onerror(new ProgressEvent("error", {target:me})); |
|
2338 } |
|
2339 |
|
2340 // If onloadend callback |
|
2341 if (typeof me.onloadend === "function") { |
|
2342 me.onloadend(new ProgressEvent("loadend", {target:me})); |
|
2343 } |
|
2344 }, "File", "readAsText", [this.fileName, enc]); |
|
2345 }; |
|
2346 |
|
2347 |
|
2348 /** |
|
2349 * Read file and return data as a base64 encoded data url. |
|
2350 * A data url is of the form: |
|
2351 * data:[<mediatype>][;base64],<data> |
|
2352 * |
|
2353 * @param file {File} File object containing file properties |
|
2354 */ |
|
2355 FileReader.prototype.readAsDataURL = function(file) { |
|
2356 this.fileName = ""; |
|
2357 if (typeof file.fullPath === "undefined") { |
|
2358 this.fileName = file; |
|
2359 } else { |
|
2360 this.fileName = file.fullPath; |
|
2361 } |
|
2362 |
|
2363 // Already loading something |
|
2364 if (this.readyState == FileReader.LOADING) { |
|
2365 throw new FileError(FileError.INVALID_STATE_ERR); |
|
2366 } |
|
2367 |
|
2368 // LOADING state |
|
2369 this.readyState = FileReader.LOADING; |
|
2370 |
|
2371 // If loadstart callback |
|
2372 if (typeof this.onloadstart === "function") { |
|
2373 this.onloadstart(new ProgressEvent("loadstart", {target:this})); |
|
2374 } |
|
2375 |
|
2376 var me = this; |
|
2377 |
|
2378 // Read file |
|
2379 exec( |
|
2380 // Success callback |
|
2381 function(r) { |
|
2382 // If DONE (cancelled), then don't do anything |
|
2383 if (me.readyState === FileReader.DONE) { |
|
2384 return; |
|
2385 } |
|
2386 |
|
2387 // DONE state |
|
2388 me.readyState = FileReader.DONE; |
|
2389 |
|
2390 // Save result |
|
2391 me.result = r; |
|
2392 |
|
2393 // If onload callback |
|
2394 if (typeof me.onload === "function") { |
|
2395 me.onload(new ProgressEvent("load", {target:me})); |
|
2396 } |
|
2397 |
|
2398 // If onloadend callback |
|
2399 if (typeof me.onloadend === "function") { |
|
2400 me.onloadend(new ProgressEvent("loadend", {target:me})); |
|
2401 } |
|
2402 }, |
|
2403 // Error callback |
|
2404 function(e) { |
|
2405 // If DONE (cancelled), then don't do anything |
|
2406 if (me.readyState === FileReader.DONE) { |
|
2407 return; |
|
2408 } |
|
2409 |
|
2410 // DONE state |
|
2411 me.readyState = FileReader.DONE; |
|
2412 |
|
2413 me.result = null; |
|
2414 |
|
2415 // Save error |
|
2416 me.error = new FileError(e); |
|
2417 |
|
2418 // If onerror callback |
|
2419 if (typeof me.onerror === "function") { |
|
2420 me.onerror(new ProgressEvent("error", {target:me})); |
|
2421 } |
|
2422 |
|
2423 // If onloadend callback |
|
2424 if (typeof me.onloadend === "function") { |
|
2425 me.onloadend(new ProgressEvent("loadend", {target:me})); |
|
2426 } |
|
2427 }, "File", "readAsDataURL", [this.fileName]); |
|
2428 }; |
|
2429 |
|
2430 /** |
|
2431 * Read file and return data as a binary data. |
|
2432 * |
|
2433 * @param file {File} File object containing file properties |
|
2434 */ |
|
2435 FileReader.prototype.readAsBinaryString = function(file) { |
|
2436 // TODO - Can't return binary data to browser. |
|
2437 console.log('method "readAsBinaryString" is not supported at this time.'); |
|
2438 }; |
|
2439 |
|
2440 /** |
|
2441 * Read file and return data as a binary data. |
|
2442 * |
|
2443 * @param file {File} File object containing file properties |
|
2444 */ |
|
2445 FileReader.prototype.readAsArrayBuffer = function(file) { |
|
2446 // TODO - Can't return binary data to browser. |
|
2447 console.log('This method is not supported at this time.'); |
|
2448 }; |
|
2449 |
|
2450 module.exports = FileReader; |
|
2451 }); |
|
2452 |
|
2453 // file: lib/common/plugin/FileSystem.js |
|
2454 define("cordova/plugin/FileSystem", function(require, exports, module) { |
|
2455 var DirectoryEntry = require('cordova/plugin/DirectoryEntry'); |
|
2456 |
|
2457 /** |
|
2458 * An interface representing a file system |
|
2459 * |
|
2460 * @constructor |
|
2461 * {DOMString} name the unique name of the file system (readonly) |
|
2462 * {DirectoryEntry} root directory of the file system (readonly) |
|
2463 */ |
|
2464 var FileSystem = function(name, root) { |
|
2465 this.name = name || null; |
|
2466 if (root) { |
|
2467 this.root = new DirectoryEntry(root.name, root.fullPath); |
|
2468 } |
|
2469 }; |
|
2470 |
|
2471 module.exports = FileSystem; |
|
2472 |
|
2473 }); |
|
2474 |
|
2475 // file: lib/common/plugin/FileTransfer.js |
|
2476 define("cordova/plugin/FileTransfer", function(require, exports, module) { |
|
2477 var exec = require('cordova/exec'), |
|
2478 FileTransferError = require('cordova/plugin/FileTransferError'); |
|
2479 |
|
2480 /** |
|
2481 * FileTransfer uploads a file to a remote server. |
|
2482 * @constructor |
|
2483 */ |
|
2484 var FileTransfer = function() {}; |
|
2485 |
|
2486 /** |
|
2487 * Given an absolute file path, uploads a file on the device to a remote server |
|
2488 * using a multipart HTTP request. |
|
2489 * @param filePath {String} Full path of the file on the device |
|
2490 * @param server {String} URL of the server to receive the file |
|
2491 * @param successCallback (Function} Callback to be invoked when upload has completed |
|
2492 * @param errorCallback {Function} Callback to be invoked upon error |
|
2493 * @param options {FileUploadOptions} Optional parameters such as file name and mimetype |
|
2494 * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false |
|
2495 */ |
|
2496 FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, trustAllHosts) { |
|
2497 // sanity parameter checking |
|
2498 if (!filePath || !server) throw new Error("FileTransfer.upload requires filePath and server URL parameters at the minimum."); |
|
2499 // check for options |
|
2500 var fileKey = null; |
|
2501 var fileName = null; |
|
2502 var mimeType = null; |
|
2503 var params = null; |
|
2504 var chunkedMode = true; |
|
2505 if (options) { |
|
2506 fileKey = options.fileKey; |
|
2507 fileName = options.fileName; |
|
2508 mimeType = options.mimeType; |
|
2509 if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") { |
|
2510 chunkedMode = options.chunkedMode; |
|
2511 } |
|
2512 if (options.params) { |
|
2513 params = options.params; |
|
2514 } |
|
2515 else { |
|
2516 params = {}; |
|
2517 } |
|
2518 } |
|
2519 |
|
2520 var fail = function(e) { |
|
2521 var error = new FileTransferError(e.code, e.source, e.target, e.http_status); |
|
2522 errorCallback(error); |
|
2523 }; |
|
2524 |
|
2525 exec(successCallback, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode]); |
|
2526 }; |
|
2527 |
|
2528 /** |
|
2529 * Downloads a file form a given URL and saves it to the specified directory. |
|
2530 * @param source {String} URL of the server to receive the file |
|
2531 * @param target {String} Full path of the file on the device |
|
2532 * @param successCallback (Function} Callback to be invoked when upload has completed |
|
2533 * @param errorCallback {Function} Callback to be invoked upon error |
|
2534 */ |
|
2535 FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) { |
|
2536 // sanity parameter checking |
|
2537 if (!source || !target) throw new Error("FileTransfer.download requires source URI and target URI parameters at the minimum."); |
|
2538 var win = function(result) { |
|
2539 var entry = null; |
|
2540 if (result.isDirectory) { |
|
2541 entry = new (require('cordova/plugin/DirectoryEntry'))(); |
|
2542 } |
|
2543 else if (result.isFile) { |
|
2544 entry = new (require('cordova/plugin/FileEntry'))(); |
|
2545 } |
|
2546 entry.isDirectory = result.isDirectory; |
|
2547 entry.isFile = result.isFile; |
|
2548 entry.name = result.name; |
|
2549 entry.fullPath = result.fullPath; |
|
2550 successCallback(entry); |
|
2551 }; |
|
2552 |
|
2553 var fail = function(e) { |
|
2554 var error = new FileTransferError(e.code, e.source, e.target, e.http_status); |
|
2555 errorCallback(error); |
|
2556 }; |
|
2557 |
|
2558 exec(win, errorCallback, 'FileTransfer', 'download', [source, target]); |
|
2559 }; |
|
2560 |
|
2561 module.exports = FileTransfer; |
|
2562 |
|
2563 }); |
|
2564 |
|
2565 // file: lib/common/plugin/FileTransferError.js |
|
2566 define("cordova/plugin/FileTransferError", function(require, exports, module) { |
|
2567 /** |
|
2568 * FileTransferError |
|
2569 * @constructor |
|
2570 */ |
|
2571 var FileTransferError = function(code, source, target, status) { |
|
2572 this.code = code || null; |
|
2573 this.source = source || null; |
|
2574 this.target = target || null; |
|
2575 this.http_status = status || null; |
|
2576 }; |
|
2577 |
|
2578 FileTransferError.FILE_NOT_FOUND_ERR = 1; |
|
2579 FileTransferError.INVALID_URL_ERR = 2; |
|
2580 FileTransferError.CONNECTION_ERR = 3; |
|
2581 |
|
2582 module.exports = FileTransferError; |
|
2583 |
|
2584 }); |
|
2585 |
|
2586 // file: lib/common/plugin/FileUploadOptions.js |
|
2587 define("cordova/plugin/FileUploadOptions", function(require, exports, module) { |
|
2588 /** |
|
2589 * Options to customize the HTTP request used to upload files. |
|
2590 * @constructor |
|
2591 * @param fileKey {String} Name of file request parameter. |
|
2592 * @param fileName {String} Filename to be used by the server. Defaults to image.jpg. |
|
2593 * @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg. |
|
2594 * @param params {Object} Object with key: value params to send to the server. |
|
2595 */ |
|
2596 var FileUploadOptions = function(fileKey, fileName, mimeType, params) { |
|
2597 this.fileKey = fileKey || null; |
|
2598 this.fileName = fileName || null; |
|
2599 this.mimeType = mimeType || null; |
|
2600 this.params = params || null; |
|
2601 }; |
|
2602 |
|
2603 module.exports = FileUploadOptions; |
|
2604 }); |
|
2605 |
|
2606 // file: lib/common/plugin/FileUploadResult.js |
|
2607 define("cordova/plugin/FileUploadResult", function(require, exports, module) { |
|
2608 /** |
|
2609 * FileUploadResult |
|
2610 * @constructor |
|
2611 */ |
|
2612 var FileUploadResult = function() { |
|
2613 this.bytesSent = 0; |
|
2614 this.responseCode = null; |
|
2615 this.response = null; |
|
2616 }; |
|
2617 |
|
2618 module.exports = FileUploadResult; |
|
2619 }); |
|
2620 |
|
2621 // file: lib/common/plugin/FileWriter.js |
|
2622 define("cordova/plugin/FileWriter", function(require, exports, module) { |
|
2623 var exec = require('cordova/exec'), |
|
2624 FileError = require('cordova/plugin/FileError'), |
|
2625 ProgressEvent = require('cordova/plugin/ProgressEvent'); |
|
2626 |
|
2627 /** |
|
2628 * This class writes to the mobile device file system. |
|
2629 * |
|
2630 * For Android: |
|
2631 * The root directory is the root of the file system. |
|
2632 * To write to the SD card, the file name is "sdcard/my_file.txt" |
|
2633 * |
|
2634 * @constructor |
|
2635 * @param file {File} File object containing file properties |
|
2636 * @param append if true write to the end of the file, otherwise overwrite the file |
|
2637 */ |
|
2638 var FileWriter = function(file) { |
|
2639 this.fileName = ""; |
|
2640 this.length = 0; |
|
2641 if (file) { |
|
2642 this.fileName = file.fullPath || file; |
|
2643 this.length = file.size || 0; |
|
2644 } |
|
2645 // default is to write at the beginning of the file |
|
2646 this.position = 0; |
|
2647 |
|
2648 this.readyState = 0; // EMPTY |
|
2649 |
|
2650 this.result = null; |
|
2651 |
|
2652 // Error |
|
2653 this.error = null; |
|
2654 |
|
2655 // Event handlers |
|
2656 this.onwritestart = null; // When writing starts |
|
2657 this.onprogress = null; // While writing the file, and reporting partial file data |
|
2658 this.onwrite = null; // When the write has successfully completed. |
|
2659 this.onwriteend = null; // When the request has completed (either in success or failure). |
|
2660 this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method. |
|
2661 this.onerror = null; // When the write has failed (see errors). |
|
2662 }; |
|
2663 |
|
2664 // States |
|
2665 FileWriter.INIT = 0; |
|
2666 FileWriter.WRITING = 1; |
|
2667 FileWriter.DONE = 2; |
|
2668 |
|
2669 /** |
|
2670 * Abort writing file. |
|
2671 */ |
|
2672 FileWriter.prototype.abort = function() { |
|
2673 // check for invalid state |
|
2674 if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) { |
|
2675 throw new FileError(FileError.INVALID_STATE_ERR); |
|
2676 } |
|
2677 |
|
2678 // set error |
|
2679 this.error = new FileError(FileError.ABORT_ERR); |
|
2680 |
|
2681 this.readyState = FileWriter.DONE; |
|
2682 |
|
2683 // If abort callback |
|
2684 if (typeof this.onabort === "function") { |
|
2685 this.onabort(new ProgressEvent("abort", {"target":this})); |
|
2686 } |
|
2687 |
|
2688 // If write end callback |
|
2689 if (typeof this.onwriteend === "function") { |
|
2690 this.onwriteend(new ProgressEvent("writeend", {"target":this})); |
|
2691 } |
|
2692 }; |
|
2693 |
|
2694 /** |
|
2695 * Writes data to the file |
|
2696 * |
|
2697 * @param text to be written |
|
2698 */ |
|
2699 FileWriter.prototype.write = function(text) { |
|
2700 // Throw an exception if we are already writing a file |
|
2701 if (this.readyState === FileWriter.WRITING) { |
|
2702 throw new FileError(FileError.INVALID_STATE_ERR); |
|
2703 } |
|
2704 |
|
2705 // WRITING state |
|
2706 this.readyState = FileWriter.WRITING; |
|
2707 |
|
2708 var me = this; |
|
2709 |
|
2710 // If onwritestart callback |
|
2711 if (typeof me.onwritestart === "function") { |
|
2712 me.onwritestart(new ProgressEvent("writestart", {"target":me})); |
|
2713 } |
|
2714 |
|
2715 // Write file |
|
2716 exec( |
|
2717 // Success callback |
|
2718 function(r) { |
|
2719 // If DONE (cancelled), then don't do anything |
|
2720 if (me.readyState === FileWriter.DONE) { |
|
2721 return; |
|
2722 } |
|
2723 |
|
2724 // position always increases by bytes written because file would be extended |
|
2725 me.position += r; |
|
2726 // The length of the file is now where we are done writing. |
|
2727 |
|
2728 me.length = me.position; |
|
2729 |
|
2730 // DONE state |
|
2731 me.readyState = FileWriter.DONE; |
|
2732 |
|
2733 // If onwrite callback |
|
2734 if (typeof me.onwrite === "function") { |
|
2735 me.onwrite(new ProgressEvent("write", {"target":me})); |
|
2736 } |
|
2737 |
|
2738 // If onwriteend callback |
|
2739 if (typeof me.onwriteend === "function") { |
|
2740 me.onwriteend(new ProgressEvent("writeend", {"target":me})); |
|
2741 } |
|
2742 }, |
|
2743 // Error callback |
|
2744 function(e) { |
|
2745 // If DONE (cancelled), then don't do anything |
|
2746 if (me.readyState === FileWriter.DONE) { |
|
2747 return; |
|
2748 } |
|
2749 |
|
2750 // DONE state |
|
2751 me.readyState = FileWriter.DONE; |
|
2752 |
|
2753 // Save error |
|
2754 me.error = new FileError(e); |
|
2755 |
|
2756 // If onerror callback |
|
2757 if (typeof me.onerror === "function") { |
|
2758 me.onerror(new ProgressEvent("error", {"target":me})); |
|
2759 } |
|
2760 |
|
2761 // If onwriteend callback |
|
2762 if (typeof me.onwriteend === "function") { |
|
2763 me.onwriteend(new ProgressEvent("writeend", {"target":me})); |
|
2764 } |
|
2765 }, "File", "write", [this.fileName, text, this.position]); |
|
2766 }; |
|
2767 |
|
2768 /** |
|
2769 * Moves the file pointer to the location specified. |
|
2770 * |
|
2771 * If the offset is a negative number the position of the file |
|
2772 * pointer is rewound. If the offset is greater than the file |
|
2773 * size the position is set to the end of the file. |
|
2774 * |
|
2775 * @param offset is the location to move the file pointer to. |
|
2776 */ |
|
2777 FileWriter.prototype.seek = function(offset) { |
|
2778 // Throw an exception if we are already writing a file |
|
2779 if (this.readyState === FileWriter.WRITING) { |
|
2780 throw new FileError(FileError.INVALID_STATE_ERR); |
|
2781 } |
|
2782 |
|
2783 if (!offset && offset !== 0) { |
|
2784 return; |
|
2785 } |
|
2786 |
|
2787 // See back from end of file. |
|
2788 if (offset < 0) { |
|
2789 this.position = Math.max(offset + this.length, 0); |
|
2790 } |
|
2791 // Offset is bigger then file size so set position |
|
2792 // to the end of the file. |
|
2793 else if (offset > this.length) { |
|
2794 this.position = this.length; |
|
2795 } |
|
2796 // Offset is between 0 and file size so set the position |
|
2797 // to start writing. |
|
2798 else { |
|
2799 this.position = offset; |
|
2800 } |
|
2801 }; |
|
2802 |
|
2803 /** |
|
2804 * Truncates the file to the size specified. |
|
2805 * |
|
2806 * @param size to chop the file at. |
|
2807 */ |
|
2808 FileWriter.prototype.truncate = function(size) { |
|
2809 // Throw an exception if we are already writing a file |
|
2810 if (this.readyState === FileWriter.WRITING) { |
|
2811 throw new FileError(FileError.INVALID_STATE_ERR); |
|
2812 } |
|
2813 |
|
2814 // WRITING state |
|
2815 this.readyState = FileWriter.WRITING; |
|
2816 |
|
2817 var me = this; |
|
2818 |
|
2819 // If onwritestart callback |
|
2820 if (typeof me.onwritestart === "function") { |
|
2821 me.onwritestart(new ProgressEvent("writestart", {"target":this})); |
|
2822 } |
|
2823 |
|
2824 // Write file |
|
2825 exec( |
|
2826 // Success callback |
|
2827 function(r) { |
|
2828 // If DONE (cancelled), then don't do anything |
|
2829 if (me.readyState === FileWriter.DONE) { |
|
2830 return; |
|
2831 } |
|
2832 |
|
2833 // DONE state |
|
2834 me.readyState = FileWriter.DONE; |
|
2835 |
|
2836 // Update the length of the file |
|
2837 me.length = r; |
|
2838 me.position = Math.min(me.position, r); |
|
2839 |
|
2840 // If onwrite callback |
|
2841 if (typeof me.onwrite === "function") { |
|
2842 me.onwrite(new ProgressEvent("write", {"target":me})); |
|
2843 } |
|
2844 |
|
2845 // If onwriteend callback |
|
2846 if (typeof me.onwriteend === "function") { |
|
2847 me.onwriteend(new ProgressEvent("writeend", {"target":me})); |
|
2848 } |
|
2849 }, |
|
2850 // Error callback |
|
2851 function(e) { |
|
2852 // If DONE (cancelled), then don't do anything |
|
2853 if (me.readyState === FileWriter.DONE) { |
|
2854 return; |
|
2855 } |
|
2856 |
|
2857 // DONE state |
|
2858 me.readyState = FileWriter.DONE; |
|
2859 |
|
2860 // Save error |
|
2861 me.error = new FileError(e); |
|
2862 |
|
2863 // If onerror callback |
|
2864 if (typeof me.onerror === "function") { |
|
2865 me.onerror(new ProgressEvent("error", {"target":me})); |
|
2866 } |
|
2867 |
|
2868 // If onwriteend callback |
|
2869 if (typeof me.onwriteend === "function") { |
|
2870 me.onwriteend(new ProgressEvent("writeend", {"target":me})); |
|
2871 } |
|
2872 }, "File", "truncate", [this.fileName, size]); |
|
2873 }; |
|
2874 |
|
2875 module.exports = FileWriter; |
|
2876 |
|
2877 }); |
|
2878 |
|
2879 // file: lib/common/plugin/Flags.js |
|
2880 define("cordova/plugin/Flags", function(require, exports, module) { |
|
2881 /** |
|
2882 * Supplies arguments to methods that lookup or create files and directories. |
|
2883 * |
|
2884 * @param create |
|
2885 * {boolean} file or directory if it doesn't exist |
|
2886 * @param exclusive |
|
2887 * {boolean} used with create; if true the command will fail if |
|
2888 * target path exists |
|
2889 */ |
|
2890 function Flags(create, exclusive) { |
|
2891 this.create = create || false; |
|
2892 this.exclusive = exclusive || false; |
|
2893 } |
|
2894 |
|
2895 module.exports = Flags; |
|
2896 }); |
|
2897 |
|
2898 // file: lib/common/plugin/LocalFileSystem.js |
|
2899 define("cordova/plugin/LocalFileSystem", function(require, exports, module) { |
|
2900 var exec = require('cordova/exec'); |
|
2901 |
|
2902 /** |
|
2903 * Represents a local file system. |
|
2904 */ |
|
2905 var LocalFileSystem = function() { |
|
2906 |
|
2907 }; |
|
2908 |
|
2909 LocalFileSystem.TEMPORARY = 0; //temporary, with no guarantee of persistence |
|
2910 LocalFileSystem.PERSISTENT = 1; //persistent |
|
2911 |
|
2912 module.exports = LocalFileSystem; |
|
2913 }); |
|
2914 |
|
2915 // file: lib/common/plugin/Media.js |
|
2916 define("cordova/plugin/Media", function(require, exports, module) { |
|
2917 var utils = require('cordova/utils'), |
|
2918 exec = require('cordova/exec'); |
|
2919 |
|
2920 var mediaObjects = {}; |
|
2921 |
|
2922 /** |
|
2923 * This class provides access to the device media, interfaces to both sound and video |
|
2924 * |
|
2925 * @constructor |
|
2926 * @param src The file name or url to play |
|
2927 * @param successCallback The callback to be called when the file is done playing or recording. |
|
2928 * successCallback() |
|
2929 * @param errorCallback The callback to be called if there is an error. |
|
2930 * errorCallback(int errorCode) - OPTIONAL |
|
2931 * @param statusCallback The callback to be called when media status has changed. |
|
2932 * statusCallback(int statusCode) - OPTIONAL |
|
2933 */ |
|
2934 var Media = function(src, successCallback, errorCallback, statusCallback) { |
|
2935 |
|
2936 // successCallback optional |
|
2937 if (successCallback && (typeof successCallback !== "function")) { |
|
2938 console.log("Media Error: successCallback is not a function"); |
|
2939 return; |
|
2940 } |
|
2941 |
|
2942 // errorCallback optional |
|
2943 if (errorCallback && (typeof errorCallback !== "function")) { |
|
2944 console.log("Media Error: errorCallback is not a function"); |
|
2945 return; |
|
2946 } |
|
2947 |
|
2948 // statusCallback optional |
|
2949 if (statusCallback && (typeof statusCallback !== "function")) { |
|
2950 console.log("Media Error: statusCallback is not a function"); |
|
2951 return; |
|
2952 } |
|
2953 |
|
2954 this.id = utils.createUUID(); |
|
2955 mediaObjects[this.id] = this; |
|
2956 this.src = src; |
|
2957 this.successCallback = successCallback; |
|
2958 this.errorCallback = errorCallback; |
|
2959 this.statusCallback = statusCallback; |
|
2960 this._duration = -1; |
|
2961 this._position = -1; |
|
2962 exec(null, this.errorCallback, "Media", "create", [this.id, this.src]); |
|
2963 }; |
|
2964 |
|
2965 // Media messages |
|
2966 Media.MEDIA_STATE = 1; |
|
2967 Media.MEDIA_DURATION = 2; |
|
2968 Media.MEDIA_POSITION = 3; |
|
2969 Media.MEDIA_ERROR = 9; |
|
2970 |
|
2971 // Media states |
|
2972 Media.MEDIA_NONE = 0; |
|
2973 Media.MEDIA_STARTING = 1; |
|
2974 Media.MEDIA_RUNNING = 2; |
|
2975 Media.MEDIA_PAUSED = 3; |
|
2976 Media.MEDIA_STOPPED = 4; |
|
2977 Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"]; |
|
2978 |
|
2979 // "static" function to return existing objs. |
|
2980 Media.get = function(id) { |
|
2981 return mediaObjects[id]; |
|
2982 }; |
|
2983 |
|
2984 /** |
|
2985 * Start or resume playing audio file. |
|
2986 */ |
|
2987 Media.prototype.play = function(options) { |
|
2988 exec(null, null, "Media", "startPlayingAudio", [this.id, this.src, options]); |
|
2989 }; |
|
2990 |
|
2991 /** |
|
2992 * Stop playing audio file. |
|
2993 */ |
|
2994 Media.prototype.stop = function() { |
|
2995 var me = this; |
|
2996 exec(function() { |
|
2997 me._position = 0; |
|
2998 me.successCallback(); |
|
2999 }, this.errorCallback, "Media", "stopPlayingAudio", [this.id]); |
|
3000 }; |
|
3001 |
|
3002 /** |
|
3003 * Seek or jump to a new time in the track.. |
|
3004 */ |
|
3005 Media.prototype.seekTo = function(milliseconds) { |
|
3006 var me = this; |
|
3007 exec(function(p) { |
|
3008 me._position = p; |
|
3009 }, this.errorCallback, "Media", "seekToAudio", [this.id, milliseconds]); |
|
3010 }; |
|
3011 |
|
3012 /** |
|
3013 * Pause playing audio file. |
|
3014 */ |
|
3015 Media.prototype.pause = function() { |
|
3016 exec(null, this.errorCallback, "Media", "pausePlayingAudio", [this.id]); |
|
3017 }; |
|
3018 |
|
3019 /** |
|
3020 * Get duration of an audio file. |
|
3021 * The duration is only set for audio that is playing, paused or stopped. |
|
3022 * |
|
3023 * @return duration or -1 if not known. |
|
3024 */ |
|
3025 Media.prototype.getDuration = function() { |
|
3026 return this._duration; |
|
3027 }; |
|
3028 |
|
3029 /** |
|
3030 * Get position of audio. |
|
3031 */ |
|
3032 Media.prototype.getCurrentPosition = function(success, fail) { |
|
3033 var me = this; |
|
3034 exec(function(p) { |
|
3035 me._position = p; |
|
3036 success(p); |
|
3037 }, fail, "Media", "getCurrentPositionAudio", [this.id]); |
|
3038 }; |
|
3039 |
|
3040 /** |
|
3041 * Start recording audio file. |
|
3042 */ |
|
3043 Media.prototype.startRecord = function() { |
|
3044 exec(this.successCallback, this.errorCallback, "Media", "startRecordingAudio", [this.id, this.src]); |
|
3045 }; |
|
3046 |
|
3047 /** |
|
3048 * Stop recording audio file. |
|
3049 */ |
|
3050 Media.prototype.stopRecord = function() { |
|
3051 exec(this.successCallback, this.errorCallback, "Media", "stopRecordingAudio", [this.id]); |
|
3052 }; |
|
3053 |
|
3054 /** |
|
3055 * Release the resources. |
|
3056 */ |
|
3057 Media.prototype.release = function() { |
|
3058 exec(null, this.errorCallback, "Media", "release", [this.id]); |
|
3059 }; |
|
3060 |
|
3061 /** |
|
3062 * Adjust the volume. |
|
3063 */ |
|
3064 Media.prototype.setVolume = function(volume) { |
|
3065 exec(null, null, "Media", "setVolume", [this.id, volume]); |
|
3066 }; |
|
3067 |
|
3068 /** |
|
3069 * Audio has status update. |
|
3070 * PRIVATE |
|
3071 * |
|
3072 * @param id The media object id (string) |
|
3073 * @param status The status code (int) |
|
3074 * @param msg The status message (string) |
|
3075 */ |
|
3076 Media.onStatus = function(id, msg, value) { |
|
3077 var media = mediaObjects[id]; |
|
3078 // If state update |
|
3079 if (msg === Media.MEDIA_STATE) { |
|
3080 if (value === Media.MEDIA_STOPPED) { |
|
3081 if (media.successCallback) { |
|
3082 media.successCallback(); |
|
3083 } |
|
3084 } |
|
3085 if (media.statusCallback) { |
|
3086 media.statusCallback(value); |
|
3087 } |
|
3088 } |
|
3089 else if (msg === Media.MEDIA_DURATION) { |
|
3090 media._duration = value; |
|
3091 } |
|
3092 else if (msg === Media.MEDIA_ERROR) { |
|
3093 if (media.errorCallback) { |
|
3094 // value should be a MediaError object when msg == MEDIA_ERROR |
|
3095 media.errorCallback(value); |
|
3096 } |
|
3097 } |
|
3098 else if (msg === Media.MEDIA_POSITION) { |
|
3099 media._position = value; |
|
3100 } |
|
3101 }; |
|
3102 |
|
3103 module.exports = Media; |
|
3104 }); |
|
3105 |
|
3106 // file: lib/common/plugin/MediaError.js |
|
3107 define("cordova/plugin/MediaError", function(require, exports, module) { |
|
3108 /** |
|
3109 * This class contains information about any Media errors. |
|
3110 * @constructor |
|
3111 */ |
|
3112 var MediaError = function(code, msg) { |
|
3113 this.code = (code !== undefined ? code : null); |
|
3114 this.message = msg || ""; |
|
3115 }; |
|
3116 |
|
3117 MediaError.MEDIA_ERR_NONE_ACTIVE = 0; |
|
3118 MediaError.MEDIA_ERR_ABORTED = 1; |
|
3119 MediaError.MEDIA_ERR_NETWORK = 2; |
|
3120 MediaError.MEDIA_ERR_DECODE = 3; |
|
3121 MediaError.MEDIA_ERR_NONE_SUPPORTED = 4; |
|
3122 |
|
3123 module.exports = MediaError; |
|
3124 }); |
|
3125 |
|
3126 // file: lib/common/plugin/MediaFile.js |
|
3127 define("cordova/plugin/MediaFile", function(require, exports, module) { |
|
3128 var utils = require('cordova/utils'), |
|
3129 exec = require('cordova/exec'), |
|
3130 File = require('cordova/plugin/File'), |
|
3131 CaptureError = require('cordova/plugin/CaptureError'); |
|
3132 /** |
|
3133 * Represents a single file. |
|
3134 * |
|
3135 * name {DOMString} name of the file, without path information |
|
3136 * fullPath {DOMString} the full path of the file, including the name |
|
3137 * type {DOMString} mime type |
|
3138 * lastModifiedDate {Date} last modified date |
|
3139 * size {Number} size of the file in bytes |
|
3140 */ |
|
3141 var MediaFile = function(name, fullPath, type, lastModifiedDate, size){ |
|
3142 MediaFile.__super__.constructor.apply(this, arguments); |
|
3143 }; |
|
3144 |
|
3145 utils.extend(MediaFile, File); |
|
3146 |
|
3147 /** |
|
3148 * Request capture format data for a specific file and type |
|
3149 * |
|
3150 * @param {Function} successCB |
|
3151 * @param {Function} errorCB |
|
3152 */ |
|
3153 MediaFile.prototype.getFormatData = function(successCallback, errorCallback) { |
|
3154 if (typeof this.fullPath === "undefined" || this.fullPath === null) { |
|
3155 errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT)); |
|
3156 } else { |
|
3157 exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]); |
|
3158 } |
|
3159 }; |
|
3160 |
|
3161 // TODO: can we axe this? |
|
3162 /** |
|
3163 * Casts a PluginResult message property (array of objects) to an array of MediaFile objects |
|
3164 * (used in Objective-C and Android) |
|
3165 * |
|
3166 * @param {PluginResult} pluginResult |
|
3167 */ |
|
3168 MediaFile.cast = function(pluginResult) { |
|
3169 var mediaFiles = []; |
|
3170 for (var i=0; i<pluginResult.message.length; i++) { |
|
3171 var mediaFile = new MediaFile(); |
|
3172 mediaFile.name = pluginResult.message[i].name; |
|
3173 mediaFile.fullPath = pluginResult.message[i].fullPath; |
|
3174 mediaFile.type = pluginResult.message[i].type; |
|
3175 mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate; |
|
3176 mediaFile.size = pluginResult.message[i].size; |
|
3177 mediaFiles.push(mediaFile); |
|
3178 } |
|
3179 pluginResult.message = mediaFiles; |
|
3180 return pluginResult; |
|
3181 }; |
|
3182 |
|
3183 module.exports = MediaFile; |
|
3184 |
|
3185 }); |
|
3186 |
|
3187 // file: lib/common/plugin/MediaFileData.js |
|
3188 define("cordova/plugin/MediaFileData", function(require, exports, module) { |
|
3189 /** |
|
3190 * MediaFileData encapsulates format information of a media file. |
|
3191 * |
|
3192 * @param {DOMString} codecs |
|
3193 * @param {long} bitrate |
|
3194 * @param {long} height |
|
3195 * @param {long} width |
|
3196 * @param {float} duration |
|
3197 */ |
|
3198 var MediaFileData = function(codecs, bitrate, height, width, duration){ |
|
3199 this.codecs = codecs || null; |
|
3200 this.bitrate = bitrate || 0; |
|
3201 this.height = height || 0; |
|
3202 this.width = width || 0; |
|
3203 this.duration = duration || 0; |
|
3204 }; |
|
3205 |
|
3206 module.exports = MediaFileData; |
|
3207 }); |
|
3208 |
|
3209 // file: lib/common/plugin/Metadata.js |
|
3210 define("cordova/plugin/Metadata", function(require, exports, module) { |
|
3211 /** |
|
3212 * Information about the state of the file or directory |
|
3213 * |
|
3214 * {Date} modificationTime (readonly) |
|
3215 */ |
|
3216 var Metadata = function(time) { |
|
3217 this.modificationTime = (typeof time != 'undefined'?new Date(time):null); |
|
3218 }; |
|
3219 |
|
3220 module.exports = Metadata; |
|
3221 }); |
|
3222 |
|
3223 // file: lib/common/plugin/Position.js |
|
3224 define("cordova/plugin/Position", function(require, exports, module) { |
|
3225 var Coordinates = require('cordova/plugin/Coordinates'); |
|
3226 |
|
3227 var Position = function(coords, timestamp) { |
|
3228 if (coords) { |
|
3229 this.coords = new Coordinates(coords.latitude, coords.longitude, coords.altitude, coords.accuracy, coords.heading, coords.velocity, coords.altitudeAccuracy); |
|
3230 } else { |
|
3231 this.coords = new Coordinates(); |
|
3232 } |
|
3233 this.timestamp = (timestamp !== undefined) ? timestamp : new Date(); |
|
3234 }; |
|
3235 |
|
3236 module.exports = Position; |
|
3237 |
|
3238 }); |
|
3239 |
|
3240 // file: lib/common/plugin/PositionError.js |
|
3241 define("cordova/plugin/PositionError", function(require, exports, module) { |
|
3242 /** |
|
3243 * Position error object |
|
3244 * |
|
3245 * @constructor |
|
3246 * @param code |
|
3247 * @param message |
|
3248 */ |
|
3249 var PositionError = function(code, message) { |
|
3250 this.code = code || null; |
|
3251 this.message = message || ''; |
|
3252 }; |
|
3253 |
|
3254 PositionError.PERMISSION_DENIED = 1; |
|
3255 PositionError.POSITION_UNAVAILABLE = 2; |
|
3256 PositionError.TIMEOUT = 3; |
|
3257 |
|
3258 module.exports = PositionError; |
|
3259 }); |
|
3260 |
|
3261 // file: lib/common/plugin/ProgressEvent.js |
|
3262 define("cordova/plugin/ProgressEvent", function(require, exports, module) { |
|
3263 // If ProgressEvent exists in global context, use it already, otherwise use our own polyfill |
|
3264 // Feature test: See if we can instantiate a native ProgressEvent; |
|
3265 // if so, use that approach, |
|
3266 // otherwise fill-in with our own implementation. |
|
3267 // |
|
3268 // 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. |
|
3269 var ProgressEvent = (function() { |
|
3270 /* |
|
3271 var createEvent = function(data) { |
|
3272 var event = document.createEvent('Events'); |
|
3273 event.initEvent('ProgressEvent', false, false); |
|
3274 if (data) { |
|
3275 for (var i in data) { |
|
3276 if (data.hasOwnProperty(i)) { |
|
3277 event[i] = data[i]; |
|
3278 } |
|
3279 } |
|
3280 if (data.target) { |
|
3281 // TODO: cannot call <some_custom_object>.dispatchEvent |
|
3282 // need to first figure out how to implement EventTarget |
|
3283 } |
|
3284 } |
|
3285 return event; |
|
3286 }; |
|
3287 try { |
|
3288 var ev = createEvent({type:"abort",target:document}); |
|
3289 return function ProgressEvent(type, data) { |
|
3290 data.type = type; |
|
3291 return createEvent(data); |
|
3292 }; |
|
3293 } catch(e){ |
|
3294 */ |
|
3295 return function ProgressEvent(type, dict) { |
|
3296 this.type = type; |
|
3297 this.bubbles = false; |
|
3298 this.cancelBubble = false; |
|
3299 this.cancelable = false; |
|
3300 this.lengthComputable = false; |
|
3301 this.loaded = dict && dict.loaded ? dict.loaded : 0; |
|
3302 this.total = dict && dict.total ? dict.total : 0; |
|
3303 this.target = dict && dict.target ? dict.target : null; |
|
3304 }; |
|
3305 //} |
|
3306 })(); |
|
3307 |
|
3308 module.exports = ProgressEvent; |
|
3309 }); |
|
3310 |
|
3311 // file: lib/common/plugin/accelerometer.js |
|
3312 define("cordova/plugin/accelerometer", function(require, exports, module) { |
|
3313 /** |
|
3314 * This class provides access to device accelerometer data. |
|
3315 * @constructor |
|
3316 */ |
|
3317 var utils = require("cordova/utils"), |
|
3318 exec = require("cordova/exec"), |
|
3319 Acceleration = require('cordova/plugin/Acceleration'); |
|
3320 |
|
3321 // Is the accel sensor running? |
|
3322 var running = false; |
|
3323 |
|
3324 // Keeps reference to watchAcceleration calls. |
|
3325 var timers = {}; |
|
3326 |
|
3327 // Array of listeners; used to keep track of when we should call start and stop. |
|
3328 var listeners = []; |
|
3329 |
|
3330 // Last returned acceleration object from native |
|
3331 var accel = null; |
|
3332 |
|
3333 // Tells native to start. |
|
3334 function start() { |
|
3335 exec(function(a) { |
|
3336 var tempListeners = listeners.slice(0); |
|
3337 accel = new Acceleration(a.x, a.y, a.z, a.timestamp); |
|
3338 for (var i = 0, l = tempListeners.length; i < l; i++) { |
|
3339 tempListeners[i].win(accel); |
|
3340 } |
|
3341 }, function(e) { |
|
3342 var tempListeners = listeners.slice(0); |
|
3343 for (var i = 0, l = tempListeners.length; i < l; i++) { |
|
3344 tempListeners[i].fail(e); |
|
3345 } |
|
3346 }, "Accelerometer", "start", []); |
|
3347 running = true; |
|
3348 } |
|
3349 |
|
3350 // Tells native to stop. |
|
3351 function stop() { |
|
3352 exec(null, null, "Accelerometer", "stop", []); |
|
3353 running = false; |
|
3354 } |
|
3355 |
|
3356 // Adds a callback pair to the listeners array |
|
3357 function createCallbackPair(win, fail) { |
|
3358 return {win:win, fail:fail}; |
|
3359 } |
|
3360 |
|
3361 // Removes a win/fail listener pair from the listeners array |
|
3362 function removeListeners(l) { |
|
3363 var idx = listeners.indexOf(l); |
|
3364 if (idx > -1) { |
|
3365 listeners.splice(idx, 1); |
|
3366 if (listeners.length === 0) { |
|
3367 stop(); |
|
3368 } |
|
3369 } |
|
3370 } |
|
3371 |
|
3372 var accelerometer = { |
|
3373 /** |
|
3374 * Asynchronously aquires the current acceleration. |
|
3375 * |
|
3376 * @param {Function} successCallback The function to call when the acceleration data is available |
|
3377 * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL) |
|
3378 * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL) |
|
3379 */ |
|
3380 getCurrentAcceleration: function(successCallback, errorCallback, options) { |
|
3381 // successCallback required |
|
3382 if (typeof successCallback !== "function") { |
|
3383 throw "getCurrentAcceleration must be called with at least a success callback function as first parameter."; |
|
3384 } |
|
3385 |
|
3386 var p; |
|
3387 var win = function(a) { |
|
3388 removeListeners(p); |
|
3389 successCallback(a); |
|
3390 }; |
|
3391 var fail = function(e) { |
|
3392 removeListeners(p); |
|
3393 errorCallback(e); |
|
3394 }; |
|
3395 |
|
3396 p = createCallbackPair(win, fail); |
|
3397 listeners.push(p); |
|
3398 |
|
3399 if (!running) { |
|
3400 start(); |
|
3401 } |
|
3402 }, |
|
3403 |
|
3404 /** |
|
3405 * Asynchronously aquires the acceleration repeatedly at a given interval. |
|
3406 * |
|
3407 * @param {Function} successCallback The function to call each time the acceleration data is available |
|
3408 * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL) |
|
3409 * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL) |
|
3410 * @return String The watch id that must be passed to #clearWatch to stop watching. |
|
3411 */ |
|
3412 watchAcceleration: function(successCallback, errorCallback, options) { |
|
3413 // Default interval (10 sec) |
|
3414 var frequency = (options && options.frequency && typeof options.frequency == 'number') ? options.frequency : 10000; |
|
3415 |
|
3416 // successCallback required |
|
3417 if (typeof successCallback !== "function") { |
|
3418 throw "watchAcceleration must be called with at least a success callback function as first parameter."; |
|
3419 } |
|
3420 |
|
3421 // Keep reference to watch id, and report accel readings as often as defined in frequency |
|
3422 var id = utils.createUUID(); |
|
3423 |
|
3424 var p = createCallbackPair(function(){}, function(e) { |
|
3425 removeListeners(p); |
|
3426 errorCallback(e); |
|
3427 }); |
|
3428 listeners.push(p); |
|
3429 |
|
3430 timers[id] = { |
|
3431 timer:window.setInterval(function() { |
|
3432 if (accel) { |
|
3433 successCallback(accel); |
|
3434 } |
|
3435 }, frequency), |
|
3436 listeners:p |
|
3437 }; |
|
3438 |
|
3439 if (running) { |
|
3440 // If we're already running then immediately invoke the success callback |
|
3441 // but only if we have retreived a value, sample code does not check for null ... |
|
3442 if(accel) { |
|
3443 successCallback(accel); |
|
3444 } |
|
3445 } else { |
|
3446 start(); |
|
3447 } |
|
3448 |
|
3449 return id; |
|
3450 }, |
|
3451 |
|
3452 /** |
|
3453 * Clears the specified accelerometer watch. |
|
3454 * |
|
3455 * @param {String} id The id of the watch returned from #watchAcceleration. |
|
3456 */ |
|
3457 clearWatch: function(id) { |
|
3458 // Stop javascript timer & remove from timer list |
|
3459 if (id && timers[id]) { |
|
3460 window.clearInterval(timers[id].timer); |
|
3461 removeListeners(timers[id].listeners); |
|
3462 delete timers[id]; |
|
3463 } |
|
3464 } |
|
3465 }; |
|
3466 |
|
3467 module.exports = accelerometer; |
|
3468 |
|
3469 }); |
|
3470 |
|
3471 // file: lib/common/plugin/battery.js |
|
3472 define("cordova/plugin/battery", function(require, exports, module) { |
|
3473 /** |
|
3474 * This class contains information about the current battery status. |
|
3475 * @constructor |
|
3476 */ |
|
3477 var cordova = require('cordova'), |
|
3478 exec = require('cordova/exec'); |
|
3479 |
|
3480 function handlers() { |
|
3481 return battery.channels.batterystatus.numHandlers + |
|
3482 battery.channels.batterylow.numHandlers + |
|
3483 battery.channels.batterycritical.numHandlers; |
|
3484 } |
|
3485 |
|
3486 var Battery = function() { |
|
3487 this._level = null; |
|
3488 this._isPlugged = null; |
|
3489 // Create new event handlers on the window (returns a channel instance) |
|
3490 var subscriptionEvents = { |
|
3491 onSubscribe:this.onSubscribe, |
|
3492 onUnsubscribe:this.onUnsubscribe |
|
3493 }; |
|
3494 this.channels = { |
|
3495 batterystatus:cordova.addWindowEventHandler("batterystatus", subscriptionEvents), |
|
3496 batterylow:cordova.addWindowEventHandler("batterylow", subscriptionEvents), |
|
3497 batterycritical:cordova.addWindowEventHandler("batterycritical", subscriptionEvents) |
|
3498 }; |
|
3499 }; |
|
3500 /** |
|
3501 * Event handlers for when callbacks get registered for the battery. |
|
3502 * Keep track of how many handlers we have so we can start and stop the native battery listener |
|
3503 * appropriately (and hopefully save on battery life!). |
|
3504 */ |
|
3505 Battery.prototype.onSubscribe = function() { |
|
3506 var me = battery; |
|
3507 // If we just registered the first handler, make sure native listener is started. |
|
3508 if (handlers() === 1) { |
|
3509 exec(me._status, me._error, "Battery", "start", []); |
|
3510 } |
|
3511 }; |
|
3512 |
|
3513 Battery.prototype.onUnsubscribe = function() { |
|
3514 var me = battery; |
|
3515 |
|
3516 // If we just unregistered the last handler, make sure native listener is stopped. |
|
3517 if (handlers() === 0) { |
|
3518 exec(null, null, "Battery", "stop", []); |
|
3519 } |
|
3520 }; |
|
3521 |
|
3522 /** |
|
3523 * Callback for battery status |
|
3524 * |
|
3525 * @param {Object} info keys: level, isPlugged |
|
3526 */ |
|
3527 Battery.prototype._status = function(info) { |
|
3528 if (info) { |
|
3529 var me = battery; |
|
3530 var level = info.level; |
|
3531 if (me._level !== level || me._isPlugged !== info.isPlugged) { |
|
3532 // Fire batterystatus event |
|
3533 cordova.fireWindowEvent("batterystatus", info); |
|
3534 |
|
3535 // Fire low battery event |
|
3536 if (level === 20 || level === 5) { |
|
3537 if (level === 20) { |
|
3538 cordova.fireWindowEvent("batterylow", info); |
|
3539 } |
|
3540 else { |
|
3541 cordova.fireWindowEvent("batterycritical", info); |
|
3542 } |
|
3543 } |
|
3544 } |
|
3545 me._level = level; |
|
3546 me._isPlugged = info.isPlugged; |
|
3547 } |
|
3548 }; |
|
3549 |
|
3550 /** |
|
3551 * Error callback for battery start |
|
3552 */ |
|
3553 Battery.prototype._error = function(e) { |
|
3554 console.log("Error initializing Battery: " + e); |
|
3555 }; |
|
3556 |
|
3557 var battery = new Battery(); |
|
3558 |
|
3559 module.exports = battery; |
|
3560 }); |
|
3561 |
|
3562 // file: lib/common/plugin/capture.js |
|
3563 define("cordova/plugin/capture", function(require, exports, module) { |
|
3564 var exec = require('cordova/exec'), |
|
3565 MediaFile = require('cordova/plugin/MediaFile'); |
|
3566 |
|
3567 /** |
|
3568 * Launches a capture of different types. |
|
3569 * |
|
3570 * @param (DOMString} type |
|
3571 * @param {Function} successCB |
|
3572 * @param {Function} errorCB |
|
3573 * @param {CaptureVideoOptions} options |
|
3574 */ |
|
3575 function _capture(type, successCallback, errorCallback, options) { |
|
3576 var win = function(pluginResult) { |
|
3577 var mediaFiles = []; |
|
3578 var i; |
|
3579 for (i = 0; i < pluginResult.length; i++) { |
|
3580 var mediaFile = new MediaFile(); |
|
3581 mediaFile.name = pluginResult[i].name; |
|
3582 mediaFile.fullPath = pluginResult[i].fullPath; |
|
3583 mediaFile.type = pluginResult[i].type; |
|
3584 mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate; |
|
3585 mediaFile.size = pluginResult[i].size; |
|
3586 mediaFiles.push(mediaFile); |
|
3587 } |
|
3588 successCallback(mediaFiles); |
|
3589 }; |
|
3590 exec(win, errorCallback, "Capture", type, [options]); |
|
3591 } |
|
3592 /** |
|
3593 * The Capture interface exposes an interface to the camera and microphone of the hosting device. |
|
3594 */ |
|
3595 function Capture() { |
|
3596 this.supportedAudioModes = []; |
|
3597 this.supportedImageModes = []; |
|
3598 this.supportedVideoModes = []; |
|
3599 } |
|
3600 |
|
3601 /** |
|
3602 * Launch audio recorder application for recording audio clip(s). |
|
3603 * |
|
3604 * @param {Function} successCB |
|
3605 * @param {Function} errorCB |
|
3606 * @param {CaptureAudioOptions} options |
|
3607 */ |
|
3608 Capture.prototype.captureAudio = function(successCallback, errorCallback, options){ |
|
3609 _capture("captureAudio", successCallback, errorCallback, options); |
|
3610 }; |
|
3611 |
|
3612 /** |
|
3613 * Launch camera application for taking image(s). |
|
3614 * |
|
3615 * @param {Function} successCB |
|
3616 * @param {Function} errorCB |
|
3617 * @param {CaptureImageOptions} options |
|
3618 */ |
|
3619 Capture.prototype.captureImage = function(successCallback, errorCallback, options){ |
|
3620 _capture("captureImage", successCallback, errorCallback, options); |
|
3621 }; |
|
3622 |
|
3623 /** |
|
3624 * Launch device camera application for recording video(s). |
|
3625 * |
|
3626 * @param {Function} successCB |
|
3627 * @param {Function} errorCB |
|
3628 * @param {CaptureVideoOptions} options |
|
3629 */ |
|
3630 Capture.prototype.captureVideo = function(successCallback, errorCallback, options){ |
|
3631 _capture("captureVideo", successCallback, errorCallback, options); |
|
3632 }; |
|
3633 |
|
3634 |
|
3635 module.exports = new Capture(); |
|
3636 |
|
3637 }); |
|
3638 |
|
3639 // file: lib/common/plugin/compass.js |
|
3640 define("cordova/plugin/compass", function(require, exports, module) { |
|
3641 var exec = require('cordova/exec'), |
|
3642 utils = require('cordova/utils'), |
|
3643 CompassHeading = require('cordova/plugin/CompassHeading'), |
|
3644 CompassError = require('cordova/plugin/CompassError'), |
|
3645 timers = {}, |
|
3646 compass = { |
|
3647 /** |
|
3648 * Asynchronously acquires the current heading. |
|
3649 * @param {Function} successCallback The function to call when the heading |
|
3650 * data is available |
|
3651 * @param {Function} errorCallback The function to call when there is an error |
|
3652 * getting the heading data. |
|
3653 * @param {CompassOptions} options The options for getting the heading data (not used). |
|
3654 */ |
|
3655 getCurrentHeading:function(successCallback, errorCallback, options) { |
|
3656 // successCallback required |
|
3657 if (typeof successCallback !== "function") { |
|
3658 console.log("Compass Error: successCallback is not a function"); |
|
3659 return; |
|
3660 } |
|
3661 |
|
3662 // errorCallback optional |
|
3663 if (errorCallback && (typeof errorCallback !== "function")) { |
|
3664 console.log("Compass Error: errorCallback is not a function"); |
|
3665 return; |
|
3666 } |
|
3667 |
|
3668 var win = function(result) { |
|
3669 var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp); |
|
3670 successCallback(ch); |
|
3671 }; |
|
3672 var fail = function(code) { |
|
3673 var ce = new CompassError(code); |
|
3674 errorCallback(ce); |
|
3675 }; |
|
3676 |
|
3677 // Get heading |
|
3678 exec(win, fail, "Compass", "getHeading", [options]); |
|
3679 }, |
|
3680 |
|
3681 /** |
|
3682 * Asynchronously acquires the heading repeatedly at a given interval. |
|
3683 * @param {Function} successCallback The function to call each time the heading |
|
3684 * data is available |
|
3685 * @param {Function} errorCallback The function to call when there is an error |
|
3686 * getting the heading data. |
|
3687 * @param {HeadingOptions} options The options for getting the heading data |
|
3688 * such as timeout and the frequency of the watch. For iOS, filter parameter |
|
3689 * specifies to watch via a distance filter rather than time. |
|
3690 */ |
|
3691 watchHeading:function(successCallback, errorCallback, options) { |
|
3692 // Default interval (100 msec) |
|
3693 var frequency = (options !== undefined && options.frequency !== undefined) ? options.frequency : 100; |
|
3694 var filter = (options !== undefined && options.filter !== undefined) ? options.filter : 0; |
|
3695 |
|
3696 // successCallback required |
|
3697 if (typeof successCallback !== "function") { |
|
3698 console.log("Compass Error: successCallback is not a function"); |
|
3699 return; |
|
3700 } |
|
3701 |
|
3702 // errorCallback optional |
|
3703 if (errorCallback && (typeof errorCallback !== "function")) { |
|
3704 console.log("Compass Error: errorCallback is not a function"); |
|
3705 return; |
|
3706 } |
|
3707 |
|
3708 var id = utils.createUUID(); |
|
3709 if (filter > 0) { |
|
3710 // is an iOS request for watch by filter, no timer needed |
|
3711 timers[id] = "iOS"; |
|
3712 compass.getCurrentHeading(successCallback, errorCallback, options); |
|
3713 } else { |
|
3714 // Start watch timer to get headings |
|
3715 timers[id] = window.setInterval(function() { |
|
3716 compass.getCurrentHeading(successCallback, errorCallback); |
|
3717 }, frequency); |
|
3718 } |
|
3719 |
|
3720 return id; |
|
3721 }, |
|
3722 |
|
3723 /** |
|
3724 * Clears the specified heading watch. |
|
3725 * @param {String} watchId The ID of the watch returned from #watchHeading. |
|
3726 */ |
|
3727 clearWatch:function(id) { |
|
3728 // Stop javascript timer & remove from timer list |
|
3729 if (id && timers[id]) { |
|
3730 if (timers[id] != "iOS") { |
|
3731 clearInterval(timers[id]); |
|
3732 } else { |
|
3733 // is iOS watch by filter so call into device to stop |
|
3734 exec(null, null, "Compass", "stopHeading", []); |
|
3735 } |
|
3736 delete timers[id]; |
|
3737 } |
|
3738 } |
|
3739 }; |
|
3740 |
|
3741 module.exports = compass; |
|
3742 }); |
|
3743 |
|
3744 // file: lib/common/plugin/console-via-logger.js |
|
3745 define("cordova/plugin/console-via-logger", function(require, exports, module) { |
|
3746 //------------------------------------------------------------------------------ |
|
3747 |
|
3748 var logger = require("cordova/plugin/logger"); |
|
3749 var utils = require("cordova/utils"); |
|
3750 |
|
3751 //------------------------------------------------------------------------------ |
|
3752 // object that we're exporting |
|
3753 //------------------------------------------------------------------------------ |
|
3754 var console = module.exports; |
|
3755 |
|
3756 //------------------------------------------------------------------------------ |
|
3757 // copy of the original console object |
|
3758 //------------------------------------------------------------------------------ |
|
3759 var WinConsole = window.console; |
|
3760 |
|
3761 //------------------------------------------------------------------------------ |
|
3762 // whether to use the logger |
|
3763 //------------------------------------------------------------------------------ |
|
3764 var UseLogger = false; |
|
3765 |
|
3766 //------------------------------------------------------------------------------ |
|
3767 // Timers |
|
3768 //------------------------------------------------------------------------------ |
|
3769 var Timers = {}; |
|
3770 |
|
3771 //------------------------------------------------------------------------------ |
|
3772 // used for unimplemented methods |
|
3773 //------------------------------------------------------------------------------ |
|
3774 function noop() {} |
|
3775 |
|
3776 //------------------------------------------------------------------------------ |
|
3777 // used for unimplemented methods |
|
3778 //------------------------------------------------------------------------------ |
|
3779 console.useLogger = function (value) { |
|
3780 if (arguments.length) UseLogger = !!value; |
|
3781 |
|
3782 if (UseLogger) { |
|
3783 if (logger.useConsole()) { |
|
3784 throw new Error("console and logger are too intertwingly"); |
|
3785 } |
|
3786 } |
|
3787 |
|
3788 return UseLogger; |
|
3789 }; |
|
3790 |
|
3791 //------------------------------------------------------------------------------ |
|
3792 console.log = function() { |
|
3793 if (logger.useConsole()) return; |
|
3794 logger.log.apply(logger, [].slice.call(arguments)); |
|
3795 }; |
|
3796 |
|
3797 //------------------------------------------------------------------------------ |
|
3798 console.error = function() { |
|
3799 if (logger.useConsole()) return; |
|
3800 logger.error.apply(logger, [].slice.call(arguments)); |
|
3801 }; |
|
3802 |
|
3803 //------------------------------------------------------------------------------ |
|
3804 console.warn = function() { |
|
3805 if (logger.useConsole()) return; |
|
3806 logger.warn.apply(logger, [].slice.call(arguments)); |
|
3807 }; |
|
3808 |
|
3809 //------------------------------------------------------------------------------ |
|
3810 console.info = function() { |
|
3811 if (logger.useConsole()) return; |
|
3812 logger.info.apply(logger, [].slice.call(arguments)); |
|
3813 }; |
|
3814 |
|
3815 //------------------------------------------------------------------------------ |
|
3816 console.debug = function() { |
|
3817 if (logger.useConsole()) return; |
|
3818 logger.debug.apply(logger, [].slice.call(arguments)); |
|
3819 }; |
|
3820 |
|
3821 //------------------------------------------------------------------------------ |
|
3822 console.assert = function(expression) { |
|
3823 if (expression) return; |
|
3824 |
|
3825 var message = utils.vformat(arguments[1], [].slice.call(arguments, 2)); |
|
3826 console.log("ASSERT: " + message); |
|
3827 }; |
|
3828 |
|
3829 //------------------------------------------------------------------------------ |
|
3830 console.clear = function() {}; |
|
3831 |
|
3832 //------------------------------------------------------------------------------ |
|
3833 console.dir = function(object) { |
|
3834 console.log("%o", object); |
|
3835 }; |
|
3836 |
|
3837 //------------------------------------------------------------------------------ |
|
3838 console.dirxml = function(node) { |
|
3839 console.log(node.innerHTML); |
|
3840 }; |
|
3841 |
|
3842 //------------------------------------------------------------------------------ |
|
3843 console.trace = noop; |
|
3844 |
|
3845 //------------------------------------------------------------------------------ |
|
3846 console.group = console.log; |
|
3847 |
|
3848 //------------------------------------------------------------------------------ |
|
3849 console.groupCollapsed = console.log; |
|
3850 |
|
3851 //------------------------------------------------------------------------------ |
|
3852 console.groupEnd = noop; |
|
3853 |
|
3854 //------------------------------------------------------------------------------ |
|
3855 console.time = function(name) { |
|
3856 Timers[name] = new Date().valueOf(); |
|
3857 }; |
|
3858 |
|
3859 //------------------------------------------------------------------------------ |
|
3860 console.timeEnd = function(name) { |
|
3861 var timeStart = Timers[name]; |
|
3862 if (!timeStart) { |
|
3863 console.warn("unknown timer: " + name); |
|
3864 return; |
|
3865 } |
|
3866 |
|
3867 var timeElapsed = new Date().valueOf() - timeStart; |
|
3868 console.log(name + ": " + timeElapsed + "ms"); |
|
3869 }; |
|
3870 |
|
3871 //------------------------------------------------------------------------------ |
|
3872 console.timeStamp = noop; |
|
3873 |
|
3874 //------------------------------------------------------------------------------ |
|
3875 console.profile = noop; |
|
3876 |
|
3877 //------------------------------------------------------------------------------ |
|
3878 console.profileEnd = noop; |
|
3879 |
|
3880 //------------------------------------------------------------------------------ |
|
3881 console.count = noop; |
|
3882 |
|
3883 //------------------------------------------------------------------------------ |
|
3884 console.exception = console.log; |
|
3885 |
|
3886 //------------------------------------------------------------------------------ |
|
3887 console.table = function(data, columns) { |
|
3888 console.log("%o", data); |
|
3889 }; |
|
3890 |
|
3891 //------------------------------------------------------------------------------ |
|
3892 // return a new function that calls both functions passed as args |
|
3893 //------------------------------------------------------------------------------ |
|
3894 function wrapperedOrigCall(orgFunc, newFunc) { |
|
3895 return function() { |
|
3896 var args = [].slice.call(arguments); |
|
3897 try { orgFunc.apply(WinConsole, args); } catch (e) {} |
|
3898 try { newFunc.apply(console, args); } catch (e) {} |
|
3899 }; |
|
3900 } |
|
3901 |
|
3902 //------------------------------------------------------------------------------ |
|
3903 // For every function that exists in the original console object, that |
|
3904 // also exists in the new console object, wrap the new console method |
|
3905 // with one that calls both |
|
3906 //------------------------------------------------------------------------------ |
|
3907 for (var key in console) { |
|
3908 if (typeof WinConsole[key] == "function") { |
|
3909 console[key] = wrapperedOrigCall(WinConsole[key], console[key]); |
|
3910 } |
|
3911 } |
|
3912 |
|
3913 }); |
|
3914 |
|
3915 // file: lib/common/plugin/contacts.js |
|
3916 define("cordova/plugin/contacts", function(require, exports, module) { |
|
3917 var exec = require('cordova/exec'), |
|
3918 ContactError = require('cordova/plugin/ContactError'), |
|
3919 utils = require('cordova/utils'), |
|
3920 Contact = require('cordova/plugin/Contact'); |
|
3921 |
|
3922 /** |
|
3923 * Represents a group of Contacts. |
|
3924 * @constructor |
|
3925 */ |
|
3926 var contacts = { |
|
3927 /** |
|
3928 * Returns an array of Contacts matching the search criteria. |
|
3929 * @param fields that should be searched |
|
3930 * @param successCB success callback |
|
3931 * @param errorCB error callback |
|
3932 * @param {ContactFindOptions} options that can be applied to contact searching |
|
3933 * @return array of Contacts matching search criteria |
|
3934 */ |
|
3935 find:function(fields, successCB, errorCB, options) { |
|
3936 if (!successCB) { |
|
3937 throw new TypeError("You must specify a success callback for the find command."); |
|
3938 } |
|
3939 if (!fields || (utils.isArray(fields) && fields.length === 0)) { |
|
3940 if (typeof errorCB === "function") { |
|
3941 errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR)); |
|
3942 } |
|
3943 } else { |
|
3944 var win = function(result) { |
|
3945 var cs = []; |
|
3946 for (var i = 0, l = result.length; i < l; i++) { |
|
3947 cs.push(contacts.create(result[i])); |
|
3948 } |
|
3949 successCB(cs); |
|
3950 }; |
|
3951 exec(win, errorCB, "Contacts", "search", [fields, options]); |
|
3952 } |
|
3953 }, |
|
3954 |
|
3955 /** |
|
3956 * This function creates a new contact, but it does not persist the contact |
|
3957 * to device storage. To persist the contact to device storage, invoke |
|
3958 * contact.save(). |
|
3959 * @param properties an object who's properties will be examined to create a new Contact |
|
3960 * @returns new Contact object |
|
3961 */ |
|
3962 create:function(properties) { |
|
3963 var i; |
|
3964 var contact = new Contact(); |
|
3965 for (i in properties) { |
|
3966 if (typeof contact[i] !== 'undefined' && properties.hasOwnProperty(i)) { |
|
3967 contact[i] = properties[i]; |
|
3968 } |
|
3969 } |
|
3970 return contact; |
|
3971 } |
|
3972 }; |
|
3973 |
|
3974 module.exports = contacts; |
|
3975 |
|
3976 }); |
|
3977 |
|
3978 // file: lib/common/plugin/device.js |
|
3979 define("cordova/plugin/device", function(require, exports, module) { |
|
3980 var channel = require('cordova/channel'), |
|
3981 utils = require('cordova/utils'), |
|
3982 exec = require('cordova/exec'); |
|
3983 |
|
3984 // Tell cordova channel to wait on the CordovaInfoReady event |
|
3985 channel.waitForInitialization('onCordovaInfoReady'); |
|
3986 |
|
3987 /** |
|
3988 * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the |
|
3989 * phone, etc. |
|
3990 * @constructor |
|
3991 */ |
|
3992 function Device() { |
|
3993 this.available = false; |
|
3994 this.platform = null; |
|
3995 this.version = null; |
|
3996 this.name = null; |
|
3997 this.uuid = null; |
|
3998 this.cordova = null; |
|
3999 |
|
4000 var me = this; |
|
4001 |
|
4002 channel.onCordovaReady.subscribeOnce(function() { |
|
4003 me.getInfo(function(info) { |
|
4004 me.available = true; |
|
4005 me.platform = info.platform; |
|
4006 me.version = info.version; |
|
4007 me.name = info.name; |
|
4008 me.uuid = info.uuid; |
|
4009 me.cordova = info.cordova; |
|
4010 channel.onCordovaInfoReady.fire(); |
|
4011 },function(e) { |
|
4012 me.available = false; |
|
4013 utils.alert("[ERROR] Error initializing Cordova: " + e); |
|
4014 }); |
|
4015 }); |
|
4016 } |
|
4017 |
|
4018 /** |
|
4019 * Get device info |
|
4020 * |
|
4021 * @param {Function} successCallback The function to call when the heading data is available |
|
4022 * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) |
|
4023 */ |
|
4024 Device.prototype.getInfo = function(successCallback, errorCallback) { |
|
4025 |
|
4026 // successCallback required |
|
4027 if (typeof successCallback !== "function") { |
|
4028 console.log("Device Error: successCallback is not a function"); |
|
4029 return; |
|
4030 } |
|
4031 |
|
4032 // errorCallback optional |
|
4033 if (errorCallback && (typeof errorCallback !== "function")) { |
|
4034 console.log("Device Error: errorCallback is not a function"); |
|
4035 return; |
|
4036 } |
|
4037 |
|
4038 // Get info |
|
4039 exec(successCallback, errorCallback, "Device", "getDeviceInfo", []); |
|
4040 }; |
|
4041 |
|
4042 module.exports = new Device(); |
|
4043 |
|
4044 }); |
|
4045 |
|
4046 // file: lib/common/plugin/geolocation.js |
|
4047 define("cordova/plugin/geolocation", function(require, exports, module) { |
|
4048 var utils = require('cordova/utils'), |
|
4049 exec = require('cordova/exec'), |
|
4050 PositionError = require('cordova/plugin/PositionError'), |
|
4051 Position = require('cordova/plugin/Position'); |
|
4052 |
|
4053 var timers = {}; // list of timers in use |
|
4054 |
|
4055 // Returns default params, overrides if provided with values |
|
4056 function parseParameters(options) { |
|
4057 var opt = { |
|
4058 maximumAge: 0, |
|
4059 enableHighAccuracy: false, |
|
4060 timeout: Infinity |
|
4061 }; |
|
4062 |
|
4063 if (options) { |
|
4064 if (options.maximumAge !== undefined && !isNaN(options.maximumAge) && options.maximumAge > 0) { |
|
4065 opt.maximumAge = options.maximumAge; |
|
4066 } |
|
4067 if (options.enableHighAccuracy !== undefined) { |
|
4068 opt.enableHighAccuracy = options.enableHighAccuracy; |
|
4069 } |
|
4070 if (options.timeout !== undefined && !isNaN(options.timeout)) { |
|
4071 if (options.timeout < 0) { |
|
4072 opt.timeout = 0; |
|
4073 } else { |
|
4074 opt.timeout = options.timeout; |
|
4075 } |
|
4076 } |
|
4077 } |
|
4078 |
|
4079 return opt; |
|
4080 } |
|
4081 |
|
4082 // Returns a timeout failure, closed over a specified timeout value and error callback. |
|
4083 function createTimeout(errorCallback, timeout) { |
|
4084 var t = setTimeout(function() { |
|
4085 clearTimeout(t); |
|
4086 t = null; |
|
4087 errorCallback({ |
|
4088 code:PositionError.TIMEOUT, |
|
4089 message:"Position retrieval timed out." |
|
4090 }); |
|
4091 }, timeout); |
|
4092 return t; |
|
4093 } |
|
4094 |
|
4095 var geolocation = { |
|
4096 lastPosition:null, // reference to last known (cached) position returned |
|
4097 /** |
|
4098 * Asynchronously aquires the current position. |
|
4099 * |
|
4100 * @param {Function} successCallback The function to call when the position data is available |
|
4101 * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL) |
|
4102 * @param {PositionOptions} options The options for getting the position data. (OPTIONAL) |
|
4103 */ |
|
4104 getCurrentPosition:function(successCallback, errorCallback, options) { |
|
4105 if (arguments.length === 0) { |
|
4106 throw new Error("getCurrentPosition must be called with at least one argument."); |
|
4107 } |
|
4108 options = parseParameters(options); |
|
4109 |
|
4110 // Timer var that will fire an error callback if no position is retrieved from native |
|
4111 // before the "timeout" param provided expires |
|
4112 var timeoutTimer = null; |
|
4113 |
|
4114 var win = function(p) { |
|
4115 clearTimeout(timeoutTimer); |
|
4116 if (!timeoutTimer) { |
|
4117 // Timeout already happened, or native fired error callback for |
|
4118 // this geo request. |
|
4119 // Don't continue with success callback. |
|
4120 return; |
|
4121 } |
|
4122 var pos = new Position( |
|
4123 { |
|
4124 latitude:p.latitude, |
|
4125 longitude:p.longitude, |
|
4126 altitude:p.altitude, |
|
4127 accuracy:p.accuracy, |
|
4128 heading:p.heading, |
|
4129 velocity:p.velocity, |
|
4130 altitudeAccuracy:p.altitudeAccuracy |
|
4131 }, |
|
4132 (p.timestamp === undefined ? new Date() : ((p.timestamp instanceof Date) ? p.timestamp : new Date(p.timestamp))) |
|
4133 ); |
|
4134 geolocation.lastPosition = pos; |
|
4135 successCallback(pos); |
|
4136 }; |
|
4137 var fail = function(e) { |
|
4138 clearTimeout(timeoutTimer); |
|
4139 timeoutTimer = null; |
|
4140 var err = new PositionError(e.code, e.message); |
|
4141 if (errorCallback) { |
|
4142 errorCallback(err); |
|
4143 } |
|
4144 }; |
|
4145 |
|
4146 // Check our cached position, if its timestamp difference with current time is less than the maximumAge, then just |
|
4147 // fire the success callback with the cached position. |
|
4148 if (geolocation.lastPosition && options.maximumAge && (((new Date()).getTime() - geolocation.lastPosition.timestamp.getTime()) <= options.maximumAge)) { |
|
4149 successCallback(geolocation.lastPosition); |
|
4150 // If the cached position check failed and the timeout was set to 0, error out with a TIMEOUT error object. |
|
4151 } else if (options.timeout === 0) { |
|
4152 fail({ |
|
4153 code:PositionError.TIMEOUT, |
|
4154 message:"timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceed's provided PositionOptions' maximumAge parameter." |
|
4155 }); |
|
4156 // Otherwise we have to call into native to retrieve a position. |
|
4157 } else { |
|
4158 if (options.timeout !== Infinity) { |
|
4159 // If the timeout value was not set to Infinity (default), then |
|
4160 // set up a timeout function that will fire the error callback |
|
4161 // if no successful position was retrieved before timeout expired. |
|
4162 timeoutTimer = createTimeout(fail, options.timeout); |
|
4163 } else { |
|
4164 // This is here so the check in the win function doesn't mess stuff up |
|
4165 // may seem weird but this guarantees timeoutTimer is |
|
4166 // always truthy before we call into native |
|
4167 timeoutTimer = true; |
|
4168 } |
|
4169 exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.maximumAge]); |
|
4170 } |
|
4171 return timeoutTimer; |
|
4172 }, |
|
4173 /** |
|
4174 * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, |
|
4175 * the successCallback is called with the new location. |
|
4176 * |
|
4177 * @param {Function} successCallback The function to call each time the location data is available |
|
4178 * @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL) |
|
4179 * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL) |
|
4180 * @return String The watch id that must be passed to #clearWatch to stop watching. |
|
4181 */ |
|
4182 watchPosition:function(successCallback, errorCallback, options) { |
|
4183 if (arguments.length === 0) { |
|
4184 throw new Error("watchPosition must be called with at least one argument."); |
|
4185 } |
|
4186 options = parseParameters(options); |
|
4187 |
|
4188 var id = utils.createUUID(); |
|
4189 |
|
4190 // Tell device to get a position ASAP, and also retrieve a reference to the timeout timer generated in getCurrentPosition |
|
4191 timers[id] = geolocation.getCurrentPosition(successCallback, errorCallback, options); |
|
4192 |
|
4193 var fail = function(e) { |
|
4194 clearTimeout(timers[id]); |
|
4195 var err = new PositionError(e.code, e.message); |
|
4196 if (errorCallback) { |
|
4197 errorCallback(err); |
|
4198 } |
|
4199 }; |
|
4200 |
|
4201 var win = function(p) { |
|
4202 clearTimeout(timers[id]); |
|
4203 if (options.timeout !== Infinity) { |
|
4204 timers[id] = createTimeout(fail, options.timeout); |
|
4205 } |
|
4206 var pos = new Position( |
|
4207 { |
|
4208 latitude:p.latitude, |
|
4209 longitude:p.longitude, |
|
4210 altitude:p.altitude, |
|
4211 accuracy:p.accuracy, |
|
4212 heading:p.heading, |
|
4213 velocity:p.velocity, |
|
4214 altitudeAccuracy:p.altitudeAccuracy |
|
4215 }, |
|
4216 (p.timestamp === undefined ? new Date() : ((p.timestamp instanceof Date) ? p.timestamp : new Date(p.timestamp))) |
|
4217 ); |
|
4218 geolocation.lastPosition = pos; |
|
4219 successCallback(pos); |
|
4220 }; |
|
4221 |
|
4222 exec(win, fail, "Geolocation", "addWatch", [id, options.enableHighAccuracy]); |
|
4223 |
|
4224 return id; |
|
4225 }, |
|
4226 /** |
|
4227 * Clears the specified heading watch. |
|
4228 * |
|
4229 * @param {String} id The ID of the watch returned from #watchPosition |
|
4230 */ |
|
4231 clearWatch:function(id) { |
|
4232 if (id && timers[id] !== undefined) { |
|
4233 clearTimeout(timers[id]); |
|
4234 delete timers[id]; |
|
4235 exec(null, null, "Geolocation", "clearWatch", [id]); |
|
4236 } |
|
4237 } |
|
4238 }; |
|
4239 |
|
4240 module.exports = geolocation; |
|
4241 |
|
4242 }); |
|
4243 |
|
4244 // file: lib/ios/plugin/ios/Contact.js |
|
4245 define("cordova/plugin/ios/Contact", function(require, exports, module) { |
|
4246 var exec = require('cordova/exec'), |
|
4247 ContactError = require('cordova/plugin/ContactError'); |
|
4248 |
|
4249 /** |
|
4250 * Provides iOS Contact.display API. |
|
4251 */ |
|
4252 module.exports = { |
|
4253 display : function(errorCB, options) { |
|
4254 /* |
|
4255 * Display a contact using the iOS Contact Picker UI |
|
4256 * NOT part of W3C spec so no official documentation |
|
4257 * |
|
4258 * @param errorCB error callback |
|
4259 * @param options object |
|
4260 * allowsEditing: boolean AS STRING |
|
4261 * "true" to allow editing the contact |
|
4262 * "false" (default) display contact |
|
4263 */ |
|
4264 |
|
4265 if (this.id === null) { |
|
4266 if (typeof errorCB === "function") { |
|
4267 var errorObj = new ContactError(ContactError.UNKNOWN_ERROR); |
|
4268 errorCB(errorObj); |
|
4269 } |
|
4270 } |
|
4271 else { |
|
4272 exec(null, errorCB, "Contacts","displayContact", [this.id, options]); |
|
4273 } |
|
4274 } |
|
4275 }; |
|
4276 }); |
|
4277 |
|
4278 // file: lib/ios/plugin/ios/Entry.js |
|
4279 define("cordova/plugin/ios/Entry", function(require, exports, module) { |
|
4280 module.exports = { |
|
4281 toURL:function() { |
|
4282 // TODO: refactor path in a cross-platform way so we can eliminate |
|
4283 // these kinds of platform-specific hacks. |
|
4284 return "file://localhost" + this.fullPath; |
|
4285 }, |
|
4286 toURI: function() { |
|
4287 console.log("DEPRECATED: Update your code to use 'toURL'"); |
|
4288 return "file://localhost" + this.fullPath; |
|
4289 } |
|
4290 }; |
|
4291 }); |
|
4292 |
|
4293 // file: lib/ios/plugin/ios/FileReader.js |
|
4294 define("cordova/plugin/ios/FileReader", function(require, exports, module) { |
|
4295 var exec = require('cordova/exec'), |
|
4296 FileError = require('cordova/plugin/FileError'), |
|
4297 FileReader = require('cordova/plugin/FileReader'), |
|
4298 ProgressEvent = require('cordova/plugin/ProgressEvent'); |
|
4299 |
|
4300 module.exports = { |
|
4301 readAsText:function(file, encoding) { |
|
4302 // Figure out pathing |
|
4303 this.fileName = ''; |
|
4304 if (typeof file.fullPath === 'undefined') { |
|
4305 this.fileName = file; |
|
4306 } else { |
|
4307 this.fileName = file.fullPath; |
|
4308 } |
|
4309 |
|
4310 // Already loading something |
|
4311 if (this.readyState == FileReader.LOADING) { |
|
4312 throw new FileError(FileError.INVALID_STATE_ERR); |
|
4313 } |
|
4314 |
|
4315 // LOADING state |
|
4316 this.readyState = FileReader.LOADING; |
|
4317 |
|
4318 // If loadstart callback |
|
4319 if (typeof this.onloadstart === "function") { |
|
4320 this.onloadstart(new ProgressEvent("loadstart", {target:this})); |
|
4321 } |
|
4322 |
|
4323 // Default encoding is UTF-8 |
|
4324 var enc = encoding ? encoding : "UTF-8"; |
|
4325 |
|
4326 var me = this; |
|
4327 |
|
4328 // Read file |
|
4329 exec( |
|
4330 // Success callback |
|
4331 function(r) { |
|
4332 // If DONE (cancelled), then don't do anything |
|
4333 if (me.readyState === FileReader.DONE) { |
|
4334 return; |
|
4335 } |
|
4336 |
|
4337 // Save result |
|
4338 me.result = decodeURIComponent(r); |
|
4339 |
|
4340 // If onload callback |
|
4341 if (typeof me.onload === "function") { |
|
4342 me.onload(new ProgressEvent("load", {target:me})); |
|
4343 } |
|
4344 |
|
4345 // DONE state |
|
4346 me.readyState = FileReader.DONE; |
|
4347 |
|
4348 // If onloadend callback |
|
4349 if (typeof me.onloadend === "function") { |
|
4350 me.onloadend(new ProgressEvent("loadend", {target:me})); |
|
4351 } |
|
4352 }, |
|
4353 // Error callback |
|
4354 function(e) { |
|
4355 // If DONE (cancelled), then don't do anything |
|
4356 if (me.readyState === FileReader.DONE) { |
|
4357 return; |
|
4358 } |
|
4359 |
|
4360 // DONE state |
|
4361 me.readyState = FileReader.DONE; |
|
4362 |
|
4363 // null result |
|
4364 me.result = null; |
|
4365 |
|
4366 // Save error |
|
4367 me.error = new FileError(e); |
|
4368 |
|
4369 // If onerror callback |
|
4370 if (typeof me.onerror === "function") { |
|
4371 me.onerror(new ProgressEvent("error", {target:me})); |
|
4372 } |
|
4373 |
|
4374 // If onloadend callback |
|
4375 if (typeof me.onloadend === "function") { |
|
4376 me.onloadend(new ProgressEvent("loadend", {target:me})); |
|
4377 } |
|
4378 }, |
|
4379 "File", "readAsText", [this.fileName, enc]); |
|
4380 } |
|
4381 }; |
|
4382 }); |
|
4383 |
|
4384 // file: lib/ios/plugin/ios/console.js |
|
4385 define("cordova/plugin/ios/console", function(require, exports, module) { |
|
4386 var exec = require('cordova/exec'); |
|
4387 |
|
4388 /** |
|
4389 * This class provides access to the debugging console. |
|
4390 * @constructor |
|
4391 */ |
|
4392 var DebugConsole = function() { |
|
4393 this.winConsole = window.console; |
|
4394 this.logLevel = DebugConsole.INFO_LEVEL; |
|
4395 }; |
|
4396 |
|
4397 // from most verbose, to least verbose |
|
4398 DebugConsole.ALL_LEVEL = 1; // same as first level |
|
4399 DebugConsole.INFO_LEVEL = 1; |
|
4400 DebugConsole.WARN_LEVEL = 2; |
|
4401 DebugConsole.ERROR_LEVEL = 4; |
|
4402 DebugConsole.NONE_LEVEL = 8; |
|
4403 |
|
4404 DebugConsole.prototype.setLevel = function(level) { |
|
4405 this.logLevel = level; |
|
4406 }; |
|
4407 |
|
4408 var stringify = function(message) { |
|
4409 try { |
|
4410 if (typeof message === "object" && JSON && JSON.stringify) { |
|
4411 try { |
|
4412 return JSON.stringify(message); |
|
4413 } |
|
4414 catch (e) { |
|
4415 return "error JSON.stringify()ing argument: " + e; |
|
4416 } |
|
4417 } else { |
|
4418 return message.toString(); |
|
4419 } |
|
4420 } catch (e) { |
|
4421 return e.toString(); |
|
4422 } |
|
4423 }; |
|
4424 |
|
4425 /** |
|
4426 * Print a normal log message to the console |
|
4427 * @param {Object|String} message Message or object to print to the console |
|
4428 */ |
|
4429 DebugConsole.prototype.log = function(message) { |
|
4430 if (this.logLevel <= DebugConsole.INFO_LEVEL) { |
|
4431 exec(null, null, 'Debug Console', 'log', [ stringify(message), { logLevel: 'INFO' } ]); |
|
4432 } |
|
4433 else if (this.winConsole && this.winConsole.log) { |
|
4434 this.winConsole.log(message); |
|
4435 } |
|
4436 }; |
|
4437 |
|
4438 /** |
|
4439 * Print a warning message to the console |
|
4440 * @param {Object|String} message Message or object to print to the console |
|
4441 */ |
|
4442 DebugConsole.prototype.warn = function(message) { |
|
4443 if (this.logLevel <= DebugConsole.WARN_LEVEL) { |
|
4444 exec(null, null, 'Debug Console', 'log', [ stringify(message), { logLevel: 'WARN' } ]); |
|
4445 } |
|
4446 else if (this.winConsole && this.winConsole.warn) { |
|
4447 this.winConsole.warn(message); |
|
4448 } |
|
4449 }; |
|
4450 |
|
4451 /** |
|
4452 * Print an error message to the console |
|
4453 * @param {Object|String} message Message or object to print to the console |
|
4454 */ |
|
4455 DebugConsole.prototype.error = function(message) { |
|
4456 if (this.logLevel <= DebugConsole.ERROR_LEVEL) { |
|
4457 exec(null, null, 'Debug Console', 'log', [ stringify(message), { logLevel: 'ERROR' } ]); |
|
4458 } |
|
4459 else if (this.winConsole && this.winConsole.error){ |
|
4460 this.winConsole.error(message); |
|
4461 } |
|
4462 }; |
|
4463 |
|
4464 module.exports = new DebugConsole(); |
|
4465 }); |
|
4466 |
|
4467 // file: lib/ios/plugin/ios/contacts.js |
|
4468 define("cordova/plugin/ios/contacts", function(require, exports, module) { |
|
4469 var exec = require('cordova/exec'); |
|
4470 |
|
4471 /** |
|
4472 * Provides iOS enhanced contacts API. |
|
4473 */ |
|
4474 module.exports = { |
|
4475 newContactUI : function(successCallback) { |
|
4476 /* |
|
4477 * Create a contact using the iOS Contact Picker UI |
|
4478 * NOT part of W3C spec so no official documentation |
|
4479 * |
|
4480 * returns: the id of the created contact as param to successCallback |
|
4481 */ |
|
4482 exec(successCallback, null, "Contacts","newContact", []); |
|
4483 }, |
|
4484 chooseContact : function(successCallback, options) { |
|
4485 /* |
|
4486 * Select a contact using the iOS Contact Picker UI |
|
4487 * NOT part of W3C spec so no official documentation |
|
4488 * |
|
4489 * @param errorCB error callback |
|
4490 * @param options object |
|
4491 * allowsEditing: boolean AS STRING |
|
4492 * "true" to allow editing the contact |
|
4493 * "false" (default) display contact |
|
4494 * |
|
4495 * returns: the id of the selected contact as param to successCallback |
|
4496 */ |
|
4497 exec(successCallback, null, "Contacts","chooseContact", [options]); |
|
4498 } |
|
4499 }; |
|
4500 }); |
|
4501 |
|
4502 // file: lib/ios/plugin/ios/nativecomm.js |
|
4503 define("cordova/plugin/ios/nativecomm", function(require, exports, module) { |
|
4504 var cordova = require('cordova'); |
|
4505 |
|
4506 /** |
|
4507 * Called by native code to retrieve all queued commands and clear the queue. |
|
4508 */ |
|
4509 module.exports = function() { |
|
4510 var json = JSON.stringify(cordova.commandQueue); |
|
4511 cordova.commandQueue = []; |
|
4512 return json; |
|
4513 }; |
|
4514 }); |
|
4515 |
|
4516 // file: lib/ios/plugin/ios/notification.js |
|
4517 define("cordova/plugin/ios/notification", function(require, exports, module) { |
|
4518 var Media = require('cordova/plugin/Media'); |
|
4519 |
|
4520 module.exports = { |
|
4521 beep:function(count) { |
|
4522 (new Media('beep.wav')).play(); |
|
4523 } |
|
4524 }; |
|
4525 }); |
|
4526 |
|
4527 // file: lib/common/plugin/logger.js |
|
4528 define("cordova/plugin/logger", function(require, exports, module) { |
|
4529 //------------------------------------------------------------------------------ |
|
4530 // The logger module exports the following properties/functions: |
|
4531 // |
|
4532 // LOG - constant for the level LOG |
|
4533 // ERROR - constant for the level ERROR |
|
4534 // WARN - constant for the level WARN |
|
4535 // INFO - constant for the level INFO |
|
4536 // DEBUG - constant for the level DEBUG |
|
4537 // logLevel() - returns current log level |
|
4538 // logLevel(value) - sets and returns a new log level |
|
4539 // useConsole() - returns whether logger is using console |
|
4540 // useConsole(value) - sets and returns whether logger is using console |
|
4541 // log(message,...) - logs a message at level LOG |
|
4542 // error(message,...) - logs a message at level ERROR |
|
4543 // warn(message,...) - logs a message at level WARN |
|
4544 // info(message,...) - logs a message at level INFO |
|
4545 // debug(message,...) - logs a message at level DEBUG |
|
4546 // logLevel(level,message,...) - logs a message specified level |
|
4547 // |
|
4548 //------------------------------------------------------------------------------ |
|
4549 |
|
4550 var logger = exports; |
|
4551 |
|
4552 var exec = require('cordova/exec'); |
|
4553 var utils = require('cordova/utils'); |
|
4554 |
|
4555 var UseConsole = true; |
|
4556 var Queued = []; |
|
4557 var DeviceReady = false; |
|
4558 var CurrentLevel; |
|
4559 |
|
4560 /** |
|
4561 * Logging levels |
|
4562 */ |
|
4563 |
|
4564 var Levels = [ |
|
4565 "LOG", |
|
4566 "ERROR", |
|
4567 "WARN", |
|
4568 "INFO", |
|
4569 "DEBUG" |
|
4570 ]; |
|
4571 |
|
4572 /* |
|
4573 * add the logging levels to the logger object and |
|
4574 * to a separate levelsMap object for testing |
|
4575 */ |
|
4576 |
|
4577 var LevelsMap = {}; |
|
4578 for (var i=0; i<Levels.length; i++) { |
|
4579 var level = Levels[i]; |
|
4580 LevelsMap[level] = i; |
|
4581 logger[level] = level; |
|
4582 } |
|
4583 |
|
4584 CurrentLevel = LevelsMap.WARN; |
|
4585 |
|
4586 /** |
|
4587 * Getter/Setter for the logging level |
|
4588 * |
|
4589 * Returns the current logging level. |
|
4590 * |
|
4591 * When a value is passed, sets the logging level to that value. |
|
4592 * The values should be one of the following constants: |
|
4593 * logger.LOG |
|
4594 * logger.ERROR |
|
4595 * logger.WARN |
|
4596 * logger.INFO |
|
4597 * logger.DEBUG |
|
4598 * |
|
4599 * The value used determines which messages get printed. The logging |
|
4600 * values above are in order, and only messages logged at the logging |
|
4601 * level or above will actually be displayed to the user. Eg, the |
|
4602 * default level is WARN, so only messages logged with LOG, ERROR, or |
|
4603 * WARN will be displayed; INFO and DEBUG messages will be ignored. |
|
4604 */ |
|
4605 logger.level = function (value) { |
|
4606 if (arguments.length) { |
|
4607 if (LevelsMap[value] === null) { |
|
4608 throw new Error("invalid logging level: " + value); |
|
4609 } |
|
4610 CurrentLevel = LevelsMap[value]; |
|
4611 } |
|
4612 |
|
4613 return Levels[CurrentLevel]; |
|
4614 }; |
|
4615 |
|
4616 /** |
|
4617 * Getter/Setter for the useConsole functionality |
|
4618 * |
|
4619 * When useConsole is true, the logger will log via the |
|
4620 * browser 'console' object. Otherwise, it will use the |
|
4621 * native Logger plugin. |
|
4622 */ |
|
4623 logger.useConsole = function (value) { |
|
4624 if (arguments.length) UseConsole = !!value; |
|
4625 |
|
4626 if (UseConsole) { |
|
4627 if (typeof console == "undefined") { |
|
4628 throw new Error("global console object is not defined"); |
|
4629 } |
|
4630 |
|
4631 if (typeof console.log != "function") { |
|
4632 throw new Error("global console object does not have a log function"); |
|
4633 } |
|
4634 |
|
4635 if (typeof console.useLogger == "function") { |
|
4636 if (console.useLogger()) { |
|
4637 throw new Error("console and logger are too intertwingly"); |
|
4638 } |
|
4639 } |
|
4640 } |
|
4641 |
|
4642 return UseConsole; |
|
4643 }; |
|
4644 |
|
4645 /** |
|
4646 * Logs a message at the LOG level. |
|
4647 * |
|
4648 * Parameters passed after message are used applied to |
|
4649 * the message with utils.format() |
|
4650 */ |
|
4651 logger.log = function(message) { logWithArgs("LOG", arguments); }; |
|
4652 |
|
4653 /** |
|
4654 * Logs a message at the ERROR level. |
|
4655 * |
|
4656 * Parameters passed after message are used applied to |
|
4657 * the message with utils.format() |
|
4658 */ |
|
4659 logger.error = function(message) { logWithArgs("ERROR", arguments); }; |
|
4660 |
|
4661 /** |
|
4662 * Logs a message at the WARN level. |
|
4663 * |
|
4664 * Parameters passed after message are used applied to |
|
4665 * the message with utils.format() |
|
4666 */ |
|
4667 logger.warn = function(message) { logWithArgs("WARN", arguments); }; |
|
4668 |
|
4669 /** |
|
4670 * Logs a message at the INFO level. |
|
4671 * |
|
4672 * Parameters passed after message are used applied to |
|
4673 * the message with utils.format() |
|
4674 */ |
|
4675 logger.info = function(message) { logWithArgs("INFO", arguments); }; |
|
4676 |
|
4677 /** |
|
4678 * Logs a message at the DEBUG level. |
|
4679 * |
|
4680 * Parameters passed after message are used applied to |
|
4681 * the message with utils.format() |
|
4682 */ |
|
4683 logger.debug = function(message) { logWithArgs("DEBUG", arguments); }; |
|
4684 |
|
4685 // log at the specified level with args |
|
4686 function logWithArgs(level, args) { |
|
4687 args = [level].concat([].slice.call(args)); |
|
4688 logger.logLevel.apply(logger, args); |
|
4689 } |
|
4690 |
|
4691 /** |
|
4692 * Logs a message at the specified level. |
|
4693 * |
|
4694 * Parameters passed after message are used applied to |
|
4695 * the message with utils.format() |
|
4696 */ |
|
4697 logger.logLevel = function(level, message /* , ... */) { |
|
4698 // format the message with the parameters |
|
4699 var formatArgs = [].slice.call(arguments, 2); |
|
4700 message = utils.vformat(message, formatArgs); |
|
4701 |
|
4702 if (LevelsMap[level] === null) { |
|
4703 throw new Error("invalid logging level: " + level); |
|
4704 } |
|
4705 |
|
4706 if (LevelsMap[level] > CurrentLevel) return; |
|
4707 |
|
4708 // queue the message if not yet at deviceready |
|
4709 if (!DeviceReady && !UseConsole) { |
|
4710 Queued.push([level, message]); |
|
4711 return; |
|
4712 } |
|
4713 |
|
4714 // if not using the console, use the native logger |
|
4715 if (!UseConsole) { |
|
4716 exec(null, null, "Logger", "logLevel", [level, message]); |
|
4717 return; |
|
4718 } |
|
4719 |
|
4720 // make sure console is not using logger |
|
4721 if (console.__usingCordovaLogger) { |
|
4722 throw new Error("console and logger are too intertwingly"); |
|
4723 } |
|
4724 |
|
4725 // log to the console |
|
4726 switch (level) { |
|
4727 case logger.LOG: console.log(message); break; |
|
4728 case logger.ERROR: console.log("ERROR: " + message); break; |
|
4729 case logger.WARN: console.log("WARN: " + message); break; |
|
4730 case logger.INFO: console.log("INFO: " + message); break; |
|
4731 case logger.DEBUG: console.log("DEBUG: " + message); break; |
|
4732 } |
|
4733 }; |
|
4734 |
|
4735 // when deviceready fires, log queued messages |
|
4736 logger.__onDeviceReady = function() { |
|
4737 if (DeviceReady) return; |
|
4738 |
|
4739 DeviceReady = true; |
|
4740 |
|
4741 for (var i=0; i<Queued.length; i++) { |
|
4742 var messageArgs = Queued[i]; |
|
4743 logger.logLevel(messageArgs[0], messageArgs[1]); |
|
4744 } |
|
4745 |
|
4746 Queued = null; |
|
4747 }; |
|
4748 |
|
4749 // add a deviceready event to log queued messages |
|
4750 document.addEventListener("deviceready", logger.__onDeviceReady, false); |
|
4751 |
|
4752 }); |
|
4753 |
|
4754 // file: lib/common/plugin/network.js |
|
4755 define("cordova/plugin/network", function(require, exports, module) { |
|
4756 var exec = require('cordova/exec'), |
|
4757 cordova = require('cordova'), |
|
4758 channel = require('cordova/channel'); |
|
4759 |
|
4760 var NetworkConnection = function () { |
|
4761 this.type = null; |
|
4762 this._firstRun = true; |
|
4763 this._timer = null; |
|
4764 this.timeout = 500; |
|
4765 |
|
4766 var me = this; |
|
4767 |
|
4768 channel.onCordovaReady.subscribeOnce(function() { |
|
4769 me.getInfo(function (info) { |
|
4770 me.type = info; |
|
4771 if (info === "none") { |
|
4772 // set a timer if still offline at the end of timer send the offline event |
|
4773 me._timer = setTimeout(function(){ |
|
4774 cordova.fireDocumentEvent("offline"); |
|
4775 me._timer = null; |
|
4776 }, me.timeout); |
|
4777 } else { |
|
4778 // If there is a current offline event pending clear it |
|
4779 if (me._timer !== null) { |
|
4780 clearTimeout(me._timer); |
|
4781 me._timer = null; |
|
4782 } |
|
4783 cordova.fireDocumentEvent("online"); |
|
4784 } |
|
4785 |
|
4786 // should only fire this once |
|
4787 if (me._firstRun) { |
|
4788 me._firstRun = false; |
|
4789 channel.onCordovaConnectionReady.fire(); |
|
4790 } |
|
4791 }, |
|
4792 function (e) { |
|
4793 // If we can't get the network info we should still tell Cordova |
|
4794 // to fire the deviceready event. |
|
4795 if (me._firstRun) { |
|
4796 me._firstRun = false; |
|
4797 channel.onCordovaConnectionReady.fire(); |
|
4798 } |
|
4799 console.log("Error initializing Network Connection: " + e); |
|
4800 }); |
|
4801 }); |
|
4802 }; |
|
4803 |
|
4804 /** |
|
4805 * Get connection info |
|
4806 * |
|
4807 * @param {Function} successCallback The function to call when the Connection data is available |
|
4808 * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL) |
|
4809 */ |
|
4810 NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) { |
|
4811 // Get info |
|
4812 exec(successCallback, errorCallback, "NetworkStatus", "getConnectionInfo", []); |
|
4813 }; |
|
4814 |
|
4815 module.exports = new NetworkConnection(); |
|
4816 }); |
|
4817 |
|
4818 // file: lib/common/plugin/notification.js |
|
4819 define("cordova/plugin/notification", function(require, exports, module) { |
|
4820 var exec = require('cordova/exec'); |
|
4821 |
|
4822 /** |
|
4823 * Provides access to notifications on the device. |
|
4824 */ |
|
4825 |
|
4826 module.exports = { |
|
4827 |
|
4828 /** |
|
4829 * Open a native alert dialog, with a customizable title and button text. |
|
4830 * |
|
4831 * @param {String} message Message to print in the body of the alert |
|
4832 * @param {Function} completeCallback The callback that is called when user clicks on a button. |
|
4833 * @param {String} title Title of the alert dialog (default: Alert) |
|
4834 * @param {String} buttonLabel Label of the close button (default: OK) |
|
4835 */ |
|
4836 alert: function(message, completeCallback, title, buttonLabel) { |
|
4837 var _title = (title || "Alert"); |
|
4838 var _buttonLabel = (buttonLabel || "OK"); |
|
4839 exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]); |
|
4840 }, |
|
4841 |
|
4842 /** |
|
4843 * Open a native confirm dialog, with a customizable title and button text. |
|
4844 * The result that the user selects is returned to the result callback. |
|
4845 * |
|
4846 * @param {String} message Message to print in the body of the alert |
|
4847 * @param {Function} resultCallback The callback that is called when user clicks on a button. |
|
4848 * @param {String} title Title of the alert dialog (default: Confirm) |
|
4849 * @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel') |
|
4850 */ |
|
4851 confirm: function(message, resultCallback, title, buttonLabels) { |
|
4852 var _title = (title || "Confirm"); |
|
4853 var _buttonLabels = (buttonLabels || "OK,Cancel"); |
|
4854 exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); |
|
4855 }, |
|
4856 |
|
4857 /** |
|
4858 * Causes the device to vibrate. |
|
4859 * |
|
4860 * @param {Integer} mills The number of milliseconds to vibrate for. |
|
4861 */ |
|
4862 vibrate: function(mills) { |
|
4863 exec(null, null, "Notification", "vibrate", [mills]); |
|
4864 }, |
|
4865 |
|
4866 /** |
|
4867 * Causes the device to beep. |
|
4868 * On Android, the default notification ringtone is played "count" times. |
|
4869 * |
|
4870 * @param {Integer} count The number of beeps. |
|
4871 */ |
|
4872 beep: function(count) { |
|
4873 exec(null, null, "Notification", "beep", [count]); |
|
4874 } |
|
4875 }; |
|
4876 }); |
|
4877 |
|
4878 // file: lib/common/plugin/requestFileSystem.js |
|
4879 define("cordova/plugin/requestFileSystem", function(require, exports, module) { |
|
4880 var FileError = require('cordova/plugin/FileError'), |
|
4881 FileSystem = require('cordova/plugin/FileSystem'), |
|
4882 exec = require('cordova/exec'); |
|
4883 |
|
4884 /** |
|
4885 * Request a file system in which to store application data. |
|
4886 * @param type local file system type |
|
4887 * @param size indicates how much storage space, in bytes, the application expects to need |
|
4888 * @param successCallback invoked with a FileSystem object |
|
4889 * @param errorCallback invoked if error occurs retrieving file system |
|
4890 */ |
|
4891 var requestFileSystem = function(type, size, successCallback, errorCallback) { |
|
4892 var fail = function(code) { |
|
4893 if (typeof errorCallback === 'function') { |
|
4894 errorCallback(new FileError(code)); |
|
4895 } |
|
4896 }; |
|
4897 |
|
4898 if (type < 0 || type > 3) { |
|
4899 fail(FileError.SYNTAX_ERR); |
|
4900 } else { |
|
4901 // if successful, return a FileSystem object |
|
4902 var success = function(file_system) { |
|
4903 if (file_system) { |
|
4904 if (typeof successCallback === 'function') { |
|
4905 // grab the name and root from the file system object |
|
4906 var result = new FileSystem(file_system.name, file_system.root); |
|
4907 successCallback(result); |
|
4908 } |
|
4909 } |
|
4910 else { |
|
4911 // no FileSystem object returned |
|
4912 fail(FileError.NOT_FOUND_ERR); |
|
4913 } |
|
4914 }; |
|
4915 exec(success, fail, "File", "requestFileSystem", [type, size]); |
|
4916 } |
|
4917 }; |
|
4918 |
|
4919 module.exports = requestFileSystem; |
|
4920 }); |
|
4921 |
|
4922 // file: lib/common/plugin/resolveLocalFileSystemURI.js |
|
4923 define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { |
|
4924 var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), |
|
4925 FileEntry = require('cordova/plugin/FileEntry'), |
|
4926 FileError = require('cordova/plugin/FileError'), |
|
4927 exec = require('cordova/exec'); |
|
4928 |
|
4929 /** |
|
4930 * Look up file system Entry referred to by local URI. |
|
4931 * @param {DOMString} uri URI referring to a local file or directory |
|
4932 * @param successCallback invoked with Entry object corresponding to URI |
|
4933 * @param errorCallback invoked if error occurs retrieving file system entry |
|
4934 */ |
|
4935 module.exports = function(uri, successCallback, errorCallback) { |
|
4936 // error callback |
|
4937 var fail = function(error) { |
|
4938 if (typeof errorCallback === 'function') { |
|
4939 errorCallback(new FileError(error)); |
|
4940 } |
|
4941 }; |
|
4942 // sanity check for 'not:valid:filename' |
|
4943 if(!uri || uri.split(":").length > 2) { |
|
4944 setTimeout( function() { |
|
4945 fail(FileError.ENCODING_ERR); |
|
4946 },0); |
|
4947 return; |
|
4948 } |
|
4949 // if successful, return either a file or directory entry |
|
4950 var success = function(entry) { |
|
4951 var result; |
|
4952 if (entry) { |
|
4953 if (typeof successCallback === 'function') { |
|
4954 // create appropriate Entry object |
|
4955 result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath); |
|
4956 try { |
|
4957 successCallback(result); |
|
4958 } |
|
4959 catch (e) { |
|
4960 console.log('Error invoking callback: ' + e); |
|
4961 } |
|
4962 } |
|
4963 } |
|
4964 else { |
|
4965 // no Entry object returned |
|
4966 fail(FileError.NOT_FOUND_ERR); |
|
4967 } |
|
4968 }; |
|
4969 |
|
4970 exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]); |
|
4971 }; |
|
4972 |
|
4973 }); |
|
4974 |
|
4975 // file: lib/common/plugin/splashscreen.js |
|
4976 define("cordova/plugin/splashscreen", function(require, exports, module) { |
|
4977 var exec = require('cordova/exec'); |
|
4978 |
|
4979 var splashscreen = { |
|
4980 show:function() { |
|
4981 exec(null, null, "SplashScreen", "show", []); |
|
4982 }, |
|
4983 hide:function() { |
|
4984 exec(null, null, "SplashScreen", "hide", []); |
|
4985 } |
|
4986 }; |
|
4987 |
|
4988 module.exports = splashscreen; |
|
4989 }); |
|
4990 |
|
4991 // file: lib/common/utils.js |
|
4992 define("cordova/utils", function(require, exports, module) { |
|
4993 var utils = exports; |
|
4994 |
|
4995 /** |
|
4996 * Returns an indication of whether the argument is an array or not |
|
4997 */ |
|
4998 utils.isArray = function(a) { |
|
4999 return Object.prototype.toString.call(a) == '[object Array]'; |
|
5000 }; |
|
5001 |
|
5002 /** |
|
5003 * Returns an indication of whether the argument is a Date or not |
|
5004 */ |
|
5005 utils.isDate = function(d) { |
|
5006 return Object.prototype.toString.call(d) == '[object Date]'; |
|
5007 }; |
|
5008 |
|
5009 /** |
|
5010 * Does a deep clone of the object. |
|
5011 */ |
|
5012 utils.clone = function(obj) { |
|
5013 if(!obj || typeof obj == 'function' || utils.isDate(obj) || typeof obj != 'object') { |
|
5014 return obj; |
|
5015 } |
|
5016 |
|
5017 var retVal, i; |
|
5018 |
|
5019 if(utils.isArray(obj)){ |
|
5020 retVal = []; |
|
5021 for(i = 0; i < obj.length; ++i){ |
|
5022 retVal.push(utils.clone(obj[i])); |
|
5023 } |
|
5024 return retVal; |
|
5025 } |
|
5026 |
|
5027 retVal = {}; |
|
5028 for(i in obj){ |
|
5029 if(!(i in retVal) || retVal[i] != obj[i]) { |
|
5030 retVal[i] = utils.clone(obj[i]); |
|
5031 } |
|
5032 } |
|
5033 return retVal; |
|
5034 }; |
|
5035 |
|
5036 /** |
|
5037 * Returns a wrappered version of the function |
|
5038 */ |
|
5039 utils.close = function(context, func, params) { |
|
5040 if (typeof params == 'undefined') { |
|
5041 return function() { |
|
5042 return func.apply(context, arguments); |
|
5043 }; |
|
5044 } else { |
|
5045 return function() { |
|
5046 return func.apply(context, params); |
|
5047 }; |
|
5048 } |
|
5049 }; |
|
5050 |
|
5051 /** |
|
5052 * Create a UUID |
|
5053 */ |
|
5054 utils.createUUID = function() { |
|
5055 return UUIDcreatePart(4) + '-' + |
|
5056 UUIDcreatePart(2) + '-' + |
|
5057 UUIDcreatePart(2) + '-' + |
|
5058 UUIDcreatePart(2) + '-' + |
|
5059 UUIDcreatePart(6); |
|
5060 }; |
|
5061 |
|
5062 /** |
|
5063 * Extends a child object from a parent object using classical inheritance |
|
5064 * pattern. |
|
5065 */ |
|
5066 utils.extend = (function() { |
|
5067 // proxy used to establish prototype chain |
|
5068 var F = function() {}; |
|
5069 // extend Child from Parent |
|
5070 return function(Child, Parent) { |
|
5071 F.prototype = Parent.prototype; |
|
5072 Child.prototype = new F(); |
|
5073 Child.__super__ = Parent.prototype; |
|
5074 Child.prototype.constructor = Child; |
|
5075 }; |
|
5076 }()); |
|
5077 |
|
5078 /** |
|
5079 * Alerts a message in any available way: alert or console.log. |
|
5080 */ |
|
5081 utils.alert = function(msg) { |
|
5082 if (alert) { |
|
5083 alert(msg); |
|
5084 } else if (console && console.log) { |
|
5085 console.log(msg); |
|
5086 } |
|
5087 }; |
|
5088 |
|
5089 /** |
|
5090 * Formats a string and arguments following it ala sprintf() |
|
5091 * |
|
5092 * see utils.vformat() for more information |
|
5093 */ |
|
5094 utils.format = function(formatString /* ,... */) { |
|
5095 var args = [].slice.call(arguments, 1); |
|
5096 return utils.vformat(formatString, args); |
|
5097 }; |
|
5098 |
|
5099 /** |
|
5100 * Formats a string and arguments following it ala vsprintf() |
|
5101 * |
|
5102 * format chars: |
|
5103 * %j - format arg as JSON |
|
5104 * %o - format arg as JSON |
|
5105 * %c - format arg as '' |
|
5106 * %% - replace with '%' |
|
5107 * any other char following % will format it's |
|
5108 * arg via toString(). |
|
5109 * |
|
5110 * for rationale, see FireBug's Console API: |
|
5111 * http://getfirebug.com/wiki/index.php/Console_API |
|
5112 */ |
|
5113 utils.vformat = function(formatString, args) { |
|
5114 if (formatString === null || formatString === undefined) return ""; |
|
5115 if (arguments.length == 1) return formatString.toString(); |
|
5116 if (typeof formatString != "string") return formatString.toString(); |
|
5117 |
|
5118 var pattern = /(.*?)%(.)(.*)/; |
|
5119 var rest = formatString; |
|
5120 var result = []; |
|
5121 |
|
5122 while (args.length) { |
|
5123 var arg = args.shift(); |
|
5124 var match = pattern.exec(rest); |
|
5125 |
|
5126 if (!match) break; |
|
5127 |
|
5128 rest = match[3]; |
|
5129 |
|
5130 result.push(match[1]); |
|
5131 |
|
5132 if (match[2] == '%') { |
|
5133 result.push('%'); |
|
5134 args.unshift(arg); |
|
5135 continue; |
|
5136 } |
|
5137 |
|
5138 result.push(formatted(arg, match[2])); |
|
5139 } |
|
5140 |
|
5141 result.push(rest); |
|
5142 |
|
5143 return result.join(''); |
|
5144 }; |
|
5145 |
|
5146 //------------------------------------------------------------------------------ |
|
5147 function UUIDcreatePart(length) { |
|
5148 var uuidpart = ""; |
|
5149 for (var i=0; i<length; i++) { |
|
5150 var uuidchar = parseInt((Math.random() * 256), 10).toString(16); |
|
5151 if (uuidchar.length == 1) { |
|
5152 uuidchar = "0" + uuidchar; |
|
5153 } |
|
5154 uuidpart += uuidchar; |
|
5155 } |
|
5156 return uuidpart; |
|
5157 } |
|
5158 |
|
5159 //------------------------------------------------------------------------------ |
|
5160 function formatted(object, formatChar) { |
|
5161 |
|
5162 try { |
|
5163 switch(formatChar) { |
|
5164 case 'j': |
|
5165 case 'o': return JSON.stringify(object); |
|
5166 case 'c': return ''; |
|
5167 } |
|
5168 } |
|
5169 catch (e) { |
|
5170 return "error JSON.stringify()ing argument: " + e; |
|
5171 } |
|
5172 |
|
5173 if ((object === null) || (object === undefined)) { |
|
5174 return Object.prototype.toString.call(object); |
|
5175 } |
|
5176 |
|
5177 return object.toString(); |
|
5178 } |
|
5179 |
|
5180 }); |
|
5181 |
|
5182 |
|
5183 window.cordova = require('cordova'); |
|
5184 |
|
5185 // file: lib/scripts/bootstrap.js |
|
5186 (function (context) { |
|
5187 var channel = require("cordova/channel"), |
|
5188 _self = { |
|
5189 boot: function () { |
|
5190 /** |
|
5191 * Create all cordova objects once page has fully loaded and native side is ready. |
|
5192 */ |
|
5193 channel.join(function() { |
|
5194 var builder = require('cordova/builder'), |
|
5195 base = require('cordova/common'), |
|
5196 platform = require('cordova/platform'); |
|
5197 |
|
5198 // Drop the common globals into the window object, but be nice and don't overwrite anything. |
|
5199 builder.build(base.objects).intoButDontClobber(window); |
|
5200 |
|
5201 // Drop the platform-specific globals into the window object |
|
5202 // and clobber any existing object. |
|
5203 builder.build(platform.objects).intoAndClobber(window); |
|
5204 |
|
5205 // Merge the platform-specific overrides/enhancements into |
|
5206 // the window object. |
|
5207 if (typeof platform.merges !== 'undefined') { |
|
5208 builder.build(platform.merges).intoAndMerge(window); |
|
5209 } |
|
5210 |
|
5211 // Call the platform-specific initialization |
|
5212 platform.initialize(); |
|
5213 |
|
5214 // Fire event to notify that all objects are created |
|
5215 channel.onCordovaReady.fire(); |
|
5216 |
|
5217 // Fire onDeviceReady event once all constructors have run and |
|
5218 // cordova info has been received from native side. |
|
5219 channel.join(function() { |
|
5220 require('cordova').fireDocumentEvent('deviceready'); |
|
5221 }, channel.deviceReadyChannelsArray); |
|
5222 |
|
5223 }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); |
|
5224 } |
|
5225 }; |
|
5226 |
|
5227 // boot up once native side is ready |
|
5228 channel.onNativeReady.subscribeOnce(_self.boot); |
|
5229 |
|
5230 // _nativeReady is global variable that the native side can set |
|
5231 // to signify that the native code is ready. It is a global since |
|
5232 // it may be called before any cordova JS is ready. |
|
5233 if (window._nativeReady) { |
|
5234 channel.onNativeReady.fire(); |
|
5235 } |
|
5236 |
|
5237 }(window)); |
|
5238 |
|
5239 |
|
5240 })(); |