Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
go-tour: add local storage and use it to store syntax highlight mode
Browse files Browse the repository at this point in the history
LGTM=adg
R=adg
CC=golang-codereviews
https://codereview.appspot.com/139720043
  • Loading branch information
campoy committed Aug 28, 2014
1 parent 5491a8a commit 1470951
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions static/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,35 @@ factory('fmt', ['$http',
}
]).

// 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() {
Expand Down

0 comments on commit 1470951

Please sign in to comment.