This repository has been archived on 2025-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
moodle-local_treestudyplan/amd/src/primary-nav-tools.js
2023-12-12 00:07:52 +01:00

33 lines
960 B
JavaScript

/*eslint-env es6*/
/**
* Hide a primary navigation item by href
* @param {string|Array} hrefs The link that should be hidden
*/
export function hide_primary(hrefs) {
let element = document.createElement('style');
document.head.appendChild(element);
let sheet = element.sheet;
if(typeof hrefs === 'string' || hrefs instanceof String){
hrefs = [hrefs];
}
if(typeof hrefs === 'object' && Array.isArray(hrefs)){
for(const ix in hrefs){
const href = hrefs[ix];
let style = `
.primary-navigation li.nav-item > a[href*="${href}"] {
display: none;
}
`;
sheet.insertRule(style, sheet.cssRules.length);
style = `
#usernavigation a[href*="${href}"] {
display: none;
}
`;
sheet.insertRule(style, sheet.cssRules.length);
}
}
}