1

Improved local storage handling

This commit is contained in:
Alex Yatskov 2015-03-11 16:18:44 +09:00
parent 34b4eac3c1
commit 491dccbbe9
2 changed files with 13 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 <name of copyright holder>
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@ -24,11 +24,14 @@
'use strict';
function setProfileValue(id, value) {
localStorage[id] = value;
var profile = JSON.parse(localStorage.profile || '{}');
profile[id] = value;
localStorage.profile = JSON.stringify(profile);
}
function getProfileValue(id) {
return localStorage[id] || 0;
var profile = JSON.parse(localStorage.profile || '{}');
return profile[id] || 0;
}
function addCategory(description) {

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -43,7 +44,7 @@
$('#profileDlg').on('hidden.bs.modal', onSearch);
window.accessReview = function(id) {
$.getJSON('/access', {id: id, profile: localStorage}, function(results) {
$.getJSON('/access', {id: id, profile: getProfile()}, function(results) {
if (results.success) {
location.replace(results.url);
}
@ -57,7 +58,7 @@
_ctx.query = {
features: _ctx.query.features || {},
range: { min: -1.0, max: 1.0 },
profile: localStorage,
profile: getProfile(),
walkingDist: parseFloat($('#walkingDist').val()),
minScore: parseFloat($('#minScore').val()),
hintSteps: parseInt($('#hintSteps').val()),
@ -147,6 +148,10 @@
}
}
function getProfile() {
return JSON.parse(localStorage.profile || '{}');
}
window.onpopstate = function(state) {
if (state.state) {
outputSnapshot(state.state, false);