mobile_template 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/lib/mobile_template/version.rb +1 -1
  2. data/mobile_template.gemspec +1 -1
  3. data/templates/assets/Gemfile +1 -1
  4. data/templates/assets/source/javascripts/vendor/cordova.js +2106 -1975
  5. data/templates/assets/source/javascripts/vendor/jquery.js +614 -477
  6. data/templates/assets/source/javascripts/vendor/jquery.mobile.js +519 -378
  7. data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +683 -502
  8. data/templates/cordova_android/VERSION +1 -1
  9. data/templates/cordova_android/bin/create +5 -1
  10. data/templates/cordova_android/bin/templates/project/cordova/create +5 -0
  11. data/templates/cordova_android/bin/templates/project/cordova/debug +1 -1
  12. data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +18 -25
  13. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +6 -6
  14. data/templates/cordova_android/framework/assets/js/cordova.android.js +2106 -1975
  15. data/templates/cordova_android/framework/assets/www/index.html +1 -1
  16. data/templates/cordova_android/framework/build.xml +2 -42
  17. data/templates/cordova_android/framework/project.properties +1 -1
  18. data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
  19. data/templates/cordova_android/framework/res/drawable-hdpi/icon.png +0 -0
  20. data/templates/cordova_android/framework/res/drawable-ldpi/icon.png +0 -0
  21. data/templates/cordova_android/framework/res/drawable-mdpi/icon.png +0 -0
  22. data/templates/cordova_android/framework/res/xml/plugins.xml +2 -1
  23. data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +1 -0
  24. data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +24 -16
  25. data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +35 -10
  26. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +2 -1
  27. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +67 -65
  28. data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +51 -63
  29. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +3 -0
  30. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +6 -2
  31. data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +108 -108
  32. data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +110 -77
  33. data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +90 -44
  34. data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +20 -20
  35. data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +2 -2
  36. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +7 -8
  37. data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +2 -2
  38. data/templates/cordova_android/framework/src/org/apache/cordova/SplashScreen.java +23 -0
  39. data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +3 -3
  40. data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +2 -0
  41. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginEntry.java +119 -0
  42. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +260 -258
  43. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +2 -2
  44. data/templates/cordova_android/releasenotes.md +42 -0
  45. data/templates/cordova_android/test/.classpath +8 -0
  46. data/templates/cordova_android/test/.project +33 -0
  47. data/templates/cordova_android/test/AndroidManifest.xml +87 -0
  48. data/templates/cordova_android/test/README.md +23 -0
  49. data/templates/cordova_android/test/ant.properties +17 -0
  50. data/templates/cordova_android/test/assets/www/backbuttonmultipage/index.html +23 -0
  51. data/templates/cordova_android/test/assets/www/backbuttonmultipage/sample2.html +23 -0
  52. data/templates/cordova_android/test/assets/www/backbuttonmultipage/sample3.html +26 -0
  53. data/templates/cordova_android/test/assets/www/background/index.html +99 -0
  54. data/templates/cordova_android/test/assets/www/background/index2.html +98 -0
  55. data/templates/cordova_android/test/assets/www/cordova-1.6.0.js +4985 -0
  56. data/templates/cordova_android/test/assets/www/cordova.js +2 -0
  57. data/templates/cordova_android/test/assets/www/htmlnotfound/error.html +1 -0
  58. data/templates/cordova_android/test/assets/www/iframe/index.html +33 -0
  59. data/templates/cordova_android/test/assets/www/iframe/index2.html +24 -0
  60. data/templates/cordova_android/test/assets/www/index.html +47 -0
  61. data/templates/cordova_android/test/assets/www/jqmtabbackbutton/index.html +49 -0
  62. data/templates/cordova_android/test/assets/www/jqmtabbackbutton/tab1.html +29 -0
  63. data/templates/cordova_android/test/assets/www/jqmtabbackbutton/tab2.html +30 -0
  64. data/templates/cordova_android/test/assets/www/jqmtabbackbutton/tab3.html +30 -0
  65. data/templates/cordova_android/test/assets/www/lifecycle/index.html +108 -0
  66. data/templates/cordova_android/test/assets/www/lifecycle/index2.html +104 -0
  67. data/templates/cordova_android/test/assets/www/main.js +150 -0
  68. data/templates/cordova_android/test/assets/www/master.css +117 -0
  69. data/templates/cordova_android/test/assets/www/menus/index.html +29 -0
  70. data/templates/cordova_android/test/assets/www/splashscreen/index.html +22 -0
  71. data/templates/cordova_android/test/assets/www/userwebview/index.html +49 -0
  72. data/templates/cordova_android/test/assets/www/whitelist/index.html +29 -0
  73. data/templates/cordova_android/test/assets/www/whitelist/index2.html +23 -0
  74. data/templates/cordova_android/test/assets/www/xhr/index.html +48 -0
  75. data/templates/cordova_android/test/build.xml +85 -0
  76. data/templates/cordova_android/test/libs/cordova-1.6.0.jar +0 -0
  77. data/templates/cordova_android/test/project.properties +11 -0
  78. data/templates/cordova_android/{framework → test}/res/drawable/icon.png +0 -0
  79. data/templates/cordova_android/test/res/drawable/sandy.jpg +0 -0
  80. data/templates/cordova_android/test/res/drawable-hdpi/ic_launcher.png +0 -0
  81. data/templates/cordova_android/test/res/drawable-ldpi/ic_launcher.png +0 -0
  82. data/templates/cordova_android/test/res/drawable-mdpi/ic_launcher.png +0 -0
  83. data/templates/cordova_android/test/res/layout/main.xml +13 -0
  84. data/templates/cordova_android/test/res/values/strings.xml +4 -0
  85. data/templates/cordova_android/{bin/templates/project/cordova/templates/project → test}/res/xml/cordova.xml +0 -0
  86. data/templates/cordova_android/{bin/templates/project/cordova/templates/project → test}/res/xml/plugins.xml +1 -1
  87. data/templates/cordova_android/test/src/org/apache/cordova/test/ActivityPlugin.java +81 -0
  88. data/templates/cordova_android/test/src/org/apache/cordova/test/FixWebView.java +43 -0
  89. data/templates/cordova_android/test/src/org/apache/cordova/test/backbuttonmultipage.java +30 -0
  90. data/templates/cordova_android/test/src/org/apache/cordova/test/background.java +34 -0
  91. data/templates/cordova_android/test/src/org/apache/cordova/test/errorurl.java +32 -0
  92. data/templates/cordova_android/test/src/org/apache/cordova/test/htmlnotfound.java +31 -0
  93. data/templates/cordova_android/test/src/org/apache/cordova/test/iframe.java +30 -0
  94. data/templates/cordova_android/test/src/org/apache/cordova/test/jqmtabbackbutton.java +30 -0
  95. data/templates/cordova_android/test/src/org/apache/cordova/test/lifecycle.java +30 -0
  96. data/templates/cordova_android/test/src/org/apache/cordova/test/loading.java +31 -0
  97. data/templates/cordova_android/test/src/org/apache/cordova/test/menus.java +80 -0
  98. data/templates/cordova_android/test/src/org/apache/cordova/test/splashscreen.java +35 -0
  99. data/templates/cordova_android/test/src/org/apache/cordova/test/tests.java +32 -0
  100. data/templates/cordova_android/test/src/org/apache/cordova/test/timeout.java +34 -0
  101. data/templates/cordova_android/test/src/org/apache/cordova/test/userwebview.java +72 -0
  102. data/templates/cordova_android/test/src/org/apache/cordova/test/whitelist.java +51 -0
  103. data/templates/cordova_android/test/src/org/apache/cordova/test/xhr.java +30 -0
  104. metadata +83 -30
  105. data/templates/cordova_android/framework/assets/js/accelerometer.js +0 -137
  106. data/templates/cordova_android/framework/assets/js/app.js +0 -89
  107. data/templates/cordova_android/framework/assets/js/battery.js +0 -134
  108. data/templates/cordova_android/framework/assets/js/camera.js +0 -168
  109. data/templates/cordova_android/framework/assets/js/capture.js +0 -203
  110. data/templates/cordova_android/framework/assets/js/compass.js +0 -168
  111. data/templates/cordova_android/framework/assets/js/contact.js +0 -310
  112. data/templates/cordova_android/framework/assets/js/cordova.js.base +0 -924
  113. data/templates/cordova_android/framework/assets/js/crypto.js +0 -54
  114. data/templates/cordova_android/framework/assets/js/device.js +0 -83
  115. data/templates/cordova_android/framework/assets/js/file.js +0 -1082
  116. data/templates/cordova_android/framework/assets/js/filetransfer.js +0 -125
  117. data/templates/cordova_android/framework/assets/js/geolocation.js +0 -209
  118. data/templates/cordova_android/framework/assets/js/header.txt +0 -19
  119. data/templates/cordova_android/framework/assets/js/media.js +0 -233
  120. data/templates/cordova_android/framework/assets/js/network.js +0 -100
  121. data/templates/cordova_android/framework/assets/js/notification.js +0 -133
  122. data/templates/cordova_android/framework/assets/js/position.js +0 -100
  123. data/templates/cordova_android/framework/assets/js/storage.js +0 -439
@@ -1,924 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
- if (typeof Cordova === "undefined") {
21
-
22
- /**
23
- * The order of events during page load and Cordova startup is as follows:
24
- *
25
- * onDOMContentLoaded Internal event that is received when the web page is loaded and parsed.
26
- * window.onload Body onload event.
27
- * onNativeReady Internal event that indicates the Cordova native side is ready.
28
- * onCordovaInit Internal event that kicks off creation of all Cordova JavaScript objects (runs constructors).
29
- * onCordovaReady Internal event fired when all Cordova JavaScript objects have been created
30
- * onCordovaInfoReady Internal event fired when device properties are available
31
- * onDeviceReady User event fired to indicate that Cordova is ready
32
- * onResume User event fired to indicate a start/resume lifecycle event
33
- * onPause User event fired to indicate a pause lifecycle event
34
- * onDestroy Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
35
- *
36
- * The only Cordova events that user code should register for are:
37
- * deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
38
- * pause App has moved to background
39
- * resume App has returned to foreground
40
- *
41
- * Listeners can be registered as:
42
- * document.addEventListener("deviceready", myDeviceReadyListener, false);
43
- * document.addEventListener("resume", myResumeListener, false);
44
- * document.addEventListener("pause", myPauseListener, false);
45
- *
46
- * The DOM lifecycle events should be used for saving and restoring state
47
- * window.onload
48
- * window.onunload
49
- */
50
-
51
- /**
52
- * This represents the Cordova API itself, and provides a global namespace for accessing
53
- * information about the state of Cordova.
54
- * @class
55
- */
56
- var Cordova = {
57
- documentEventHandler: {}, // Collection of custom document event handlers
58
- windowEventHandler: {} // Collection of custom window event handlers
59
- };
60
-
61
- /**
62
- * List of resource files loaded by Cordova.
63
- * This is used to ensure JS and other files are loaded only once.
64
- */
65
- Cordova.resources = {base: true};
66
-
67
- /**
68
- * Determine if resource has been loaded by Cordova
69
- *
70
- * @param name
71
- * @return
72
- */
73
- Cordova.hasResource = function(name) {
74
- return Cordova.resources[name];
75
- };
76
-
77
- /**
78
- * Add a resource to list of loaded resources by Cordova
79
- *
80
- * @param name
81
- */
82
- Cordova.addResource = function(name) {
83
- Cordova.resources[name] = true;
84
- };
85
-
86
- /**
87
- * Custom pub-sub channel that can have functions subscribed to it
88
- * @constructor
89
- */
90
- Cordova.Channel = function (type)
91
- {
92
- this.type = type;
93
- this.handlers = {};
94
- this.guid = 0;
95
- this.fired = false;
96
- this.enabled = true;
97
- };
98
-
99
- /**
100
- * Subscribes the given function to the channel. Any time that
101
- * Channel.fire is called so too will the function.
102
- * Optionally specify an execution context for the function
103
- * and a guid that can be used to stop subscribing to the channel.
104
- * Returns the guid.
105
- */
106
- Cordova.Channel.prototype.subscribe = function(f, c, g) {
107
- // need a function to call
108
- if (f === null) { return; }
109
-
110
- var func = f;
111
- if (typeof c === "object" && typeof f === "function") { func = Cordova.close(c, f); }
112
-
113
- g = g || func.observer_guid || f.observer_guid || this.guid++;
114
- func.observer_guid = g;
115
- f.observer_guid = g;
116
- this.handlers[g] = func;
117
- return g;
118
- };
119
-
120
- /**
121
- * Like subscribe but the function is only called once and then it
122
- * auto-unsubscribes itself.
123
- */
124
- Cordova.Channel.prototype.subscribeOnce = function(f, c) {
125
- var g = null;
126
- var _this = this;
127
- var m = function() {
128
- f.apply(c || null, arguments);
129
- _this.unsubscribe(g);
130
- };
131
- if (this.fired) {
132
- if (typeof c === "object" && typeof f === "function") { f = Cordova.close(c, f); }
133
- f.apply(this, this.fireArgs);
134
- } else {
135
- g = this.subscribe(m);
136
- }
137
- return g;
138
- };
139
-
140
- /**
141
- * Unsubscribes the function with the given guid from the channel.
142
- */
143
- Cordova.Channel.prototype.unsubscribe = function(g) {
144
- if (typeof g === "function") { g = g.observer_guid; }
145
- this.handlers[g] = null;
146
- delete this.handlers[g];
147
- };
148
-
149
- /**
150
- * Calls all functions subscribed to this channel.
151
- */
152
- Cordova.Channel.prototype.fire = function(e) {
153
- if (this.enabled) {
154
- var fail = false;
155
- var item, handler, rv;
156
- for (item in this.handlers) {
157
- if (this.handlers.hasOwnProperty(item)) {
158
- handler = this.handlers[item];
159
- if (typeof handler === "function") {
160
- rv = (handler.apply(this, arguments) === false);
161
- fail = fail || rv;
162
- }
163
- }
164
- }
165
- this.fired = true;
166
- this.fireArgs = arguments;
167
- return !fail;
168
- }
169
- return true;
170
- };
171
-
172
- /**
173
- * Calls the provided function only after all of the channels specified
174
- * have been fired.
175
- */
176
- Cordova.Channel.join = function(h, c) {
177
- var i = c.length;
178
- var f = function() {
179
- if (!(--i)) {
180
- h();
181
- }
182
- };
183
- var len = i;
184
- var j;
185
- for (j=0; j<len; j++) {
186
- if (!c[j].fired) {
187
- c[j].subscribeOnce(f);
188
- }
189
- else {
190
- i--;
191
- }
192
- }
193
- if (!i) {
194
- h();
195
- }
196
- };
197
-
198
- /**
199
- * Add an initialization function to a queue that ensures it will run and initialize
200
- * application constructors only once Cordova has been initialized.
201
- * @param {Function} func The function callback you want run once Cordova is initialized
202
- */
203
- Cordova.addConstructor = function(func) {
204
- Cordova.onCordovaInit.subscribeOnce(function() {
205
- try {
206
- func();
207
- } catch(e) {
208
- console.log("Failed to run constructor: " + e);
209
- }
210
- });
211
- };
212
-
213
- /**
214
- * Plugins object
215
- */
216
- if (!window.plugins) {
217
- window.plugins = {};
218
- }
219
-
220
- /**
221
- * Adds a plugin object to window.plugins.
222
- * The plugin is accessed using window.plugins.<name>
223
- *
224
- * @param name The plugin name
225
- * @param obj The plugin object
226
- */
227
- Cordova.addPlugin = function(name, obj) {
228
- if (!window.plugins[name]) {
229
- window.plugins[name] = obj;
230
- }
231
- else {
232
- console.log("Error: Plugin "+name+" already exists.");
233
- }
234
- };
235
-
236
- /**
237
- * onDOMContentLoaded channel is fired when the DOM content
238
- * of the page has been parsed.
239
- */
240
- Cordova.onDOMContentLoaded = new Cordova.Channel('onDOMContentLoaded');
241
-
242
- /**
243
- * onNativeReady channel is fired when the Cordova native code
244
- * has been initialized.
245
- */
246
- Cordova.onNativeReady = new Cordova.Channel('onNativeReady');
247
-
248
- /**
249
- * onCordovaInit channel is fired when the web page is fully loaded and
250
- * Cordova native code has been initialized.
251
- */
252
- Cordova.onCordovaInit = new Cordova.Channel('onCordovaInit');
253
-
254
- /**
255
- * onCordovaReady channel is fired when the JS Cordova objects have been created.
256
- */
257
- Cordova.onCordovaReady = new Cordova.Channel('onCordovaReady');
258
-
259
- /**
260
- * onCordovaInfoReady channel is fired when the Cordova device properties
261
- * has been set.
262
- */
263
- Cordova.onCordovaInfoReady = new Cordova.Channel('onCordovaInfoReady');
264
-
265
- /**
266
- * onCordovaConnectionReady channel is fired when the Cordova connection properties
267
- * has been set.
268
- */
269
- Cordova.onCordovaConnectionReady = new Cordova.Channel('onCordovaConnectionReady');
270
-
271
- /**
272
- * onDestroy channel is fired when the Cordova native code
273
- * is destroyed. It is used internally.
274
- * Window.onunload should be used by the user.
275
- */
276
- Cordova.onDestroy = new Cordova.Channel('onDestroy');
277
- Cordova.onDestroy.subscribeOnce(function() {
278
- Cordova.shuttingDown = true;
279
- });
280
- Cordova.shuttingDown = false;
281
-
282
- // _nativeReady is global variable that the native side can set
283
- // to signify that the native code is ready. It is a global since
284
- // it may be called before any Cordova JS is ready.
285
- if (typeof _nativeReady !== 'undefined') { Cordova.onNativeReady.fire(); }
286
-
287
- /**
288
- * onDeviceReady is fired only after all Cordova objects are created and
289
- * the device properties are set.
290
- */
291
- Cordova.onDeviceReady = new Cordova.Channel('onDeviceReady');
292
-
293
-
294
- // Array of channels that must fire before "deviceready" is fired
295
- Cordova.deviceReadyChannelsArray = [ Cordova.onCordovaReady, Cordova.onCordovaInfoReady, Cordova.onCordovaConnectionReady];
296
-
297
- // Hashtable of user defined channels that must also fire before "deviceready" is fired
298
- Cordova.deviceReadyChannelsMap = {};
299
-
300
- /**
301
- * Indicate that a feature needs to be initialized before it is ready to be used.
302
- * This holds up Cordova's "deviceready" event until the feature has been initialized
303
- * and Cordova.initComplete(feature) is called.
304
- *
305
- * @param feature {String} The unique feature name
306
- */
307
- Cordova.waitForInitialization = function(feature) {
308
- if (feature) {
309
- var channel = new Cordova.Channel(feature);
310
- Cordova.deviceReadyChannelsMap[feature] = channel;
311
- Cordova.deviceReadyChannelsArray.push(channel);
312
- }
313
- };
314
-
315
- /**
316
- * Indicate that initialization code has completed and the feature is ready to be used.
317
- *
318
- * @param feature {String} The unique feature name
319
- */
320
- Cordova.initializationComplete = function(feature) {
321
- var channel = Cordova.deviceReadyChannelsMap[feature];
322
- if (channel) {
323
- channel.fire();
324
- }
325
- };
326
-
327
- /**
328
- * Create all Cordova objects once page has fully loaded and native side is ready.
329
- */
330
- Cordova.Channel.join(function() {
331
-
332
- // Start listening for XHR callbacks
333
- setTimeout(function() {
334
- if (Cordova.UsePolling) {
335
- Cordova.JSCallbackPolling();
336
- }
337
- else {
338
- var polling = prompt("usePolling", "gap_callbackServer:");
339
- Cordova.UsePolling = polling;
340
- if (polling == "true") {
341
- Cordova.UsePolling = true;
342
- Cordova.JSCallbackPolling();
343
- }
344
- else {
345
- Cordova.UsePolling = false;
346
- Cordova.JSCallback();
347
- }
348
- }
349
- }, 1);
350
-
351
- // Run Cordova constructors
352
- Cordova.onCordovaInit.fire();
353
-
354
- // Fire event to notify that all objects are created
355
- Cordova.onCordovaReady.fire();
356
-
357
- // Fire onDeviceReady event once all constructors have run and Cordova info has been
358
- // received from native side, and any user defined initialization channels.
359
- Cordova.Channel.join(function() {
360
- // Let native code know we are inited on JS side
361
- prompt("", "gap_init:");
362
-
363
- Cordova.onDeviceReady.fire();
364
- }, Cordova.deviceReadyChannelsArray);
365
-
366
- }, [ Cordova.onDOMContentLoaded, Cordova.onNativeReady ]);
367
-
368
- // Listen for DOMContentLoaded and notify our channel subscribers
369
- document.addEventListener('DOMContentLoaded', function() {
370
- Cordova.onDOMContentLoaded.fire();
371
- }, false);
372
-
373
- // Intercept calls to document.addEventListener and watch for deviceready
374
- Cordova.m_document_addEventListener = document.addEventListener;
375
-
376
- // Intercept calls to window.addEventListener
377
- Cordova.m_window_addEventListener = window.addEventListener;
378
-
379
- /**
380
- * Add a custom window event handler.
381
- *
382
- * @param {String} event The event name that callback handles
383
- * @param {Function} callback The event handler
384
- */
385
- Cordova.addWindowEventHandler = function(event, callback) {
386
- Cordova.windowEventHandler[event] = callback;
387
- };
388
-
389
- /**
390
- * Add a custom document event handler.
391
- *
392
- * @param {String} event The event name that callback handles
393
- * @param {Function} callback The event handler
394
- */
395
- Cordova.addDocumentEventHandler = function(event, callback) {
396
- Cordova.documentEventHandler[event] = callback;
397
- };
398
-
399
- /**
400
- * Intercept adding document event listeners and handle our own
401
- *
402
- * @param {Object} evt
403
- * @param {Function} handler
404
- * @param capture
405
- */
406
- document.addEventListener = function(evt, handler, capture) {
407
- var e = evt.toLowerCase();
408
- if (e === 'deviceready') {
409
- Cordova.onDeviceReady.subscribeOnce(handler);
410
- }
411
- else {
412
- // If subscribing to Android backbutton
413
- if (e === 'backbutton') {
414
- Cordova.exec(null, null, "App", "overrideBackbutton", [true]);
415
- }
416
-
417
- // If subscribing to an event that is handled by a plugin
418
- else if (typeof Cordova.documentEventHandler[e] !== "undefined") {
419
- if (Cordova.documentEventHandler[e](e, handler, true)) {
420
- return; // Stop default behavior
421
- }
422
- }
423
-
424
- Cordova.m_document_addEventListener.call(document, evt, handler, capture);
425
- }
426
- };
427
-
428
- /**
429
- * Intercept adding window event listeners and handle our own
430
- *
431
- * @param {Object} evt
432
- * @param {Function} handler
433
- * @param capture
434
- */
435
- window.addEventListener = function(evt, handler, capture) {
436
- var e = evt.toLowerCase();
437
-
438
- // If subscribing to an event that is handled by a plugin
439
- if (typeof Cordova.windowEventHandler[e] !== "undefined") {
440
- if (Cordova.windowEventHandler[e](e, handler, true)) {
441
- return; // Stop default behavior
442
- }
443
- }
444
-
445
- Cordova.m_window_addEventListener.call(window, evt, handler, capture);
446
- };
447
-
448
- // Intercept calls to document.removeEventListener and watch for events that
449
- // are generated by Cordova native code
450
- Cordova.m_document_removeEventListener = document.removeEventListener;
451
-
452
- // Intercept calls to window.removeEventListener
453
- Cordova.m_window_removeEventListener = window.removeEventListener;
454
-
455
- /**
456
- * Intercept removing document event listeners and handle our own
457
- *
458
- * @param {Object} evt
459
- * @param {Function} handler
460
- * @param capture
461
- */
462
- document.removeEventListener = function(evt, handler, capture) {
463
- var e = evt.toLowerCase();
464
-
465
- // If unsubscribing to Android backbutton
466
- if (e === 'backbutton') {
467
- Cordova.exec(null, null, "App", "overrideBackbutton", [false]);
468
- }
469
-
470
- // If unsubcribing from an event that is handled by a plugin
471
- if (typeof Cordova.documentEventHandler[e] !== "undefined") {
472
- if (Cordova.documentEventHandler[e](e, handler, false)) {
473
- return; // Stop default behavior
474
- }
475
- }
476
-
477
- Cordova.m_document_removeEventListener.call(document, evt, handler, capture);
478
- };
479
-
480
- /**
481
- * Intercept removing window event listeners and handle our own
482
- *
483
- * @param {Object} evt
484
- * @param {Function} handler
485
- * @param capture
486
- */
487
- window.removeEventListener = function(evt, handler, capture) {
488
- var e = evt.toLowerCase();
489
-
490
- // If unsubcribing from an event that is handled by a plugin
491
- if (typeof Cordova.windowEventHandler[e] !== "undefined") {
492
- if (Cordova.windowEventHandler[e](e, handler, false)) {
493
- return; // Stop default behavior
494
- }
495
- }
496
-
497
- Cordova.m_window_removeEventListener.call(window, evt, handler, capture);
498
- };
499
-
500
- /**
501
- * Method to fire document event
502
- *
503
- * @param {String} type The event type to fire
504
- * @param {Object} data Data to send with event
505
- */
506
- Cordova.fireDocumentEvent = function(type, data) {
507
- var e = document.createEvent('Events');
508
- e.initEvent(type);
509
- if (data) {
510
- for (var i in data) {
511
- e[i] = data[i];
512
- }
513
- }
514
- document.dispatchEvent(e);
515
- };
516
-
517
- /**
518
- * Method to fire window event
519
- *
520
- * @param {String} type The event type to fire
521
- * @param {Object} data Data to send with event
522
- */
523
- Cordova.fireWindowEvent = function(type, data) {
524
- var e = document.createEvent('Events');
525
- e.initEvent(type);
526
- if (data) {
527
- for (var i in data) {
528
- e[i] = data[i];
529
- }
530
- }
531
- window.dispatchEvent(e);
532
- };
533
-
534
- /**
535
- * Does a deep clone of the object.
536
- *
537
- * @param obj
538
- * @return {Object}
539
- */
540
- Cordova.clone = function(obj) {
541
- var i, retVal;
542
- if(!obj) {
543
- return obj;
544
- }
545
-
546
- if(obj instanceof Array){
547
- retVal = [];
548
- for(i = 0; i < obj.length; ++i){
549
- retVal.push(Cordova.clone(obj[i]));
550
- }
551
- return retVal;
552
- }
553
-
554
- if (typeof obj === "function") {
555
- return obj;
556
- }
557
-
558
- if(!(obj instanceof Object)){
559
- return obj;
560
- }
561
-
562
- if (obj instanceof Date) {
563
- return obj;
564
- }
565
-
566
- retVal = {};
567
- for(i in obj){
568
- if(!(i in retVal) || retVal[i] !== obj[i]) {
569
- retVal[i] = Cordova.clone(obj[i]);
570
- }
571
- }
572
- return retVal;
573
- };
574
-
575
- Cordova.callbackId = 0;
576
- Cordova.callbacks = {};
577
- Cordova.callbackStatus = {
578
- NO_RESULT: 0,
579
- OK: 1,
580
- CLASS_NOT_FOUND_EXCEPTION: 2,
581
- ILLEGAL_ACCESS_EXCEPTION: 3,
582
- INSTANTIATION_EXCEPTION: 4,
583
- MALFORMED_URL_EXCEPTION: 5,
584
- IO_EXCEPTION: 6,
585
- INVALID_ACTION: 7,
586
- JSON_EXCEPTION: 8,
587
- ERROR: 9
588
- };
589
-
590
-
591
- /**
592
- * Execute a Cordova command. It is up to the native side whether this action is synch or async.
593
- * The native side can return:
594
- * Synchronous: PluginResult object as a JSON string
595
- * Asynchrounous: Empty string ""
596
- * If async, the native side will Cordova.callbackSuccess or Cordova.callbackError,
597
- * depending upon the result of the action.
598
- *
599
- * @param {Function} success The success callback
600
- * @param {Function} fail The fail callback
601
- * @param {String} service The name of the service to use
602
- * @param {String} action Action to be run in Cordova
603
- * @param {Array.<String>} [args] Zero or more arguments to pass to the method
604
- */
605
- Cordova.exec = function(success, fail, service, action, args) {
606
- try {
607
- var callbackId = service + Cordova.callbackId++;
608
- if (success || fail) {
609
- Cordova.callbacks[callbackId] = {success:success, fail:fail};
610
- }
611
-
612
- var r = prompt(JSON.stringify(args), "gap:"+JSON.stringify([service, action, callbackId, true]));
613
-
614
- // If a result was returned
615
- if (r.length > 0) {
616
- eval("var v="+r+";");
617
-
618
- // If status is OK, then return value back to caller
619
- if (v.status === Cordova.callbackStatus.OK) {
620
-
621
- // If there is a success callback, then call it now with
622
- // returned value
623
- if (success) {
624
- try {
625
- success(v.message);
626
- } catch (e) {
627
- console.log("Error in success callback: " + callbackId + " = " + e);
628
- }
629
-
630
- // Clear callback if not expecting any more results
631
- if (!v.keepCallback) {
632
- delete Cordova.callbacks[callbackId];
633
- }
634
- }
635
- return v.message;
636
- }
637
-
638
- // If no result
639
- else if (v.status === Cordova.callbackStatus.NO_RESULT) {
640
-
641
- // Clear callback if not expecting any more results
642
- if (!v.keepCallback) {
643
- delete Cordova.callbacks[callbackId];
644
- }
645
- }
646
-
647
- // If error, then display error
648
- else {
649
- console.log("Error: Status="+v.status+" Message="+v.message);
650
-
651
- // If there is a fail callback, then call it now with returned value
652
- if (fail) {
653
- try {
654
- fail(v.message);
655
- }
656
- catch (e1) {
657
- console.log("Error in error callback: "+callbackId+" = "+e1);
658
- }
659
-
660
- // Clear callback if not expecting any more results
661
- if (!v.keepCallback) {
662
- delete Cordova.callbacks[callbackId];
663
- }
664
- }
665
- return null;
666
- }
667
- }
668
- } catch (e2) {
669
- console.log("Error: "+e2);
670
- }
671
- };
672
-
673
- /**
674
- * Called by native code when returning successful result from an action.
675
- *
676
- * @param callbackId
677
- * @param args
678
- */
679
- Cordova.callbackSuccess = function(callbackId, args) {
680
- if (Cordova.callbacks[callbackId]) {
681
-
682
- // If result is to be sent to callback
683
- if (args.status === Cordova.callbackStatus.OK) {
684
- try {
685
- if (Cordova.callbacks[callbackId].success) {
686
- Cordova.callbacks[callbackId].success(args.message);
687
- }
688
- }
689
- catch (e) {
690
- console.log("Error in success callback: "+callbackId+" = "+e);
691
- }
692
- }
693
-
694
- // Clear callback if not expecting any more results
695
- if (!args.keepCallback) {
696
- delete Cordova.callbacks[callbackId];
697
- }
698
- }
699
- };
700
-
701
- /**
702
- * Called by native code when returning error result from an action.
703
- *
704
- * @param callbackId
705
- * @param args
706
- */
707
- Cordova.callbackError = function(callbackId, args) {
708
- if (Cordova.callbacks[callbackId]) {
709
- try {
710
- if (Cordova.callbacks[callbackId].fail) {
711
- Cordova.callbacks[callbackId].fail(args.message);
712
- }
713
- }
714
- catch (e) {
715
- console.log("Error in error callback: "+callbackId+" = "+e);
716
- }
717
-
718
- // Clear callback if not expecting any more results
719
- if (!args.keepCallback) {
720
- delete Cordova.callbacks[callbackId];
721
- }
722
- }
723
- };
724
-
725
- Cordova.JSCallbackPort = null;
726
- Cordova.JSCallbackToken = null;
727
-
728
- /**
729
- * This is only for Android.
730
- *
731
- * Internal function that uses XHR to call into Cordova Java code and retrieve
732
- * any JavaScript code that needs to be run. This is used for callbacks from
733
- * Java to JavaScript.
734
- */
735
- Cordova.JSCallback = function() {
736
-
737
- // Exit if shutting down app
738
- if (Cordova.shuttingDown) {
739
- return;
740
- }
741
-
742
- // If polling flag was changed, start using polling from now on
743
- if (Cordova.UsePolling) {
744
- Cordova.JSCallbackPolling();
745
- return;
746
- }
747
-
748
- var xmlhttp = new XMLHttpRequest();
749
-
750
- // Callback function when XMLHttpRequest is ready
751
- xmlhttp.onreadystatechange=function(){
752
- if(xmlhttp.readyState === 4){
753
-
754
- // Exit if shutting down app
755
- if (Cordova.shuttingDown) {
756
- return;
757
- }
758
-
759
- // If callback has JavaScript statement to execute
760
- if (xmlhttp.status === 200) {
761
-
762
- // Need to url decode the response
763
- var msg = decodeURIComponent(xmlhttp.responseText);
764
- setTimeout(function() {
765
- try {
766
- var t = eval(msg);
767
- }
768
- catch (e) {
769
- // If we're getting an error here, seeing the message will help in debugging
770
- console.log("JSCallback: Message from Server: " + msg);
771
- console.log("JSCallback Error: "+e);
772
- }
773
- }, 1);
774
- setTimeout(Cordova.JSCallback, 1);
775
- }
776
-
777
- // If callback ping (used to keep XHR request from timing out)
778
- else if (xmlhttp.status === 404) {
779
- setTimeout(Cordova.JSCallback, 10);
780
- }
781
-
782
- // If security error
783
- else if (xmlhttp.status === 403) {
784
- console.log("JSCallback Error: Invalid token. Stopping callbacks.");
785
- }
786
-
787
- // If server is stopping
788
- else if (xmlhttp.status === 503) {
789
- console.log("JSCallback Server Closed: Stopping callbacks.");
790
- }
791
-
792
- // If request wasn't GET
793
- else if (xmlhttp.status === 400) {
794
- console.log("JSCallback Error: Bad request. Stopping callbacks.");
795
- }
796
-
797
- // If error, revert to polling
798
- else {
799
- console.log("JSCallback Error: Request failed.");
800
- Cordova.UsePolling = true;
801
- Cordova.JSCallbackPolling();
802
- }
803
- }
804
- };
805
-
806
- if (Cordova.JSCallbackPort === null) {
807
- Cordova.JSCallbackPort = prompt("getPort", "gap_callbackServer:");
808
- }
809
- if (Cordova.JSCallbackToken === null) {
810
- Cordova.JSCallbackToken = prompt("getToken", "gap_callbackServer:");
811
- }
812
- xmlhttp.open("GET", "http://127.0.0.1:"+Cordova.JSCallbackPort+"/"+Cordova.JSCallbackToken , true);
813
- xmlhttp.send();
814
- };
815
-
816
- /**
817
- * The polling period to use with JSCallbackPolling.
818
- * This can be changed by the application. The default is 50ms.
819
- */
820
- Cordova.JSCallbackPollingPeriod = 50;
821
-
822
- /**
823
- * Flag that can be set by the user to force polling to be used or force XHR to be used.
824
- */
825
- Cordova.UsePolling = false; // T=use polling, F=use XHR
826
-
827
- /**
828
- * This is only for Android.
829
- *
830
- * Internal function that uses polling to call into Cordova Java code and retrieve
831
- * any JavaScript code that needs to be run. This is used for callbacks from
832
- * Java to JavaScript.
833
- */
834
- Cordova.JSCallbackPolling = function() {
835
-
836
- // Exit if shutting down app
837
- if (Cordova.shuttingDown) {
838
- return;
839
- }
840
-
841
- // If polling flag was changed, stop using polling from now on
842
- if (!Cordova.UsePolling) {
843
- Cordova.JSCallback();
844
- return;
845
- }
846
-
847
- var msg = prompt("", "gap_poll:");
848
- if (msg) {
849
- setTimeout(function() {
850
- try {
851
- var t = eval(""+msg);
852
- }
853
- catch (e) {
854
- console.log("JSCallbackPolling: Message from Server: " + msg);
855
- console.log("JSCallbackPolling Error: "+e);
856
- }
857
- }, 1);
858
- setTimeout(Cordova.JSCallbackPolling, 1);
859
- }
860
- else {
861
- setTimeout(Cordova.JSCallbackPolling, Cordova.JSCallbackPollingPeriod);
862
- }
863
- };
864
-
865
- /**
866
- * Create a UUID
867
- *
868
- * @return {String}
869
- */
870
- Cordova.createUUID = function() {
871
- return Cordova.UUIDcreatePart(4) + '-' +
872
- Cordova.UUIDcreatePart(2) + '-' +
873
- Cordova.UUIDcreatePart(2) + '-' +
874
- Cordova.UUIDcreatePart(2) + '-' +
875
- Cordova.UUIDcreatePart(6);
876
- };
877
-
878
- Cordova.UUIDcreatePart = function(length) {
879
- var uuidpart = "";
880
- var i, uuidchar;
881
- for (i=0; i<length; i++) {
882
- uuidchar = parseInt((Math.random() * 256),0).toString(16);
883
- if (uuidchar.length === 1) {
884
- uuidchar = "0" + uuidchar;
885
- }
886
- uuidpart += uuidchar;
887
- }
888
- return uuidpart;
889
- };
890
-
891
- Cordova.close = function(context, func, params) {
892
- if (typeof params === 'undefined') {
893
- return function() {
894
- return func.apply(context, arguments);
895
- };
896
- } else {
897
- return function() {
898
- return func.apply(context, params);
899
- };
900
- }
901
- };
902
-
903
- /**
904
- * Load a JavaScript file after page has loaded.
905
- *
906
- * @param {String} jsfile The url of the JavaScript file to load.
907
- * @param {Function} successCallback The callback to call when the file has been loaded.
908
- */
909
- Cordova.includeJavascript = function(jsfile, successCallback) {
910
- var id = document.getElementsByTagName("head")[0];
911
- var el = document.createElement('script');
912
- el.type = 'text/javascript';
913
- if (typeof successCallback === 'function') {
914
- el.onload = successCallback;
915
- }
916
- el.src = jsfile;
917
- id.appendChild(el);
918
- };
919
-
920
- /**
921
- * Legacy variable for old plugins.
922
- */
923
- var PhoneGap = Cordova;
924
- }