Skip to content

Commit

Permalink
Use view components for the thumbnails
Browse files Browse the repository at this point in the history
This will assist in our move to blacklight 8.  This also removes a interactive element that behaves like a link but wasn't accessible.

Fixes #3798
  • Loading branch information
jcoyne committed Jan 25, 2024
1 parent b669d3e commit abdd071
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 68 deletions.
9 changes: 0 additions & 9 deletions app/assets/stylesheets/modules/results-documents.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
}
}

.cover-image-wrapper {
margin: 0;
padding: 0;
}

.cover-image {
border: 1px solid #ddd;
max-height: 150px;
Expand All @@ -28,10 +23,6 @@
white-space: nowrap;
}

.cursor-pointer {
cursor: pointer;
}

.results-metadata-section {
border-bottom: 1px solid $cloud;
clear: left;
Expand Down
8 changes: 8 additions & 0 deletions app/components/thumbnail_with_iiif_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% value = presenter.thumbnail.render(@image_options) %>

<% if value %>
<div class="document-thumbnail">
<%= helpers.link_to_document(presenter.document, value, 'aria-hidden': true, tabindex: -1, counter: @counter) %>
<%= helpers.iiif_drag_n_drop(@document.iiif_manifest, position: 'top') if @document.iiif_manifest %>
</div>
<% end %>
4 changes: 4 additions & 0 deletions app/components/thumbnail_with_iiif_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class ThumbnailWithIiifComponent < Blacklight::Document::ThumbnailComponent
end
1 change: 0 additions & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import "./jquery.turbolinks-cursor";
import "./location-hours";
import "./preview-content";
import "./recent-selections";
import "./search-context";
import "./select-all";
import "./sfx-panel";
import "./skip-to-nav";
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/jquery.plug-google-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
if(typeof imageEl.attr('src') === 'undefined') {
imageEl.attr('src', thumbUrl)[0].hidden = false;

const fakeCover = imageEl.parent().parent().find('span.fake-cover')[0]
const fakeCover = imageEl.parent().find('span.fake-cover')[0]
if (fakeCover) {
fakeCover.hidden = true
}
Expand Down
5 changes: 0 additions & 5 deletions app/javascript/search-context.js

This file was deleted.

11 changes: 2 additions & 9 deletions app/views/catalog/_index_gallery.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
<%
preview_container = 'preview-container-' + document.id
counter = document_counter_with_offset(document_counter)
options = {
:counter => counter,
:suppress_link => true
}
context_href = (document_link_params(document, {:counter => counter})).dig(:data, :"context-href")
preview_container = 'preview-container-' + document.id
%>

<div class="gallery-document" <%= preview_data_attrs(true, "preview-gallery", document[:id], ".#{preview_container}") %> data-preview-in-gallery="true" data-doc-id=<%= document.id %> >
<div class="item-thumb">
<div class="cover-image-wrapper" data-target="<%= solr_document_path document %>" data-context-href="<%= context_href %>">
<%= document_presenter(document).thumbnail.thumbnail_tag({}, options) %>
</div>
<%= render Blacklight::Document::ThumbnailComponent.new(counter:, document:) %>
</div>
<div class="caption">
<%= render_document_partials document, blacklight_config.view_config(:gallery).partials, document_counter: document_counter %>
Expand Down
20 changes: 2 additions & 18 deletions app/views/catalog/_thumbnail_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
<%
counter = document_counter_with_offset(document_counter)
options = {
:counter => counter,
:suppress_link => true
}
context_href = document_link_params(document, {:counter => counter}).dig(:data, :"context-href")
presenter = document_presenter(document)
%>

<% if presenter.thumbnail.exists? && tn = presenter.thumbnail.thumbnail_tag({}, options) %>
<div class="document-thumbnail">
<div class="cover-image-wrapper" data-target="<%= solr_document_path document %>" data-context-href="<%= context_href %>">
<%= tn %>
</div>
<%= iiif_drag_n_drop(document.iiif_manifest, position: 'top') if document.iiif_manifest %>
</div>
<% end %>
<%= render ThumbnailWithIiifComponent.new(counter: document_counter_with_offset(document_counter),
presenter: document_presenter(document)) %>
12 changes: 5 additions & 7 deletions app/views/catalog/thumbnails/_collection_thumbnail.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<% if document_index_view_type == :gallery %>
<%= link_to document, tabindex: '-1' do %>
<% if document.collection_members.present? && document.collection_members.first.image_urls(:large).present? %>
<%= image_tag(document.collection_members.first.image_urls(:large).first, class: 'stacks-image', alt: '') %>
<% else %>
<%= content_tag(:span, class:"fake-cover", aria: { hidden: true }) do %>
<%= content_tag(:div, document_presenter(document).heading, class: "fake-cover-text") %>
<% end %>
<% if document.collection_members.present? && document.collection_members.first.image_urls(:large).present? %>
<%= image_tag(document.collection_members.first.image_urls(:large).first, class: 'stacks-image', alt: '') %>
<% else %>
<%= content_tag(:span, class:"fake-cover", aria: { hidden: true }) do %>
<%= content_tag(:div, document_presenter(document).heading, class: "fake-cover-text") %>
<% end %>
<% end %>
<% end %>
6 changes: 2 additions & 4 deletions app/views/catalog/thumbnails/_item_thumbnail.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
<img class="cover-image center-block <%= css_class %>" hidden alt="" data-isbn="<%= isbn %>" data-oclc="<%= oclc %>" data-lccn="<%= lccn %>">

<% if document_index_view_type == :gallery %>
<%= link_to document, tabindex: '-1', aria: { hidden: true } do %>
<%= content_tag(:span, class:"fake-cover") do %>
<%= content_tag(:div, document_presenter(document).heading, class: "fake-cover-text") %>
<% end %>
<%= content_tag(:span, class:"fake-cover") do %>
<%= content_tag(:div, document_presenter(document).heading, class: "fake-cover-text") %>
<% end %>
<% end %>
<% end %>
14 changes: 0 additions & 14 deletions spec/features/blacklight_customizations/results_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@
end
end

scenario 'should have the correct cover image wrapper attributes' do
visit root_path
first('#q').set '10'
click_button 'search'

within '#documents' do
within 'div.document' do
expect(page).to have_css('div.cover-image-wrapper', visible: true)
expect(page).to have_css("div.cover-image-wrapper[data-target='/view/10']")
expect(page).to have_css("div.cover-image-wrapper[data-context-href^='/catalog/10/track?']")
end
end
end

scenario 'should have the stacks image for objects with image behavior' do
visit root_path
first('#q').set '35'
Expand Down

0 comments on commit abdd071

Please sign in to comment.