-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Blacklight::Gallery::OpenseadragonEmbedComponent
- Loading branch information
Showing
4 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/components/blacklight/gallery/openseadragon_embed_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
app/components/blacklight/gallery/openseadragon_embed_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) %> |