From 8fd20f1b98e41d883d6bf055e34910237c07c7e7 Mon Sep 17 00:00:00 2001 From: Jessie Keck Date: Tue, 7 Feb 2017 16:08:30 -0800 Subject: [PATCH] Destroy multiImageSelectors before instantiating new ones (#1728) --- .../javascripts/spotlight/multi_image_selector.js | 8 ++++++++ .../javascripts/spotlight/search_typeahead.js | 1 + spec/features/autocomplete_typeahead_spec.rb | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/app/assets/javascripts/spotlight/multi_image_selector.js b/app/assets/javascripts/spotlight/multi_image_selector.js index 16f9a6b57..e637a3ca8 100644 --- a/app/assets/javascripts/spotlight/multi_image_selector.js +++ b/app/assets/javascripts/spotlight/multi_image_selector.js @@ -13,6 +13,8 @@ function init(el) { panel = el; + + destroyExistingImageSelector(); if(image_versions && image_versions.length > 1) { addChangeLink(); addThumbsList(); @@ -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; diff --git a/app/assets/javascripts/spotlight/search_typeahead.js b/app/assets/javascripts/spotlight/search_typeahead.js index 660d957ea..acc7f2a9f 100644 --- a/app/assets/javascripts/spotlight/search_typeahead.js +++ b/app/assets/javascripts/spotlight/search_typeahead.js @@ -82,6 +82,7 @@ function addImageSelector(input, panel, manifestUrl, initialize) { if (initialize) { cropper.setIiifFields(thumbs[0]); + panel.multiImageSelector(); // Clears out existing selector } if(thumbs.length > 1) { diff --git a/spec/features/autocomplete_typeahead_spec.rb b/spec/features/autocomplete_typeahead_spec.rb index e24673192..4742c15d4 100644 --- a/spec/features/autocomplete_typeahead_spec.rb +++ b/spec/features/autocomplete_typeahead_spec.rb @@ -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