Skip to content

Commit

Permalink
Remove optional chaining operator ?. to improve browser support
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed May 27, 2023
1 parent 304fbef commit 605ae6f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ export const reset = (deleteCookie) => {
/**
* Remove main container from DOM
*/
_ccMain?.remove();
_ccMain && _ccMain.remove();

/**
* Remove any remaining classes
*/
_htmlDom?.classList.remove(
_htmlDom && _htmlDom.classList.remove(
TOGGLE_DISABLE_INTERACTION_CLASS,
TOGGLE_PREFERENCES_MODAL_CLASS,
TOGGLE_CONSENT_MODAL_CLASS
Expand Down
4 changes: 2 additions & 2 deletions src/core/modals/consentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export const createConsentModal = (api, createMainContainer) => {
const
boxLayout = 'box',
guiOptions = state._userConfig.guiOptions,
consentModalOptions = guiOptions?.consentModal,
consentModalLayout = consentModalOptions?.layout || boxLayout,
consentModalOptions = guiOptions && guiOptions.consentModal,
consentModalLayout = consentModalOptions && consentModalOptions.layout || boxLayout,
isBoxLayout = consentModalLayout.split(' ')[0] === boxLayout;

/**
Expand Down
10 changes: 5 additions & 5 deletions src/core/modals/preferencesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ export const createPreferencesModal = (api, createMainContainer) => {

let sectionToggleContainer;

sectionsData?.forEach((section, sectionIndex) => {
sectionsData && sectionsData.forEach((section, sectionIndex) => {

const
sTitleData = section.title,
sDescriptionData = section.description,
sLinkedCategory = section.linkedCategory,
sCurrentCategoryObject = sLinkedCategory && state._allDefinedCategories[sLinkedCategory],
sCookieTableData = section.cookieTable,
sCookieTableBody = sCookieTableData?.body,
sCookieTableCaption = sCookieTableData?.caption,
sCreateCookieTable = sCookieTableBody?.length > 0,
sCookieTableBody = sCookieTableData && sCookieTableData.body,
sCookieTableCaption = sCookieTableData && sCookieTableData.caption,
sCreateCookieTable = sCookieTableBody && sCookieTableBody.length > 0,
hasToggle = !!sCurrentCategoryObject,

/**
Expand Down Expand Up @@ -204,7 +204,7 @@ export const createPreferencesModal = (api, createMainContainer) => {
for(const serviceName of sServiceNames){

const service = sServices[serviceName];
const serviceLabel = service?.label || serviceName;
const serviceLabel = service && service.label || serviceName;
const serviceDiv = createNode(DIV_TAG);
const serviceHeader = createNode(DIV_TAG);
const serviceIconContainer = createNode(DIV_TAG);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const autoclearCookiesHelper = (clearOnFirstConsent) => {
const
category = state._allDefinedCategories[currentCategoryName],
autoClear = category.autoClear,
autoClearCookies = autoClear?.cookies || [],
autoClearCookies = autoClear && autoClear.cookies || [],

categoryWasJustChanged = elContains(state._lastChangedCategoryNames, currentCategoryName),
categoryIsDisabled = !elContains(state._acceptedCategories, currentCategoryName),
Expand Down
6 changes: 3 additions & 3 deletions src/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export const resolveEnabledServices = (relativeCategory) => {

const services = _allDefinedServices[categoryName];
const serviceNames = getKeys(services);
const customServicesSelection = _enabledServices[categoryName]?.length > 0;
const customServicesSelection = _enabledServices[categoryName] && _enabledServices[categoryName].length > 0;
const readOnlyCategory = elContains(_readOnlyCategories, categoryName);

/**
Expand Down Expand Up @@ -559,7 +559,7 @@ export const fetchJson = async (url) => {

const response = await fetch(url);

return response?.ok
return response && response.ok
? await response.json()
: false;

Expand Down Expand Up @@ -727,7 +727,7 @@ export const addDataButtonListeners = (elem, api, createPreferencesModal, create
* @param {1 | 2} [modalId]
*/
export const focus = (el, modalId) => {
el?.focus();
el && el.focus();

if(modalId) {
globalObj._state._currentFocusedModal = modalId === 1
Expand Down
16 changes: 8 additions & 8 deletions src/utils/gui-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const ALL_PM_LAYOUTS = {
export const guiManager = (applyToModal) => {

const guiOptions = globalObj._state._userConfig.guiOptions;
const consentModalOptions = guiOptions?.consentModal;
const preferencesModalOptions = guiOptions?.preferencesModal;
const consentModalOptions = guiOptions && guiOptions.consentModal;
const preferencesModalOptions = guiOptions && guiOptions.preferencesModal;

if(applyToModal === 0){
setLayout(
Expand Down Expand Up @@ -130,12 +130,12 @@ const setLayout = (modal, allowedLayoutsObj, userGuiOptions, modalClassPrefix, d
*/
modal.className = modalClassName;

const layout = userGuiOptions?.layout;
const position = userGuiOptions?.position;
const flipButtons = userGuiOptions?.flipButtons;
const equalWeightButtons = userGuiOptions?.equalWeightButtons !== false;
const layout = userGuiOptions && userGuiOptions.layout;
const position = userGuiOptions && userGuiOptions.position;
const flipButtons = userGuiOptions && userGuiOptions.flipButtons;
const equalWeightButtons = userGuiOptions && userGuiOptions.equalWeightButtons !== false;

const layoutSplit = layout?.split(' ') || [];
const layoutSplit = layout && layout.split(' ') || [];

const layoutName = layoutSplit[0];
const layoutVariant = layoutSplit[1];
Expand All @@ -147,7 +147,7 @@ const setLayout = (modal, allowedLayoutsObj, userGuiOptions, modalClassPrefix, d
const currentLayout = allowedLayoutsObj[currentLayoutName];
const currentLayoutVariant = elContains(currentLayout._variants, layoutVariant) && layoutVariant;

const positionSplit = position?.split(' ') || [];
const positionSplit = position && position.split(' ') || [];
const positionV = positionSplit[0];

const positionH = modalClassPrefix === CLASS_CONSTANTS._pmPrefix
Expand Down

0 comments on commit 605ae6f

Please sign in to comment.