From 4fe74f45e81841f79cc214510074239d2e799408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Tue, 28 Nov 2017 15:55:52 +0100 Subject: [PATCH] Restore selector scripts before duplication, fixes #90 --- src/Resources/public/js/be_main.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Resources/public/js/be_main.js b/src/Resources/public/js/be_main.js index fe60bb3..e77b210 100644 --- a/src/Resources/public/js/be_main.js +++ b/src/Resources/public/js/be_main.js @@ -103,6 +103,30 @@ var removeACEs = function(element) { $(element).getElements('div.ace_editor').destroy(); } +var restoreSelectorScripts = function(element) { + + $(element).getElements('.selector_container').each(function(container) { + + var input = container.getPrevious('input'); + if (container.getElement('script') || !input) { + return; + } + + var name = input.name; + var dummyName = name.replace(/__\d+__/g, '__rsce_dummy__'); + var dummyScript = $(document.body).getElement('input[name="' + dummyName + '"] + .selector_container > script'); + if (!dummyScript) { + return; + } + + var script = new Element('script', { + html: dummyScript.get('html').split(dummyName).join(name), + }).inject(container); + + }); + +} + var updateListButtons = function(listElement) { listElement = $(listElement); @@ -383,6 +407,7 @@ var duplicateElement = function(linkElement) { // remove tinyMCEs => duplicate the element => rename => restoring tinyMCEs removeTinyMCEs(element); + restoreSelectorScripts(element); var newItem = element.cloneNode(true);