Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-8004: Fix the tabs that were broken #536

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/tabs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,8 @@ function hdbt_preprocess_html(&$variables) {
$variables['#attached']['library'][] = 'hdbt/nav-local';
}

/** @var \Drupal\Core\File\FileUrlGeneratorInterface $service */
$service = \Drupal::service('file_url_generator');

// Add theme path to as variable.
$theme = \Drupal::service('theme_handler')->getTheme('hdbt');
$variables['theme_path'] = $service->generate($theme->getPath())
->toString(TRUE)->getGeneratedUrl();
// Set theme path variable.
$variables['theme_path'] = _hdbt_get_theme_path();
}

/**
Expand Down Expand Up @@ -253,6 +248,9 @@ function hdbt_preprocess_page(&$variables) {
if (isset($variables['page']['header_branding']['profileblock'])) {
$variables['use_profile_block'] = TRUE;
}

// Set theme path variable.
$variables['theme_path'] = _hdbt_get_theme_path();
}

/**
Expand Down Expand Up @@ -1568,3 +1566,16 @@ function hdbt_preprocess_paragraph__event_list(&$variables) {
$variables['#attached']['library'][] = 'hdbt/event-list';
$variables['#attached']['drupalSettings']['helfi_events']['baseUrl'] = LinkedEvents::BASE_URL;
}

/**
* Helper function to hdbt theme path.
*/
function _hdbt_get_theme_path(): string {
/** @var \Drupal\Core\File\FileUrlGeneratorInterface $service */
$service = \Drupal::service('file_url_generator');

// Add theme path to as variable.
$theme = \Drupal::service('theme_handler')->getTheme('hdbt');
return $service->generate($theme->getPath())
->toString(TRUE)->getGeneratedUrl();
}
3 changes: 1 addition & 2 deletions src/js/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
function hideEverything(tabbedContent) {
const allTabs = tabbedContent.querySelectorAll('.tab');
const allContent = tabbedContent.querySelectorAll('.tab__content');

// Update visibility
for (let i = 0; i < allTabs.length; i++) {
allTabs[i].setAttribute('aria-selected', 'false');
Expand Down Expand Up @@ -70,7 +69,7 @@

// Go through all tabs and add a listener for mouse click or keyboard enter.
for (let j = 0; j < allTabs.length; j++) {
const tab = allTabs[i];
const tab = allTabs[j];

tab.addEventListener('click', function onTabClick() {
// Toggle function.
Expand Down