+
+ Object.keys(data)
+ .filter(function(key) {
+ return key !== 'history' && key !== 'document';
+ })
+ .forEach(function(key) {
+ wlxmlDocument.setProperty(key, data[key]);
+ });
+
+ wlxmlDocument.registerExtension(listExtension);
+ sandbox.getPlugins().forEach(function(plugin) {
+ if(plugin.documentExtension) {
+ wlxmlDocument.registerExtension(plugin.documentExtension);
+ }
+ });
+
+ var modificationFlag = true;
+ var handleChange = function() {
+ documentDirty = true;
+ draftDirty = true;
+ modificationFlag = true;
+ };
+ wlxmlDocument.on('change', handleChange);
+ wlxmlDocument.on('contentSet', handleChange);
+
+ if(window.localStorage) {
+ window.setInterval(function() {
+ if(modificationFlag) {
+ modificationFlag = false;
+ return;
+ }
+ if(wlxmlDocument && documentDirty && draftDirty) {
+ var timestamp = datetime.currentStrfmt();
+ logger.debug('Saving draft to local storage.');
+ sandbox.publish('savingStarted', 'local');
+ window.localStorage.setItem(getLocalStorageKey().content, wlxmlDocument.toXML());
+ window.localStorage.setItem(getLocalStorageKey().contentTimestamp, timestamp);
+ sandbox.publish('savingEnded', 'success', 'local', {timestamp: timestamp});
+ draftDirty = false;
+ }
+ }, sandbox.getConfig().autoSaveInterval || 2500);
+ }
+ sandbox.publish('ready', isDraft, draftTimestamp);
+ };