var scriptPath = "https://static.advance.net/static/common/js/piano-frame.js";
var script = document.createElement("script");
script.onload = function(e) {
function runPiano() {
var config = {
type: 'anchor',
};
window.Advance.piano.build(config);
}
window.Advance.piano.start(runPiano);
}
script.type = "text/javascript"; script.async = true; script.src = scriptPath; document.head.appendChild(script);
var subPromo = document.getElementsByClassName('anchor-modal')[0];
var header = document.getElementsByClassName('anchor-modal__header')[0];
var wrapper = document.getElementsByClassName('anchor-modal__wrapper')[0];
var maxminButtonHeader = document.querySelector('.anchor-modal__header .anchor-modal__maxmin-button');
var maxminButtonFooter = document.querySelector('.anchor-modal__wrapper .anchor-modal__maxmin-button');
var maxminMessageHeader = document.querySelector('.anchor-modal__header .anchor-modal__maxmin-button span');
var maxminMessageFooter = document.querySelector('.anchor-modal__wrapper .anchor-modal__maxmin-button span');
var maxminButtonHeaderImage = document.querySelector('.anchor-modal__header .anchor-modal__maxmin-image');
var maxminButtonFooterImage = document.querySelector('.anchor-modal__wrapper .anchor-modal__maxmin-image');
var initialLoad = true;
function maxmin(cookieMinimized, clickEvent) {
var minimized = subPromo.getAttribute('data-minimized');
function minimizeModal() {
subPromo.setAttribute('data-minimized', 'true');
maxminMessageFooter.textContent = 'Expand';
maxminMessageHeader.textContent = 'Expand';
header.className = 'anchor-modal__header';
wrapper.className = 'anchor-modal__wrapper anchor-modal__wrapper--hidden';
subPromo.className = 'anchor-modal anchor-modal--oregonlive';
window.parent.postMessage('anchorModalMinimized', 'https://www.oregonlive.com');
setTimeout(function() {
maxminButtonHeaderImage.className = 'anchor-modal__maxmin-image anchor-modal__maxmin-image--maximize';
maxminButtonFooterImage.className = 'anchor-modal__maxmin-image anchor-modal__maxmin-image--maximize';
}, 1);
}
function maximizeModal() {
subPromo.setAttribute('data-minimized', 'false');
maxminMessageFooter.textContent = 'Collapse';
maxminMessageHeader.textContent = 'Collapse';
header.className = 'anchor-modal__header anchor-modal__header--hidden';
wrapper.className = 'anchor-modal__wrapper';
subPromo.className = 'anchor-modal anchor-modal--oregonlive';
window.parent.postMessage('anchorModalMaximized', 'https://www.oregonlive.com');
setTimeout(function() {
maxminButtonHeaderImage.className = 'anchor-modal__maxmin-image';
maxminButtonFooterImage.className = 'anchor-modal__maxmin-image';
}, 1);
}
// To mitigate the Safari jarring, set the initial height to 0 then to auto
document.getElementById('template-container').style.height = "auto";
// 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);