Skip to content

Commit

Permalink
Restore selector scripts before duplication, fixes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 28, 2017
1 parent a4478a8 commit 4fe74f4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Resources/public/js/be_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 4fe74f4

Please sign in to comment.