Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter expand/collapse text when adding/removing parts #357

Merged
merged 1 commit into from Feb 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/assets/javascripts/modules/collapsible_group.js
Expand Up @@ -16,7 +16,7 @@
$links = element.find('.js-toggle-all');

element.on('click', '.js-toggle-all', toggleAll);
element.on('shown.bs.collapse hidden.bs.collapse', updateLinkText);
element.on('shown.bs.collapse hidden.bs.collapse nested:fieldRemoved nested:fieldAdded', updateLinkText);

function toggleAll(event) {
var action = hasOpenItems() ? 'hide' : 'show';
Expand All @@ -26,7 +26,7 @@
}

function hasOpenItems() {
return element.find('.collapse.in').length > 0;
return element.find('.collapse.in:visible').length > 0;
}

function updateLinkText() {
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_part.html.erb
Expand Up @@ -7,7 +7,7 @@
</a>
</h4>
</div>
<div id="<%= f.object.slug || 'untitled-part' %>" class="js-part-toggle-target panel-collapse <% if f.object.valid? %>collapse <% end %>in" aria-expanded="true">
<div id="<%= f.object.slug || 'untitled-part' %>" class="js-part-toggle-target panel-collapse collapse in" aria-expanded="true">
<div class="panel-body">
<%= f.inputs do %>
<%= f.input :title,
Expand Down
12 changes: 12 additions & 0 deletions spec/javascripts/spec/collapsible_group.spec.js
Expand Up @@ -92,4 +92,16 @@ describe('A collapsible group module', function() {
});
});

describe('when a new group is added or removed', function() {
it('updates the link text', function() {
element.find('.collapse').first().addClass('in');
element.trigger('nested:fieldAdded');
expect(element.find('.js-toggle-all').text()).toBe('Collapse');

element.find('.collapse.in').first().hide();
element.trigger('nested:fieldRemoved');
expect(element.find('.js-toggle-all').text()).toBe('Expand');
});
});

});