Updates storage.

This commit is contained in:
Lars Jung 2012-10-16 22:50:41 +02:00
parent e6bbb7c2cd
commit e43d43933a
6 changed files with 45 additions and 19 deletions

View file

@ -1,25 +1,37 @@
modulejs.define('core/store', ['_'], function (_) { modulejs.define('core/store', ['_', 'modernizr'], function (_, modernizr) {
var store = window.localStorage, var store = modernizr.localstorage ? window.localStorage : null,
key = '_h5ai',
load = function () {
if (store) {
try {
return JSON.parse(store[key]);
} catch (e) {}
}
return {};
},
save = function (obj) {
if (store) {
store[key] = JSON.stringify(obj);
}
},
put = function (key, value) { put = function (key, value) {
if (store && _.isString(key)) { var obj = load();
store[key] = JSON.stringify({data: value}); obj[key] = value;
} return save(obj);
}, },
get = function (key) { get = function (key) {
if (store && _.isString(key)) { return load()[key];
var json = store[key],
obj = {};
try { obj = JSON.parse(json); } catch (e) {}
return obj.data;
}
}; };
return { return {

View file

@ -34,7 +34,7 @@ modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/form
'</span>', '</span>',
langOptionTemplate = '<li class="langOption"/>', langOptionTemplate = '<li class="langOption"/>',
storekey = 'h5ai.language', storekey = 'l10n.lang',
loaded = { loaded = {
en: _.extend({}, defaultTranslations) en: _.extend({}, defaultTranslations)

View file

@ -28,7 +28,7 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource',
'</div>' + '</div>' +
'</div>', '</div>',
storekey = 'h5ai.preview-img.isFullscreen', storekey = 'preview-img.isFullscreen',
currentEntries = [], currentEntries = [],
currentIdx = 0, currentIdx = 0,

View file

@ -6,7 +6,7 @@ modulejs.define('ext/sort', ['_', '$', 'core/settings', 'core/resource', 'core/e
order: 'na' order: 'na'
}, allsettings.sort), }, allsettings.sort),
storekey = 'h5ai.sortorder', storekey = 'sort.order',
type = function (entry) { type = function (entry) {

View file

@ -7,7 +7,7 @@ modulejs.define('view/viewmode', ['_', '$', 'core/settings', 'core/resource', 'c
modes: modes modes: modes
}, allsettings.view), }, allsettings.view),
storekey = 'h5ai.viewmode', storekey = 'viewmode',
template = '<li id="view-[MODE]" class="view">' + template = '<li id="view-[MODE]" class="view">' +
'<a href="#">' + '<a href="#">' +

View file

@ -1,5 +1,5 @@
/* Modernizr 2.6.2 (Custom Build) | MIT & BSD /* Modernizr 2.6.2 (Custom Build) | MIT & BSD
* Build: http://modernizr.com/download/#-opacity-rgba-canvas-history-audio-video-shiv-cssclasses-prefixes * Build: http://modernizr.com/download/#-opacity-rgba-canvas-history-audio-video-localstorage-shiv-cssclasses-prefixes
*/ */
; ;
@ -182,7 +182,21 @@ window.Modernizr = (function( window, document, undefined ) {
} catch(e) { } } catch(e) { }
return bool; return bool;
}; for ( var feature in tests ) { };
tests['localstorage'] = function() {
try {
localStorage.setItem(mod, mod);
localStorage.removeItem(mod);
return true;
} catch(e) {
return false;
}
};
for ( var feature in tests ) {
if ( hasOwnProp(tests, feature) ) { if ( hasOwnProp(tests, feature) ) {
featureName = feature.toLowerCase(); featureName = feature.toLowerCase();
Modernizr[featureName] = tests[feature](); Modernizr[featureName] = tests[feature]();