// v2
var INTERVAL_DELAY = 100;
var MAX_INTERVAL_ITERATIONS = 150; // 15s at 100ms intervals
var FORM_ID = 'myDynamicForm';
var rfLocale = window.rfLocale || { lang: 'en', region: 'US' };
// Only set the initial NC value once.
var initialNCValueSet = false;
// Flag to add event listener for Certfication id
var initialCertIdListener = false;
//updated and verified based on IBM Optin Country list, Nov 2021
var countryOptInMap = {
AE: { email: 'opt-out', },
AF: { email: 'opt-out', },
AS: { email: 'opt-out', },
BD: { email: 'opt-out', },
BH: { email: 'opt-out', },
BN: { email: 'opt-out', },
BO: { email: 'opt-out', },
BT: { email: 'opt-out', },
BZ: { email: 'opt-out', },
CC: { email: 'opt-out', },
CI: { email: 'opt-out', },
CK: { email: 'opt-out', },
CL: { email: 'opt-out', },
CR: { email: 'opt-out', },
CX: { email: 'opt-out', },
DO: { email: 'opt-out', },
EC: { email: 'opt-out', },
EG: { email: 'opt-out', },
ET: { email: 'opt-out', },
FJ: { email: 'opt-out', },
FM: { email: 'opt-out', },
GF: { email: 'opt-out', },
GP: { email: 'opt-out', },
GT: { email: 'opt-out', },
GU: { email: 'opt-out', },
HK: { email: 'opt-out', },
HM: { email: 'opt-out', },
HN: { email: 'opt-out', },
HT: { email: 'opt-out', },
IN: { email: 'opt-out', },
IQ: { email: 'opt-out', },
JM: { email: 'opt-out', },
JO: { email: 'opt-out', },
KH: { email: 'opt-out', },
KI: { email: 'opt-out', },
KW: { email: 'opt-out', },
LA: { email: 'opt-out', },
LB: { email: 'opt-out', },
LC: { email: 'opt-out', },
LK: { email: 'opt-out', },
MC: { email: 'opt-out', },
MH: { email: 'opt-out', },
MM: { email: 'opt-out', },
MN: { email: 'opt-out', },
MO: { email: 'opt-out', },
MP: { email: 'opt-out', },
MQ: { email: 'opt-out', },
MU: { email: 'opt-out', },
MV: { email: 'opt-out', },
MX: { email: 'opt-out', },
NF: { email: 'opt-out', },
NI: { email: 'opt-out', },
NP: { email: 'opt-out', },
NR: { email: 'opt-out', },
NU: { email: 'opt-out', },
OM: { email: 'opt-out', },
PA: { email: 'opt-out', },
PG: { email: 'opt-out', },
PM: { email: 'opt-out', },
PR: { email: 'opt-out', },
PS: { email: 'opt-out', },
PW: { email: 'opt-out', },
PY: { email: 'opt-out', },
RE: { email: 'opt-out', },
SB: { email: 'opt-out', },
SV: { email: 'opt-out', },
TF: { email: 'opt-out', },
TK: { email: 'opt-out', },
TL: { email: 'opt-out', },
TO: { email: 'opt-out', },
TV: { email: 'opt-out', },
TW: { email: 'opt-out', },
TZ: { email: 'opt-out', },
US: { email: 'opt-out', },
UY: { email: 'opt-out', },
VE: { email: 'opt-out', },
VI: { email: 'opt-out', },
WS: { email: 'opt-out', },
YE: { email: 'opt-out', },
};
//new as of 11-Jan-23 JKW
//change amp; to && in both places --JKW
function setCheckbox(box, value) {
if (!(!box.checked || value) || !(box.checked || !value)) // if ((box.checked && !value) || (!box.checked && value))
box.click();
}
//242 needs to be 16567043433000010fZB not 1603837935923002p7c8
function simulateClick(elementId) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var element = document.getElementById(elementId);
var canceled = !element.dispatchEvent(evt);
if(canceled) {
// A handler called preventDefault
alert("unchecked");
} else {
// None of the handlers called preventDefault
alert("checked");
}
}
function applyNoticeChoice(e) {
var selectedCountry = e.target.value;
var notifyMeBox = document.getElementById('opt-1603837935923001pcr7');
var doNotNotifyMeBox = document.getElementById('opt-16567043433000010fZB');
var countryDefaults = countryOptInMap[selectedCountry] || {
email: '',
};
//opt-in means do not contact me is chosen by default. opt-out means you can contact me is chosen by default
setTimeout(function () {
if(countryDefaults.email)
setCheckbox(notifyMeBox, true);
else {
console.log('Testing', new Date());
// notifyMeBox.checked = false;
// doNotNotifyMeBox.checked = false;
// setCheckbox(notifyMeBox, false);
// setCheckbox(doNotNotifyMeBox, false);
// if (notifyMeBox.checked) simulateClick(notifyMeBox);
// if (doNotNotifyMeBox.checked) simulateClick(doNotNotifyMeBox);
if (notifyMeBox.checked) {
//-------setNativeValue
let lastValue = notifyMeBox.checked;
notifyMeBox.checked = false;
notifyMeBox.value = false;
let event = new Event("change", { target: notifyMeBox, bubbles: true });
// let tracker = notifyMeBox._valueTracker;
// if (tracker) {
// tracker.setValue(lastValue);
// }
notifyMeBox.dispatchEvent(event);
//-------
}
if (doNotNotifyMeBox.checked) {
//-------setNativeValue
let lastValue2 = doNotNotifyMeBox.checked;
doNotNotifyMeBox.checked = false;
doNotNotifyMeBox.value = false;
let event2 = new Event("change", { target: doNotNotifyMeBox, bubbles: true });
// let tracker2 = doNotNotifyMeBox._valueTracker;
// if (tracker2) {
// tracker.setValue(lastValue2);
// }
doNotNotifyMeBox.dispatchEvent(event2);
//-------
}
}});
}
function removeCertificationNumberMessage(event) {
const messageContainer = document.getElementById('wf-1603923186460001otqg');
const messageDiv = messageContainer.children[0];
const messageSpan = document.querySelector('.form-element-feedback');
if (messageSpan) messageDiv.removeChild(messageSpan);
}
function validateCertificationNumber(event) {
const messageContainer = document.getElementById('wf-1603923186460001otqg');
const messageDiv = messageContainer.children[0];
var messageSpan = null;
if (event.target.value) {
messageSpan = document.createElement('span');
messageDiv.appendChild(messageSpan);
messageSpan.classList.add('form-element-feedback');
messageSpan.classList.add('success-feedback');
messageSpan.textContent = 'Validating...';
var submitButton = document.getElementById('wf-btn-submit');
var submitButtonParent = submitButton.parentNode;
var tempButton = document.createElement('button');
tempButton.className = 'mdBtnR mdBtnR-primary';
var textTempButton = document.createElement('span');
textTempButton.innerText = 'Continue';
textTempButton.className = 'mdBtnR-text';
tempButton.append(textTempButton);
submitButtonParent.append(tempButton);
tempButton.addEventListener('click', function(e){
e.preventDefault();
e.stopPropagation();
});
submitButton.style.display = 'none';
try {
fetch(`https://reg.experiences.redhat.com/flow/redhatRedirect?certificationId=${event.target.value}`).then(function (response) {
return response.json();
}).then(function (data) {
if (data.data.responseCode === '0') {
messageSpan.textContent = 'Username has been accepted';
}
else {
messageDiv.classList.add('rf-error');
messageSpan.classList.remove('success-feedback');
messageSpan.classList.add('error-feedback');
messageSpan.textContent = 'Username is not valid';
var certificationNumberInput = document.getElementById("1603923186460001otqg");
//-------setNativeValue
let lastValue = certificationNumberInput.value;
certificationNumberInput.value = '';
let event = new Event("input", { target: certificationNumberInput, bubbles: true });
// React 15
// event.simulated = true;
// React 16
let tracker = certificationNumberInput._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
certificationNumberInput.dispatchEvent(event);
//-------
}
submitButton.style.display = 'block';
tempButton.remove();
});
} catch(err) {
console.log(err);
}
}
}
//change => to >
/**
* options: {
* enableLogs: Boolean,
* intervalFrequency: Number,
* logIdentifier: String,
* maxIterations: Number,
* onSuccess: () => void,
* successCheck: () => Boolean,
* }
*/
function waitForX(options) {
var log = function log() {
if (options.enableLogs)
console.log.apply(console, arguments);
};
var logSuffix = options.logIdentifier ? ' -- [' + options.logIdentifier + ']' : '';
var intervalFrequency = options.intervalFrequency || 100;
var maxIterations = options.maxIterations || 100;
// Do 1 immediate check before the interval starts.
if (options.successCheck()) {
log('SUCCESS (immediate), no interval needed' + logSuffix);
options.onSuccess();
return;
}
log('every ' + intervalFrequency + 'ms, for ' + intervalFrequency * maxIterations + 'ms' + logSuffix);
var iterations = 0;
var waitTimer = window.setInterval(function () {
if (options.successCheck.apply(options)) {
log('SUCCESS, waited: ' + ((iterations + 1) * intervalFrequency) + 'ms (' + (iterations + 1) + ' iterations)' + logSuffix);
options.onSuccess.apply(options);
window.clearInterval(waitTimer);
log('cleared interval' + logSuffix);
}
if (Math.max(iterations, maxIterations) === iterations) { // if (iterations >= maxIterations) {
log('TIMED OUT' + logSuffix);
// Safety net to ensure this interval won't run forever.
window.clearInterval(waitTimer);
log('cleared interval' + logSuffix);
}
iterations++;
}, options.intervalFrequency);
}
//Script Created/modified by Robbie D 2-FEB-22
//Opt-in list modified by Joshua Wright 4-FEB-2022
// && modification of comments - 01/09/2023
var pageCodes = ['regSurvey', 'attendeeInfo'];
if (pageCodes.includes(data.page)) {
//Modified so this will run for all places in which the Global Opt-In attribute will run.
//(data.page === 'contactInfo' || data.page === 'createaccount' || data.page === 'attendeeInfo' ||data.page ==='attendeepage2') {
waitForX({
intervalFrequency: INTERVAL_DELAY,
maxIterations: MAX_INTERVAL_ITERATIONS,
onSuccess: function () {
var countrySelectBox = document.querySelector('#formAttendee-countryId');
if (document.getElementById('1603923186460001otqg')) { // case when the user goes back from the Orders page to the form again or when the form has been visited once
var certificationNumberInput = document.getElementById('1603923186460001otqg');
certificationNumberInput.addEventListener('blur', validateCertificationNumber);
certificationNumberInput.addEventListener('focus', removeCertificationNumberMessage);
}
else { // first time visiting the form
var certificationRadioButton = document.getElementById('opt-1603923159004001oiI5');
if (certificationRadioButton) {
certificationRadioButton.addEventListener('click', function () {
setTimeout(function(){
var certificationNumberInput = document.getElementById('1603923186460001otqg');
certificationNumberInput.addEventListener('blur', validateCertificationNumber);
certificationNumberInput.addEventListener('focus', removeCertificationNumberMessage);
},0);
});
}
}
if (countrySelectBox) {
if (!initialNCValueSet) {
initialNCValueSet = true;
applyNoticeChoice({ target: countrySelectBox });
}
countrySelectBox.addEventListener('change', applyNoticeChoice);
}
},
successCheck: function () {
return document.querySelector('#' + FORM_ID);
},
});
}
/**
* options: {
* enableLogs: Boolean,
* intervalFrequency: Number,
* logIdentifier: String,
* maxIterations: Number,
* onSuccess: () => void,
* successCheck: () => Boolean,
* }
*/
function waitForX(options) {
var log = function log() {
if (options.enableLogs)
console.log.apply(console, arguments)
}
var logSuffix = options.logIdentifier ? ' -- [' + options.logIdentifier + ']' : ''
var intervalFrequency = options.intervalFrequency || 100
var maxIterations = options.maxIterations || 100
// Do 1 immediate check before the interval starts.
if (options.successCheck()) {
log('SUCCESS (immediate), no interval needed' + logSuffix)
options.onSuccess()
return;
}
log('every ' + intervalFrequency + 'ms, for ' + intervalFrequency * maxIterations + 'ms' + logSuffix)
var iterations = 0
var waitTimer = window.setInterval(function () {
if (options.successCheck.apply(options)) {
log('SUCCESS, waited: ' + ((iterations + 1) * intervalFrequency) + 'ms (' + (iterations + 1) + ' iterations)' + logSuffix)
options.onSuccess.apply(options)
window.clearInterval(waitTimer);
log('cleared interval' + logSuffix)
}
if (iterations >= maxIterations) {
log('TIMED OUT' + logSuffix)
// Safety net to ensure this interval won't run forever.
window.clearInterval(waitTimer)
log('cleared interval' + logSuffix)
}
iterations++
}, options.intervalFrequency)
}
var autocompleteScript = document.createElement('script')
autocompleteScript.src = 'https://api.demandbase.com/autocomplete/widget.js'
document.body.appendChild(autocompleteScript)
var DEMANDBASE_FORM_SCRIPT_ID = 'demandbaseFormScript'
if (data.page !== null) {
waitForX({
intervalFrequency: 100,
maxIterations: 150,
onSuccess: function () {
if (!document.querySelector('#' + DEMANDBASE_FORM_SCRIPT_ID)) {
var formScript = document.createElement('script')
formScript.src = 'https://events.rainfocus.com/pages/redhat/global/demandbaseform'
formScript.id = DEMANDBASE_FORM_SCRIPT_ID
document.body.appendChild(formScript)
} else {
// This is terrible, but it's the only way to re-initialize the autocomplete on a SPA.
// Fortunately, it is an uncommon use case.
window.Demandbase.CompanyAutocomplete.setup = false
window.Demandbase.CompanyAutocomplete.initialized = false
window.DemandbaseForm.formConnector.form = document.querySelector('#myDynamicForm')
window.DemandbaseForm.formConnector.init()
}
},
successCheck: function () {
return document.querySelector('#formAttendee-companyname');
},
});
}