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,133 +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("notification")) {
21
- Cordova.addResource("notification");
22
-
23
- /**
24
- * This class provides access to notifications on the device.
25
- * @constructor
26
- */
27
- var Notification = function() {
28
- };
29
-
30
- /**
31
- * Open a native alert dialog, with a customizable title and button text.
32
- *
33
- * @param {String} message Message to print in the body of the alert
34
- * @param {Function} completeCallback The callback that is called when user clicks on a button.
35
- * @param {String} title Title of the alert dialog (default: Alert)
36
- * @param {String} buttonLabel Label of the close button (default: OK)
37
- */
38
- Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
39
- var _title = (title || "Alert");
40
- var _buttonLabel = (buttonLabel || "OK");
41
- Cordova.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
42
- };
43
-
44
- /**
45
- * Open a native confirm dialog, with a customizable title and button text.
46
- * The result that the user selects is returned to the result callback.
47
- *
48
- * @param {String} message Message to print in the body of the alert
49
- * @param {Function} resultCallback The callback that is called when user clicks on a button.
50
- * @param {String} title Title of the alert dialog (default: Confirm)
51
- * @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel')
52
- */
53
- Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) {
54
- var _title = (title || "Confirm");
55
- var _buttonLabels = (buttonLabels || "OK,Cancel");
56
- Cordova.exec(resultCallback, null, "Notification", "confirm", [message,_title,_buttonLabels]);
57
- };
58
-
59
- /**
60
- * Start spinning the activity indicator on the statusbar
61
- */
62
- Notification.prototype.activityStart = function() {
63
- Cordova.exec(null, null, "Notification", "activityStart", ["Busy","Please wait..."]);
64
- };
65
-
66
- /**
67
- * Stop spinning the activity indicator on the statusbar, if it's currently spinning
68
- */
69
- Notification.prototype.activityStop = function() {
70
- Cordova.exec(null, null, "Notification", "activityStop", []);
71
- };
72
-
73
- /**
74
- * Display a progress dialog with progress bar that goes from 0 to 100.
75
- *
76
- * @param {String} title Title of the progress dialog.
77
- * @param {String} message Message to display in the dialog.
78
- */
79
- Notification.prototype.progressStart = function(title, message) {
80
- Cordova.exec(null, null, "Notification", "progressStart", [title, message]);
81
- };
82
-
83
- /**
84
- * Set the progress dialog value.
85
- *
86
- * @param {Number} value 0-100
87
- */
88
- Notification.prototype.progressValue = function(value) {
89
- Cordova.exec(null, null, "Notification", "progressValue", [value]);
90
- };
91
-
92
- /**
93
- * Close the progress dialog.
94
- */
95
- Notification.prototype.progressStop = function() {
96
- Cordova.exec(null, null, "Notification", "progressStop", []);
97
- };
98
-
99
- /**
100
- * Causes the device to blink a status LED.
101
- *
102
- * @param {Integer} count The number of blinks.
103
- * @param {String} colour The colour of the light.
104
- */
105
- Notification.prototype.blink = function(count, colour) {
106
- // NOT IMPLEMENTED
107
- };
108
-
109
- /**
110
- * Causes the device to vibrate.
111
- *
112
- * @param {Integer} mills The number of milliseconds to vibrate for.
113
- */
114
- Notification.prototype.vibrate = function(mills) {
115
- Cordova.exec(null, null, "Notification", "vibrate", [mills]);
116
- };
117
-
118
- /**
119
- * Causes the device to beep.
120
- * On Android, the default notification ringtone is played "count" times.
121
- *
122
- * @param {Integer} count The number of beeps.
123
- */
124
- Notification.prototype.beep = function(count) {
125
- Cordova.exec(null, null, "Notification", "beep", [count]);
126
- };
127
-
128
- Cordova.addConstructor(function() {
129
- if (typeof navigator.notification === "undefined") {
130
- navigator.notification = new Notification();
131
- }
132
- });
133
- }
@@ -1,100 +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("position")) {
21
- Cordova.addResource("position");
22
-
23
- /**
24
- * This class contains position information.
25
- * @param {Object} lat
26
- * @param {Object} lng
27
- * @param {Object} acc
28
- * @param {Object} alt
29
- * @param {Object} altacc
30
- * @param {Object} head
31
- * @param {Object} vel
32
- * @constructor
33
- */
34
- var Position = function(coords, timestamp) {
35
- this.coords = coords;
36
- this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime();
37
- };
38
-
39
- /** @constructor */
40
- var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) {
41
- /**
42
- * The latitude of the position.
43
- */
44
- this.latitude = lat;
45
- /**
46
- * The longitude of the position,
47
- */
48
- this.longitude = lng;
49
- /**
50
- * The accuracy of the position.
51
- */
52
- this.accuracy = acc;
53
- /**
54
- * The altitude of the position.
55
- */
56
- this.altitude = alt;
57
- /**
58
- * The direction the device is moving at the position.
59
- */
60
- this.heading = head;
61
- /**
62
- * The velocity with which the device is moving at the position.
63
- */
64
- this.speed = vel;
65
- /**
66
- * The altitude accuracy of the position.
67
- */
68
- this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null;
69
- };
70
-
71
- /**
72
- * This class specifies the options for requesting position data.
73
- * @constructor
74
- */
75
- var PositionOptions = function() {
76
- /**
77
- * Specifies the desired position accuracy.
78
- */
79
- this.enableHighAccuracy = true;
80
- /**
81
- * The timeout after which if position data cannot be obtained the errorCallback
82
- * is called.
83
- */
84
- this.timeout = 10000;
85
- };
86
-
87
- /**
88
- * This class contains information about any GSP errors.
89
- * @constructor
90
- */
91
- var PositionError = function() {
92
- this.code = null;
93
- this.message = "";
94
- };
95
-
96
- PositionError.UNKNOWN_ERROR = 0;
97
- PositionError.PERMISSION_DENIED = 1;
98
- PositionError.POSITION_UNAVAILABLE = 2;
99
- PositionError.TIMEOUT = 3;
100
- }
@@ -1,439 +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
- /*
21
- * This is purely for the Android 1.5/1.6 HTML 5 Storage
22
- * I was hoping that Android 2.0 would deprecate this, but given the fact that
23
- * most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required
24
- */
25
-
26
- if (!Cordova.hasResource("storage")) {
27
- Cordova.addResource("storage");
28
-
29
- /**
30
- * SQL result set object
31
- * PRIVATE METHOD
32
- * @constructor
33
- */
34
- var DroidDB_Rows = function() {
35
- this.resultSet = []; // results array
36
- this.length = 0; // number of rows
37
- };
38
-
39
- /**
40
- * Get item from SQL result set
41
- *
42
- * @param row The row number to return
43
- * @return The row object
44
- */
45
- DroidDB_Rows.prototype.item = function(row) {
46
- return this.resultSet[row];
47
- };
48
-
49
- /**
50
- * SQL result set that is returned to user.
51
- * PRIVATE METHOD
52
- * @constructor
53
- */
54
- var DroidDB_Result = function() {
55
- this.rows = new DroidDB_Rows();
56
- };
57
-
58
- /**
59
- * Storage object that is called by native code when performing queries.
60
- * PRIVATE METHOD
61
- * @constructor
62
- */
63
- var DroidDB = function() {
64
- this.queryQueue = {};
65
- };
66
-
67
- /**
68
- * Callback from native code when query is complete.
69
- * PRIVATE METHOD
70
- *
71
- * @param id Query id
72
- */
73
- DroidDB.prototype.completeQuery = function(id, data) {
74
- var query = this.queryQueue[id];
75
- if (query) {
76
- try {
77
- delete this.queryQueue[id];
78
-
79
- // Get transaction
80
- var tx = query.tx;
81
-
82
- // If transaction hasn't failed
83
- // Note: We ignore all query results if previous query
84
- // in the same transaction failed.
85
- if (tx && tx.queryList[id]) {
86
-
87
- // Save query results
88
- var r = new DroidDB_Result();
89
- r.rows.resultSet = data;
90
- r.rows.length = data.length;
91
- try {
92
- if (typeof query.successCallback === 'function') {
93
- query.successCallback(query.tx, r);
94
- }
95
- } catch (ex) {
96
- console.log("executeSql error calling user success callback: "+ex);
97
- }
98
-
99
- tx.queryComplete(id);
100
- }
101
- } catch (e) {
102
- console.log("executeSql error: "+e);
103
- }
104
- }
105
- };
106
-
107
- /**
108
- * Callback from native code when query fails
109
- * PRIVATE METHOD
110
- *
111
- * @param reason Error message
112
- * @param id Query id
113
- */
114
- DroidDB.prototype.fail = function(reason, id) {
115
- var query = this.queryQueue[id];
116
- if (query) {
117
- try {
118
- delete this.queryQueue[id];
119
-
120
- // Get transaction
121
- var tx = query.tx;
122
-
123
- // If transaction hasn't failed
124
- // Note: We ignore all query results if previous query
125
- // in the same transaction failed.
126
- if (tx && tx.queryList[id]) {
127
- tx.queryList = {};
128
-
129
- try {
130
- if (typeof query.errorCallback === 'function') {
131
- query.errorCallback(query.tx, reason);
132
- }
133
- } catch (ex) {
134
- console.log("executeSql error calling user error callback: "+ex);
135
- }
136
-
137
- tx.queryFailed(id, reason);
138
- }
139
-
140
- } catch (e) {
141
- console.log("executeSql error: "+e);
142
- }
143
- }
144
- };
145
-
146
- /**
147
- * SQL query object
148
- * PRIVATE METHOD
149
- *
150
- * @constructor
151
- * @param tx The transaction object that this query belongs to
152
- */
153
- var DroidDB_Query = function(tx) {
154
-
155
- // Set the id of the query
156
- this.id = Cordova.createUUID();
157
-
158
- // Add this query to the queue
159
- droiddb.queryQueue[this.id] = this;
160
-
161
- // Init result
162
- this.resultSet = [];
163
-
164
- // Set transaction that this query belongs to
165
- this.tx = tx;
166
-
167
- // Add this query to transaction list
168
- this.tx.queryList[this.id] = this;
169
-
170
- // Callbacks
171
- this.successCallback = null;
172
- this.errorCallback = null;
173
-
174
- };
175
-
176
- /**
177
- * Transaction object
178
- * PRIVATE METHOD
179
- * @constructor
180
- */
181
- var DroidDB_Tx = function() {
182
-
183
- // Set the id of the transaction
184
- this.id = Cordova.createUUID();
185
-
186
- // Callbacks
187
- this.successCallback = null;
188
- this.errorCallback = null;
189
-
190
- // Query list
191
- this.queryList = {};
192
- };
193
-
194
- /**
195
- * Mark query in transaction as complete.
196
- * If all queries are complete, call the user's transaction success callback.
197
- *
198
- * @param id Query id
199
- */
200
- DroidDB_Tx.prototype.queryComplete = function(id) {
201
- delete this.queryList[id];
202
-
203
- // If no more outstanding queries, then fire transaction success
204
- if (this.successCallback) {
205
- var count = 0;
206
- var i;
207
- for (i in this.queryList) {
208
- if (this.queryList.hasOwnProperty(i)) {
209
- count++;
210
- }
211
- }
212
- if (count === 0) {
213
- try {
214
- this.successCallback();
215
- } catch(e) {
216
- console.log("Transaction error calling user success callback: " + e);
217
- }
218
- }
219
- }
220
- };
221
-
222
- /**
223
- * Mark query in transaction as failed.
224
- *
225
- * @param id Query id
226
- * @param reason Error message
227
- */
228
- DroidDB_Tx.prototype.queryFailed = function(id, reason) {
229
-
230
- // The sql queries in this transaction have already been run, since
231
- // we really don't have a real transaction implemented in native code.
232
- // However, the user callbacks for the remaining sql queries in transaction
233
- // will not be called.
234
- this.queryList = {};
235
-
236
- if (this.errorCallback) {
237
- try {
238
- this.errorCallback(reason);
239
- } catch(e) {
240
- console.log("Transaction error calling user error callback: " + e);
241
- }
242
- }
243
- };
244
-
245
- /**
246
- * Execute SQL statement
247
- *
248
- * @param sql SQL statement to execute
249
- * @param params Statement parameters
250
- * @param successCallback Success callback
251
- * @param errorCallback Error callback
252
- */
253
- DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCallback) {
254
-
255
- // Init params array
256
- if (typeof params === 'undefined') {
257
- params = [];
258
- }
259
-
260
- // Create query and add to queue
261
- var query = new DroidDB_Query(this);
262
- droiddb.queryQueue[query.id] = query;
263
-
264
- // Save callbacks
265
- query.successCallback = successCallback;
266
- query.errorCallback = errorCallback;
267
-
268
- // Call native code
269
- Cordova.exec(null, null, "Storage", "executeSql", [sql, params, query.id]);
270
- };
271
-
272
- var DatabaseShell = function() {
273
- };
274
-
275
- /**
276
- * Start a transaction.
277
- * Does not support rollback in event of failure.
278
- *
279
- * @param process {Function} The transaction function
280
- * @param successCallback {Function}
281
- * @param errorCallback {Function}
282
- */
283
- DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) {
284
- var tx = new DroidDB_Tx();
285
- tx.successCallback = successCallback;
286
- tx.errorCallback = errorCallback;
287
- try {
288
- process(tx);
289
- } catch (e) {
290
- console.log("Transaction error: "+e);
291
- if (tx.errorCallback) {
292
- try {
293
- tx.errorCallback(e);
294
- } catch (ex) {
295
- console.log("Transaction error calling user error callback: "+e);
296
- }
297
- }
298
- }
299
- };
300
-
301
- /**
302
- * Open database
303
- *
304
- * @param name Database name
305
- * @param version Database version
306
- * @param display_name Database display name
307
- * @param size Database size in bytes
308
- * @return Database object
309
- */
310
- var DroidDB_openDatabase = function(name, version, display_name, size) {
311
- Cordova.exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]);
312
- var db = new DatabaseShell();
313
- return db;
314
- };
315
-
316
- /**
317
- * For browsers with no localStorage we emulate it with SQLite. Follows the w3c api.
318
- * TODO: Do similar for sessionStorage.
319
- */
320
-
321
- /**
322
- * @constructor
323
- */
324
- var CupcakeLocalStorage = function() {
325
- try {
326
-
327
- this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440);
328
- var storage = {};
329
- this.length = 0;
330
- function setLength (length) {
331
- this.length = length;
332
- localStorage.length = length;
333
- }
334
- this.db.transaction(
335
- function (transaction) {
336
- var i;
337
- transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
338
- transaction.executeSql('SELECT * FROM storage', [], function(tx, result) {
339
- for(var i = 0; i < result.rows.length; i++) {
340
- storage[result.rows.item(i)['id']] = result.rows.item(i)['body'];
341
- }
342
- setLength(result.rows.length);
343
- Cordova.initializationComplete("cupcakeStorage");
344
- });
345
-
346
- },
347
- function (err) {
348
- alert(err.message);
349
- }
350
- );
351
- this.setItem = function(key, val) {
352
- if (typeof(storage[key])=='undefined') {
353
- this.length++;
354
- }
355
- storage[key] = val;
356
- this.db.transaction(
357
- function (transaction) {
358
- transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
359
- transaction.executeSql('REPLACE INTO storage (id, body) values(?,?)', [key,val]);
360
- }
361
- );
362
- };
363
- this.getItem = function(key) {
364
- return storage[key];
365
- };
366
- this.removeItem = function(key) {
367
- delete storage[key];
368
- this.length--;
369
- this.db.transaction(
370
- function (transaction) {
371
- transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
372
- transaction.executeSql('DELETE FROM storage where id=?', [key]);
373
- }
374
- );
375
- };
376
- this.clear = function() {
377
- storage = {};
378
- this.length = 0;
379
- this.db.transaction(
380
- function (transaction) {
381
- transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
382
- transaction.executeSql('DELETE FROM storage', []);
383
- }
384
- );
385
- };
386
- this.key = function(index) {
387
- var i = 0;
388
- for (var j in storage) {
389
- if (i==index) {
390
- return j;
391
- } else {
392
- i++;
393
- }
394
- }
395
- return null;
396
- };
397
-
398
- } catch(e) {
399
- alert("Database error "+e+".");
400
- return;
401
- }
402
- };
403
-
404
- Cordova.addConstructor(function() {
405
- var setupDroidDB = function() {
406
- navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
407
- window.droiddb = new DroidDB();
408
- }
409
- if (typeof window.openDatabase === "undefined") {
410
- setupDroidDB();
411
- } else {
412
- window.openDatabase_orig = window.openDatabase;
413
- window.openDatabase = function(name, version, desc, size){
414
- // Some versions of Android will throw a SECURITY_ERR so we need
415
- // to catch the exception and seutp our own DB handling.
416
- var db = null;
417
- try {
418
- db = window.openDatabase_orig(name, version, desc, size);
419
- }
420
- catch (ex) {
421
- db = null;
422
- }
423
-
424
- if (db == null) {
425
- setupDroidDB();
426
- return DroidDB_openDatabase(name, version, desc, size);
427
- }
428
- else {
429
- return db;
430
- }
431
- };
432
- }
433
-
434
- if ((typeof window.localStorage == "undefined") || (window.localStorage == null)) {
435
- navigator.localStorage = window.localStorage = new CupcakeLocalStorage();
436
- Cordova.waitForInitialization("cupcakeStorage");
437
- }
438
- });
439
- }