<!-- @tuanphan - 04.26c13v1 WM Tabs Autoscroll -->
<script>
window.wmAutoTabConfig = {
  instances: 'all',
  interval: 4000,
  pauseOnHover: true,
  clickToOpen: true,
  openInNewTab: true,
  mobileDelay: 5000,
  disableScrollBack: true,
};
</script>
<script>
window.addEventListener('wmTabs:afterOpenTab', function init() {
  window.removeEventListener('wmTabs:afterOpenTab', init);

  var cfg = window.wmAutoTabConfig;
  var allInstances = wmTabs.instances;
  if (!allInstances || !allInstances.length) return;

  var targets = cfg.instances === 'all'
    ? allInstances
    : cfg.instances.map(function(i) { return allInstances[i]; }).filter(Boolean);

  function isMobile() {
    return window.matchMedia('(pointer: coarse)').matches;
  }

  targets.forEach(function(instance) {
    var current = 0;
    var total = instance.tabs.length;
    var paused = false;
    var mobileOpenTimers = {};

    if (cfg.disableScrollBack) {
      instance.scrollBackToTop = function() {};
    }

    setInterval(function() {
      if (paused) return;
      current = (current + 1) % total;
      instance.openTab(instance.tabs[current].id);
    }, cfg.interval);

    if (cfg.pauseOnHover) {
      instance.el.addEventListener('mouseenter', function() { paused = true; });
      instance.el.addEventListener('mouseleave', function() { paused = false; });
    }

    if (cfg.clickToOpen) {
      instance.tabs.forEach(function(tab, index) {
        tab.button.addEventListener('click', function() {
          var url = tab.item && tab.item.fullUrl;
          if (!url) return;

          if (isMobile()) {
            if (mobileOpenTimers[index]) {
              clearTimeout(mobileOpenTimers[index]);
              delete mobileOpenTimers[index];
              return;
            }
            mobileOpenTimers[index] = setTimeout(function() {
              delete mobileOpenTimers[index];
              cfg.openInNewTab ? window.open(url, '_blank') : window.location.href = url;
            }, cfg.mobileDelay);
          } else {
            cfg.openInNewTab ? window.open(url, '_blank') : window.location.href = url;
          }
        });
      });
    }
  });
});
</script>

 

Buy me a coffee