Permalink
Browse files

adding db for better persistance

  • Loading branch information...
1 parent d5d8149 commit 0a9eea74c361e7b7e18848fc1e5810aea4a32e86 @aaronpowell committed Feb 24, 2011
Showing with 80 additions and 2 deletions.
  1. +76 −1 public/scripts/app.js
  2. +1 −1 public/scripts/chart.js
  3. +2 −0 public/scripts/modernizr-1.7.min.js
  4. +1 −0 views/layout.haml
View
@@ -65,4 +65,79 @@ doinnothin = (function(sw, $) {
return ret;
-})(stopwatch, jQuery);
+})(stopwatch, jQuery);
+
+window.localDB = (function() {
+
+ var pageStorage = (function() {
+ var db = {};
+ return {
+ getItem: function(key) {
+ if(!key) return;
+ return db[key];
+ },
+ setItem: function(key, value) {
+ if(!key) return;
+ db[key] = value;
+ },
+ removeItem: function(key) {
+ if(!key || !db[key]) return;
+ return db[key];
+ },
+ clear: function() {
+ db = {};
+ }
+ };
+ })();
+
+ function get(key, storage) {
+ var s = storage.getItem(key);
+ if(s) {
+ return JSON.parse(s);
+ }
+ return undefined;
+ }
+
+ function getStorage(type) {
+ type = type || 'localStorage';
+ switch(type) {
+ case 'sessionStorage':
+ return sessionStorage;
+ case 'pageStorage':
+ return pageStorage;
+ default:
+ return localStorage;
+ };
+ }
+
+ function set(key, value, storage) {
+ storage.setItem(key, JSON.stringify(value));
+ }
+
+ function del(key, storage) {
+ storage.removeItem(key);
+ }
+
+ return {
+ getItem: function(key, type) {
+ if(!key) return;
+ var storage = getStorage(type);
+ return get(key, storage);
+ },
+ setItem: function(key, value, type) {
+ if(!key) return;
+ var storage = getStorage(type);
+ set(key, value, storage);
+ },
+ removeItem: function(key, type) {
+ if(!key) return;
+ var storage = getStorage(type);
+ del(key, type);
+ },
+ clear: function(type) {
+ var storage = getStorage(type);
+ storage.clear();
+ }
+ };
+
+})();
View
@@ -20,7 +20,7 @@ doinnothin.chart = (function(Raphael, $) {
var chart = r.g.hbarchart(10, 25, 200, 20 * times.length, [times.map(function(x) {
return x.seconds;
- })])
+ })], { type: 'soft' })
.hover(fin, fout);
};
Oops, something went wrong.
View
@@ -58,6 +58,7 @@
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
%script{:src => 'http://ajax.microsoft.com/ajax/jquery/jquery-1.5.min.js'}
+ %script{:src => '/scripts/modernizr-1.7.min.js'}
%script{:src => '/scripts/stopwatch.js'}
%script{:src => '/scripts/eventManager.js'}
%script{:src => '/scripts/app.js'}

0 comments on commit 0a9eea7

Please sign in to comment.