Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
12 kB
2
Indexable
Never
(function () {
  try {
    /* main variables */
    var debug = 0;
    var variation_name = "";
    var $;
    /* all Pure helper functions */
    function waitforMarketo(trigger) {
      var interval = setInterval(function () {
        if (
          window.MktoForms2
        ) {
          clearInterval(interval);
          trigger();
        }
      }, 700);
      setTimeout(function () {
        clearInterval(interval);
      }, 15000);
    }
    function waitForjQuery(trigger) {
      var interval = setInterval(function () {
        if (window.jQuery != undefined) {
          clearInterval(interval);
          trigger();
        } else {
          addJQuery();
        }
      }, 50);
      setTimeout(function () {
        clearInterval(interval);
      }, 15000)
    }
    function waitForElement(selector, trigger, delayInterval, delayTimeout) {
      var interval = setInterval(function () {
        if (
          document &&
          document.querySelector(selector) &&
          document.querySelectorAll(selector).length > 0
        ) {
          clearInterval(interval);
          trigger();
        }
      }, delayInterval);
      setTimeout(function () {
        clearInterval(interval);
      }, delayTimeout);
    }

    function live(selector, event, callback, context) {
      /****Helper Functions****/
      // helper for enabling IE 8 event bindings
      function addEvent(el, type, handler) {
        if (el.attachEvent) el.attachEvent("on" + type, handler);
        else el.addEventListener(type, handler);
      }
      // matches polyfill
      this.Element &&
        (function (ElementPrototype) {
          ElementPrototype.matches =
            ElementPrototype.matches ||
            ElementPrototype.matchesSelector ||
            ElementPrototype.webkitMatchesSelector ||
            ElementPrototype.msMatchesSelector ||
            function (selector) {
              var node = this,
                nodes = (node.parentNode || node.document).querySelectorAll(selector),
                i = -1;
              while (nodes[++i] && nodes[i] != node);
              return !!nodes[i];
            };
        })(Element.prototype);
      // live binding helper using matchesSelector
      function live(selector, event, callback, context) {
        addEvent(context || document, event, function (e) {
          var found,
            el = e.target || e.srcElement;
          while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
          if (el && found) callback.call(el, e);
        });
      }
      live(selector, event, callback, context);
    }


    let egPopupOverlayModal = `
    <div class="eg-popup_modal_overlay">
    <div class="eg-popup_modal-container">
    <div class="eg-card-section" data-form-popup="" data-video="">
      <div class="eg-card">
        <iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ffast.wistia.net%2Fembed%2Fiframe%2Fzdvvllqsyf&display_name=Wistia%2C+Inc.&url=https%3A%2F%2Flatticehr.wistia.com%2Fmedias%2Fzdvvllqsyf&image=https%3A%2F%2Fembed-ssl.wistia.com%2Fdeliveries%2Fd3aaf61a12e03dcdd27fba70b9dba84a62f69fbc.jpg%3Fimage_crop_resized%3D960x540&key=96f1f04c5f4143bcb0f2e68c87d65feb&type=text%2Fhtml&schema=wistia"></iframe>
      </div>
    </div>
        <div class="eg-card-section" data-form-popup="">
    <div class="eg-card">
        <div class="eg-start-journey">
            <h1></h1>
            <p></p>
            <div class="eg-lattice-badges">
                <div class="eg-badge">
        <img src="https://www.vanderkraken.com/wp-content/uploads/2023/09/Image1.png" alt="">
    </div>
    <div class="eg-badge">
        <img src="https://www.vanderkraken.com/wp-content/uploads/2023/09/Image3.png" alt="">
    </div>
    <div class="eg-badge">
        <img src="https://www.vanderkraken.com/wp-content/uploads/2023/09/Image5.png" alt="">
    </div>
            </div>
        </div>
        <div class="eg-form-section">
        <div class="form full-width"><div class="form-card"></div></div></div>
    </div>
</div>
    </div>
</div>
    `;

    let egbottomsection = `
    <div class="eg-card-section">
    <div class="eg-card">
        <div class="eg-start-journey">
            <h1>Start your journey with Lattice</h1>
            <p>Leave your details below, and our friendly team of experts will be in touch to provide your personalized people strategy assesment.</p>
            <div class="eg-lattice-badges">
                <div class="eg-badge">
        <img src="https://www.vanderkraken.com/wp-content/uploads/2023/09/Image1.png" alt="">
    </div>
    <div class="eg-badge">
        <img src="https://www.vanderkraken.com/wp-content/uploads/2023/09/Image3.png" alt="">
    </div>
    <div class="eg-badge">
        <img src="https://www.vanderkraken.com/wp-content/uploads/2023/09/Image5.png" alt="">
    </div>
            </div>
        </div>
        <div class="eg-form-section">
        </div>
    </div>
</div>`

    let herobtn = `
<div class="eg-hero-btn">
    <a class="eg-scroll-btn">Talk to Sales</a>
    <a href="#" data-watch-quick-demo-cta>Watch Quick Demo</a>
</div>`

    /* Variation Init */
    function init() {
      waitForjQuery(function () {
        $ = window.jQuery;
        if (!document.querySelector(".eg-card-section")) {
          document.querySelector('[role="navigation"] > .minimal .w-button').textContent = "Talk to Sales";
          document.querySelector('[role="navigation"] > .minimal .w-button').classList.add("eg-scroll-btn")
          let egbutton = `<a href="#" class="eg-book-a-demo" data-watch-quick-demo-cta>Watch Quick Demo</a>`
          document.querySelector('[role="navigation"] > .minimal .is-sign-in').insertAdjacentHTML("afterend", egbutton);
          document.querySelector("html body .footer").insertAdjacentHTML("beforebegin", egbottomsection);
          document.querySelector(".eg-card-section .eg-form-section").insertAdjacentElement("beforeend", document.querySelector(".small-hero  .hero-grid > div:nth-child(2)"));
          document.querySelector(".small-hero .hero-grid ").insertAdjacentElement("beforeend", document.querySelector(".small-hero .hero-grid .lp-visual-wrapper"));
          document.querySelector(".small-hero .hero-grid > div:first-child").insertAdjacentHTML("beforeend", herobtn);

          document.querySelectorAll('html body .eg-scroll-btn').forEach(function (e) {
            e.addEventListener('click', function (event) {
              event.preventDefault();
              document.querySelector('html body .eg-card-section').scrollIntoView({
                behavior: 'smooth'
              });
            });
          });

          document.body.insertAdjacentHTML("beforeend", egPopupOverlayModal);

          live('[data-watch-quick-demo-cta]', 'click', function () {
            document.body.classList.add('eg-show-popup');
          });

          live('.eg-popup_modal_overlay', 'click', function (e) {
            if (e.target.classList.contains('eg-popup_modal_overlay')) {
              document.body.classList.remove('eg-show-popup');
            }
          });

          waitforMarketo(function () {
            loadFrm("372-AAD-485", 3115, `html body [data-form-popup] .eg-form-section .form-card`);
            window.MktoForms2.whenReady(function (form) {

              $('#FirstName').focus();

              var freemailDomains = ["yahoo.com", "hotmail.com", "live.com", "aol.com", "msn.com", "outlook.com", "gmail.com", "cloudmdrive.my.id", "driveplus.my.id", "meniti.my.id"],

                errorFreemail = "Must be business email.";

              /\ *no need to touch below this line* /

              var formEl = form.getFormElem()[0],

                emailEl = formEl.querySelector("input[name='Email']"),

                emailJq = MktoForms2.$(emailEl);

              form.onValidate(function (native) {

                if (!native) return;

                var currentValues = form.getValues(),

                  currentEmail = currentValues.Email;

                if (inDomainList(currentEmail, freemailDomains)) {

                  form.submittable(false);

                  form.showErrorMessage(errorFreemail, emailJq);

                } else {

                  form.submittable(true);

                }

              });

            });
          });
        }
      });
    }

    function loadFrm(egMID, egFrmId, targetSel) {
      let egTarget;
      egTarget = document.querySelector(targetSel);
      let mkform = `<form class="eg-step-submit-form" id="mktoForm_${egFrmId}"></form>`;
      console.log(mkform)
      if (!egTarget.querySelector(".eg-step-submit-form")) {
        egTarget.insertAdjacentHTML("afterbegin", mkform);
        reloadForm(egMID, egFrmId);
      } else {
        const frmEl = egTarget.querySelector('.eg-step-submit-form:empty');
        if (frmEl) {
          reloadForm(egMID, egFrmId);
        }
      }
    }
    const reloadForm = (egMID, egFrmId) => {
      MktoForms2.loadForm("//people.lattice.com", egMID, egFrmId, function (form) {
        console.log('form loaded', egFrmId);
        waitForElement('[id^="LblContent_Demo_Request_LD"]', function () {
          document.querySelector('[id^="LblContent_Demo_Request_LD"]').closest('.mktoFormRow').classList.add('eg-separator-mkto_row');
          document.querySelector('[id^="LblContent_Demo_Request_LD"]').parentElement.classList.add('eg-separator-mkto');
          document.querySelector('.eg-step-submit-form button[type="submit"]').style.cssText = "font-family: Matter,sans-serif !important;";
          document.querySelector('.eg-step-submit-form button[type="submit"]').innerText = "Get Started";
          const firstFormEls = [
            document.querySelector('html body .eg-step-submit-form [id="LblEmail"]'),
            document.querySelector('html body .eg-step-submit-form [id^="LblCompany_Size"]'),
            document.querySelector('html body .eg-step-submit-form [id="LblCountry"]')
          ];
          firstFormEls.forEach(firstFormEl => {
            if (firstFormEl) {
              firstFormEl.closest('.mktoFormRow').classList.add('eg-stage-1formrowsfilled');
            }
          });
          if (!document.querySelector('.eg-stage-1submit-cta_mkto')) {
            document.querySelector('.eg-step-submit-form button[type="submit"]').insertAdjacentHTML('afterend', `<button type="button" class="eg-stage-1submit-cta_mkto mktoButton" style="font-family: Matter, sans-serif !important;">Watch Quick Demo</button>`);
            document.querySelector('.eg-stage-1submit-cta_mkto').addEventListener('click', function () {
              const isValid = form.validate();
              console.log("Form is valid: ", isValid);
              if (isValid) {
                document.querySelector('html body .eg-popup_modal-container').setAttribute('data-show-entered', true);
                const nxtFrmlbl = document.querySelector('html body .eg-separator-mkto>label#LblContent_Demo_Request_LD_Special_Route__c.mktoLabel');
                if (nxtFrmlbl) {
                  const nxtFrmCheck = document.querySelector('html body .eg-separator-mkto>label#LblContent_Demo_Request_LD_Special_Route__c.mktoLabel ~ div input');
                  if (nxtFrmCheck && !nxtFrmCheck.checked) {
                    nxtFrmlbl.click();
                  }
                }
              }
            });
          }
        }, 50, 15000);
        // prevent redirection from happening of outer form
        // form.onSuccess(function (values, followUpUrl) {
        //   return false;
        // });
      });
    }

    function inDomainList(email, domains) {

      return domains

        .map(function (domain) {

          return new RegExp('@' + domain.replace('.', '\.') + '$', 'i');

        })

        .some(function (reDomain) {

          return reDomain.test(email);

        });

    }

    /* Initialize variation */
    waitForElement('html body .footer', init, 1000, 15000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();


Leave a Comment