Skip to content

Commit

Permalink
Add destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jun 8, 2018
1 parent ce79a94 commit 52f8bdf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
27 changes: 27 additions & 0 deletions src/editor/model/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 52f8bdf

Please sign in to comment.