Advertisement
Guest User

Untitled

a guest
Jan 21st, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="es" manifest="cache.manifest">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>HTML5 Offline Storage Experiment - Notes panel</title>
  6. <link href="websql.css" rel="stylesheet" type="text/css" />
  7. <script type="text/javascript" src="storage.js"></script>
  8. <script>
  9. var html5rocks = {};
  10. html5rocks.webdb = {};
  11. html5rocks.webdb.db = null;
  12.  
  13. html5rocks.webdb.open = function() {
  14.   var dbSize = 5 * 1024 * 1024; // 5MB
  15.   html5rocks.webdb.db = openDatabase("Todo", "1.0", "Todo manager", dbSize);
  16. }
  17.  
  18. html5rocks.webdb.createTable = function() {
  19.   var db = html5rocks.webdb.db;
  20.   db.transaction(function(tx) {
  21.     tx.executeSql("CREATE TABLE IF NOT EXISTS todo(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on DATETIME)", []);
  22.   });
  23. }
  24.  
  25. html5rocks.webdb.addTodo = function(todoText) {
  26.   var db = html5rocks.webdb.db;
  27.   db.transaction(function(tx){
  28.     var addedOn = new Date();
  29.     tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)",
  30.         [todoText, addedOn],
  31.         html5rocks.webdb.onSuccess,
  32.         html5rocks.webdb.onError);
  33.    });
  34. }
  35.  
  36.  
  37. html5rocks.webdb.onError = function(tx, e) {
  38.   alert("There has been an error: " + e.message);
  39. }
  40.  
  41. html5rocks.webdb.onSuccess = function(tx, r) {
  42.  alert ("success");
  43.   }
  44.  
  45. try {
  46.     if (window.openDatabase) {
  47.         var dbSize = 1024 * 1024; // 5MB
  48.   html5rocks.webdb.db = openDatabase("Todo", "1.0", "Todo manager", dbSize);
  49.   db = html5rocks.webdb.db;
  50.         if (!db)
  51.             alert("Failed to open the database on disk.  This is probably because the version was bad or there is not enough space left in this domain's quota");
  52.     } else
  53.         alert("Couldn't open the database.  Please try with a WebKit nightly with this feature enabled");
  54. } catch(err) {
  55.     db = null;
  56.     alert("Couldn't open the database.  Please try with a WebKit nightly with this feature enabled");
  57. }
  58. html5rocks.webdb.open();  
  59. html5rocks.webdb.createTable();
  60. </script>
  61. </head>
  62. <body>
  63.     <header>
  64.      Asi sí! :-) -- !! --
  65.     </header>
  66.         <h2>HTML5 App Cache Events</h2>
  67.           <button id="installButton">Check for Updates</button>
  68.         <div id="info"></div>
  69.      <div id="status"><p id="state"></p></div>  
  70.     <form name="note_form" id="notes_form" action="#">
  71.        
  72.     </form>
  73.  
  74.     <ul id="todoItems"></ul>
  75.     <input type="text" id="todo" name="todo" placeholder="What do you need to do?" style="width: 200px;" />
  76.     <input type="submit" value="Add Todo Item" onclick="html5rocks.webdb.addTodo(); return false;"/>
  77.     <div id="notes"></div>
  78.     <div id="todo"></div>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement