Untitled

 avatar
unknown
plain_text
a year ago
6.2 kB
2
Indexable
(function () {
  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 live(selector, event, callback, context) {
      function addEvent(el, type, handler) {
        if (el.attachEvent) el.attachEvent('on' + type, handler);
        else el.addEventListener(type, handler);
      }
      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);
      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 (found) callback.call(el, e);
        });
      }
      live(selector, event, callback, context);
    };

    function initdesk() {
      let factsheetcta = document.querySelector('.fund-mod-buttons [data-ga4-type="Factsheet"]');
      if (factsheetcta) {
        let href = factsheetcta.getAttribute('href');
        factsheetcta.removeAttribute('href');

        live('.eg-showform #modal-form [type="submit"]', 'click', function () {
          document.body.classList.remove('eg-showform');
          let element = document.querySelector('.fund-mod-buttons [data-ga4-type="Factsheet"]');
          element.setAttribute('href', href);
          element.click();
        });
      }

      testeventsdesk();
    }

    function testeventsdesk() {
      live('.fund-mod-buttons [data-ga4-type="Factsheet"]', 'click', function () {
        document.body.classList.add('eg-showform');
        document.querySelector('.fund-mod-buttons > button:nth-of-type(1)').click();
        let interval = setInterval(() => {
          document.querySelector('#modal-form .modal-title').innerText = 'Request factsheet';
          document.querySelector('#modal-form [type="submit"]').removeAttribute('onclick')
        }, 500);

        setTimeout(() => {
          clearInterval(interval);
        }, 3000);
      });

      document.querySelector('#modal-form [aria-label="Close modal"]').addEventListener('click', function () {
        document.body.classList.remove('eg-showform');
        setTimeout(() => {
          document.querySelector('#modal-form .modal-title').innerText = 'Request info pack';
        }, 2000);
      })
    }

    function initmob() {
      let factsheetcta = document.querySelector(".bg-orange  a[href*='/files/factsheets/adviser']");
      if (factsheetcta) {
        let href = factsheetcta.getAttribute('href');
        factsheetcta.removeAttribute('href');

        live('.eg-showform #modal-form [type="submit"]', 'click', function () {
          let element = document.querySelector('.eg-showform .bg-orange [data-ga4-type="Factsheet"]');
          element.setAttribute('href', href);
          element.click();
        });
      }

      testeventsmob();
    }

    function testeventsmob() {
      live('.bg-orange [data-ga4-type="Factsheet"]', 'click', function () {
        document.body.classList.add('eg-showform');
        document.querySelector('#request-menu > button:first-of-type').click();
        let interval = setInterval(() => {
          document.querySelector('#modal-form .modal-title').innerText = 'Request factsheet';
          document.querySelector('#modal-form [type="submit"]').removeAttribute('onclick');
        }, 500);

        setTimeout(() => {
          clearInterval(interval);
        }, 3000);
      });

      document.querySelector('#modal-form [aria-label="Close modal"]').addEventListener('click', function () {
        document.body.classList.remove('eg-showform');
        setTimeout(() => {
          document.querySelector('#modal-form .modal-title').innerText = 'Request info pack';
        }, 2000);
      })
    }

    waitForElement('#modal-form', function () {
      const targetNode = document.querySelector('#modal-form');
      const config = {
        attributes: true,
        attributeFilter: ['class']
      };

      const callback = function (mutationsList, observer) {
        for (const mutation of mutationsList) {
          if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
            if (!targetNode.classList.contains('is-open')) {
              document.body.classList.remove('eg-showform');
              setTimeout(() => {
                document.querySelector('#modal-form .modal-title').innerText = 'Request info pack';
              }, 1000);
            }
          }
        }
      };

      const observer = new MutationObserver(callback);
      observer.observe(targetNode, config);
    }, 50, 15000);

    if (window.innerWidth > 767) {
      waitForElement('.fund-mod-buttons [data-ga4-type="Factsheet"]', initdesk, 50, 15000);
    } else {
      waitForElement(".bg-orange  a[href*='/files/factsheets/adviser']", initmob, 50, 15000);
    }
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();


Editor is loading...
Leave a Comment