mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
define(['backbone'],
|
|
function (Backbone) {
|
|
/**
|
|
* @class LocalStorage
|
|
* */
|
|
return Backbone.Model.extend({
|
|
|
|
id: 'local',
|
|
|
|
defaults: {
|
|
checkSupport : true,
|
|
errorNoSupport : 'Error encountered while parsing JSON response',
|
|
},
|
|
|
|
/** @inheritdoc */
|
|
getId : function() {
|
|
return this.id;
|
|
},
|
|
|
|
/** @inheritdoc */
|
|
store : function(name, value) {
|
|
this.checkStorageEnvironment();
|
|
localStorage.setItem(name, value );
|
|
},
|
|
|
|
/** @inheritdoc */
|
|
load: function(name){
|
|
var result = null;
|
|
this.checkStorageEnvironment();
|
|
if(localStorage.getItem(name))
|
|
result = localStorage.getItem(name);
|
|
try{
|
|
var prx = "Loading '" + name + "': ";
|
|
if(!result)
|
|
throw prx + ' Resource was not found';
|
|
}catch(err){
|
|
console.warn(err);
|
|
}
|
|
return result;
|
|
},
|
|
|
|
/** @inheritdoc */
|
|
remove : function(name) {
|
|
this.checkStorageEnvironment();
|
|
localStorage.removeItem(name);
|
|
},
|
|
|
|
/**
|
|
* Check storage environment
|
|
* @return void
|
|
* */
|
|
checkStorageEnvironment: function(){
|
|
if(this.get('checkSupport'))
|
|
if( !localStorage )
|
|
console.warn(this.get('errorNoSupport'));
|
|
},
|
|
|
|
});
|
|
});
|
|
|