mobile_template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +28 -0
  5. data/Rakefile +3 -0
  6. data/bin/mobile_template +71 -0
  7. data/lib/mobile_template/version.rb +4 -0
  8. data/lib/mobile_template.rb +5 -0
  9. data/mobile_template.gemspec +21 -0
  10. data/templates/assets/Gemfile +4 -0
  11. data/templates/assets/config.rb +96 -0
  12. data/templates/assets/config.ru +4 -0
  13. data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
  14. data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
  15. data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
  16. data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
  17. data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
  18. data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
  19. data/templates/assets/source/index.html.erb +2 -0
  20. data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
  21. data/templates/assets/source/javascripts/application.js.coffee +5 -0
  22. data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
  23. data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
  24. data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
  25. data/templates/assets/source/layout.erb +24 -0
  26. data/templates/assets/source/stylesheets/application.css.scss +2 -0
  27. data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
  28. data/templates/cordova_android/.gitignore +18 -0
  29. data/templates/cordova_android/LICENSE +202 -0
  30. data/templates/cordova_android/NOTICE +5 -0
  31. data/templates/cordova_android/README.md +95 -0
  32. data/templates/cordova_android/VERSION +1 -0
  33. data/templates/cordova_android/bin/BOOM +4 -0
  34. data/templates/cordova_android/bin/autotest +2 -0
  35. data/templates/cordova_android/bin/bench +29 -0
  36. data/templates/cordova_android/bin/create +46 -0
  37. data/templates/cordova_android/bin/create.bat +1 -0
  38. data/templates/cordova_android/bin/create.js +88 -0
  39. data/templates/cordova_android/bin/create.xml +79 -0
  40. data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
  41. data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
  42. data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
  43. data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
  44. data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
  45. data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
  46. data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
  47. data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
  48. data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
  49. data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
  50. data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
  51. data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
  52. data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
  53. data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
  54. data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
  55. data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
  56. data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
  57. data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
  58. data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
  59. data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
  60. data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
  61. data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
  62. data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
  63. data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
  64. data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
  65. data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
  66. data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
  67. data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
  68. data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
  69. data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
  70. data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
  71. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
  72. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
  73. data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
  74. data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
  75. data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
  76. data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
  77. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
  78. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
  79. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
  80. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
  81. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
  82. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
  83. data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
  84. data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
  85. data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
  86. data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
  87. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
  88. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
  89. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
  90. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
  91. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
  92. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
  93. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
  94. data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
  95. data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
  96. data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
  97. data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
  98. data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
  99. data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
  100. data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
  101. data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
  102. data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
  103. data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
  104. data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
  105. data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
  106. data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
  107. data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
  108. data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
  109. data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
  110. data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
  111. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
  112. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
  113. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
  114. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
  115. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
  116. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
  117. data/templates/cordova_android/bin/test +26 -0
  118. data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
  119. data/templates/cordova_android/bin/tests/create.coffee +21 -0
  120. data/templates/cordova_android/bin/tests/debug.coffee +0 -0
  121. data/templates/cordova_android/bin/tests/test.coffee +0 -0
  122. data/templates/cordova_android/framework/.classpath +8 -0
  123. data/templates/cordova_android/framework/.project +33 -0
  124. data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
  125. data/templates/cordova_android/framework/ant.properties +34 -0
  126. data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
  127. data/templates/cordova_android/framework/assets/js/app.js +89 -0
  128. data/templates/cordova_android/framework/assets/js/battery.js +134 -0
  129. data/templates/cordova_android/framework/assets/js/camera.js +168 -0
  130. data/templates/cordova_android/framework/assets/js/capture.js +203 -0
  131. data/templates/cordova_android/framework/assets/js/compass.js +168 -0
  132. data/templates/cordova_android/framework/assets/js/contact.js +310 -0
  133. data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
  134. data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
  135. data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
  136. data/templates/cordova_android/framework/assets/js/device.js +83 -0
  137. data/templates/cordova_android/framework/assets/js/file.js +1082 -0
  138. data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
  139. data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
  140. data/templates/cordova_android/framework/assets/js/header.txt +19 -0
  141. data/templates/cordova_android/framework/assets/js/media.js +233 -0
  142. data/templates/cordova_android/framework/assets/js/network.js +100 -0
  143. data/templates/cordova_android/framework/assets/js/notification.js +133 -0
  144. data/templates/cordova_android/framework/assets/js/position.js +100 -0
  145. data/templates/cordova_android/framework/assets/js/storage.js +439 -0
  146. data/templates/cordova_android/framework/assets/www/index.html +27 -0
  147. data/templates/cordova_android/framework/build.xml +216 -0
  148. data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
  149. data/templates/cordova_android/framework/proguard-project.txt +20 -0
  150. data/templates/cordova_android/framework/project.properties +14 -0
  151. data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
  152. data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
  153. data/templates/cordova_android/framework/res/layout/main.xml +29 -0
  154. data/templates/cordova_android/framework/res/values/strings.xml +23 -0
  155. data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
  156. data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
  157. data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
  158. data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
  159. data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
  160. data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
  161. data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
  162. data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
  163. data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
  164. data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
  165. data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
  166. data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
  167. data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
  168. data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
  169. data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
  170. data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
  171. data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
  172. data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
  173. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
  174. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
  175. data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
  176. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
  177. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
  178. data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
  179. data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
  180. data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
  181. data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
  182. data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
  183. data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
  184. data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
  185. data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
  186. data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
  187. data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
  188. data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
  189. data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
  190. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
  191. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
  192. data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
  193. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
  194. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
  195. data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
  196. data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
  197. data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
  198. data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
  199. data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
  200. data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
  201. data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
  202. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
  203. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
  204. data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
  205. data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
  206. data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
  207. data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
  208. data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
  209. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
  210. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
  211. metadata +279 -0
@@ -0,0 +1,1082 @@
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
+ }