Skip to content

Commit

Permalink
Code refactoring/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed Apr 20, 2023
1 parent 4c6cd11 commit b10a04f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
19 changes: 9 additions & 10 deletions src/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ export const hide = () => {
if(_state._disablePageInteraction)
toggleDisableInteraction();

removeClass(_dom._htmlDom, TOGGLE_CONSENT_MODAL_CLASS);
setAttribute(_dom._cm, ARIA_HIDDEN, 'true');

/**
* Fix focus restoration
*/
focus(_dom._focusSpan);

removeClass(_dom._htmlDom, TOGGLE_CONSENT_MODAL_CLASS);
setAttribute(_dom._cm, ARIA_HIDDEN, 'true');

/**
* Restore focus to last focused element
*/
Expand Down Expand Up @@ -289,22 +289,21 @@ export const hidePreferences = () => {

state._preferencesModalVisible = false;

/**
* Fix focus restoration
*/
focus(globalObj._dom._pmFocusSpan);

removeClass(globalObj._dom._htmlDom, TOGGLE_PREFERENCES_MODAL_CLASS);
setAttribute(globalObj._dom._pm, ARIA_HIDDEN, 'true');

/**
* If consent modal is visible, focus him (instead of page document)
*/
if(state._consentModalVisible){
focus(state._lastFocusedModalElement);
focus(state._lastFocusedModalElement, 1);
state._lastFocusedModalElement = null;
}else{

/**
* Fix focus restoration
*/
focus(globalObj._dom._pmFocusSpan);

/**
* Restore focus to last page element which had focus before modal opening
*/
Expand Down
7 changes: 1 addition & 6 deletions src/core/modals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ import { createPreferencesModal } from './preferencesModal';
import { DIV_TAG } from '../../utils/constants';
import { handleRtlLanguage } from '../../utils/language';

/**
* @param {import('../global').Api} api
*/
export const createMainContainer = (api) => {
export const createMainContainer = () => {
const dom = globalObj._dom;

if(!dom._ccMain){
dom._ccMain = createNode(DIV_TAG);
dom._ccMain.id = 'cc-main';

dom._ccMain.style.position = 'fixed';

handleRtlLanguage();

let root = globalObj._state._userConfig.root;
Expand Down
4 changes: 3 additions & 1 deletion src/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,9 @@ export const focus = (el, modalId) => {
el?.focus();

if(modalId) {
globalObj._state._currentFocusedModal = el;
globalObj._state._currentFocusedModal = modalId === 1
? globalObj._dom._cmContainer
: globalObj._dom._pmContainer;

globalObj._state._currentFocusEdges = modalId === 1
? globalObj._state._cmFocusableElements
Expand Down

0 comments on commit b10a04f

Please sign in to comment.