Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.5 kB
3
Indexable
Never
(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);
    }

     // wait for jquery
        function waitForjQuery(trigger) {
            var interval = setInterval(function() {
                if (window.jQuery != undefined) {
                    clearInterval(interval);
                    trigger();
                } else {
                    addJQuery();
                }
            }, 50);
            setTimeout(function() {
                clearInterval(interval);
            }, 15000)
        }

        function addJQuery() {
            var jQueryScript = document.createElement('script');
            // check for updated jquery cdn
            jQueryScript.src = 'https://code.jquery.com/jquery-3.6.3.min.js';
            document.getElementsByTagName('head')[0].appendChild(jQueryScript);
        }

        
        // wait for slick

        function waitForSlick(trigger) {
            var interval = setInterval(function() {
                if (window.jQuery.fn.slick != undefined) {
                    clearInterval(interval);
                    trigger();
                }
            }, 50);
            setTimeout(function() {
                clearInterval(interval);
            }, 15000)
        }

        // slick script and css cdn
        function addScript() {
            var cssScript = '' +
                "<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css'/>";
            let themeCssScript = `<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick-theme.css'/>`;
            document.querySelector('head').insertAdjacentHTML('beforeend', cssScript);
            document.querySelector('head').insertAdjacentHTML('beforeend', themeCssScript);

            var swiperScript = document.createElement('script');
            swiperScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js';
            document.getElementsByTagName('head')[0].appendChild(swiperScript);
        }



    let egTrust = `
    <div class="s-logo-slider egSliderWrapper">
        <div class="egHeading">
            <h3>Trusted by over 4k сompanies, including:</h3>
        </div>
        
        
        <div class="egLogos flex">
            <div class="logo-container">
            <img src="//cdn-static.altium.com/sites/default/files/media_icon/2022-11/logo-slider-2-1.svg"
            alt="Volkswagen" loading="lazy" />
            </div>

            <div class="logo-container">
            <img src="//cdn-static.altium.com/sites/default/files/media_icon/2022-11/logo-slider-2-2.svg"
            alt="Toyota" loading="lazy" />
            </div>

            <div class="logo-container">
            <img src="//cdn-static.altium.com/sites/default/files/media_icon/2022-11/logo-slider-2-3.svg"
            alt="Texas Instruments" loading="lazy" />
            </div>

            <div class="logo-container">
            <img src="//cdn-static.altium.com/sites/default/files/media_icon/2022-11/logo-slider-2-4.svg"
            alt="ST" loading="lazy" />
            </div>

            <div class="logo-container">
            <img src="//cdn-static.altium.com/sites/default/files/media_icon/2022-11/logo-slider-2-5.svg"
            alt="Siemens" loading="lazy" />
            </div>
        </div>
</div>
`

    
    /* Variation Init */
    function init() {
      /* start your code here */

      waitForjQuery(function() {
        addScript();

        waitForSlick(function() {
          var $ = window.jQuery;
          $('.egLogos').slick({
            infinite: true,
            autoplay: true,
            speed: 300,
            slidesToShow: 5,
            centerMode: true,

            responsive: [
              {
                breakpoint: 1024,
                settings: {
                  slidesToShow: 3,
                  slidesToScroll: 3,
                  infinite: true,
                  dots: true
                }
              },
              {
                breakpoint: 600,
                settings: {
                  slidesToShow: 2,
                  slidesToScroll: 2
                }
              },
              {
                breakpoint: 480,
                settings: {
                  slidesToShow: 2,
                  slidesToScroll: 2
                }
              }
            ]
          });   

        });

      });

      document.querySelector("div.l-page__in article > section.s-hero").insertAdjacentHTML("afterend" , egTrust);
    }

    /* Initialize variation */
    waitForElement(' div.l-page__in article > section.s-hero', init, 50, 15000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();