2015-11-18 05:25:16 +00:00
|
|
|
// depends on: codeUri
|
|
|
|
window.common = (function(global) {
|
|
|
|
const {
|
|
|
|
localStorage,
|
|
|
|
common = { init: [] }
|
|
|
|
} = global;
|
|
|
|
|
|
|
|
var codeStorage = {
|
|
|
|
getStoredValue(key) {
|
2015-11-20 05:51:38 +00:00
|
|
|
if (
|
|
|
|
!localStorage ||
|
|
|
|
typeof localStorage.getItem !== 'function' ||
|
|
|
|
!key ||
|
|
|
|
typeof key !== 'string'
|
|
|
|
) {
|
2015-12-06 09:17:19 +00:00
|
|
|
console.log('unable to read from storage');
|
2015-11-20 05:51:38 +00:00
|
|
|
return '';
|
|
|
|
}
|
2015-11-18 05:25:16 +00:00
|
|
|
return '' + localStorage.getItem(key + 'Val');
|
|
|
|
},
|
|
|
|
|
2015-11-22 04:30:30 +00:00
|
|
|
isAlive: function(key) {
|
|
|
|
var val = this.getStoredValue(key);
|
2015-11-18 05:25:16 +00:00
|
|
|
return val !== 'null' &&
|
|
|
|
val !== 'undefined' &&
|
|
|
|
(val && val.length > 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateStorage(key, code) {
|
|
|
|
if (
|
|
|
|
!localStorage ||
|
2015-11-20 05:51:38 +00:00
|
|
|
typeof localStorage.setItem !== 'function' ||
|
2015-11-18 05:25:16 +00:00
|
|
|
!key ||
|
|
|
|
typeof key !== 'string'
|
|
|
|
) {
|
|
|
|
console.log('unable to save to storage');
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
localStorage.setItem(key + 'Val', code);
|
2015-11-20 05:51:38 +00:00
|
|
|
return code;
|
2015-11-18 05:25:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
common.codeStorage = codeStorage;
|
|
|
|
|
|
|
|
return common;
|
|
|
|
}(window, window.common));
|