UNPKG

@mikezimm/fps-library-v2

Version:

Library of reusable typescript/javascript functions, interfaces and constants

202 lines (200 loc) 11.5 kB
/** * CodeAnalizerComment: Updated 7 imports on 2024-09-21 23:07:24 * Update:: import { IPageLayoutType } to '@mikezimm/fps-core-v7/lib/types/@msft/1.15.2/layout;' * Update:: import { IFPSPinMenu } to '@mikezimm/fps-core-v7/lib/banner/features/PinMe/Interfaces;' * Update:: import { IPinStatus } to '@mikezimm/fps-core-v7/lib/banner/features/PinMe/Interfaces;' * Update:: import { IPinMeState } to '@mikezimm/fps-core-v7/lib/banner/features/PinMe/Interfaces;' * Update:: import { DisplayMode } to '@mikezimm/fps-core-v7/lib/types/@msft/1.15.2/displayMode;' * Update:: import { check4This } to '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch;' * Update:: import { deleteSearchParamFromUrl } to '@mikezimm/fps-core-v7/lib/banner/FPSWebPartClass/functions/updateUrlParam;' */ import { findParentElementLikeThis } from '@mikezimm/fps-core-v7/lib/logic/DOM/Search/domSearch'; // import { updateByClassNameEleChild } from '../otherDOMAttempts'; import { DisplayMode } from '@mikezimm/fps-core-v7/lib/types/@msft/1.15.2/displayMode'; import { check4This, Check4 } from '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch'; import { deleteSearchParamFromUrl } from '@mikezimm/fps-core-v7/lib/banner/FPSWebPartClass/functions/updateUrlParam'; require('@mikezimm/fps-styles/dist/FPSPinMe.css'); /** * getDefaultFPSPinState gets the default defPinState depending on if the page is in Edit Mode. * Edit Mode requires the pinMode to change so that it does not hide the Edit/Save buttons. * Originally copied from FPSPageInfo.tsx * @param prevfpsPinMenu * @param currfpsPinMenu * @param displayMode - basically current component must have displayMode in it's props and passed in here. * @returns */ export function getDefaultFPSPinState(prevfpsPinMenu, currfpsPinMenu, displayMode) { let refresh = false; let defPinState = currfpsPinMenu.defPinState; const collapseFpsPinMe = new URL(window.location.href).searchParams.get('collapseFpsPinMe'); if (collapseFpsPinMe === 'true') { defPinState = 'pinMini'; deleteSearchParamFromUrl('collapseFpsPinMe', false); } if (defPinState !== prevfpsPinMenu.defPinState) { refresh = true; } else if (prevfpsPinMenu.forcePinState !== currfpsPinMenu.forcePinState) { refresh = true; } //This fixed https://github.com/mikezimm/PageInfo/issues/47 if (displayMode === DisplayMode.Edit) { defPinState = 'normal'; } const result = { defPinState: defPinState, refresh: refresh }; return result; } export function checkIsInVerticalSection(domElement) { //CanvasVerticalSection let isVertical = false; let verticalSection = findParentElementLikeThis(domElement, 'classList', 'CanvasVerticalSection', 10, 'contains', false, true); if (verticalSection) { isVertical = true; } return isVertical; } /** * * @param domElement * @param overRide * @param overClass like 'pinMeOverRideMxHt500' */ export function FPSMinMeOverRide(domElement, overRide, overClass) { if (check4This(Check4.skipStyleChanges_Eq_true) === true) { console.log(`${Check4.skipStyleChanges_Eq_true} @ FPSMinMeOverRide`); return; } let searchParams = window.location.search ? window.location.search : ''; let findClass = searchParams.indexOf('Mode=Edit') > -1 ? ['ControlZone-control', 'ControlZone--control'] : ['ControlZone--control', 'ControlZone-control']; // let thisControlZome: Element = null; let thisControlZome = null; let foundElement = false; //Need to be any to pass tslint findClass.map(checkClass => { if (foundElement === false) { thisControlZome = findParentElementLikeThis(domElement, 'classList', checkClass, 10, 'contains', false, true); if (thisControlZome) { foundElement = true; if (overRide === true) { thisControlZome.classList.add(overClass); } else { thisControlZome.classList.remove(overClass); } } } }); } export function FPSPinMe(domElement, pinState, controlStyle, alertError = true, consoleResult = false, pinMePadding, host, displayMode) { if (check4This(Check4.skipStyleChanges_Eq_true) === true) { console.log(`${Check4.skipStyleChanges_Eq_true} @ FPSPinMe`); return; } //https://github.com/mikezimm/drilldown7/issues/184 //Had to add || host === "SingleWebPartAppPageLayout" because that is what layout was consoled in Drilldown 1.3.1.1 if (host === "SharePointFullPage" || host === "SingleWebPartAppPageLayout") { //If this is a SPA, then there is no reason to do PinMe since there is nothing else to show. //Just return if (check4This(Check4.fpsInitRender_Eq_true) === true) console.log('FPSPinMe host == SPA: host=', host); return; } else { if (check4This(Check4.fpsInitRender_Eq_true) === true) console.log('FPSPinMe host !== NOT SPA: host=', host); //This might be option to bring this line of code in from FetchBannerElement.tsx //Just need to change the incoming paramter from pinState to tempPinState // let pinState: IPinMeState = displayMode === DisplayMode.Edit ? 'normal' : tempPinState; let searchParams = window.location.search ? window.location.search : ''; searchParams = searchParams.split('%3a').join(':'); //Had to add this just as a precaution.... //the classnames change depending on if the page is in EditMode. //When in EditMode, they have single -, in View mode, the have -- let findClass = searchParams.indexOf('Mode=Edit') > -1 ? ['ControlZone-control', 'ControlZone--control'] : ['ControlZone--control', 'ControlZone-control']; // let thisControlZome: Element = null; let thisControlZome = null; let thisCanvasSection = null; let foundElement = false; //Need to be any to pass tslint findClass.map(checkClass => { if (foundElement === false) { thisControlZome = findParentElementLikeThis(domElement, 'classList', checkClass, 10, 'contains', false, true); if (thisControlZome) { foundElement = true; thisCanvasSection = thisControlZome.parentElement; } } }); // console.log('FPSPinMe thisControlZome, thisCanvasSection = ', thisControlZome, thisCanvasSection ); if (thisControlZome && thisCanvasSection) { // Moved into if because was breaking on classic pages let classList = thisControlZome.classList; if (foundElement === true && pinState === 'disabled') { //Added this if to resolve https://github.com/mikezimm/pivottiles7/issues/190 - if pinCanvasDefault class is found, it shrinks the panel title width if (thisControlZome.classList.contains('pinMeWebPartDefault')) thisControlZome.classList.remove('pinMeWebPartDefault'); if (thisCanvasSection.classList.contains('pinCanvasDefault')) thisCanvasSection.classList.remove('pinCanvasDefault'); if (thisCanvasSection.classList.contains('pinMeCanvasMinimize')) thisCanvasSection.classList.remove('pinMeCanvasMinimize'); } else { if (foundElement === true) { // console.log( 'classList b4 = ', classList ); if (classList) { thisControlZome.classList.add('pinMeWebPartDefault'); } // console.log( 'classList af = ', thisControlZome.classList ); } if (displayMode !== DisplayMode.Edit && pinState === 'pinFull') { if (!thisControlZome.classList.contains('pinMeTop')) thisControlZome.classList.add('pinMeTop'); if (!thisControlZome.classList.contains('pinMeFull')) thisControlZome.classList.add('pinMeFull'); if (thisControlZome.classList.contains('pinMeMini')) thisControlZome.classList.remove('pinMeMini'); // thisControlZome.classList.remove( 'pinMeNormal' ) ; if (!thisCanvasSection.classList.contains('pinCanvasDefault')) thisCanvasSection.classList.add('pinCanvasDefault'); if (!thisCanvasSection.classList.contains('pinMeCanvasMinimize')) thisCanvasSection.classList.add('pinMeCanvasMinimize'); } else if ((displayMode === DisplayMode.Edit && pinState === 'pinFull') || pinState === 'pinMini') { if (!thisControlZome.classList.contains('pinMeTop')) thisControlZome.classList.add('pinMeTop'); if (!thisControlZome.classList.contains('pinMeMini')) thisControlZome.classList.add('pinMeMini'); if (thisControlZome.classList.contains('pinMeFull')) thisControlZome.classList.remove('pinMeFull'); if (thisControlZome.classList.contains('pinMeNormal')) thisControlZome.classList.remove('pinMeNormal'); if (displayMode === DisplayMode.Edit) { if (thisCanvasSection.classList.contains('pinCanvasDefault')) thisCanvasSection.classList.remove('pinCanvasDefault'); if (thisCanvasSection.classList.contains('pinMeCanvasMinimize')) thisCanvasSection.classList.remove('pinMeCanvasMinimize'); } else { //Is display mode and state === 'pinFull' or 'pinMini' if (!thisCanvasSection.classList.contains('pinCanvasDefault')) thisCanvasSection.classList.add('pinCanvasDefault'); if (!thisCanvasSection.classList.contains('pinMeCanvasMinimize')) thisCanvasSection.classList.add('pinMeCanvasMinimize'); } } else if (pinState === 'normal') { // thisControlZome.classList.add( 'pinMeNormal' ) ; if (thisControlZome.classList.contains('pinMeTop')) thisControlZome.classList.remove('pinMeTop'); if (thisControlZome.classList.contains('pinMeMini')) thisControlZome.classList.remove('pinMeMini'); if (thisControlZome.classList.contains('pinMeFull')) thisControlZome.classList.remove('pinMeFull'); if (thisCanvasSection.classList.contains('pinCanvasDefault')) thisCanvasSection.classList.remove('pinCanvasDefault'); if (thisCanvasSection.classList.contains('pinMeCanvasMinimize')) thisCanvasSection.classList.remove('pinMeCanvasMinimize'); } } // console.log( 'classList af = ', thisControlZome.classList ); } } } //# sourceMappingURL=FPSPinMenu.js.map