Skip to content

Commit

Permalink
Fixed #103 bug with colorpicker inside lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Sep 19, 2018
1 parent 6f5dd46 commit b10cd2e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Resources/public/js/be_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ var restoreChosens = function(element) {

};

var removeMooRainbows = function(element) {
$(element).getElements('script').each(function(script) {
var match = script.get('html').match(/new MooRainbow\("(moo_rsce_field_[^"]+)"[^]*?id:\s*"([^"]+)"/);
if (!match) {
return;
}
$(match[1]).removeEvents('click');
$(document.body).getChildren('#'+match[2]).destroy();
});
};

var restoreMooRainbows = function(element) {
$(element).getElements('script').each(function(script) {
var match = script.get('html').match(/new MooRainbow\("(moo_rsce_field_[^"]+)"[^]*?id:\s*"([^"]+)"/);
if (!match) {
return;
}
Browser.exec(script.get('html'));
});
};

var removeACEs = function(element) {
$(element).getElements('div.ace_editor').destroy();
}
Expand Down Expand Up @@ -216,6 +237,7 @@ var initListSort = function(listInner) {
},
onComplete: function() {
ds.stop();
removeMooRainbows(listInner);
listInner.getChildren('.rsce_list_item').each(function(el) {
removeTinyMCEs(el);
});
Expand All @@ -226,6 +248,7 @@ var initListSort = function(listInner) {
restoreTinyMCEs(el);
});
updateListButtons(listInner.getParent('.rsce_list'));
restoreMooRainbows(listInner);
restoreChosens(listInner);
}
}));
Expand Down Expand Up @@ -260,6 +283,7 @@ var newElementAtPosition = function(listElement, position) {

allItems.each(function(el) {
removeTinyMCEs(el);
removeMooRainbows(el);
});
removeTinyMCEs(dummyItem);
removeACEs(dummyItem);
Expand Down Expand Up @@ -327,6 +351,7 @@ var newElementAtPosition = function(listElement, position) {
});

allItems.each(function(el) {
restoreMooRainbows(el);
restoreTinyMCEs(el);
});
restoreTinyMCEs(newItem);
Expand Down Expand Up @@ -426,6 +451,7 @@ var duplicateElement = function(linkElement) {
// remove tinyMCEs => duplicate the element => rename => restoring tinyMCEs

removeTinyMCEs(element);
removeMooRainbows(listInner);
restoreSelectorScripts(element);
persistSelects(element);

Expand Down Expand Up @@ -460,6 +486,9 @@ var duplicateElement = function(linkElement) {

executeHtmlScripts(newItem.get('html'));

removeMooRainbows(newItem);
restoreMooRainbows(listInner);

if (listInner.retrieve('listSort')) {
listInner.retrieve('listSort').addItems(newItem);
}
Expand All @@ -485,6 +514,8 @@ var deleteElement = function(linkElement) {
return;
}

removeMooRainbows(listInner);

removeTinyMCEs(element);
if (listInner.retrieve('listSort')) {
listInner.retrieve('listSort').removeItems(element);
Expand All @@ -501,6 +532,8 @@ var deleteElement = function(linkElement) {
restoreTinyMCEs(nextElement);
});

restoreMooRainbows(listInner);

updateListButtons(listElement);

$(document.body).getChildren('.tip-wrap').each(function(el) {
Expand Down Expand Up @@ -534,6 +567,9 @@ var moveElement = function(linkElement, offset) {
removeTinyMCEs(swapElement);
removeTinyMCEs(element);

removeMooRainbows(swapElement);
removeMooRainbows(element);

element.inject(swapElement, offset > 0 ? 'after' : 'before');

renameElement(swapElement);
Expand All @@ -542,6 +578,9 @@ var moveElement = function(linkElement, offset) {
restoreChosens(swapElement);
restoreChosens(element);

restoreMooRainbows(swapElement);
restoreMooRainbows(element);

restoreTinyMCEs(swapElement);
restoreTinyMCEs(element);

Expand Down

0 comments on commit b10cd2e

Please sign in to comment.