docbrown/app/javascript/packs/profileDropdown.js
Suzanne Aitchison f607cf8722
Optimise dropdowns for accessibility - Profile page (#13916)
* use initializedropdown in profileDropdown

* improve aria in html

* add cypress tests, stop buttons and dropdown initializing twice or more

* make sure dropdown shows when logged out
2021-06-14 12:31:23 +01:00

46 lines
1.3 KiB
JavaScript

import { initBlock } from '../profileDropdown/blockButton';
import { initFlag } from '../profileDropdown/flagButton';
import { initializeDropdown } from '@utilities/dropdownUtils';
/* global userData */
function initButtons() {
initBlock();
initFlag();
}
function initDropdown() {
const profileDropdownDiv = document.querySelector('.profile-dropdown');
if (profileDropdownDiv.dataset.dropdownInitialized === 'true') {
return;
}
const currentUser = userData();
if (
!profileDropdownDiv ||
(currentUser &&
currentUser.username === profileDropdownDiv.dataset.username)
) {
// Hide this menu when user views their own profile
return;
}
profileDropdownDiv.classList.remove('hidden');
initializeDropdown({
triggerElementId: 'user-profile-dropdown',
dropdownContentId: 'user-profile-dropdownmenu',
});
// Add actual link location (SEO doesn't like these "useless" links, so adding in here instead of in HTML)
const reportAbuseLink = profileDropdownDiv.querySelector(
'.report-abuse-link-wrapper',
);
reportAbuseLink.innerHTML = `<a href="${reportAbuseLink.dataset.path}" class="crayons-link crayons-link--block">Report Abuse</a>`;
initButtons();
profileDropdownDiv.dataset.dropdownInitialized = true;
}
initDropdown();