diff --git a/app/assets/stylesheets/earthworks.css b/app/assets/stylesheets/earthworks.css index 83270e31..6b30e23b 100644 --- a/app/assets/stylesheets/earthworks.css +++ b/app/assets/stylesheets/earthworks.css @@ -164,6 +164,21 @@ Uncomment lines 142-144 --bs-pagination-focus-bg: none; --bs-pagination-focus-box-shadow: none; } + +/* Styles for search result description expand/collapse */ + +.expand-collapse .btn-outline-secondary { + display: flex; + &.active { + color: white; + background-color:var(--stanford-cardinal); + } +} + +.expand-collapse i { + align-self: center; +} + /* Styles for code snippet */ .code-snippet-content { @@ -199,18 +214,3 @@ Uncomment lines 142-144 color: var(--stanford-digital-blue-dark) !important; border-color: var(--stanford-digital-blue-dark) !important; } - -/* Styles for search result description expand/collapse */ - -.expand-collapse .btn-outline-secondary { - display: flex; - &.active { - color: white; - background-color:var(--stanford-cardinal); - } -} - -.expand-collapse i { - align-self: center; -} - diff --git a/app/javascript/controllers/description_controller.js b/app/javascript/controllers/description_controller.js index 4a74342e..0ce869ac 100644 --- a/app/javascript/controllers/description_controller.js +++ b/app/javascript/controllers/description_controller.js @@ -1,4 +1,11 @@ import { Controller } from "@hotwired/stimulus" export default class extends Controller { + expand() { + this.element.classList.remove("collapse"); + } + + collapse() { + this.element.classList.add("collapse"); + } } diff --git a/app/javascript/controllers/expandcollapse_controller.js b/app/javascript/controllers/expandcollapse_controller.js index 267362b4..3a0bdb80 100644 --- a/app/javascript/controllers/expandcollapse_controller.js +++ b/app/javascript/controllers/expandcollapse_controller.js @@ -1,16 +1,29 @@ import { Controller } from "@hotwired/stimulus" export default class extends Controller { - static outlets = [ "description" ] - toggleDescriptions(evt) { - const activeClass = 'active' - const currentActive = this.element.querySelector(`.${activeClass}`) - currentActive.classList.remove(activeClass) - currentActive.disabled = false; - evt.currentTarget.disabled = true; - evt.currentTarget.classList.add(activeClass) - this.descriptionOutletElements.forEach(function(element) { - element.classList.toggle("collapse"); + static outlets = ["description"] + static targets = ["expandButton", "collapseButton"] + + expandDescriptions() { + this.descriptionOutlets.forEach(description => { + description.expand(); + }); + + this.toggleButtonStates(); + } + + + collapseDescriptions() { + this.descriptionOutlets.forEach(description => { + description.collapse(); }); + + this.toggleButtonStates(); } + + toggleButtonStates() { + this.expandButtonTarget.classList.toggle("active"); + this.collapseButtonTarget.classList.toggle("active"); + } + } \ No newline at end of file diff --git a/app/views/catalog/_sort_and_per_page.html.erb b/app/views/catalog/_sort_and_per_page.html.erb index 044bb53f..f79f97bf 100644 --- a/app/views/catalog/_sort_and_per_page.html.erb +++ b/app/views/catalog/_sort_and_per_page.html.erb @@ -3,14 +3,14 @@
- \ No newline at end of file + \ No newline at end of file