<|start_filename|>sphinx_book_theme/layout.html<|end_filename|>
{% extends "pydata_sphinx_theme/layout.html" %}

{% set is_single_page = (theme_single_page == True) or (theme_single_page == "True") %}
{% if is_single_page %}
    {%- set sidebar_width_class = "col-md-2" %}
{% else %}
    {%- set sidebar_width_class = "col-md-3" %}
{% endif %}

<!-- Docs TOC is "d-none d-xl-block col-xl-2" -->
{% block docs_sidebar %}
<div class="col-12 {{ sidebar_width_class }} bd-sidebar site-navigation show{% if is_single_page %} single-page{% endif %}" id="site-navigation">
    {% if not is_single_page %}
        {% include "sidebar.html" %}
    {%- endif %}
</div>
{% endblock %}

{% block docs_main %}
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
    {% block docs_body %}
    {% include "topbar.html" %}
    <div id="main-content" class="row">
        <div class="col-12 col-md-9 pl-md-3 pr-md-0">
        {{ super() }}
        {% if theme_show_prev_next %}
            {% include "_templates/prev-next.html" %}
        {% endif %}
        </div>
    </div>
    {% endblock %}
    {%- include "footer.html" %}
</main>
{% endblock %}

{% block docs_toc %}
{% endblock %}

{% block docs_navbar %}
{%- endblock %}

{%- block footer %}
{%- endblock %}


<|start_filename|>sphinx_book_theme/_templates/sbt-sidebar-nav.html<|end_filename|>
<nav class="bd-links" id="bd-docs-nav" aria-label="Main">
    <div class="bd-toc-item active">
        {{ sbt_generate_nav_html(include_item_names=True, with_home_page=theme_home_page_in_toc, show_depth=theme_show_navbar_depth) }}
    </div>
</nav>


<|start_filename|>src/js/sphinx-book-theme.js<|end_filename|>
// Navbar toggle button
var initTriggerNavBar = () => {
    if ($(window).width() < 768) {
        $("#navbar-toggler").trigger("click")
    }
}


// NavBar scrolling
var scrollToActive = () => {
  var navbar = document.getElementById('site-navigation')
  var active_pages = navbar.querySelectorAll(".active")
  var active_page = active_pages[active_pages.length-1]
  // Only scroll the navbar if the active link is lower than 50% of the page
  if (active_page !== undefined && active_page.offsetTop > ($(window).height() * .5)) {
    navbar.scrollTop = active_page.offsetTop - ($(window).height() * .2)
  }
}

// Helper function to run when the DOM is finished
var sbRunWhenDOMLoaded = cb => {
    if (document.readyState != 'loading') {
      cb()
    } else if (document.addEventListener) {
      document.addEventListener('DOMContentLoaded', cb)
    } else {
      document.attachEvent('onreadystatechange', function() {
        if (document.readyState == 'complete') cb()
      })
    }
}

// Toggle full-screen with button
function toggleFullScreen() {
  var navToggler = $("#navbar-toggler");
  if (!document.fullscreenElement) {
      document.documentElement.requestFullscreen();
      if (!navToggler.hasClass("collapsed")) {
        navToggler.click();
      }
  } else {
    if (document.exitFullscreen) {
      document.exitFullscreen();
      if (navToggler.hasClass("collapsed")) {
        navToggler.click();
      }
    }
  }
}

// Enable tooltips
var initTooltips = () => {
  $(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
  });
}

var initTocHide = () => {
  // Hide the TOC when we scroll down
  var scrollTimeout;
  var throttle = 200;  // in milliseconds
  var tocHeight = $("#bd-toc-nav").outerHeight(true) + $(".bd-toc").outerHeight(true);
  var hideTocAfter = tocHeight + 200;  // Height of TOC + some extra padding
  var checkTocScroll = function () {
      var margin_content = $(".margin, .tag_margin, .full-width, .full_width, .tag_full-width, .tag_full_width, .sidebar, .tag_sidebar, .popout, .tag_popout");
      margin_content.each((index, item) => {
        // Defining the boundaries that we care about for checking TOC hiding
        var topOffset = $(item).offset().top - $(window).scrollTop();
        var bottomOffset = topOffset + $(item).outerHeight(true);

        // Check whether we should hide the TOC (if it overlaps with a margin content)
        var topOverlaps = ((topOffset >= 0) && (topOffset < hideTocAfter));
        var bottomOverlaps = ((bottomOffset >= 0) && (bottomOffset < hideTocAfter));
        var removeToc = (topOverlaps || bottomOverlaps);
        if (removeToc && window.pageYOffset > 20) {
          $("div.bd-toc").removeClass("show")
          return false
        } else {
          $("div.bd-toc").addClass("show")
        };
      })
  };
  var manageScrolledClassOnBody = function () {
    if (window.scrollY > 0) {
      document.body.classList.add("scrolled");
    } else {
      document.body.classList.remove("scrolled");
    }
  }

  $(window).on('scroll', function () {
      if (!scrollTimeout) {
          scrollTimeout = setTimeout(function () {
              checkTocScroll();
              manageScrolledClassOnBody();
              scrollTimeout = null;
          }, throttle);
      }
  });
}


var initThebeSBT = () => {
  var title  = $("div.section h1")[0]
  if (!$(title).next().hasClass("thebe-launch-button")) {
    $("<button class='thebe-launch-button'></button>").insertAfter($(title))
  }
  initThebe();
}

sbRunWhenDOMLoaded(initTooltips)
sbRunWhenDOMLoaded(initTriggerNavBar)
sbRunWhenDOMLoaded(scrollToActive)
sbRunWhenDOMLoaded(initTocHide)
