From a31b5f6a0ac266d0c17682703808aedcddfe32d2 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Sat, 16 Oct 2021 16:30:17 -0400 Subject: [PATCH 01/11] hide shortcuts-wrapper at bottom --- js/side-menus.js | 3 +++ pytorch_sphinx_theme/static/js/theme.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/js/side-menus.js b/js/side-menus.js index 9e4b0a79..7351f42a 100644 --- a/js/side-menus.js +++ b/js/side-menus.js @@ -183,12 +183,14 @@ window.sideMenus = { rightMenu.style.top = utilities.scrollTop() - mainHeaderHeight + "px"; rightMenu.classList.add("scrolling-absolute"); rightMenu.classList.remove("scrolling-fixed"); + document.getElementById("sphinx-template-shortcuts-wrapper").style.display = "none"; } } else { rightMenuWrapper.style.height = articleHeight + mainHeaderHeight + "px"; rightMenu.style.top = articleBottom - mainHeaderHeight - rightMenuList.offsetHeight + "px"; rightMenu.classList.add("scrolling-absolute"); + document.getElementById("sphinx-template-shortcuts-wrapper").style.display = "none"; } if (utilities.scrollTop() < articleBottom - rightMenuList.offsetHeight) { @@ -196,6 +198,7 @@ window.sideMenus = { rightMenu.style.top = ""; rightMenu.classList.remove("scrolling-absolute"); rightMenu.classList.add("scrolling-fixed"); + document.getElementById("sphinx-template-shortcuts-wrapper").style.display = "block"; } } diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index 798a8fe3..a962dc67 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -669,12 +669,14 @@ window.sideMenus = { rightMenu.style.top = utilities.scrollTop() - mainHeaderHeight + "px"; rightMenu.classList.add("scrolling-absolute"); rightMenu.classList.remove("scrolling-fixed"); + document.getElementById("sphinx-template-shortcuts-wrapper").style.display = "none"; } } else { rightMenuWrapper.style.height = articleHeight + mainHeaderHeight + "px"; rightMenu.style.top = articleBottom - mainHeaderHeight - rightMenuList.offsetHeight + "px"; rightMenu.classList.add("scrolling-absolute"); + document.getElementById("sphinx-template-shortcuts-wrapper").style.display = "none"; } if (utilities.scrollTop() < articleBottom - rightMenuList.offsetHeight) { @@ -682,6 +684,7 @@ window.sideMenus = { rightMenu.style.top = ""; rightMenu.classList.remove("scrolling-absolute"); rightMenu.classList.add("scrolling-fixed"); + document.getElementById("sphinx-template-shortcuts-wrapper").style.display = "block"; } } From cd5fa337304ae33c3414feee78b4682becd599f5 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Sat, 16 Oct 2021 16:32:01 -0400 Subject: [PATCH 02/11] fix initial not-expanded expanded error --- js/side-menus.js | 1 + pytorch_sphinx_theme/static/js/theme.js | 1 + 2 files changed, 2 insertions(+) diff --git a/js/side-menus.js b/js/side-menus.js index 7351f42a..2cfaa2e5 100644 --- a/js/side-menus.js +++ b/js/side-menus.js @@ -72,6 +72,7 @@ window.sideMenus = { linkWithHash.nextElementSibling.children.length > 0 ) { linkWithHash.nextElementSibling.style.display = "block"; + linkWithHash.classList.remove("not-expanded"); linkWithHash.classList.add("expanded"); } diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index a962dc67..9c4df213 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -558,6 +558,7 @@ window.sideMenus = { linkWithHash.nextElementSibling.children.length > 0 ) { linkWithHash.nextElementSibling.style.display = "block"; + linkWithHash.classList.remove("not-expanded"); linkWithHash.classList.add("expanded"); } From 8b2e02e9cf78e85f581abf4790007c355e868028 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Sun, 17 Oct 2021 13:25:55 -0400 Subject: [PATCH 03/11] escape dot in href for jquery search using id --- js/theme.js | 2 +- pytorch_sphinx_theme/static/js/theme.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/theme.js b/js/theme.js index 1c44e34c..3abfaf44 100644 --- a/js/theme.js +++ b/js/theme.js @@ -391,7 +391,7 @@ $(".stars-outer > i").on("click", function() { }) $("#pytorch-side-scroll-right li a").on("click", function (e) { - var href = $(this).attr("href"); + var href = $(this).attr("href").replaceAll('.', '\\.'); $('html, body').stop().animate({ scrollTop: $(href).offset().top - 100 }, 850); diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index 9c4df213..7fce2c04 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -1090,7 +1090,7 @@ $(".stars-outer > i").on("click", function() { }) $("#pytorch-side-scroll-right li a").on("click", function (e) { - var href = $(this).attr("href"); + var href = $(this).attr("href").replaceAll('.', '\\.'); $('html, body').stop().animate({ scrollTop: $(href).offset().top - 100 }, 850); From 3b0f1290c976d9858a5989bce2380f96ed4a9935 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Sun, 17 Oct 2021 14:13:01 -0400 Subject: [PATCH 04/11] fix support for sphinx 4.2.0 --- pytorch_sphinx_theme/static/css/theme.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytorch_sphinx_theme/static/css/theme.css b/pytorch_sphinx_theme/static/css/theme.css index 42b57139..5c72801f 100644 --- a/pytorch_sphinx_theme/static/css/theme.css +++ b/pytorch_sphinx_theme/static/css/theme.css @@ -10474,7 +10474,7 @@ article.pytorch-article p.caption { margin-top: 1.25rem; } -article.pytorch-article .section:first-of-type h1:first-of-type { +article.pytorch-article section:first-of-type h1:first-of-type { margin-top: 0; } @@ -10561,7 +10561,7 @@ article.pytorch-article .sphx-glr-thumbcontainer .figure a.reference.internal { } } -article.pytorch-article .section :not(dt) > code { +article.pytorch-article section :not(dt) > code { color: #262626; border-top: solid 2px #ffffff; background-color: #ffffff; @@ -10570,7 +10570,7 @@ article.pytorch-article .section :not(dt) > code { -webkit-box-decoration-break: clone; box-decoration-break: clone; } -article.pytorch-article .section :not(dt) > code .pre { +article.pytorch-article section :not(dt) > code .pre { outline: 0px; padding: 0px; } From f7e4dc5c3f2196ef95f36c8c363e6dc345aafc4b Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Sun, 17 Oct 2021 21:44:59 -0400 Subject: [PATCH 05/11] fix support for object highlight --- js/highlight-navigation.js | 2 +- js/theme.js | 27 ++++++++++++------------ pytorch_sphinx_theme/static/js/theme.js | 28 ++++++++++++------------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/js/highlight-navigation.js b/js/highlight-navigation.js index 60f6b2e6..de11d6ff 100644 --- a/js/highlight-navigation.js +++ b/js/highlight-navigation.js @@ -1,7 +1,7 @@ // Modified from https://stackoverflow.com/a/32396543 window.highlightNavigation = { navigationListItems: document.querySelectorAll("#pytorch-right-menu li"), - sections: document.querySelectorAll(".pytorch-article .section"), + sections: document.querySelectorAll(".pytorch-article section section, .sig.sig-object"), sectionIdTonavigationLink: {}, bind: function() { diff --git a/js/theme.js b/js/theme.js index 3abfaf44..0cb82ddb 100644 --- a/js/theme.js +++ b/js/theme.js @@ -134,7 +134,7 @@ function ThemeNav () { // Find associated id element, then its closest section // in the document and try with that one. var id_elt = $('.document [id="' + anchor.substring(1) + '"]'); - var closest_section = id_elt.closest('div.section'); + var closest_section = id_elt.closest('section section'); link = vmenu.find('[href="#' + closest_section.attr("id") + '"]'); if (link.length === 0) { // still not found in the sidebar. fall back to main section @@ -402,29 +402,28 @@ var lastId, topMenu = $("#pytorch-side-scroll-right"), topMenuHeight = topMenu.outerHeight() + 1, // All sidenav items - menuItems = topMenu.find("a"), + menuItems = topMenu.find("a[href^='#']"), // Anchors for menu items - scrollItems = menuItems.map(function () { - var item = $(this).attr("href"); - if (item.length) { - return item; + scrollItems = {}; + for (var i = 0; i < menuItems.length; i++) { + var ref = menuItems[i].getAttribute("href").replaceAll('.', '\\.'); + if (ref.length > 1 && $(ref).length) { + scrollItems[ref] = menuItems[i]; } - }); + } $(window).scroll(function () { - var fromTop = $(this).scrollTop() + topMenuHeight; - var article = ".section"; + var article = Object.keys(scrollItems).join(', '); - $(article).each(function (i) { + $(article).each(function () { var offsetScroll = $(this).offset().top - $(window).scrollTop(); if ( - offsetScroll <= topMenuHeight + 200 && - offsetScroll >= topMenuHeight - 200 && - scrollItems[i] == "#" + $(this).attr("id") && + offsetScroll <= 120 && + offsetScroll >= -120 && $(".hidden:visible") ) { $(menuItems).removeClass("side-scroll-highlight"); - $(menuItems[i]).addClass("side-scroll-highlight"); + $(scrollItems['#' + this.id.replaceAll('.', '\\.')]).addClass("side-scroll-highlight"); } }); }); diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index 7fce2c04..44b0ef57 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -213,7 +213,7 @@ window.filterTags = { // Modified from https://stackoverflow.com/a/32396543 window.highlightNavigation = { navigationListItems: document.querySelectorAll("#pytorch-right-menu li"), - sections: document.querySelectorAll(".pytorch-article .section"), + sections: document.querySelectorAll(".pytorch-article section section, .sig.sig-object"), sectionIdTonavigationLink: {}, bind: function() { @@ -833,7 +833,7 @@ function ThemeNav () { // Find associated id element, then its closest section // in the document and try with that one. var id_elt = $('.document [id="' + anchor.substring(1) + '"]'); - var closest_section = id_elt.closest('div.section'); + var closest_section = id_elt.closest('section section'); link = vmenu.find('[href="#' + closest_section.attr("id") + '"]'); if (link.length === 0) { // still not found in the sidebar. fall back to main section @@ -1101,29 +1101,29 @@ var lastId, topMenu = $("#pytorch-side-scroll-right"), topMenuHeight = topMenu.outerHeight() + 1, // All sidenav items - menuItems = topMenu.find("a"), + menuItems = topMenu.find("a[href^='#']"), // Anchors for menu items - scrollItems = menuItems.map(function () { - var item = $(this).attr("href"); - if (item.length) { - return item; + scrollItems = {}; + for (var i = 0; i < menuItems.length; i++) { + var ref = menuItems[i].getAttribute("href").replaceAll('.', '\\.'); + if (ref.length > 1 && $(ref).length) { + scrollItems[ref] = menuItems[i]; } - }); + } $(window).scroll(function () { - var fromTop = $(this).scrollTop() + topMenuHeight; - var article = ".section"; + var article = Object.keys(scrollItems).join(', '); - $(article).each(function (i) { + $(article).each(function () { var offsetScroll = $(this).offset().top - $(window).scrollTop(); if ( - offsetScroll <= topMenuHeight + 200 && - offsetScroll >= topMenuHeight - 200 && + offsetScroll <= 120 && + offsetScroll >= -120 && scrollItems[i] == "#" + $(this).attr("id") && $(".hidden:visible") ) { $(menuItems).removeClass("side-scroll-highlight"); - $(menuItems[i]).addClass("side-scroll-highlight"); + $(scrollItems['#' + this.id.replaceAll('.', '\\.')]).addClass("side-scroll-highlight"); } }); }); From 990d7605d5eb6f5d516a6be0cf0d25e53b168905 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Mon, 18 Oct 2021 15:27:27 -0400 Subject: [PATCH 06/11] fix initial bar and menus --- js/side-menus.js | 8 +++++--- pytorch_sphinx_theme/static/js/theme.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/js/side-menus.js b/js/side-menus.js index 2cfaa2e5..6dcfd753 100644 --- a/js/side-menus.js +++ b/js/side-menus.js @@ -6,8 +6,6 @@ window.sideMenus = { isFixedToBottom: false, bind: function() { - sideMenus.handleLeftMenu(); - var rightMenuLinks = document.querySelectorAll("#pytorch-right-menu li"); var rightMenuHasLinks = rightMenuLinks.length > 1; @@ -93,7 +91,11 @@ window.sideMenus = { } }); - sideMenus.handleRightMenu(); + sideMenus.handleNavBar(); + sideMenus.handleLeftMenu(); + if (sideMenus.rightMenuIsOnScreen()) { + sideMenus.handleRightMenu(); + } } $(window).on('resize scroll', function(e) { diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index 44b0ef57..aae3e722 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -492,8 +492,6 @@ window.sideMenus = { isFixedToBottom: false, bind: function() { - sideMenus.handleLeftMenu(); - var rightMenuLinks = document.querySelectorAll("#pytorch-right-menu li"); var rightMenuHasLinks = rightMenuLinks.length > 1; @@ -579,7 +577,11 @@ window.sideMenus = { } }); - sideMenus.handleRightMenu(); + sideMenus.handleNavBar(); + sideMenus.handleLeftMenu(); + if (sideMenus.rightMenuIsOnScreen()) { + sideMenus.handleRightMenu(); + } } $(window).on('resize scroll', function(e) { From a30eb7eed5380b4bce2f81bc4bfadb8576912db4 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Mon, 18 Oct 2021 19:35:18 -0400 Subject: [PATCH 07/11] fix initial anchor location --- js/scroll-to-anchor.js | 2 +- pytorch_sphinx_theme/static/js/theme.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/scroll-to-anchor.js b/js/scroll-to-anchor.js index da092e5c..c2f08bf2 100644 --- a/js/scroll-to-anchor.js +++ b/js/scroll-to-anchor.js @@ -23,7 +23,7 @@ window.scrollToAnchor = { init: function() { this.scrollToCurrent(); // This interferes with clicks below it, causing a double fire - // $(window).on('hashchange', $.proxy(this, 'scrollToCurrent')); + $(window).on('hashchange', $.proxy(this, 'scrollToCurrent')); $('body').on('click', 'a', $.proxy(this, 'delegateAnchors')); $('body').on('click', '#pytorch-right-menu li span', $.proxy(this, 'delegateSpans')); }, diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index aae3e722..fadf8952 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -408,7 +408,7 @@ window.scrollToAnchor = { init: function() { this.scrollToCurrent(); // This interferes with clicks below it, causing a double fire - // $(window).on('hashchange', $.proxy(this, 'scrollToCurrent')); + $(window).on('hashchange', $.proxy(this, 'scrollToCurrent')); $('body').on('click', 'a', $.proxy(this, 'delegateAnchors')); $('body').on('click', '#pytorch-right-menu li span', $.proxy(this, 'delegateSpans')); }, From c488295542157544741513d6e4dce333ca6e6a25 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Mon, 18 Oct 2021 20:26:11 -0400 Subject: [PATCH 08/11] optimize scrolls --- js/_utilities.js | 12 ++++++++- js/scroll-to-anchor.js | 15 +---------- js/theme.js | 8 +++--- pytorch_sphinx_theme/static/js/theme.js | 34 +++++++++++-------------- 4 files changed, 31 insertions(+), 38 deletions(-) diff --git a/js/_utilities.js b/js/_utilities.js index eb3648c7..d13ab73e 100644 --- a/js/_utilities.js +++ b/js/_utilities.js @@ -98,5 +98,15 @@ window.utilities = { return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; - } + }, + + /** + * Return the offset amount to deduct from the normal scroll position. + * Modify as appropriate to allow for dynamic calculations + */ + getFixedOffset: function() { + var OFFSET_HEIGHT_PADDING = 20; + // TODO: this is a little janky. We should try to not rely on JS for this + return headersHeight() + OFFSET_HEIGHT_PADDING; + }, } diff --git a/js/scroll-to-anchor.js b/js/scroll-to-anchor.js index c2f08bf2..dff467c4 100644 --- a/js/scroll-to-anchor.js +++ b/js/scroll-to-anchor.js @@ -11,11 +11,6 @@ window.scrollToAnchor = { var anchorScrolls = { ANCHOR_REGEX: /^#[^ ]+$/, - offsetHeightPx: function() { - var OFFSET_HEIGHT_PADDING = 20; - // TODO: this is a little janky. We should try to not rely on JS for this - return utilities.headersHeight() + OFFSET_HEIGHT_PADDING; - }, /** * Establish events, and fix initial scroll position if a hash is provided. @@ -28,14 +23,6 @@ window.scrollToAnchor = { $('body').on('click', '#pytorch-right-menu li span', $.proxy(this, 'delegateSpans')); }, - /** - * Return the offset amount to deduct from the normal scroll position. - * Modify as appropriate to allow for dynamic calculations - */ - getFixedOffset: function() { - return this.offsetHeightPx(); - }, - /** * If the provided href is an anchor which resolves to an element on the * page, scroll to it. @@ -52,7 +39,7 @@ window.scrollToAnchor = { match = document.getElementById(href.slice(1)); if(match) { - var anchorOffset = $(match).offset().top - this.getFixedOffset(); + var anchorOffset = $(match).offset().top - utilities.getFixedOffset(); $('html, body').scrollTop(anchorOffset); diff --git a/js/theme.js b/js/theme.js index 0cb82ddb..920935d6 100644 --- a/js/theme.js +++ b/js/theme.js @@ -393,7 +393,7 @@ $(".stars-outer > i").on("click", function() { $("#pytorch-side-scroll-right li a").on("click", function (e) { var href = $(this).attr("href").replaceAll('.', '\\.'); $('html, body').stop().animate({ - scrollTop: $(href).offset().top - 100 + scrollTop: $(href).offset().top - utilities.getFixedOffset() }, 850); e.preventDefault; }); @@ -416,10 +416,10 @@ $(window).scroll(function () { var article = Object.keys(scrollItems).join(', '); $(article).each(function () { - var offsetScroll = $(this).offset().top - $(window).scrollTop(); + var offsetScroll = $(this).offset().top - $(window).scrollTop() - utilities.getFixedOffset(); if ( - offsetScroll <= 120 && - offsetScroll >= -120 && + offsetScroll <= 50 && + offsetScroll >= -50 && $(".hidden:visible") ) { $(menuItems).removeClass("side-scroll-highlight"); diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index fadf8952..86143684 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -99,7 +99,17 @@ window.utilities = { return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; - } + }, + + /** + * Return the offset amount to deduct from the normal scroll position. + * Modify as appropriate to allow for dynamic calculations + */ + getFixedOffset: function() { + var OFFSET_HEIGHT_PADDING = 20; + // TODO: this is a little janky. We should try to not rely on JS for this + return headersHeight() + OFFSET_HEIGHT_PADDING; + }, } },{}],2:[function(require,module,exports){ @@ -396,11 +406,6 @@ window.scrollToAnchor = { var anchorScrolls = { ANCHOR_REGEX: /^#[^ ]+$/, - offsetHeightPx: function() { - var OFFSET_HEIGHT_PADDING = 20; - // TODO: this is a little janky. We should try to not rely on JS for this - return utilities.headersHeight() + OFFSET_HEIGHT_PADDING; - }, /** * Establish events, and fix initial scroll position if a hash is provided. @@ -413,14 +418,6 @@ window.scrollToAnchor = { $('body').on('click', '#pytorch-right-menu li span', $.proxy(this, 'delegateSpans')); }, - /** - * Return the offset amount to deduct from the normal scroll position. - * Modify as appropriate to allow for dynamic calculations - */ - getFixedOffset: function() { - return this.offsetHeightPx(); - }, - /** * If the provided href is an anchor which resolves to an element on the * page, scroll to it. @@ -437,7 +434,7 @@ window.scrollToAnchor = { match = document.getElementById(href.slice(1)); if(match) { - var anchorOffset = $(match).offset().top - this.getFixedOffset(); + var anchorOffset = $(match).offset().top - utilities.getFixedOffset(); $('html, body').scrollTop(anchorOffset); @@ -1117,11 +1114,10 @@ $(window).scroll(function () { var article = Object.keys(scrollItems).join(', '); $(article).each(function () { - var offsetScroll = $(this).offset().top - $(window).scrollTop(); + var offsetScroll = $(this).offset().top - $(window).scrollTop() - utilities.getFixedOffset(); if ( - offsetScroll <= 120 && - offsetScroll >= -120 && - scrollItems[i] == "#" + $(this).attr("id") && + offsetScroll <= 50 && + offsetScroll >= -50 && $(".hidden:visible") ) { $(menuItems).removeClass("side-scroll-highlight"); From 045d46f1b8afd04990396d1190cda3c6a92177d5 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Mon, 18 Oct 2021 20:50:53 -0400 Subject: [PATCH 09/11] better scroll navigation --- js/_utilities.js | 2 +- pytorch_sphinx_theme/static/js/theme.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/_utilities.js b/js/_utilities.js index d13ab73e..a0044185 100644 --- a/js/_utilities.js +++ b/js/_utilities.js @@ -107,6 +107,6 @@ window.utilities = { getFixedOffset: function() { var OFFSET_HEIGHT_PADDING = 20; // TODO: this is a little janky. We should try to not rely on JS for this - return headersHeight() + OFFSET_HEIGHT_PADDING; + return document.getElementById("sphinx-template-page-level-bar").offsetHeight + OFFSET_HEIGHT_PADDING; }, } diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index 86143684..e6635d36 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -108,7 +108,7 @@ window.utilities = { getFixedOffset: function() { var OFFSET_HEIGHT_PADDING = 20; // TODO: this is a little janky. We should try to not rely on JS for this - return headersHeight() + OFFSET_HEIGHT_PADDING; + return document.getElementById("sphinx-template-page-level-bar").offsetHeight + OFFSET_HEIGHT_PADDING; }, } From 3695862a1f99e32cc7461b831095e79bc1642a67 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Mon, 18 Oct 2021 23:31:03 -0400 Subject: [PATCH 10/11] improve side-scroll-highlight --- js/_utilities.js | 25 +++++++++++++++++++++++ js/theme.js | 2 +- pytorch_sphinx_theme/static/js/theme.js | 27 ++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/js/_utilities.js b/js/_utilities.js index a0044185..bb7f8395 100644 --- a/js/_utilities.js +++ b/js/_utilities.js @@ -109,4 +109,29 @@ window.utilities = { // TODO: this is a little janky. We should try to not rely on JS for this return document.getElementById("sphinx-template-page-level-bar").offsetHeight + OFFSET_HEIGHT_PADDING; }, + + findParent: function(item) { + return $(item).parent().parent().siblings("a.reference.internal") + }, + makeHighlight: function(item) { + if ($(item).hasClass("title-link")) { + return + } + var parent = utilities.findParent(item); + if (parent.hasClass("title-link")) { + $(item).addClass("side-scroll-highlight"); + } + else if (parent.hasClass("not-expanded")) { + utilities.makeHighlight(parent) + } + else if (parent.hasClass("expanded")) { + $(item).addClass("side-scroll-highlight"); + utilities.makeHighlight($(item).parent().parent().siblings("a.reference.internal")) + } + else { + console.log(item) + console.log(parent) + throw "Unexpected Error"; + } + } } diff --git a/js/theme.js b/js/theme.js index 920935d6..693838b1 100644 --- a/js/theme.js +++ b/js/theme.js @@ -423,7 +423,7 @@ $(window).scroll(function () { $(".hidden:visible") ) { $(menuItems).removeClass("side-scroll-highlight"); - $(scrollItems['#' + this.id.replaceAll('.', '\\.')]).addClass("side-scroll-highlight"); + utilities.makeHighlight(scrollItems['#' + this.id.replaceAll('.', '\\.')]); } }); }); diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index e6635d36..f0d4f534 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -110,6 +110,31 @@ window.utilities = { // TODO: this is a little janky. We should try to not rely on JS for this return document.getElementById("sphinx-template-page-level-bar").offsetHeight + OFFSET_HEIGHT_PADDING; }, + + findParent: function(item) { + return $(item).parent().parent().siblings("a.reference.internal") + }, + makeHighlight: function(item) { + if ($(item).hasClass("title-link")) { + return + } + var parent = utilities.findParent(item); + if (parent.hasClass("title-link")) { + $(item).addClass("side-scroll-highlight"); + } + else if (parent.hasClass("not-expanded")) { + utilities.makeHighlight(parent) + } + else if (parent.hasClass("expanded")) { + $(item).addClass("side-scroll-highlight"); + utilities.makeHighlight($(item).parent().parent().siblings("a.reference.internal")) + } + else { + console.log(item) + console.log(parent) + throw "Unexpected Error"; + } + } } },{}],2:[function(require,module,exports){ @@ -1121,7 +1146,7 @@ $(window).scroll(function () { $(".hidden:visible") ) { $(menuItems).removeClass("side-scroll-highlight"); - $(scrollItems['#' + this.id.replaceAll('.', '\\.')]).addClass("side-scroll-highlight"); + utilities.makeHighlight(scrollItems['#' + this.id.replaceAll('.', '\\.')]); } }); }); From ac022ae52b7eb1e244f42592a55ce2f89043b862 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Tue, 19 Oct 2021 00:56:50 -0400 Subject: [PATCH 11/11] improve highlight --- js/_utilities.js | 15 ++------- js/theme.js | 29 ++++++++--------- pytorch_sphinx_theme/static/js/theme.js | 43 +++++++++---------------- 3 files changed, 32 insertions(+), 55 deletions(-) diff --git a/js/_utilities.js b/js/_utilities.js index bb7f8395..06bfe4c3 100644 --- a/js/_utilities.js +++ b/js/_utilities.js @@ -117,21 +117,10 @@ window.utilities = { if ($(item).hasClass("title-link")) { return } + $(item).addClass("side-scroll-highlight"); var parent = utilities.findParent(item); - if (parent.hasClass("title-link")) { - $(item).addClass("side-scroll-highlight"); - } - else if (parent.hasClass("not-expanded")) { + if (~parent.hasClass("title-link")) { utilities.makeHighlight(parent) } - else if (parent.hasClass("expanded")) { - $(item).addClass("side-scroll-highlight"); - utilities.makeHighlight($(item).parent().parent().siblings("a.reference.internal")) - } - else { - console.log(item) - console.log(parent) - throw "Unexpected Error"; - } } } diff --git a/js/theme.js b/js/theme.js index 693838b1..cc207796 100644 --- a/js/theme.js +++ b/js/theme.js @@ -398,21 +398,19 @@ $("#pytorch-side-scroll-right li a").on("click", function (e) { e.preventDefault; }); -var lastId, - topMenu = $("#pytorch-side-scroll-right"), - topMenuHeight = topMenu.outerHeight() + 1, - // All sidenav items - menuItems = topMenu.find("a[href^='#']"), - // Anchors for menu items - scrollItems = {}; - for (var i = 0; i < menuItems.length; i++) { - var ref = menuItems[i].getAttribute("href").replaceAll('.', '\\.'); - if (ref.length > 1 && $(ref).length) { - scrollItems[ref] = menuItems[i]; - } +topMenu = $("#sphinx-template-side-scroll-right"), +// All sidenav items +menuItems = topMenu.find("a[href^='#']"), +// Anchors for menu items +scrollItems = {}; +for (var i = 0; i < menuItems.length; i++) { + var ref = menuItems[i].getAttribute("href").replaceAll('.', '\\.'); + if (ref.length > 1 && $(ref).length) { + scrollItems[ref] = menuItems[i]; } +} -$(window).scroll(function () { +highlightCurrent = function() { var article = Object.keys(scrollItems).join(', '); $(article).each(function () { @@ -426,5 +424,6 @@ $(window).scroll(function () { utilities.makeHighlight(scrollItems['#' + this.id.replaceAll('.', '\\.')]); } }); -}); - +} +$(window).scroll(highlightCurrent); +$(document).ready(highlightCurrent) diff --git a/pytorch_sphinx_theme/static/js/theme.js b/pytorch_sphinx_theme/static/js/theme.js index f0d4f534..bb76cb98 100644 --- a/pytorch_sphinx_theme/static/js/theme.js +++ b/pytorch_sphinx_theme/static/js/theme.js @@ -118,22 +118,11 @@ window.utilities = { if ($(item).hasClass("title-link")) { return } + $(item).addClass("side-scroll-highlight"); var parent = utilities.findParent(item); - if (parent.hasClass("title-link")) { - $(item).addClass("side-scroll-highlight"); - } - else if (parent.hasClass("not-expanded")) { + if (~parent.hasClass("title-link")) { utilities.makeHighlight(parent) } - else if (parent.hasClass("expanded")) { - $(item).addClass("side-scroll-highlight"); - utilities.makeHighlight($(item).parent().parent().siblings("a.reference.internal")) - } - else { - console.log(item) - console.log(parent) - throw "Unexpected Error"; - } } } @@ -1121,21 +1110,19 @@ $("#pytorch-side-scroll-right li a").on("click", function (e) { e.preventDefault; }); -var lastId, - topMenu = $("#pytorch-side-scroll-right"), - topMenuHeight = topMenu.outerHeight() + 1, - // All sidenav items - menuItems = topMenu.find("a[href^='#']"), - // Anchors for menu items - scrollItems = {}; - for (var i = 0; i < menuItems.length; i++) { - var ref = menuItems[i].getAttribute("href").replaceAll('.', '\\.'); - if (ref.length > 1 && $(ref).length) { - scrollItems[ref] = menuItems[i]; - } +topMenu = $("#sphinx-template-side-scroll-right"), +// All sidenav items +menuItems = topMenu.find("a[href^='#']"), +// Anchors for menu items +scrollItems = {}; +for (var i = 0; i < menuItems.length; i++) { + var ref = menuItems[i].getAttribute("href").replaceAll('.', '\\.'); + if (ref.length > 1 && $(ref).length) { + scrollItems[ref] = menuItems[i]; } +} -$(window).scroll(function () { +highlightCurrent = function() { var article = Object.keys(scrollItems).join(', '); $(article).each(function () { @@ -1149,6 +1136,8 @@ $(window).scroll(function () { utilities.makeHighlight(scrollItems['#' + this.id.replaceAll('.', '\\.')]); } }); -}); +} +$(window).scroll(highlightCurrent); +$(document).ready(highlightCurrent) },{"jquery":"jquery"}]},{},[1,2,3,4,5,6,7,8,9,10,"pytorch-sphinx-theme"]);