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) {
if (store && _.isString(key)) {
store[key] = JSON.stringify({data: value});
}
var obj = load();
obj[key] = value;
return save(obj);
},
get = function (key) {
if (store && _.isString(key)) {
var json = store[key],
obj = {};
try { obj = JSON.parse(json); } catch (e) {}
return obj.data;
}
return load()[key];
};
return {

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
/* 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) { }
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) ) {
featureName = feature.toLowerCase();
Modernizr[featureName] = tests[feature]();