API Storage Manager

Artur Arseniev edited this page Aug 30, 2016 · 3 revisions

StorageManager

Before using methods you should get first the module from the editor instance, in this way:

var storageManager = editor.StorageManager;

Parameters

  • config Object Configurations
    • config.id string= The prefix for the fields, useful to differentiate storing/loading with multiple editors on the same page. For example, in local storage, the item of HTML will be saved like 'gjs-html' (optional, default 'gjs-')
    • config.autosave Boolean= Indicates if autosave mode is enabled, works in conjunction with stepsBeforeSave (optional, default true)
    • config.stepsBeforeSave number= If autosave enabled, indicates how many steps/changes are necessary before autosave is triggered (optional, default 1)
    • config.type string= Default storage type. Available: 'local' | 'remote' | ''(do not store) (optional, default 'local')

Examples

...
storageManager: {
  autosave: false,
  type: 'remote',
}
...

add

Add new storage

Parameters

Examples

storageManager.add('local2', {
  load: function(keys){
    var res = {};
    for (var i = 0, len = keys.length; i < len; i++){
      var v = localStorage.getItem(keys[i]);
      if(v) res[keys[i]] = v;
    }
    return res;
  },
  store: function(data){
    for(var key in data)
      localStorage.setItem(key, data[key]);
  }
});

Returns this

get

Returns storage by id

Parameters

Returns (Object|null)

getCurrent

Returns current storage type

Returns string

getStepsBeforeSave

Returns number of steps required before trigger autosave

Returns number

getStorages

Returns all storages

Returns Array

isAutosave

Checks if autosave is enabled

Returns Boolean

load

Load resource from the current storage by keys

Parameters

Examples

var data = storageManager.load(['item1', 'item2']);
// data -> {item1: value1, item2: value2}
var data2 = storageManager.load('item1');
// data2 -> {item1: value1}

Returns (Object|null) Loaded resources

RemoteStorage

setAutosave

Set autosave value

Parameters

Returns this

setCurrent

Set current storage type

Parameters

Returns this

setStepsBeforeSave

Set steps required before trigger autosave

Parameters

Returns this

store

Store key-value resources in the current storage

Parameters

  • data Object Data in key-value format, eg. {item1: value1, item2: value2}

Examples

storageManager.store({item1: value1, item2: value2});

Returns (Object|null)