40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
/*eslint no-var: "error" */
|
|
/*eslint no-unused-vars: "off" */
|
|
/*eslint linebreak-style: "off" */
|
|
/*eslint no-trailing-spaces: "off" */
|
|
/*eslint-env es6*/
|
|
// Put this file in path/to/plugin/amd/src
|
|
// You can call it anything you like
|
|
import Debugger from './debugger';
|
|
let debug = new Debugger("primary-nav-tools");
|
|
debug.enable();
|
|
|
|
/**
|
|
* 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];
|
|
debug.info("Hiding",href);
|
|
let style = `
|
|
.primary-navigation li.nav-item > a[href*="${href}"] {
|
|
display: none;
|
|
}
|
|
`;
|
|
debug.info("Adding style",style);
|
|
|
|
sheet.insertRule(style, sheet.cssRules.length);
|
|
}
|
|
}
|
|
debug.info("stylesheet",sheet);
|
|
}
|