Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (51 sloc) 1.9 KB
<script src="js/Snippet.js"></script>
<script>
archive = {};
archive.db = null;
archive.open = function() {
var dbSize = 10 * 1024 * 1024; // 5MB
archive.db = openDatabase('History', '1.0', 'history', dbSize);
}
archive.onError = function(tx, e) {
console.log('Something unexpected happened: ' + e.message );
}
archive.onSuccess = function(tx, r) {
}
archive.createTable = function() {
archive.db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS ' +
'history(ID INTEGER PRIMARY KEY ASC, code TEXT, link TEXT, output TEXT, lang TEXT, time INTEGER)', []);
});
}
archive.addItem = function(item, success, error) {
archive.db.transaction(function(tx){
var addedOn = (new Date()).getTime();
tx.executeSql('INSERT INTO history(code, link, output, lang, time) VALUES (?,?,?,?,?)',
[item.code,item.link,item.result,item.language,addedOn],
(success || archive.onSuccess),
(error || archive.onError));
});
}
archive.getAllItems = function(renderFunc) {
archive.db.transaction(function(tx) {
tx.executeSql('SELECT * FROM history ORDER BY time DESC', [], renderFunc,
archive.onError);
});
}
archive.deleteItem = function(id, cb) {
archive.db.transaction(function(tx) {
tx.executeSql('DELETE FROM history WHERE ID=?', [id],
cb , archive.onError);
});
}
archive.dropTable = function(succ, err) {
archive.db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS history', [], function() {archive.createTable();succ();}, archive.onError);
});
}
archive.open();
archive.createTable();
function getCurrentSnippet() {
return window.current_snippet || new Snippet();
};
</script>