Browse Source

Add destroy method

dynamic-layer-root
Artur Arseniev 8 years ago
parent
commit
52f8bdf2e8
  1. 7
      src/editor/index.js
  2. 27
      src/editor/model/Editor.js

7
src/editor/index.js

@ -618,6 +618,13 @@ module.exports = config => {
return em.trigger.apply(em, arguments);
},
/**
* Destroy the editor
*/
destroy() {
return em.destroyAll();
},
/**
* Returns editor element
* @return {HTMLElement}

27
src/editor/model/Editor.js

@ -60,6 +60,10 @@ module.exports = Backbone.Model.extend({
this.set('storables', []);
if (c.el && c.fromElement) this.config.components = c.el.innerHTML;
this.attrsOrig = [...c.el.attributes].reduce((res, next) => {
res[next.nodeName] = next.nodeValue;
return res;
}, {});
// Load modules
deps.forEach(name => this.loadModule(name));
@ -571,6 +575,29 @@ module.exports = Backbone.Model.extend({
return this.get('changesCount');
},
/**
* Destroy editor
*/
destroyAll() {
const {
DomComponents,
CssComposer,
UndoManager,
Panels,
Canvas
} = this.attributes;
DomComponents.clear();
CssComposer.clear();
UndoManager.clear().removeAll();
Panels.getPanels().reset();
Canvas.getCanvasView().remove();
this.view.remove();
this.stopListening();
$(this.config.el)
.empty()
.attr(this.attrsOrig);
},
/**
* Set/get data from the HTMLElement
* @param {HTMLElement} el

Loading…
Cancel
Save