You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by za...@apache.org on 2014/06/10 12:00:58 UTC
[06/12] Manual tests fixed
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0de5e956/sql/index.js
----------------------------------------------------------------------
diff --git a/sql/index.js b/sql/index.js
new file mode 100644
index 0000000..b5d5653
--- /dev/null
+++ b/sql/index.js
@@ -0,0 +1,125 @@
+//-------------------------------------------------------------------------
+// HTML5 Database
+//-------------------------------------------------------------------------
+var dbs = [];
+var quotas = [2000000, 2000000];
+var names = ['mydb', 'rand' + Math.random()];
+function openDb(index) {
+ try {
+ databaseOutput('Openning db with name: ' + names[index]);
+ return openDatabase(names[index], "1.0", "Apache Cordova Demo", quotas[index]);
+ } catch (e) {
+ databaseOutput('Got exception: ' + e);
+ }
+}
+
+var callDatabase = function(index) {
+ var db = dbs[index] = openDb(index);
+ if (!db) {
+ return;
+ }
+ databaseOutput("Database opened.");
+ db.transaction(function (tx) {
+ tx.executeSql('DROP TABLE IF EXISTS DEMO');
+ tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)', [],
+ function(tx,results) { console.log("Created table"); },
+ function(tx,err) { alert("Error creating table: "+err.message); });
+ tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")', [],
+ function(tx,results) { console.log("Insert row1 success"); },
+ function(tx,err) { alert("Error adding 1st row: "+err.message); });
+ tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")', [],
+ function(tx,results) { console.log("Insert row2 success"); },
+ function(tx,err) { alert("Error adding 2nd row: "+err.message); });
+ databaseOutput("Data written to DEMO table.");
+ console.log("Data written to DEMO table.");
+
+ tx.executeSql('SELECT * FROM DEMO', [], function (tx, results) {
+ var len = results.rows.length;
+ var text = "DEMO table: " + len + " rows found.<br>";
+ text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
+ for (var i=0; i<len; i++){
+ text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>";
+ }
+ text = text + "</table>";
+ databaseOutput(text);
+ }, function(tx, err) {
+ alert("Error processing SELECT * SQL: "+err.message);
+ });
+ tx.executeSql('SELECT ID FROM DEMO', [], function (tx, results) {
+ var len = results.rows.length;
+ var text = "DEMO table: " + len + " rows found.<br>";
+ text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
+ for (var i=0; i<len; i++){
+ text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + "</td></tr>";
+ }
+ text = text + "</table>";
+ databaseOutput(text);
+ }, function(tx, err) {
+ alert("Error processing SELECT ID SQL: "+err.message);
+ });
+
+ },
+ function(err) {
+ console.log("Transaction failed: " + err.message);
+ });
+
+
+};
+
+var readDatabase = function(index) {
+ var db = dbs[index];
+ if (!db) {
+ db = dbs[index] = openDb(index);
+ if (!db) {
+ return;
+ }
+ }
+ db.transaction(function (tx) {
+ tx.executeSql('SELECT * FROM DEMO WHERE id=2', [], function (tx, results) {
+ var len = results.rows.length;
+ var text = "DEMO table: " + len + " rows found.<br>";
+ text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
+ for (var i=0; i<len; i++){
+ text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>";
+ }
+ text = text + "</table>";
+ databaseOutput(text);
+ }, function(tx, err) {
+ alert("Error processing SELECT * WHERE id=2 SQL: "+err.message);
+ });
+ });
+}
+
+function increaseQuota(index) {
+ quotas[index] *= 2;
+ databaseOutput('quota ' + index + ' is now ' + quotas[index]);
+}
+
+var databaseOutput = function(s) {
+ var el = document.getElementById("database_results");
+ el.innerHTML = el.innerHTML + s + "<br>";
+ el.scrollByLines(20000);
+};
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+ document.addEventListener("deviceready", function() {
+ console.log("Device="+device.platform+" "+device.version);
+ }, false);
+}
+
+window.onload = function() {
+ addListenerToClass('callDatabase0', callDatabase, [0]);
+ addListenerToClass('readDatabase0', readDatabase, [0]);
+ addListenerToClass('increaseQuota0', increaseQuota, [0]);
+ addListenerToClass('callDatabase1', callDatabase, 1);
+ addListenerToClass('readDatabase1', readDatabase, 1);
+ addListenerToClass('increaseQuota1', increaseQuota, 1);
+ addListenerToClass('reloadPage', function() {
+ location = location.href;
+ });
+ addListenerToClass('backBtn', backHome);
+ init();
+}
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0de5e956/storage/index.html
----------------------------------------------------------------------
diff --git a/storage/index.html b/storage/index.html
index 20e2951..0b713a2 100644
--- a/storage/index.html
+++ b/storage/index.html
@@ -28,45 +28,14 @@
<title>Cordova Mobile Spec</title>
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
-
-
-<script type="text/javascript" charset="utf-8">
-
- var deviceReady = false;
-
- /**
- * Function called when page has finished loading.
- */
- function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
- }
-
-</script>
-
+ <script type="text/javascript" charset="utf-8" src="./index.js"></script>
</head>
- <body onload="init();" id="stage" class="theme">
+ <body id="stage" class="theme">
<h1>Local Storage</h1>
<div id="info">
You have run this app <span id="count">an untold number of</span> time(s).
</div>
-
- <script>
- if (!localStorage.pageLoadCount) {
- localStorage.pageLoadCount = 0;
- }
- localStorage.pageLoadCount = parseInt(localStorage.pageLoadCount) + 1;
- document.getElementById('count').textContent = localStorage.pageLoadCount;
- </script>
-
- <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+ <h2> </h2><div class="backBtn">Back</div>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0de5e956/storage/index.js
----------------------------------------------------------------------
diff --git a/storage/index.js b/storage/index.js
new file mode 100644
index 0000000..00ae7e1
--- /dev/null
+++ b/storage/index.js
@@ -0,0 +1,27 @@
+var deviceReady = false;
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+ document.addEventListener("deviceready", function() {
+ deviceReady = true;
+ console.log("Device="+device.platform+" "+device.version);
+ }, false);
+ window.setTimeout(function() {
+ if (!deviceReady) {
+ alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
+ }
+ },1000);
+}
+
+window.onload = function() {
+ addListenerToClass('backBtn', backHome);
+ init();
+
+ if (!localStorage.pageLoadCount) {
+ localStorage.pageLoadCount = 0;
+ }
+ localStorage.pageLoadCount = parseInt(localStorage.pageLoadCount) + 1;
+ document.getElementById('count').textContent = localStorage.pageLoadCount;
+}
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0de5e956/vibration/index.html
----------------------------------------------------------------------
diff --git a/vibration/index.html b/vibration/index.html
index ef9b76e..a24110e 100644
--- a/vibration/index.html
+++ b/vibration/index.html
@@ -28,47 +28,16 @@
<title>Cordova Mobile Spec</title>
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
-
-
-<script type="text/javascript" charset="utf-8">
-
- var deviceReady = false;
-
- //-------------------------------------------------------------------------
- // Vibrations
- //-------------------------------------------------------------------------
-
- var vibrate = function(){
- navigator.notification.vibrate(2500);
- };
-
-
- /**
- * Function called when page has finished loading.
- */
- function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
- }
-
-</script>
-
+ <script type="text/javascript" charset="utf-8" src="./index.js"></script>
</head>
- <body onload="init();" id="stage" class="theme">
+ <body id="stage" class="theme">
<h1>Vibrations</h1>
<div id="info">
</div>
<h2>Action</h2>
- <div class="btn large" onclick="vibrate();">Vibrate</div>
- <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+ <div class="btn large vibrate">Vibrate</div>
+ <h2> </h2><div class="backBtn">Back</div>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0de5e956/vibration/index.js
----------------------------------------------------------------------
diff --git a/vibration/index.js b/vibration/index.js
new file mode 100644
index 0000000..0d28902
--- /dev/null
+++ b/vibration/index.js
@@ -0,0 +1,31 @@
+var deviceReady = false;
+
+//-------------------------------------------------------------------------
+// Vibrations
+//-------------------------------------------------------------------------
+
+var vibrate = function(){
+ navigator.notification.vibrate(2500);
+};
+
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+ document.addEventListener("deviceready", function() {
+ deviceReady = true;
+ console.log("Device="+device.platform+" "+device.version);
+ }, false);
+ window.setTimeout(function() {
+ if (!deviceReady) {
+ alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
+ }
+ },1000);
+}
+
+window.onload = function() {
+ addListenerToClass('vibrate', vibrate);
+ addListenerToClass('backBtn', backHome);
+ init();
+}