go-tour: add local storage and use it to store syntax highlight mode
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/139720043
diff --git a/static/js/services.js b/static/js/services.js
index b16e3f9..344e8b8 100755
--- a/static/js/services.js
+++ b/static/js/services.js
@@ -60,13 +60,35 @@
}
]).
-// Editor context service, kept through the whole app.
-factory('editor', ['$window',
+factory('storage', ['$window',
function(win) {
+ if (win.localStorage) {
+ return {
+ get: function(key) {
+ return win.localStorage.getItem(key);
+ },
+ set: function(key, val) {
+ win.localStorage.setItem(key, val);
+ }
+ };
+ }
+ return {
+ get: function(key, def) {
+ return def;
+ },
+ set: function() {}
+ };
+ }
+]).
+
+// Editor context service, kept through the whole app.
+factory('editor', ['$window', 'storage',
+ function(win, storage) {
var ctx = {
- syntax: false,
+ syntax: storage.get('syntax') === 'true',
toggleSyntax: function() {
ctx.syntax = !ctx.syntax;
+ storage.set('syntax', ctx.syntax);
ctx.paint();
},
paint: function() {