Skip to content

Commit

Permalink
Extract Blacklight::Gallery::OpenseadragonEmbedComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 23, 2024
1 parent e870213 commit 9860be5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="openseadragon-container <%= class_names(classes) %>">
<div class="osd-toolbar row">
<div class="col-md-6 pagination">
<% if count > 1 %>
<% osd_config = osd_config_referencestrip.merge(osd_config) %>
<a id="<%= id_prefix %>-previous"><%= render Blacklight::Gallery::Icons::ChevronLeftComponent.new %></a>
<span id="<%= id_prefix %>-page">1</span> of <%= count %>
<a id="<%= id_prefix %>-next"><%= render Blacklight::Gallery::Icons::ChevronRightComponent.new %></a>
<% end %>
</div>
<div class="col-md-6 controls">
<a id="<%= id_prefix %>-zoom-in"><%= render Blacklight::Gallery::Icons::AddCircleComponent.new %></a>
<a id="<%= id_prefix %>-zoom-out"><%= render Blacklight::Gallery::Icons::RemoveCircleComponent.new %></a>
<a id="<%= id_prefix %>-home"><%= render Blacklight::Gallery::Icons::ResizeSmallComponent.new %></a>
<a id="<%= id_prefix %>-full-page"><%= render Blacklight::Gallery::Icons::CustomFullscreenComponent.new %></a>
</div>
</div>
<%= helpers.openseadragon_picture_tag image, class: 'osd-image row', data: { openseadragon: osd_config } %>
</div>
60 changes: 60 additions & 0 deletions app/components/blacklight/gallery/openseadragon_embed_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

module Blacklight
module Gallery
class OpenseadragonEmbedComponent < Blacklight::Component
attr_reader :document, :presenter, :classes

def initialize(document:, presenter:, view_config: nil, classes: [], **kwargs)
super

@document = document
@presenter = presenter
@view_config = view_config
@classes = classes
end

def image
@image ||= document.to_openseadragon(view_config)
end

def count
Array(image).length
end

def view_config
@view_config || presenter.view_config
end

def render?
!image.nil?
end

def osd_config
{
crossOriginPolicy: false,
zoomInButton: "#{id_prefix}-zoom-in",
zoomOutButton: "#{id_prefix}-zoom-out",
homeButton: "#{id_prefix}-home",
fullPageButton: "#{id_prefix}-full-page",
nextButton: "#{id_prefix}-next",
previousButton: "#{id_prefix}-previous"
}
end

def osd_config_referencestrip
{
showReferenceStrip: true,
referenceStripPosition: 'OUTSIDE',
referenceStripScroll: 'vertical',
referenceStripWidth: 100,
referenceStripBackgroundColor: 'transparent'
}
end

def id_prefix
"osd-#{Blacklight::OpenseadragonHelper.mint_id}".to_param
end
end
end
end
3 changes: 2 additions & 1 deletion app/helpers/blacklight/openseadragon_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def self.mint_id
end

def osd_container_class
"col-md-6"
'col-md-6'
end

# @deprecated
def osd_html_id_prefix
"osd-#{Blacklight::OpenseadragonHelper.mint_id}".to_param
end
Expand Down
49 changes: 1 addition & 48 deletions app/views/catalog/_openseadragon_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,48 +1 @@
<%
view_config = local_assigns[:view_config] || blacklight_config&.view_config(:show)
image = document.to_openseadragon(view_config)
id_prefix = osd_html_id_prefix
%>
<%
osd_config = {
crossOriginPolicy: false,
zoomInButton: "#{id_prefix}-zoom-in",
zoomOutButton: "#{id_prefix}-zoom-out",
homeButton: "#{id_prefix}-home",
fullPageButton: "#{id_prefix}-full-page",
nextButton: "#{id_prefix}-next",
previousButton: "#{id_prefix}-previous"
}

osd_config_referencestrip = {
showReferenceStrip: true,
referenceStripPosition: 'OUTSIDE',
referenceStripScroll: 'vertical',
referenceStripWidth: 100,
referenceStripBackgroundColor: 'transparent'
}
%>
<% unless image.nil? %>
<% count = Array(image).length %>
<div class="openseadragon-container <%= osd_container_class %>">
<div class="osd-toolbar row">
<div class="col-md-6 pagination">
<% if count > 1 %>
<% osd_config = osd_config_referencestrip.merge(osd_config) %>
<a id="<%= id_prefix %>-previous"><%= render Blacklight::Gallery::Icons::ChevronLeftComponent.new %></a>
<span id="<%= id_prefix %>-page">1</span> of <%= count %>
<a id="<%= id_prefix %>-next"><%= render Blacklight::Gallery::Icons::ChevronRightComponent.new %></a>
<% end %>
</div>
<div class="col-md-6 controls">
<a id="<%= id_prefix %>-zoom-in"><%= render Blacklight::Gallery::Icons::AddCircleComponent.new %></a>
<a id="<%= id_prefix %>-zoom-out"><%= render Blacklight::Gallery::Icons::RemoveCircleComponent.new %></a>
<a id="<%= id_prefix %>-home"><%= render Blacklight::Gallery::Icons::ResizeSmallComponent.new %></a>
<a id="<%= id_prefix %>-full-page"><%= render Blacklight::Gallery::Icons::CustomFullscreenComponent.new %></a>
</div>
</div>
<%= openseadragon_picture_tag image, class: 'osd-image row', data: { openseadragon: osd_config } %>
</div>

<% end %>
<%= render Blacklight::Gallery::OpenseadragonEmbedComponent.new(document: document, presenter: document_presenter(document), view_config: local_assigns[:view_config], classes: [osd_container_class]) %>

0 comments on commit 9860be5

Please sign in to comment.