From d71882c19689ef53057f0345e5b195b861ecc819 Mon Sep 17 00:00:00 2001 From: A---- Date: Wed, 6 Sep 2017 11:16:30 +0200 Subject: [PATCH] Use HTMLElement for container --- src/grapesjs/index.js | 9 +++++++-- test/specs/grapesjs/index.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/grapesjs/index.js b/src/grapesjs/index.js index 98e650a85..9c66cfd01 100644 --- a/src/grapesjs/index.js +++ b/src/grapesjs/index.js @@ -18,7 +18,7 @@ module.exports = (config => { /** * Initializes an editor based on passed options * @param {Object} config Configuration object - * @param {string} config.container Selector which indicates where render the editor + * @param {string|DomNode} config.container Selector which indicates where render the editor * @param {Object|string} config.components='' HTML string or Component model in JSON format * @param {Object|string} config.style='' CSS string or CSS model in JSON format * @param {Boolean} [config.fromElement=false] If true, will fetch HTML and CSS from selected container @@ -52,7 +52,12 @@ module.exports = (config => { throw new Error("'container' is required"); } - c.el = document.querySelector(els); + if (els instanceof window.HTMLElement) { + c.el = els; + } + else { + c.el = document.querySelector(els); + } var editor = new Editor(c).init(); // Load plugins diff --git a/test/specs/grapesjs/index.js b/test/specs/grapesjs/index.js index fa394a929..813e237c5 100644 --- a/test/specs/grapesjs/index.js +++ b/test/specs/grapesjs/index.js @@ -59,6 +59,18 @@ describe('GrapesJS', () => { var editor = obj.init(config); expect(editor).toExist(); }); + + it('Init new editor with node for container', () => { + var configAlt = { + container: document.createElement('div'), + storageManager: { + autoload: 0, + type:'none' + }, + } + var editor = obj.init(configAlt); + expect(editor).toExist(); + }); it('New editor is empty', () => { var editor = obj.init(config);