summaryrefslogtreecommitdiff
path: root/src/www/gfse/localstorage.js
blob: 162b1db3b7b7afd4746acc226bc34fe942af5eb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

// Grammars are stored locally in the browser using localStorage.
// See http://diveintohtml5.info/storage.html

function supports_html5_storage() {
  try {
    return 'localStorage' in window && window['localStorage'] !== null;
  } catch (e) {
    return false;
  }
}

var local={
    prefix:"gf.editor.simple.grammar",
    get: function (name,def) {
	var id=this.prefix+name
	return localStorage[id] ? JSON.parse(localStorage[id]) : def;
    },
    put: function (name,value) {
	var id=this.prefix+name;
	localStorage[id]=JSON.stringify(value);
    },
    remove: function(name) {
	var id=this.prefix+name;
	localStorage.removeItem(id);
    },
    get count() { return this.get("count",0); },
    set count(v) { this.put("count",v); }
}