Sha256: 38f102c5b3c367bb1575bb680cb1f4a702baa10521eff4cccafa2d535394e6dd

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
  var h = window.location.href;
  if (h.indexOf("?theme=") === -1) {
    window.location.href = h + "?theme=dark";
  }
}

document.addEventListener("DOMContentLoaded", function() {
  // Handle people clicking on oneOf tabs by changing every one on the page
  var oneOfTabs = document.querySelectorAll('[data-tab-link]');
  Array.from(oneOfTabs).forEach(function (element) {
    element.addEventListener('click', function (event) {
      var link = event.target.getAttribute('data-tab-link');
      var matchingTabs = document.querySelectorAll('[data-tab-link="' + link + '"]');
      Array.from(matchingTabs).forEach(function (element) {
        element.dispatchEvent(new Event('toggle'));
      });
    });
  });

  var toggleTopNav = function(event, closeOnly) {

    if (event) {
      if (!Array.from(event.target.classList).includes("oas-trigger")) {
        return;
      }
    }

    var c = document.querySelector('.oas-trigger-content');
    if (closeOnly === true) {
      c.style.display = "none";
      return;
    }
    c.style.display = c.style.display == 'block' ? 'none' : "block";
  };
  document.querySelector('.oas-trigger').addEventListener("click", toggleTopNav);

  document.querySelectorAll('a').forEach((element) => {
    var href = element.getAttribute("href");
    if (!href){ return; }
    if (href.slice(0,1) !== "#"){ return; }
    element.addEventListener('click', function (event) {
      event.preventDefault();

      toggleTopNav(null, true);

      var to = document.querySelector(event.target.hash)
      history.pushState({}, '', event.target.href);
      window.scrollTo({
        top: (window.scrollY + to.getBoundingClientRect().y) - 70,
        left: 0,
      })


    });
  });

});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nexmo-oas-renderer-2.0.1 lib/nexmo/oas/renderer/public/assets/javascripts/nexmo-oas-renderer.js
nexmo-oas-renderer-2.0.0 lib/nexmo/oas/renderer/public/assets/javascripts/nexmo-oas-renderer.js