From feb9a8b67435036f12563a69017a58cf72b96143 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 27 Feb 2018 01:08:24 +0100 Subject: [PATCH] Init correctly components with javascript. Fixes #873 --- src/canvas/view/CanvasView.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/canvas/view/CanvasView.js b/src/canvas/view/CanvasView.js index b8270a9c72..92eeb1dc86 100644 --- a/src/canvas/view/CanvasView.js +++ b/src/canvas/view/CanvasView.js @@ -328,14 +328,14 @@ module.exports = Backbone.View.extend({ this.getJsContainer().append(view.scriptContainer.get(0)); } - var model = view.model; - var id = model.getId(); + const model = view.model; + const id = model.getId(); view.el.id = id; view.scriptContainer.html(''); // In editor, I make use of setTimeout as during the append process of elements // those will not be available immediatly, therefore 'item' variable const script = document.createElement('script'); - script.innerText = ` + script.innerHTML = ` setTimeout(function() { var item = document.getElementById('${id}'); if (!item) return; @@ -343,7 +343,9 @@ module.exports = Backbone.View.extend({ ${model.getScriptString()}; }.bind(item))() }, 1);`; - view.scriptContainer.get(0).appendChild(script); + // #873 + // Adding setTimeout will make js components work on init of the editor + setTimeout(() => view.scriptContainer.get(0).appendChild(script), 0); }, /**