function createElement(name, id, value, type) {
var input = document.createElement("input")
input.setAttribute("type", type)
input.setAttribute("name", name)
input.setAttribute("value", value)
input.setAttribute("id", id)
return input
}
// function setNativeValue(element, value) {
// var valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set;
// var prototype = Object.getPrototypeOf(element);
// var prototypeValueSetter = Object.getOwnPropertyDescriptor(
// prototype,
// 'value'
// ).set;
// if (valueSetter && valueSetter !== prototypeValueSetter) {
// prototypeValueSetter.call(element, value);
// } else {
// valueSetter.call(element, value);
// }
// }
// IE does not support the Event constructor. We need this fallback.
function createEvent(eventName, eventOptions) {
if (typeof Event === 'function') {
// This is a modern browser that supports the Event constructor.
return new Event(eventName, eventOptions)
} else {
// This is IE :(.
var event = document.createEvent('Event')
event.initEvent(eventName, eventOptions.bubbles, eventOptions.cancelable, eventOptions.detail)
return event
}
}
function getCookie(cname) {
const name = cname + '='
const ca = document.cookie.split(';')
for (let i = 0; i < ca.length; i++) {
let c = ca[i]
while (c.charAt(0) === ' ') {
c = c.substring(1)
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length)
}
}
return '';
}
/**
* 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)
}
if (data.page == 'contactInfo') {
waitForX({
enableLogs: true,
intervalFrequency: 50,
logIdentifier: 'LOGGING',
maxIterations: 20,
onSuccess: function() {
var inputs = [
{
element: $('#1557521510696001N5gM')[0],
value: getCookie('srcAACookie')
},
{
element: $('#1557521621200001NEx7')[0],
value: getCookie('srcIntAACookie')
},
{
element: $('#1557521556013001j9BK')[0],
value: getCookie('cidAACookie')
},
{
element: $('#1557521582125001NVVe')[0],
value: getCookie('cidIntAACookie')
}
];
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.element) {
input.element.parentElement.style.display = 'none';
if (input.value) {
input.element.setAttribute('value', input.value);
input.element.dispatchEvent(createEvent('input', { bubbles: true }));
}
}
}
// var input;
// var $ID_ATTRIBUTE_NAME = ;
// console.log(1234, $ID_ATTRIBUTE_NAME);
// $ID_ATTRIBUTE_NAME.parent().css('display', 'none');
// var COOKIE_VALUE_ID = getCookie('cidIntAACookie');
// if (COOKIE_VALUE_ID) {
// input = $ID_ATTRIBUTE_NAME[0];
// if (input) {
// // setNativeValue(input, COOKIE_VALUE_ID);
// input.setAttribute('value', COOKIE_VALUE_ID);
// input.dispatchEvent(createEvent('input', { bubbles: true }));
// }
// }
},
successCheck: function () {
return document.querySelector('#myDynamicForm');
}
});
}
var javascriptText = decodeURI('%3Cscript%20src=%22https://www.vmware.com/files/templates/inc/utag_data.js%22%3E%3C/script%3E') +
decodeURI('%3Cscript%20type=%22text/javascript%22%3E') +'utag_data.content_system="vmworld = rainfocus"'+ decodeURI('%3C/script%3E')
console.log('javascriptText', javascriptText)
if (postscribe) {
postscribe(document.head, javascriptText, {
done: function() {}
});
}
if (window.EventBus) {
window.EventBus.on('form:contactInfo:rendered', function () {
var dynamicForm = document.getElementById('myDynamicForm');
if (dynamicForm) {
// Adding this attribute to the form was an analytics request.
dynamicForm.setAttribute('name', 'form1');
}
});
}