The women reinventing business and beyondGet the ForbesWomen newsletter, and supercharge your mission with success stories, tips and more.
You’re signed up for ForbesWomen!Check your inbox for an email from the editor and a link to manage your email preferences. Browse our free newsletters
const emitShowEvent = () => {
setTimeout(() => {
var trackingShow = document.querySelector('#tracking-show');
trackingShow.click();
}, 500);
}
if(document.readyState === "complete"
|| document.readyState === "loaded"
|| document.readyState === "interactive"
) {
emitShowEvent();
} else {
document.addEventListener('DOMContentLoaded', emitShowEvent);
}
const emailInput = document.querySelector('.pn-modal__input');
const emailRegExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const errorMessage = document.querySelector('.pn-modal__error-message');
const submitButton = document.querySelector('.pn-modal__button')
let successScreen = document.getElementById('successScreen');
let initialScreen = document.getElementById('initialScreen');
/** @function showErrorMessage
* @param {boolean} isErrorMessageShowing
* @param {string} message
*/
const showErrorMessage = (isErrorMessageShowing, message) => {
emailInput.classList[isErrorMessageShowing ? 'add' : 'remove']('pn-modal__input--invalid');
submitButton.disabled = !!isErrorMessageShowing;
errorMessage.innerText = message;
}
/* SubmitButton EventListener user input when the email on successfull submission */
submitButton.addEventListener('click', () => {
if (emailRegExp.test(emailInput.value)) {
templateScope = angular.element('.pn-modal').scope();
window.parent.postMessage({ pianoUserEmail: emailInput.value }, '*');
successScreen.style.display = 'flex';
initialScreen.style.display = 'none';
}
});
/* EventListener that removes the error message and disables the submit
button when the input field is not on focus. */
emailInput.addEventListener('blur', () => {
if (emailInput.value === '') {
showErrorMessage(false, '');
submitButton.disabled = true;
}
});
/* EventListener to enable / disable error the message notification based on
users input */
emailInput.addEventListener('input', () => {
if (emailRegExp.test(emailInput.value)) {
showErrorMessage(false, '');
}
else if (emailInput.value === '') {
showErrorMessage(true, 'Please enter your email');
} else {
showErrorMessage(true, 'Please enter a valid email');
}
})