Skip to content

Commit

Permalink
Fixed #30 bug with Chosen elements in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Jan 5, 2015
1 parent 208657a commit cea2b33
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions assets/js/be_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -155,6 +169,7 @@ var initListSort = function(listInner) {
restoreTinyMCEs(el);
});
updateListButtons(listInner.getParent('.rsce_list'));
restoreChosens(listInner);
}
}));

Expand Down Expand Up @@ -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[]',
Expand All @@ -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) {
Expand Down Expand Up @@ -324,6 +342,7 @@ var deleteElement = function(linkElement) {
renameElement(nextElement);
});
nextElements.each(function(nextElement) {
restoreChosens(nextElement);
restoreTinyMCEs(nextElement);
});

Expand Down Expand Up @@ -365,6 +384,9 @@ var moveElement = function(linkElement, offset) {
renameElement(swapElement);
renameElement(element);

restoreChosens(swapElement);
restoreChosens(element);

restoreTinyMCEs(swapElement);
restoreTinyMCEs(element);

Expand Down

0 comments on commit cea2b33

Please sign in to comment.