* @param {'consentModal' | 'preferencesModal'} modalName * @param {string} key * @param {any} value
(modalName, key, value)
| 92 | * @param {any} value |
| 93 | */ |
| 94 | function updateGuiOptionsState(modalName, key, value) { |
| 95 | const state = getState(); |
| 96 | |
| 97 | if (modalName === CONSENT_MODAL_NAME) { |
| 98 | if (key === 'layout') { |
| 99 | const layout = currentCMLayoutValue; |
| 100 | const isBarLayout = layout.startsWith('bar'); |
| 101 | |
| 102 | const consentModal = state._cookieConsentConfig.guiOptions.consentModal; |
| 103 | const currentPosition = consentModal.position; |
| 104 | |
| 105 | if (validBarPositions(currentPosition)) { |
| 106 | state._lastBarPosition = currentPosition; |
| 107 | } else { |
| 108 | state._lastNonBarPosition = currentPosition; |
| 109 | } |
| 110 | |
| 111 | if (!isBarLayout && validBarPositions(currentPosition) || isBarLayout && !validBarPositions(currentPosition)) { |
| 112 | generateCMPositionOptions(!isBarLayout); |
| 113 | |
| 114 | if (isBarLayout) { |
| 115 | if (!validBarPositions(currentPosition)) |
| 116 | consentModal.position = htmlElements[CONSENT_MODAL_NAME].position.value = state._lastBarPosition || 'bottom'; |
| 117 | } else { |
| 118 | consentModal.position = htmlElements[CONSENT_MODAL_NAME].position.value = state._lastNonBarPosition || defaultConfig.guiOptions.consentModal.position; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if (key === 'position') { |
| 124 | const currentPosition = state._cookieConsentConfig.guiOptions.consentModal.position; |
| 125 | |
| 126 | if (validBarPositions(currentPosition)) { |
| 127 | state._lastBarPosition = currentPosition; |
| 128 | } else { |
| 129 | state._lastNonBarPosition = currentPosition; |
| 130 | } |
| 131 | } |
| 132 | }else { |
| 133 | if (key === 'layout') { |
| 134 | if (currentPMLayoutValue === 'box') |
| 135 | disablePMPositionOptions(true); |
| 136 | else if (pmPositionOptionsDisabled) |
| 137 | disablePMPositionOptions(false); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | state._cookieConsentConfig.guiOptions[modalName][key] = value; |
| 142 | saveState(state); |
| 143 | reRunPlugin(state, modalName === 'consentModal' ? 1 : 2); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @param {'consentModal' | 'preferencesModal'} modalName |
no test coverage detected
searching dependent graphs…