Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created September 7, 2013 02:33
Show Gist options
  • Save enjalot/6472300 to your computer and use it in GitHub Desktop.
Save enjalot/6472300 to your computer and use it in GitHub Desktop.
indexedDB testt
{"description":"indexedDB testt","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/PSJH9hL.png"}
var db;
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
if (!window.indexedDB) { alert("Sorry!Your browser doesn't support IndexedDB"); }
function go() {
console.log("go")
var objectStore = database.transaction("notes").objectStore("notes");
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
console.log("CURSOR", cursor)
};
}
init();
function init(){
var request = window.indexedDB.open("notepad",1);
request.onerror = function(event) {
console.log(event.target.errorCode);
};
request.onsuccess = function(event) {
database=request.result;
go();
};
request.onupgradeneeded = function(event) {
console.log("UPGRADE")
var db = event.target.result;
var objectStore = db.createObjectStore("notes", { keyPath: "id",autoIncrement:true});
};
}
function addNote(note){
var transaction = database.transaction(["notes"], "readwrite");
var objectStore = transaction.objectStore("notes");
var request=objectStore.put(note);
request.onsuccess = function(event) {
document.getElementById("flag").value="0";
window.location.href="index.html";
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment