Skip to content

Commit

Permalink
Highlight the collection context link when it is active
Browse files Browse the repository at this point in the history
Fixes #1280
  • Loading branch information
jcoyne committed Nov 22, 2022
1 parent 20aa68e commit d367d74
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
11 changes: 11 additions & 0 deletions app/assets/javascripts/arclight/arclight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import 'arclight/oembed_viewer'

import Truncate from 'arclight/truncate_controller'
import CollectionLink from 'arclight/collection_link_controller'

// window.addEventListener('hashchange', (event) => {
// document.querySelectorAll('[data-controller="arclight-collection-link"]').forEach((elem) => {
// const event = new CustomEvent("update-map")

// })
// })


Stimulus.register('arclight-truncate', Truncate)
Stimulus.register('arclight-collection-link', CollectionLink)
13 changes: 13 additions & 0 deletions app/assets/javascripts/arclight/collection_link_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['link']

connect() {
this.highlight({newURL: document.documentURI})
}

highlight(event) {
this.linkTarget.classList.toggle('active', event.newURL.endsWith(this.linkTarget.href))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ $hierarchy-view-collapse-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3
}
}

.al-hierarchy-highlight > .documentHeader {
.al-hierarchy-highlight > .documentHeader,
.al-sidebar-navigation-context .active {
background: $mark-bg;
}

Expand Down
4 changes: 2 additions & 2 deletions app/components/arclight/collection_sidebar_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<ul class='nav flex-column'>
<% partials.each do |section| %>
<% next unless has_section?(section) %>
<li class='nav-item'>
<li class='nav-item' data-controller="arclight-collection-link" data-action="hashchange@window->arclight-collection-link#highlight">
<%= link_to section_label(section),
document_section_path(section),
class: 'nav-link pl-0 ps-0 py-1',
data: { turbolinks: 'false' }
data: { arclight_collection_link_target: 'link' }
%>
</li>
<% end %>
Expand Down
8 changes: 5 additions & 3 deletions lib/arclight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class Engine < ::Rails::Engine
end

initializer 'arclight.assets', before: 'assets' do |app|
app.config.assets.precompile << 'arclight/arclight.js'
app.config.assets.precompile << 'arclight/oembed_viewer.js'
app.config.assets.precompile << 'arclight/truncate_controller.js'
# rubocop:disable Lint/ConstantDefinitionInBlock
PRECOMPILE_ASSETS = %w(arclight/arclight.js arclight/oembed_viewer.js arclight/truncate_controller.js arclight/collection_link_controller.js).freeze
# rubocop:enable Lint/ConstantDefinitionInBlock

app.config.assets.precompile += PRECOMPILE_ASSETS
end

initializer 'arclight.importmap', before: 'importmap' do |app|
Expand Down
1 change: 1 addition & 0 deletions lib/generators/arclight/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def pin_javascript_dependencies
# TODO: We may be able to move these to a single importmap for arclight.
pin "arclight/oembed_viewer", to: "arclight/oembed_viewer.js"
pin "arclight/truncate_controller", to: "arclight/truncate_controller.js"
pin "arclight/collection_link_controller", to: "arclight/collection_link_controller.js"
RUBY
end

Expand Down

0 comments on commit d367d74

Please sign in to comment.