Untitled

 avatar
unknown
plain_text
2 years ago
3.0 kB
2
Indexable
(function () {
  if (!document.querySelector(".eg-holiday-wrapper")) {
    try {
      /* main variables */
      var debug = 0;
      var variation_name = "";
      var $;
      /* all Pure helper functions */

      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 addFormScript() {
        var tfScript = document.createElement('script');
        tfScript.setAttribute('src', '//embed.typeform.com/next/embed.js');
        document.head.appendChild(tfScript);
      }

      function init() {
        /* start your code here */
        let key = document.querySelector('html').getAttribute('lang');
        let egSelctor = "html body #main >section:nth-child(1) .pane-moorings-search-search-widget";
        if (key === "en") egSelctor = "html body #main >section:nth-child(1) .pane-moorings-search-search-widget";

        let egTimerHtml = `
              <div class="eg-holiday-wrapper">
                  <div class="eg-holiday-container">
                      <p class="eg-holiday-message">Find a holiday that is uniquely tailored to you.</p>
                      <a class="eg-holiday-link"><strong>Find Holiday</strong></a>
                      <button data-tf-popup="cyTwpq9d" data-tf-opacity="100" data-tf-size="100" data-tf-iframe-props="title=Yachts holiday finder prototype - Moorings" data-tf-transitive-search-params data-tf-medium="snippet" data-tf-hidden="hubspot_utk=,hubspot_page_name=,hubspot_page_url=" style="all:unset;font-family:Helvetica,Arial,sans-serif;display:none;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;background-color:#0445AF;color:#fff;font-size:20px;border-radius:25px;padding:0 33px;font-weight:bold;height:50px;cursor:pointer;line-height:50px;text-align:center;margin:0;text-decoration:none;">Try me!</button><script src="//embed.typeform.com/next/embed.js"></script>
                  </div>
              </div>`;
        // inserting html before hero image ele
        waitForElement(egSelctor, function () {
          document.querySelector(egSelctor).insertAdjacentHTML("afterend", egTimerHtml);
          document.querySelector(".eg-holiday-link").addEventListener("click", function () {
            document.querySelector('.eg-holiday-link + button').click();
          });
          addFormScript();
        }, 50, 15000);

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