From cea2b33a495e366a847caf089f468c7630014337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Mon, 5 Jan 2015 14:40:09 +0100 Subject: [PATCH] Fixed #30 bug with Chosen elements in lists --- assets/js/be_main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/assets/js/be_main.js b/assets/js/be_main.js index 19d55e4..e426300 100644 --- a/assets/js/be_main.js +++ b/assets/js/be_main.js @@ -79,6 +79,20 @@ var restoreTinyMCEs = function(element) { }; +var restoreChosens = function(element) { + + $(element).getElements('.chzn-container').each(function(container) { + var select = container.getPrevious('select'); + if (!select) { + return; + } + select.setStyle('display', '').removeClass('chzn-done'); + container.destroy(); + $$([select]).chosen(); + }); + +}; + var updateListButtons = function(listElement) { listElement = $(listElement); @@ -155,6 +169,7 @@ var initListSort = function(listInner) { restoreTinyMCEs(el); }); updateListButtons(listInner.getParent('.rsce_list')); + restoreChosens(listInner); } })); @@ -245,6 +260,8 @@ var newElementAtPosition = function(listElement, position) { el.set('title', el.get('data-rsce-title')); }); + restoreChosens(newItem); + newItem.grab(new Element('input', { type: 'hidden', name: 'FORM_FIELDS[]', @@ -253,6 +270,7 @@ var newElementAtPosition = function(listElement, position) { newItem.getAllNext('.rsce_list_item').each(function(el) { renameElement(el); + restoreChosens(el); }); newItem.getElements('.rsce_list').each(function(el) { @@ -324,6 +342,7 @@ var deleteElement = function(linkElement) { renameElement(nextElement); }); nextElements.each(function(nextElement) { + restoreChosens(nextElement); restoreTinyMCEs(nextElement); }); @@ -365,6 +384,9 @@ var moveElement = function(linkElement, offset) { renameElement(swapElement); renameElement(element); + restoreChosens(swapElement); + restoreChosens(element); + restoreTinyMCEs(swapElement); restoreTinyMCEs(element);