Skip to content

Commit

Permalink
Merge pull request #1473 from CuBoulder/issue/1353
Browse files Browse the repository at this point in the history
Expandable url has updates
  • Loading branch information
jcsparks authored and web-flow committed Nov 19, 2024
2 parents a1478d1 + da80574 commit 4f4d91a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- ### Expandable url has updates
Series of updates to add functionality to expendables and ckeditor accordions for address bar hash updates.

Removed the duplicate expandable block js.
Works for expandable block's accordion/horizontal/vertical options.
Made global so that ckeditor accordions on any page type are affected

This does not handle nested accordions within expandable/accordion content. It doesn't need to at this moment.
This does not affect the FAQ page's hash stuff

Resolves #1353
---

## [20241118] - 2024-11-18

- ### Content List: Fixes the sidebar display's text
Expand Down
8 changes: 1 addition & 7 deletions boulder_base.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ucb-global:
js:
js/bootstrap/bootstrap.min.js: {}
js/ucb-rave-alert.js: {}
js/ucb-expandable-content.js: {}
dependencies:
- core/drupal

Expand Down Expand Up @@ -127,13 +128,6 @@ ucb-image-gallery:
css/block/image-gallery.css: {}
js/glightbox/glightbox.min.css: {}

ucb-expandable-content:
version: 1.x
js:
js/expandable-content.js: {}
css:
theme:

ucb-content-grid:
version: 1.x
css:
Expand Down
28 changes: 0 additions & 28 deletions js/expandable-content.js

This file was deleted.

37 changes: 37 additions & 0 deletions js/ucb-expandable-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
document.addEventListener("DOMContentLoaded", function () {
// Check if there is a hash in the URL and open the corresponding item
if (window.location.hash) {
openAccordionItem(window.location.hash.substring(1));
}

// Add event listeners for all accordion or tab elements
document.querySelectorAll('.accordion-button, .nav-link').forEach(function (link) {
link.addEventListener("click", function () {
const href = this.getAttribute("href");
if (href) {
const hash = href.substring(1);
setHashWithoutJump(hash);
}
});
});
});

// Function to set the URL hash without causing the page to jump
function setHashWithoutJump(hash) {
if (history.pushState) {
history.pushState(null, null, "#" + hash);
} else {
window.location.hash = hash;
}
}

// Function to open an accordion or tab item based on the hash
function openAccordionItem(hash) {
if (!hash) return;

// Try to find the link that matches the hash
const targetLink = document.querySelector(`.accordion-button[href="#${hash}"], .nav-link[href="#${hash}"]`);
if (targetLink) {
targetLink.click(); // Programmatically click to open the item
}
}
1 change: 0 additions & 1 deletion templates/block/block--expandable-content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

{% extends '@boulder_base/block/styled-block.html.twig' %}
{% block content %}
{{ attach_library('boulder_base/ucb-expandable-content') }}
{% if layoutSelection == 1 %}
<div class="horizontal-tab-accordion">
<ul class="nav nav-tabs justify-content-center" id="ucb-horizontal-tabs{{ id }}" role="tablist">
Expand Down

0 comments on commit 4f4d91a

Please sign in to comment.