From b2f089370b393761c2157826a2a387ff5558c896 Mon Sep 17 00:00:00 2001 From: LupusUmbrae Date: Mon, 11 Apr 2016 20:43:36 +0100 Subject: [PATCH] Added local storage --- static/javascript/kdm.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/static/javascript/kdm.js b/static/javascript/kdm.js index e5bf579..5bd7780 100644 --- a/static/javascript/kdm.js +++ b/static/javascript/kdm.js @@ -16,7 +16,6 @@ run.$inject = ['$rootScope', '$parse']; function jsonify(scope) { - console.log(scope.tabs); return JSON.stringify(scope.tabs); } @@ -49,8 +48,13 @@ $rootScope.tabs = []; - addNewSettlement($rootScope); - addNewChar($rootScope); + var local = localStorage.getItem('kdm'); + if(local ==null ) { + addNewSettlement($rootScope); + addNewChar($rootScope); + } else { + load($rootScope, local); + } $rootScope.timeline = {}; $rootScope.timeline.options = []; @@ -130,6 +134,13 @@ } }); }); + + $rootScope.$watch('tabs', function(newVal, oldVal) { + if (newVal !== undefined && oldVal !== undefined && newVal !== oldVal) + { + localStorage.setItem('kdm', jsonify($rootScope)); + } + }, true); } function addNewChar(scope) { @@ -224,7 +235,7 @@ function createEmptySettlement(id) { var kdm = loadFromFile("static/json/settlement.json"); - kdm.id = id; + kdm.id = id; return kdm; }