var maxminButtonHeader = document.getElementsByClassName('anchor-modal__header-maxmin-button')[0];
var maxminButtonFooter = document.getElementsByClassName('anchor-modal__maxmin-button')[0];
var initialLoad = true;
function maxmin(cookieMinimized, clickEvent) {
var subPromo = document.getElementsByClassName('anchor-modal')[0];
var subPromoWrapper = document.getElementsByClassName('anchor-modal__wrapper')[0];
var minimized = subPromo.getAttribute('data-minimized');
var maxminMessage = document.getElementsByClassName('anchor-modal__maxmin-message')[0];
var maxminButtonHeaderImage = document.getElementsByClassName('anchor-modal__header-maxmin-image')[0];
var maxminButtonFooterImage = document.getElementsByClassName('anchor-modal__maxmin-image')[0];
function minimizeModal() {
subPromo.setAttribute('data-minimized', 'true');
subPromoWrapper.className = 'anchor-modal__wrapper anchor-modal__wrapper--minimized';
maxminButtonHeaderImage.className = 'anchor-modal__header-maxmin-image anchor-modal__header-maxmin-image--maximize';
maxminButtonFooterImage.className = 'anchor-modal__maxmin-image anchor-modal__maxmin-image--maximize';
maxminMessage.textContent = 'Expand';
subPromo.className = 'anchor-modal anchor-modal--masslive anchor-modal--minimized';
window.parent.postMessage('anchorModalMinimized', 'https://www.masslive.com');
}
function maximizeModal() {
subPromo.setAttribute('data-minimized', 'false');
subPromoWrapper.className = 'anchor-modal__wrapper';
maxminButtonHeaderImage.className = 'anchor-modal__header-maxmin-image';
maxminButtonFooterImage.className = 'anchor-modal__maxmin-image';
maxminMessage.textContent = 'Collapse';
subPromo.className = 'anchor-modal anchor-modal--masslive';
window.parent.postMessage('anchorModalMaximized', 'https://www.masslive.com');
}
// If there is an A/B test
if (initialLoad && 'min') {
'min' === 'min' && minimizeModal();
'min' === 'max' && maximizeModal();
initialLoad = false;
// If there is a cookie
} else if (!'min'.match(/max|min/) && typeof cookieMinimized === 'string' && cookieMinimized.match(/true|false/)) {
cookieMinimized === 'true' && minimizeModal();
cookieMinimized === 'false' && maximizeModal();
// Default state
} else if (clickEvent) {
minimized === 'false' && minimizeModal();
minimized === 'true' && maximizeModal();
}
}
// If we are running an A/B test
if ('min'.match(/max|min/)) {
maxmin();
}
// Click events for collapsing and expanding the modal
maxminButtonHeader.addEventListener('click', function() {
maxmin(false, true);
});
maxminButtonFooter.addEventListener('click', function() {
maxmin(false, true);
});
// Listening to see if cookie is set for initial state of the modal
window.addEventListener('message', function (e) {
// We verify that the message is coming from Piano, so it must be what we're looking for.
if (typeof e.data.piano !== 'undefined') {
// Get the object with the result.
var result = e.data.piano;
// We know how this object should be structured, so we're checking for the "success" field.
// We're expecting it to be false, so we can show an error message.
if (result.object.minimized) {
maxmin(result.object.minimized, false);
}
}
return;
}, false);