forked from skanaar/nomnoml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnomnoml.storage.js
36 lines (32 loc) · 977 Bytes
/
nomnoml.storage.js
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
30
31
32
33
34
35
36
var nomnoml = nomnoml || {}
nomnoml.Storage = function (options){
function get(key){ return localStorage['nomnoml.' + key] }
function set(key, val){ return localStorage['nomnoml.' + key] = val }
var defaultDiagramSet = { untitled: {source: options.defaultSource} }
set('diagrams', get('diagrams') || defaultDiagramSet)
var currentDiagram = get('lastDiagramName') || 'untitled'
return {
localDiagramNames = function (){
return _.map(get('diagrams'), function (d, key){
return {
source: d.source,
name: key,
isCurrent: key === currentDiagram
}
})
},
currentDiagram = function (){
return get('diagrams')[get(currentDiagram)] || { source: '' }
},
sourceChanged = function (src){
var ds = get('diagrams')
ds[get(currentDiagram)] = { source: src }
set('diagrams', ds)
},
chooseDiagram = function (name){
var ds = get('diagrams')
ds[get(currentDiagram)] = { source: src }
set('lastDiagramName', name)
}
}
}