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,1082 +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 (!Cordova.hasResource("file")) {
21
- Cordova.addResource("file");
22
-
23
- /**
24
- * This class provides some useful information about a file.
25
- * @constructor
26
- */
27
- var FileProperties = function(filePath) {
28
- this.filePath = filePath;
29
- this.size = 0;
30
- this.lastModifiedDate = null;
31
- };
32
-
33
- /**
34
- * Represents a single file.
35
- *
36
- * @constructor
37
- * @param name {DOMString} name of the file, without path information
38
- * @param fullPath {DOMString} the full path of the file, including the name
39
- * @param type {DOMString} mime type
40
- * @param lastModifiedDate {Date} last modified date
41
- * @param size {Number} size of the file in bytes
42
- */
43
- var File = function(name, fullPath, type, lastModifiedDate, size) {
44
- this.name = name || null;
45
- this.fullPath = fullPath || null;
46
- this.type = type || null;
47
- this.lastModifiedDate = lastModifiedDate || null;
48
- this.size = size || 0;
49
- };
50
-
51
- /** @constructor */
52
- var FileError = function() {
53
- this.code = null;
54
- };
55
-
56
- // File error codes
57
- // Found in DOMException
58
- FileError.NOT_FOUND_ERR = 1;
59
- FileError.SECURITY_ERR = 2;
60
- FileError.ABORT_ERR = 3;
61
-
62
- // Added by this specification
63
- FileError.NOT_READABLE_ERR = 4;
64
- FileError.ENCODING_ERR = 5;
65
- FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
66
- FileError.INVALID_STATE_ERR = 7;
67
- FileError.SYNTAX_ERR = 8;
68
- FileError.INVALID_MODIFICATION_ERR = 9;
69
- FileError.QUOTA_EXCEEDED_ERR = 10;
70
- FileError.TYPE_MISMATCH_ERR = 11;
71
- FileError.PATH_EXISTS_ERR = 12;
72
-
73
- //-----------------------------------------------------------------------------
74
- // File Reader
75
- //-----------------------------------------------------------------------------
76
-
77
- /**
78
- * This class reads the mobile device file system.
79
- *
80
- * For Android:
81
- * The root directory is the root of the file system.
82
- * To read from the SD card, the file name is "sdcard/my_file.txt"
83
- * @constructor
84
- */
85
- var FileReader = function() {
86
- this.fileName = "";
87
-
88
- this.readyState = 0;
89
-
90
- // File data
91
- this.result = null;
92
-
93
- // Error
94
- this.error = null;
95
-
96
- // Event handlers
97
- this.onloadstart = null; // When the read starts.
98
- this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progess.loaded/progress.total)
99
- this.onload = null; // When the read has successfully completed.
100
- this.onerror = null; // When the read has failed (see errors).
101
- this.onloadend = null; // When the request has completed (either in success or failure).
102
- this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method.
103
- };
104
-
105
- // States
106
- FileReader.EMPTY = 0;
107
- FileReader.LOADING = 1;
108
- FileReader.DONE = 2;
109
-
110
- /**
111
- * Abort reading file.
112
- */
113
- FileReader.prototype.abort = function() {
114
- var evt;
115
- this.readyState = FileReader.DONE;
116
- this.result = null;
117
-
118
- // set error
119
- var error = new FileError();
120
- error.code = error.ABORT_ERR;
121
- this.error = error;
122
-
123
- // If error callback
124
- if (typeof this.onerror === "function") {
125
- this.onerror({"type":"error", "target":this});
126
- }
127
- // If abort callback
128
- if (typeof this.onabort === "function") {
129
- this.onabort({"type":"abort", "target":this});
130
- }
131
- // If load end callback
132
- if (typeof this.onloadend === "function") {
133
- this.onloadend({"type":"loadend", "target":this});
134
- }
135
- };
136
-
137
- /**
138
- * Read text file.
139
- *
140
- * @param file {File} File object containing file properties
141
- * @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
142
- */
143
- FileReader.prototype.readAsText = function(file, encoding) {
144
- this.fileName = "";
145
- if (typeof file.fullPath === "undefined") {
146
- this.fileName = file;
147
- } else {
148
- this.fileName = file.fullPath;
149
- }
150
-
151
- // LOADING state
152
- this.readyState = FileReader.LOADING;
153
-
154
- // If loadstart callback
155
- if (typeof this.onloadstart === "function") {
156
- this.onloadstart({"type":"loadstart", "target":this});
157
- }
158
-
159
- // Default encoding is UTF-8
160
- var enc = encoding ? encoding : "UTF-8";
161
-
162
- var me = this;
163
-
164
- // Read file
165
- Cordova.exec(
166
- // Success callback
167
- function(r) {
168
- var evt;
169
-
170
- // If DONE (cancelled), then don't do anything
171
- if (me.readyState === FileReader.DONE) {
172
- return;
173
- }
174
-
175
- // Save result
176
- me.result = r;
177
-
178
- // If onload callback
179
- if (typeof me.onload === "function") {
180
- me.onload({"type":"load", "target":me});
181
- }
182
-
183
- // DONE state
184
- me.readyState = FileReader.DONE;
185
-
186
- // If onloadend callback
187
- if (typeof me.onloadend === "function") {
188
- me.onloadend({"type":"loadend", "target":me});
189
- }
190
- },
191
- // Error callback
192
- function(e) {
193
- var evt;
194
- // If DONE (cancelled), then don't do anything
195
- if (me.readyState === FileReader.DONE) {
196
- return;
197
- }
198
-
199
- // Save error
200
- me.error = e;
201
-
202
- // If onerror callback
203
- if (typeof me.onerror === "function") {
204
- me.onerror({"type":"error", "target":me});
205
- }
206
-
207
- // DONE state
208
- me.readyState = FileReader.DONE;
209
-
210
- // If onloadend callback
211
- if (typeof me.onloadend === "function") {
212
- me.onloadend({"type":"loadend", "target":me});
213
- }
214
- }, "File", "readAsText", [this.fileName, enc]);
215
- };
216
-
217
-
218
- /**
219
- * Read file and return data as a base64 encoded data url.
220
- * A data url is of the form:
221
- * data:[<mediatype>][;base64],<data>
222
- *
223
- * @param file {File} File object containing file properties
224
- */
225
- FileReader.prototype.readAsDataURL = function(file) {
226
- this.fileName = "";
227
- if (typeof file.fullPath === "undefined") {
228
- this.fileName = file;
229
- } else {
230
- this.fileName = file.fullPath;
231
- }
232
-
233
- // LOADING state
234
- this.readyState = FileReader.LOADING;
235
-
236
- // If loadstart callback
237
- if (typeof this.onloadstart === "function") {
238
- this.onloadstart({"type":"loadstart", "target":this});
239
- }
240
-
241
- var me = this;
242
-
243
- // Read file
244
- Cordova.exec(
245
- // Success callback
246
- function(r) {
247
- var evt;
248
-
249
- // If DONE (cancelled), then don't do anything
250
- if (me.readyState === FileReader.DONE) {
251
- return;
252
- }
253
-
254
- // Save result
255
- me.result = r;
256
-
257
- // If onload callback
258
- if (typeof me.onload === "function") {
259
- me.onload({"type":"load", "target":me});
260
- }
261
-
262
- // DONE state
263
- me.readyState = FileReader.DONE;
264
-
265
- // If onloadend callback
266
- if (typeof me.onloadend === "function") {
267
- me.onloadend({"type":"loadend", "target":me});
268
- }
269
- },
270
- // Error callback
271
- function(e) {
272
- var evt;
273
- // If DONE (cancelled), then don't do anything
274
- if (me.readyState === FileReader.DONE) {
275
- return;
276
- }
277
-
278
- // Save error
279
- me.error = e;
280
-
281
- // If onerror callback
282
- if (typeof me.onerror === "function") {
283
- me.onerror({"type":"error", "target":me});
284
- }
285
-
286
- // DONE state
287
- me.readyState = FileReader.DONE;
288
-
289
- // If onloadend callback
290
- if (typeof me.onloadend === "function") {
291
- me.onloadend({"type":"loadend", "target":me});
292
- }
293
- }, "File", "readAsDataURL", [this.fileName]);
294
- };
295
-
296
- /**
297
- * Read file and return data as a binary data.
298
- *
299
- * @param file {File} File object containing file properties
300
- */
301
- FileReader.prototype.readAsBinaryString = function(file) {
302
- // TODO - Can't return binary data to browser.
303
- this.fileName = file;
304
- };
305
-
306
- /**
307
- * Read file and return data as a binary data.
308
- *
309
- * @param file {File} File object containing file properties
310
- */
311
- FileReader.prototype.readAsArrayBuffer = function(file) {
312
- // TODO - Can't return binary data to browser.
313
- this.fileName = file;
314
- };
315
-
316
- //-----------------------------------------------------------------------------
317
- // File Writer
318
- //-----------------------------------------------------------------------------
319
-
320
- /**
321
- * This class writes to the mobile device file system.
322
- *
323
- * For Android:
324
- * The root directory is the root of the file system.
325
- * To write to the SD card, the file name is "sdcard/my_file.txt"
326
- *
327
- * @constructor
328
- * @param file {File} File object containing file properties
329
- * @param append if true write to the end of the file, otherwise overwrite the file
330
- */
331
- var FileWriter = function(file) {
332
- this.fileName = "";
333
- this.length = 0;
334
- if (file) {
335
- this.fileName = file.fullPath || file;
336
- this.length = file.size || 0;
337
- }
338
- // default is to write at the beginning of the file
339
- this.position = 0;
340
-
341
- this.readyState = 0; // EMPTY
342
-
343
- this.result = null;
344
-
345
- // Error
346
- this.error = null;
347
-
348
- // Event handlers
349
- this.onwritestart = null; // When writing starts
350
- this.onprogress = null; // While writing the file, and reporting partial file data
351
- this.onwrite = null; // When the write has successfully completed.
352
- this.onwriteend = null; // When the request has completed (either in success or failure).
353
- this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
354
- this.onerror = null; // When the write has failed (see errors).
355
- };
356
-
357
- // States
358
- FileWriter.INIT = 0;
359
- FileWriter.WRITING = 1;
360
- FileWriter.DONE = 2;
361
-
362
- /**
363
- * Abort writing file.
364
- */
365
- FileWriter.prototype.abort = function() {
366
- // check for invalid state
367
- if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
368
- throw FileError.INVALID_STATE_ERR;
369
- }
370
-
371
- // set error
372
- var error = new FileError(), evt;
373
- error.code = error.ABORT_ERR;
374
- this.error = error;
375
-
376
- // If error callback
377
- if (typeof this.onerror === "function") {
378
- this.onerror({"type":"error", "target":this});
379
- }
380
- // If abort callback
381
- if (typeof this.onabort === "function") {
382
- this.onabort({"type":"abort", "target":this});
383
- }
384
-
385
- this.readyState = FileWriter.DONE;
386
-
387
- // If write end callback
388
- if (typeof this.onwriteend === "function") {
389
- this.onwriteend({"type":"writeend", "target":this});
390
- }
391
- };
392
-
393
- /**
394
- * Writes data to the file
395
- *
396
- * @param text to be written
397
- */
398
- FileWriter.prototype.write = function(text) {
399
- // Throw an exception if we are already writing a file
400
- if (this.readyState === FileWriter.WRITING) {
401
- throw FileError.INVALID_STATE_ERR;
402
- }
403
-
404
- // WRITING state
405
- this.readyState = FileWriter.WRITING;
406
-
407
- var me = this;
408
-
409
- // If onwritestart callback
410
- if (typeof me.onwritestart === "function") {
411
- me.onwritestart({"type":"writestart", "target":me});
412
- }
413
-
414
- // Write file
415
- Cordova.exec(
416
- // Success callback
417
- function(r) {
418
- var evt;
419
- // If DONE (cancelled), then don't do anything
420
- if (me.readyState === FileWriter.DONE) {
421
- return;
422
- }
423
-
424
- // position always increases by bytes written because file would be extended
425
- me.position += r;
426
- // The length of the file is now where we are done writing.
427
- me.length = me.position;
428
-
429
- // If onwrite callback
430
- if (typeof me.onwrite === "function") {
431
- me.onwrite({"type":"write", "target":me});
432
- }
433
-
434
- // DONE state
435
- me.readyState = FileWriter.DONE;
436
-
437
- // If onwriteend callback
438
- if (typeof me.onwriteend === "function") {
439
- me.onwriteend({"type":"writeend", "target":me});
440
- }
441
- },
442
- // Error callback
443
- function(e) {
444
- var evt;
445
-
446
- // If DONE (cancelled), then don't do anything
447
- if (me.readyState === FileWriter.DONE) {
448
- return;
449
- }
450
-
451
- // Save error
452
- me.error = e;
453
-
454
- // If onerror callback
455
- if (typeof me.onerror === "function") {
456
- me.onerror({"type":"error", "target":me});
457
- }
458
-
459
- // DONE state
460
- me.readyState = FileWriter.DONE;
461
-
462
- // If onwriteend callback
463
- if (typeof me.onwriteend === "function") {
464
- me.onwriteend({"type":"writeend", "target":me});
465
- }
466
- }, "File", "write", [this.fileName, text, this.position]);
467
- };
468
-
469
- /**
470
- * Moves the file pointer to the location specified.
471
- *
472
- * If the offset is a negative number the position of the file
473
- * pointer is rewound. If the offset is greater than the file
474
- * size the position is set to the end of the file.
475
- *
476
- * @param offset is the location to move the file pointer to.
477
- */
478
- FileWriter.prototype.seek = function(offset) {
479
- // Throw an exception if we are already writing a file
480
- if (this.readyState === FileWriter.WRITING) {
481
- throw FileError.INVALID_STATE_ERR;
482
- }
483
-
484
- if (!offset) {
485
- return;
486
- }
487
-
488
- // See back from end of file.
489
- if (offset < 0) {
490
- this.position = Math.max(offset + this.length, 0);
491
- }
492
- // Offset is bigger then file size so set position
493
- // to the end of the file.
494
- else if (offset > this.length) {
495
- this.position = this.length;
496
- }
497
- // Offset is between 0 and file size so set the position
498
- // to start writing.
499
- else {
500
- this.position = offset;
501
- }
502
- };
503
-
504
- /**
505
- * Truncates the file to the size specified.
506
- *
507
- * @param size to chop the file at.
508
- */
509
- FileWriter.prototype.truncate = function(size) {
510
- // Throw an exception if we are already writing a file
511
- if (this.readyState === FileWriter.WRITING) {
512
- throw FileError.INVALID_STATE_ERR;
513
- }
514
-
515
- // WRITING state
516
- this.readyState = FileWriter.WRITING;
517
-
518
- var me = this;
519
-
520
- // If onwritestart callback
521
- if (typeof me.onwritestart === "function") {
522
- me.onwritestart({"type":"writestart", "target":this});
523
- }
524
-
525
- // Write file
526
- Cordova.exec(
527
- // Success callback
528
- function(r) {
529
- var evt;
530
- // If DONE (cancelled), then don't do anything
531
- if (me.readyState === FileWriter.DONE) {
532
- return;
533
- }
534
-
535
- // Update the length of the file
536
- me.length = r;
537
- me.position = Math.min(me.position, r);
538
-
539
- // If onwrite callback
540
- if (typeof me.onwrite === "function") {
541
- me.onwrite({"type":"write", "target":me});
542
- }
543
-
544
- // DONE state
545
- me.readyState = FileWriter.DONE;
546
-
547
- // If onwriteend callback
548
- if (typeof me.onwriteend === "function") {
549
- me.onwriteend({"type":"writeend", "target":me});
550
- }
551
- },
552
- // Error callback
553
- function(e) {
554
- var evt;
555
- // If DONE (cancelled), then don't do anything
556
- if (me.readyState === FileWriter.DONE) {
557
- return;
558
- }
559
-
560
- // Save error
561
- me.error = e;
562
-
563
- // If onerror callback
564
- if (typeof me.onerror === "function") {
565
- me.onerror({"type":"error", "target":me});
566
- }
567
-
568
- // DONE state
569
- me.readyState = FileWriter.DONE;
570
-
571
- // If onwriteend callback
572
- if (typeof me.onwriteend === "function") {
573
- me.onwriteend({"type":"writeend", "target":me});
574
- }
575
- }, "File", "truncate", [this.fileName, size]);
576
- };
577
-
578
- /**
579
- * Information about the state of the file or directory
580
- *
581
- * @constructor
582
- * {Date} modificationTime (readonly)
583
- */
584
- var Metadata = function() {
585
- this.modificationTime=null;
586
- };
587
-
588
- /**
589
- * Supplies arguments to methods that lookup or create files and directories
590
- *
591
- * @constructor
592
- * @param {boolean} create file or directory if it doesn't exist
593
- * @param {boolean} exclusive if true the command will fail if the file or directory exists
594
- */
595
- var Flags = function(create, exclusive) {
596
- this.create = create || false;
597
- this.exclusive = exclusive || false;
598
- };
599
-
600
- /**
601
- * An interface representing a file system
602
- *
603
- * @constructor
604
- * {DOMString} name the unique name of the file system (readonly)
605
- * {DirectoryEntry} root directory of the file system (readonly)
606
- */
607
- var FileSystem = function() {
608
- this.name = null;
609
- this.root = null;
610
- };
611
-
612
- /**
613
- * An interface that lists the files and directories in a directory.
614
- * @constructor
615
- */
616
- var DirectoryReader = function(fullPath){
617
- this.fullPath = fullPath || null;
618
- };
619
-
620
- /**
621
- * Returns a list of entries from a directory.
622
- *
623
- * @param {Function} successCallback is called with a list of entries
624
- * @param {Function} errorCallback is called with a FileError
625
- */
626
- DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
627
- var win = function(result) {
628
- var retVal = [];
629
- for (var i=0; i<result.length; i++) {
630
- var entry = null;
631
- if (result[i].isDirectory) {
632
- entry = new DirectoryEntry();
633
- }
634
- else if (result[i].isFile) {
635
- entry = new FileEntry();
636
- }
637
- entry.isDirectory = result[i].isDirectory;
638
- entry.isFile = result[i].isFile;
639
- entry.name = result[i].name;
640
- entry.fullPath = result[i].fullPath;
641
- retVal.push(entry);
642
- }
643
- successCallback(retVal);
644
- };
645
- Cordova.exec(win, errorCallback, "File", "readEntries", [this.fullPath]);
646
- };
647
-
648
- /**
649
- * An interface representing a directory on the file system.
650
- *
651
- * @constructor
652
- * {boolean} isFile always false (readonly)
653
- * {boolean} isDirectory always true (readonly)
654
- * {DOMString} name of the directory, excluding the path leading to it (readonly)
655
- * {DOMString} fullPath the absolute full path to the directory (readonly)
656
- * {FileSystem} filesystem on which the directory resides (readonly)
657
- */
658
- var DirectoryEntry = function() {
659
- this.isFile = false;
660
- this.isDirectory = true;
661
- this.name = null;
662
- this.fullPath = null;
663
- this.filesystem = null;
664
- };
665
-
666
- /**
667
- * Copies a directory to a new location
668
- *
669
- * @param {DirectoryEntry} parent the directory to which to copy the entry
670
- * @param {DOMString} newName the new name of the entry, defaults to the current name
671
- * @param {Function} successCallback is called with the new entry
672
- * @param {Function} errorCallback is called with a FileError
673
- */
674
- DirectoryEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
675
- var win = function(result) {
676
- var entry = null;
677
- if (result.isDirectory) {
678
- entry = new DirectoryEntry();
679
- }
680
- else if (result.isFile) {
681
- entry = new FileEntry();
682
- }
683
- entry.isDirectory = result.isDirectory;
684
- entry.isFile = result.isFile;
685
- entry.name = result.name;
686
- entry.fullPath = result.fullPath;
687
- successCallback(entry);
688
- };
689
- Cordova.exec(win, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
690
- };
691
-
692
- /**
693
- * Looks up the metadata of the entry
694
- *
695
- * @param {Function} successCallback is called with a Metadata object
696
- * @param {Function} errorCallback is called with a FileError
697
- */
698
- DirectoryEntry.prototype.getMetadata = function(successCallback, errorCallback) {
699
- var win = function(result) {
700
- result.modificationTime = new Date(result.modificationTime);
701
- successCallback(result);
702
- };
703
- Cordova.exec(win, errorCallback, "File", "getMetadata", [this.fullPath]);
704
- };
705
-
706
- /**
707
- * Gets the parent of the entry
708
- *
709
- * @param {Function} successCallback is called with a parent entry
710
- * @param {Function} errorCallback is called with a FileError
711
- */
712
- DirectoryEntry.prototype.getParent = function(successCallback, errorCallback) {
713
- var win = function(result) {
714
- var entry = null;
715
- entry = new DirectoryEntry();
716
- entry.isDirectory = result.isDirectory;
717
- entry.isFile = result.isFile;
718
- entry.name = result.name;
719
- entry.fullPath = result.fullPath;
720
- successCallback(entry);
721
- };
722
- Cordova.exec(win, errorCallback, "File", "getParent", [this.fullPath]);
723
- };
724
-
725
- /**
726
- * Moves a directory to a new location
727
- *
728
- * @param {DirectoryEntry} parent the directory to which to move the entry
729
- * @param {DOMString} newName the new name of the entry, defaults to the current name
730
- * @param {Function} successCallback is called with the new entry
731
- * @param {Function} errorCallback is called with a FileError
732
- */
733
- DirectoryEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
734
- var win = function(result) {
735
- var entry = null;
736
- if (result.isDirectory) {
737
- entry = new DirectoryEntry();
738
- }
739
- else if (result.isFile) {
740
- entry = new FileEntry();
741
- }
742
- entry.isDirectory = result.isDirectory;
743
- entry.isFile = result.isFile;
744
- entry.name = result.name;
745
- entry.fullPath = result.fullPath;
746
- successCallback(entry);
747
- };
748
- Cordova.exec(win, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
749
- };
750
-
751
- /**
752
- * Removes the entry
753
- *
754
- * @param {Function} successCallback is called with no parameters
755
- * @param {Function} errorCallback is called with a FileError
756
- */
757
- DirectoryEntry.prototype.remove = function(successCallback, errorCallback) {
758
- Cordova.exec(successCallback, errorCallback, "File", "remove", [this.fullPath]);
759
- };
760
-
761
- /**
762
- * Returns a URI that can be used to identify this entry.
763
- *
764
- * @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI.
765
- * @return uri
766
- */
767
- DirectoryEntry.prototype.toURI = function(mimeType) {
768
- return "file://" + this.fullPath;
769
- };
770
-
771
- /**
772
- * Creates a new DirectoryReader to read entries from this directory
773
- */
774
- DirectoryEntry.prototype.createReader = function(successCallback, errorCallback) {
775
- return new DirectoryReader(this.fullPath);
776
- };
777
-
778
- /**
779
- * Creates or looks up a directory
780
- *
781
- * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory
782
- * @param {Flags} options to create or excluively create the directory
783
- * @param {Function} successCallback is called with the new entry
784
- * @param {Function} errorCallback is called with a FileError
785
- */
786
- DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
787
- var win = function(result) {
788
- var entry = null;
789
- entry = new DirectoryEntry();
790
- entry.isDirectory = result.isDirectory;
791
- entry.isFile = result.isFile;
792
- entry.name = result.name;
793
- entry.fullPath = result.fullPath;
794
- successCallback(entry);
795
- };
796
- Cordova.exec(win, errorCallback, "File", "getDirectory", [this.fullPath, path, options]);
797
- };
798
-
799
- /**
800
- * Creates or looks up a file
801
- *
802
- * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file
803
- * @param {Flags} options to create or excluively create the file
804
- * @param {Function} successCallback is called with the new entry
805
- * @param {Function} errorCallback is called with a FileError
806
- */
807
- DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
808
- var win = function(result) {
809
- var entry = null;
810
- entry = new FileEntry();
811
- entry.isDirectory = result.isDirectory;
812
- entry.isFile = result.isFile;
813
- entry.name = result.name;
814
- entry.fullPath = result.fullPath;
815
- successCallback(entry);
816
- };
817
- Cordova.exec(win, errorCallback, "File", "getFile", [this.fullPath, path, options]);
818
- };
819
-
820
- /**
821
- * Deletes a directory and all of it's contents
822
- *
823
- * @param {Function} successCallback is called with no parameters
824
- * @param {Function} errorCallback is called with a FileError
825
- */
826
- DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
827
- Cordova.exec(successCallback, errorCallback, "File", "removeRecursively", [this.fullPath]);
828
- };
829
-
830
- /**
831
- * An interface representing a directory on the file system.
832
- *
833
- * @constructor
834
- * {boolean} isFile always true (readonly)
835
- * {boolean} isDirectory always false (readonly)
836
- * {DOMString} name of the file, excluding the path leading to it (readonly)
837
- * {DOMString} fullPath the absolute full path to the file (readonly)
838
- * {FileSystem} filesystem on which the directory resides (readonly)
839
- */
840
- var FileEntry = function() {
841
- this.isFile = true;
842
- this.isDirectory = false;
843
- this.name = null;
844
- this.fullPath = null;
845
- this.filesystem = null;
846
- };
847
-
848
- /**
849
- * Copies a file to a new location
850
- *
851
- * @param {DirectoryEntry} parent the directory to which to copy the entry
852
- * @param {DOMString} newName the new name of the entry, defaults to the current name
853
- * @param {Function} successCallback is called with the new entry
854
- * @param {Function} errorCallback is called with a FileError
855
- */
856
- FileEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
857
- var win = function(result) {
858
- var entry = null;
859
- if (result.isDirectory) {
860
- entry = new DirectoryEntry();
861
- }
862
- else if (result.isFile) {
863
- entry = new FileEntry();
864
- }
865
- entry.isDirectory = result.isDirectory;
866
- entry.isFile = result.isFile;
867
- entry.name = result.name;
868
- entry.fullPath = result.fullPath;
869
- successCallback(entry);
870
- };
871
- Cordova.exec(win, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
872
- };
873
-
874
- /**
875
- * Looks up the metadata of the entry
876
- *
877
- * @param {Function} successCallback is called with a Metadata object
878
- * @param {Function} errorCallback is called with a FileError
879
- */
880
- FileEntry.prototype.getMetadata = function(successCallback, errorCallback) {
881
- var win = function(result) {
882
- result.modificationTime = new Date(result.modificationTime);
883
- successCallback(result);
884
- };
885
- Cordova.exec(win, errorCallback, "File", "getMetadata", [this.fullPath]);
886
- };
887
-
888
- /**
889
- * Gets the parent of the entry
890
- *
891
- * @param {Function} successCallback is called with a parent entry
892
- * @param {Function} errorCallback is called with a FileError
893
- */
894
- FileEntry.prototype.getParent = function(successCallback, errorCallback) {
895
- var win = function(result) {
896
- var entry = null;
897
- entry = new DirectoryEntry();
898
- entry.isDirectory = result.isDirectory;
899
- entry.isFile = result.isFile;
900
- entry.name = result.name;
901
- entry.fullPath = result.fullPath;
902
- successCallback(entry);
903
- };
904
- Cordova.exec(win, errorCallback, "File", "getParent", [this.fullPath]);
905
- };
906
-
907
- /**
908
- * Moves a directory to a new location
909
- *
910
- * @param {DirectoryEntry} parent the directory to which to move the entry
911
- * @param {DOMString} newName the new name of the entry, defaults to the current name
912
- * @param {Function} successCallback is called with the new entry
913
- * @param {Function} errorCallback is called with a FileError
914
- */
915
- FileEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
916
- var win = function(result) {
917
- var entry = null;
918
- if (result.isDirectory) {
919
- entry = new DirectoryEntry();
920
- }
921
- else if (result.isFile) {
922
- entry = new FileEntry();
923
- }
924
- entry.isDirectory = result.isDirectory;
925
- entry.isFile = result.isFile;
926
- entry.name = result.name;
927
- entry.fullPath = result.fullPath;
928
- successCallback(entry);
929
- };
930
- Cordova.exec(win, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
931
- };
932
-
933
- /**
934
- * Removes the entry
935
- *
936
- * @param {Function} successCallback is called with no parameters
937
- * @param {Function} errorCallback is called with a FileError
938
- */
939
- FileEntry.prototype.remove = function(successCallback, errorCallback) {
940
- Cordova.exec(successCallback, errorCallback, "File", "remove", [this.fullPath]);
941
- };
942
-
943
- /**
944
- * Returns a URI that can be used to identify this entry.
945
- *
946
- * @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI.
947
- * @return uri
948
- */
949
- FileEntry.prototype.toURI = function(mimeType) {
950
- return "file://" + this.fullPath;
951
- };
952
-
953
- /**
954
- * Creates a new FileWriter associated with the file that this FileEntry represents.
955
- *
956
- * @param {Function} successCallback is called with the new FileWriter
957
- * @param {Function} errorCallback is called with a FileError
958
- */
959
- FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
960
- this.file(function(filePointer) {
961
- var writer = new FileWriter(filePointer);
962
-
963
- if (writer.fileName === null || writer.fileName === "") {
964
- if (typeof errorCallback === "function") {
965
- errorCallback({
966
- "code": FileError.INVALID_STATE_ERR
967
- });
968
- }
969
- }
970
-
971
- if (typeof successCallback === "function") {
972
- successCallback(writer);
973
- }
974
- }, errorCallback);
975
- };
976
-
977
- /**
978
- * Returns a File that represents the current state of the file that this FileEntry represents.
979
- *
980
- * @param {Function} successCallback is called with the new File object
981
- * @param {Function} errorCallback is called with a FileError
982
- */
983
- FileEntry.prototype.file = function(successCallback, errorCallback) {
984
- var win = function(result) {
985
- var file = new File();
986
- file.size = result.size;
987
- file.type = result.type;
988
- file.name = result.name;
989
- file.fullPath = result.fullPath;
990
- file.lastModifiedDate = new Date(result.lastModifiedDate);
991
- successCallback(file);
992
- };
993
- Cordova.exec(win, errorCallback, "File", "getFileMetadata", [this.fullPath]);
994
- };
995
-
996
- /** @constructor */
997
- var LocalFileSystem = function() {
998
- };
999
-
1000
- // File error codes
1001
- LocalFileSystem.TEMPORARY = 0;
1002
- LocalFileSystem.PERSISTENT = 1;
1003
- LocalFileSystem.RESOURCE = 2;
1004
- LocalFileSystem.APPLICATION = 3;
1005
-
1006
- /**
1007
- * Requests a filesystem in which to store application data.
1008
- *
1009
- * @param {int} type of file system being requested
1010
- * @param {Function} successCallback is called with the new FileSystem
1011
- * @param {Function} errorCallback is called with a FileError
1012
- */
1013
- LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallback, errorCallback) {
1014
- if (type < 0 || type > 3) {
1015
- if (typeof errorCallback === "function") {
1016
- errorCallback({
1017
- "code": FileError.SYNTAX_ERR
1018
- });
1019
- }
1020
- }
1021
- else {
1022
- var win = function(result){
1023
- console.log("in win of requestFileSystem");
1024
- console.log("Result: " + JSON.stringify(result));
1025
- var entry = null;
1026
- entry = new DirectoryEntry();
1027
- entry.isDirectory = result.root.isDirectory;
1028
- entry.isFile = result.root.isFile;
1029
- entry.name = result.root.name;
1030
- entry.fullPath = result.root.fullPath;
1031
- result.root = entry;
1032
- successCallback(result);
1033
- };
1034
- console.log("about to call requestFileSystem");
1035
- Cordova.exec(win, errorCallback, "File", "requestFileSystem", [type, size]);
1036
- }
1037
- };
1038
-
1039
- /**
1040
- *
1041
- * @param {DOMString} uri referring to a local file in a filesystem
1042
- * @param {Function} successCallback is called with the new entry
1043
- * @param {Function} errorCallback is called with a FileError
1044
- */
1045
- LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
1046
- var win = function(result) {
1047
- console.log("in win of resolveLocalFileSystemURI");
1048
- console.log("Result: " + JSON.stringify(result));
1049
- var entry = null;
1050
- if (result.isDirectory) {
1051
- entry = new DirectoryEntry();
1052
- }
1053
- else if (result.isFile) {
1054
- entry = new FileEntry();
1055
- }
1056
- entry.isDirectory = result.isDirectory;
1057
- entry.isFile = result.isFile;
1058
- entry.name = result.name;
1059
- entry.fullPath = result.fullPath;
1060
- successCallback(entry);
1061
- };
1062
- console.log("about to call resolveLocalFileSystemURI");
1063
- Cordova.exec(win, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
1064
- };
1065
-
1066
- /**
1067
- * Add the FileSystem interface into the browser.
1068
- */
1069
- Cordova.addConstructor(function() {
1070
- var pgLocalFileSystem = new LocalFileSystem();
1071
- // Needed for cast methods
1072
- if (typeof window.localFileSystem === "undefined") {
1073
- window.localFileSystem = pgLocalFileSystem;
1074
- }
1075
- if (typeof window.requestFileSystem === "undefined") {
1076
- window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
1077
- }
1078
- if (typeof window.resolveLocalFileSystemURI === "undefined") {
1079
- window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
1080
- }
1081
- });
1082
- }