IndexedDB
HTML
<!DOCTYPE html>
<html>
<head></head>
<body>
<header>
<h1>IndexedDB (<span>No</span>)</h1>
</header>
<article>
<label for="wish">Enter a wish:</label>
<input type="text" id="wish" />
<button id="btnSave">Keep it</button>
<div id="result">
<h2>My wishes:</h2>
<ul id="list"></ul>
</div>
</article>
</body>
</html>
CSS
body{
font-family: "Verdana";
font-size: 9pt;
}
header{
padding: 15px;
box-shadow: 0px 1px 2px rgba(0,0,0,0.4);
background-color: rgb(27, 161, 226);
color: #fff;
}
header h1{
font-size:14pt;
}
header span{
color: red;
}
h2{
font-size: 12pt;
font-weight: bold;
}
article{
width: 80%;
margin:auto;
margin-top:20px;
}
button{
padding:10px;
background-color: #E0811B;
color: #fff;
border-radius: 4px;
}
input{
padding:10px;
}
#result{
margin-top:20px;
}
#result ul{
margin-top: 10px;
}
#result ul li{
font-style: italic;
}
#result ul li a
{
cursor: pointer;
}
JavaScript
var WishesStore = function() {
//private members
var db = null,
name = null,
version = null,
trace = function(msg) {
//Traces
console.log(msg);
},
init = function(dbname, dbversion) {
//1.Initialize variables
name = dbname;
version = dbversion;
//2. Make indexedDB compatible
if (compatibility()) {
//2.1 Delete database
//deletedb("wishes");
//3.Open database
open();
}
},
compatibility = function() {
trace("window.indexedDB: " + window.indexedDB);
trace("window.mozIndexedDB: " + window.mozIndexedDB);
trace("window.webkitIndexedDB: " + window.webkitIndexedDB);
trace("window.msIndexedDB: " + window.msIndexedDB);
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
trace("window.IDBTransaction: " + window.IDBTransaction);
trace("window.webkitIDBTransaction: " + window.webkitIDBTransaction);
trace("window.msIDBTransaction: " + window.msIDBTransaction);
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction || window.OIDBTransaction;
trace("window.IDBKeyRange: " + window.IDBKeyRange);
trace("window.webkitIDBKeyRange: " + window.webkitIDBKeyRange);
trace("window.msIDBKeyRange: " + window.msIDBKeyRange);
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
if (window.indexedDB) {
var span = document.querySelector("header h1 span");
span.textContent = "Yes";
span.style.color = "green";
return true;
}
trace("Your browser does not support a stable version of IndexedDB.");
...