cookies.phtml

Created Diff never expires
1 removal
Lines
Total75
Removed-1.3%1
Words
Total209
Removed-0.5%1
75 lines
1 addition
Lines
Total75
Added+1.3%1
Words
Total209
Added+0.5%1
75 lines
<?php
<?php
/**
/**
* Hyvä Themes - https://hyva.io
* Hyvä Themes - https://hyva.io
* Copyright © Hyvä Themes 2020-present. All rights reserved.
* Copyright © Hyvä Themes 2020-present. All rights reserved.
* This product is licensed per Magento install
* This product is licensed per Magento install
* See https://hyva.io/license
* See https://hyva.io/license
*/
*/


declare(strict_types=1);
declare(strict_types=1);


/** @var \Magento\Framework\View\Element\Template $block */
/** @var \Magento\Framework\View\Element\Template $block */
?>
?>
<script>
<script>
'use strict';
'use strict';
function dispatchMessages(messages, hideAfter) {
function dispatchMessages(messages, hideAfter) {
const messagesEvent = new CustomEvent("messages-loaded", {
const messagesEvent = new CustomEvent("messages-loaded", {
detail: {
detail: {
messages: messages,
messages: messages,
hideAfter: hideAfter
hideAfter: hideAfter
}
}
});
});
window.dispatchEvent(messagesEvent);
window.dispatchEvent(messagesEvent);
}
}


<?php
<?php
/**
/**
* The `hyva` JS namespace is being set by Hyva_Theme/src/view/frontend/templates/page/js/hyva.phtml
* The `hyva` JS namespace is being set by Hyva_Theme/src/view/frontend/templates/page/js/hyva.phtml
* and should be included through Hyva_Theme/src/view/frontend/layout/default_hyva.xml
* and should be included through Hyva_Theme/src/view/frontend/layout/default_hyva.xml
*/
*/
?>
?>
if (typeof hyva === 'undefined' || (!hyva.getBrowserStorage || !hyva.getCookie || !hyva.setCookie)) {
if (typeof hyva === 'undefined' || (!hyva.getBrowserStorage || !hyva.getCookie || !hyva.setCookie)) {
console.warn("Hyvä helpers are not loaded yet. Make sure they are included before this script");
console.warn("Hyvä helpers are not loaded yet. Make sure they are included before this script");
}
}


(function( hyva, undefined ) {
(function( hyva, undefined ) {


hyva.initFormKey = () => {
hyva.initFormKey = () => {
const inputSelector = 'input[name="form_key"]',
const inputSelector = 'input[name="form_key"]',
formKey = hyva.getFormKey();
formKey = hyva.getFormKey();


Array.from(document.querySelectorAll(inputSelector)).map(function (input) {
Array.from(document.querySelectorAll(inputSelector)).map(function (input) {
input.value = formKey
input.value = formKey
});
});
}
}


hyva.initMessages = () => {
hyva.initMessages = () => {
try {
try {
const messages = hyva.getCookie('mage-messages');
const messages = hyva.getCookie('mage-messages');
window.mageMessages = messages ? JSON.parse(decodeURIComponent(messages).replace(/\+/g, ' ')) : [];
window.mageMessages = messages ? JSON.parse(decodeURIComponent(messages).replace(/\+/g, ' ')) : [];


dispatchMessages(window.mageMessages);
dispatchMessages(window.mageMessages);


<?php
<?php
/**
/**
* In \Magento\Theme\Controller\Result\MessagePlugin::setCookie
* In \Magento\Theme\Controller\Result\MessagePlugin::setCookie
* the cookie-domain is not set. Therefore, we need to skip it
* the cookie-domain is not set. Therefore, we need to skip it
* here as well.
* here as well.
*/
*/
?>
?>
// empty `mage-messages` cookie
// empty `mage-messages` cookie
const skipSetDomain = true;
const skipSetDomain = true;
hyva.setCookie('mage-messages','', -1, skipSetDomain);
hyva.setCookie('mage-messages','', -1, skipSetDomain);


} catch (error) {
} catch (error) {
console.warn('Error parsing Cookie Messages:', error);
console.warn('Error parsing Cookie Messages:', error);
}
}
}
}


window.addEventListener('DOMContentLoaded', hyva.initFormKey);
window.addEventListener('DOMContentLoaded', hyva.initFormKey);
window.addEventListener('load', hyva.initMessages);
window.addEventListener('alpine:initialized', hyva.initMessages);




}( window.hyva = window.hyva || {} ));
}( window.hyva = window.hyva || {} ));
</script>
</script>