@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
81 lines (80 loc) • 3.56 kB
JavaScript
/**
* CodeAnalizerComment: Updated 3 imports on 2024-09-22 14:49:52
* Update:: import { IFPSMinimal } to '@mikezimm/fps-core-v7/lib/banner/features/FPSDOM/IFPSWindowProps;'
* Update:: import { IFPSWindowProps } to '@mikezimm/fps-core-v7/lib/banner/features/FPSDOM/IFPSWindowProps;'
* Update:: import { createFPSWindowProps } to '@mikezimm/fps-core-v7/lib/banner/features/FPSDOM/FPSDocument;'
*/
import { createFPSWindowProps, } from '@mikezimm/fps-core-v7/lib/banner/features/FPSDOM/FPSDocument';
import { check4This, Check4 } from '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch';
/**
* This minimizes the header on site pages where you do not want the Page Title at the top. originally copied from Pivot Tiles
* NOTE that hiding the social-bar ONLY WORKS IF THE Bar is loaded during intial page load.
* IF IT IS LAZY Loaded, it will not be hidden. This is mentioned in prop pane as well.
*
* @param document
* @param minimize
* @param dataAutoId
* @param alertError
* @param consoleResult
*/
export function hideSPODataAutoId(minimize, dataAutoId, alertError = true, consoleResult = false) {
let fpsWindowProps = createFPSWindowProps();
const fpsWindowSubProp = fpsWindowProps[dataAutoId.replace('-', '').replace(' ', '')];
//If this was already attempted, then exit
if (fpsWindowSubProp.attempted === true) {
return;
}
else if (minimize !== true) {
return;
}
else {
fpsWindowSubProp.attempted = true;
}
let height = minimize === true ? '0px' : null;
let display = minimize === true ? 'none' : null;
/**
* Was getting this ts error creating divs:
* Type 'NodeListOf<Element>' is missing the following properties from type 'any[]': pop, push, concat, join, and 26 more.ts(2740)
*
* Found this reference: https://stackoverflow.com/a/222847
* which references this: https://262.ecma-international.org/8.0/#sec-array.from
*
* Which now removes the error
*/
const divs = Array.from(document.querySelectorAll(`[data-automation-id="${dataAutoId}"]`));
if (check4This(Check4.fpsInitRender_Eq_true) === true)
console.log("divs.length: ", divs.length);
//inspiration from: https://reactgo.com/select-element-data-attribute-js/
divs.forEach((el) => {
try {
if (el.style) {
if (dataAutoId === 'pageHeader') {
el.style.height = height;
}
else if (dataAutoId === 'sp-socialbar') {
el.style.display = display;
}
}
else {
if (dataAutoId === 'pageHeader') {
el.style = { height: height };
}
else if (dataAutoId === 'sp-socialbar') {
el.style = { display: display };
}
}
if (consoleResult === true) {
console.log(`minimize ${dataAutoId}: set minimize to `, minimize);
}
fpsWindowSubProp.success++;
}
catch (e) {
if (alertError === true) {
alert(`minimize ${dataAutoId}: Could not find element with data-automation-id="${dataAutoId}"`);
}
console.log(`minimize ${dataAutoId}: Could not find element with data-automation-id="${dataAutoId}"`);
fpsWindowSubProp.errors++;
}
});
}
//# sourceMappingURL=hideSPODataAutoId.js.map