Browse Source

banner

master
rdrew 3 months ago
parent
commit
109bdee3cd
  1. 42
      js/pwc_custom.js
  2. 38
      olivespwc.theme

42
js/pwc_custom.js

@ -8,3 +8,45 @@ document.querySelectorAll('.more-link').forEach(link => {
link.setAttribute('aria-expanded', container.classList.contains('full'));
});
});
const p = document.querySelector('.node-6729 .view-abstract-block-for-collections-info-block p');
if (p) {
const fullText = p.textContent.trim();
const words = fullText.split(/\s+/);
if (words.length > 100) {
// Truncate to 100 words
const truncated = words.slice(0, 100).join(' ') + '...';
p.textContent = truncated;
p.dataset.fullText = fullText; // Store full text
p.dataset.isTruncated = 'true'; // Track truncation state
// Create and append the "More" link in a <p> tag
const linkP = document.createElement('p');
const link = document.createElement('a');
link.href = '#';
link.className = 'more-link';
link.textContent = 'More';
link.setAttribute('aria-expanded', 'false');
link.setAttribute('aria-controls', 'truncated-p-6729'); // Unique ID for ARIA
p.id = 'truncated-p-6729'; // Assign ID to <p> for ARIA
linkP.appendChild(link);
p.parentNode.insertBefore(linkP, p.nextSibling);
// Add click event to toggle text
link.addEventListener('click', (e) => {
e.preventDefault();
const isTruncated = p.dataset.isTruncated === 'true';
if (isTruncated) {
p.textContent = p.dataset.fullText;
link.textContent = 'Less';
p.dataset.isTruncated = 'false';
link.setAttribute('aria-expanded', 'true');
} else {
p.textContent = words.slice(0, 100).join(' ') + '...';
link.textContent = 'More';
p.dataset.isTruncated = 'true';
link.setAttribute('aria-expanded', 'false');
}
});
}
}

38
olivespwc.theme

@ -44,6 +44,14 @@ function olivespwc_preprocess_html(&$variables) {
'href' => $variables['olivespwc_path'] . '/css/components/navigation/nav-primary-no-js.css?' . $query_string,
],
];
// Check if the current page is a node.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
// Ensure we have a node object or ID.
$nid = is_object($node) ? $node->id() : $node;
// Add the node ID as a body class.
$variables['attributes']['class'][] = 'node-' . $nid;
}
}
@ -698,33 +706,3 @@ function _olivespwc_hex_to_hsl(string $hex_string) {
return [$h, $s, $l];
}
/*
function olivespwc_preprocess_mirador(&$variables) {
$block = \Drupal::service('plugin.manager.block')->createInstance($viewer . 'mirador_block', [
'iiif_manifest_url' => "/node/$manifest_nid/manifest-single",
'thumbnail_navigation_position' => 'hidden',
'window_config' => [
'allowClose' => FALSE,
'allowMaximize' => FALSE,
'allowTopMenuButton' => FALSE,
'allowWindowSideBar' => FALSE,
'hideWindowTitle' => TRUE,
'panels' => [
'info' => FALSE,
'attribution' => FALSE,
' canvas' => FALSE,
'annotations' => FALSE,
'search' => FALSE,
],
],
'workspace_config' => [
'allowNewWindows' => FALSE,
'isWorkspaceAddVisible' => FALSE,
'workspaceControlPanel' => [
'enable' => FALSE,
],
],
]);
}
*/

Loading…
Cancel
Save