Skip to content

Commit

Permalink
Destroy multiImageSelectors before instantiating new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeck committed Feb 7, 2017
1 parent 98d17ec commit 5ba65b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/assets/javascripts/spotlight/multi_image_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

function init(el) {
panel = el;

destroyExistingImageSelector();
if(image_versions && image_versions.length > 1) {
addChangeLink();
addThumbsList();
Expand All @@ -27,6 +29,12 @@
addChangeLinkBehavior();
}

function destroyExistingImageSelector() {
var pagination = $('[data-panel-image-pagination]', panel);
pagination.html('');
pagination.next('.' + thumbsListContainer.attr('class')).remove();
}

function indexOf(thumb){
if( (index = imageIds.indexOf(thumb)) > -1 ){
return index + 1;
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/spotlight/search_typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function addImageSelector(input, panel, manifestUrl) {

if(thumbs.length == 1) {
cropper.setIiifFields(thumbs[0]);
panel.multiImageSelector(); // Clears out existing selector
} else {
panel.show();
panel.multiImageSelector(thumbs, function(selectorImage) {
Expand Down
13 changes: 13 additions & 0 deletions spec/features/autocomplete_typeahead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@

expect(page).to have_css('[data-panel-image-pagination]', text: /Image 2 of 2/, visible: true)
end

it 'removes the multi-image selector when a non multi-image item is selected' do
visit spotlight.edit_exhibit_appearance_path(exhibit)
click_link 'Exhibit masthead'

fill_in_typeahead_field(with: 'xd327cm9378', type: 'featured-image')

expect(page).to have_css('[data-panel-image-pagination]', text: /Image 1 of 2/, visible: true)

fill_in_typeahead_field(with: 'gk446cj2442', type: 'featured-image')

expect(page).not_to have_css('[data-panel-image-pagination]', text: /Image 1 of 2/)
end
end

context 'for items that do not include a IIIF manifest' do
Expand Down

0 comments on commit 5ba65b5

Please sign in to comment.