Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👌 IMPROVE: RHS TOC sticky when scrolling option #144

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
499b061
Add condition for sticky toc
DrDrij Jun 6, 2021
7923265
Merge branch 'master' into rhs-toc-adjustments
AakashGfude Jun 11, 2021
2e6acdd
Add link highlighting function for page TOC
DrDrij Jun 22, 2021
0fe9120
Add styles for page TOC highlighting
DrDrij Jun 22, 2021
6f9d006
Page TOC style tweak
DrDrij Jun 22, 2021
0b98935
Hide nested pages in page TOC
DrDrij Jun 22, 2021
17ccb9e
Add sticky_toc option to conf
DrDrij Jun 22, 2021
85ed2f2
Only highlight if sticky
DrDrij Jun 22, 2021
341ee62
Add context to RHS TOC parameter
DrDrij Sep 9, 2021
d5e85ab
Add context to RHS TOC parameter
DrDrij Sep 9, 2021
8fe2483
Add context to RHS TOC parameter
DrDrij Sep 9, 2021
7f004f0
Add context to RHS TOC parameter
DrDrij Sep 9, 2021
cb28e45
merging master
AakashGfude May 3, 2022
1bd3d58
editing pre-commit config
AakashGfude May 3, 2022
43030f4
theme.conf
AakashGfude May 5, 2022
aa6f864
setup.py
AakashGfude May 5, 2022
67bf824
versions in pre-commit
AakashGfude May 5, 2022
23777b6
ensuring markupsafe is right version
AakashGfude May 5, 2022
db6cdca
minor setup fix
AakashGfude May 5, 2022
ba7f601
markupsafe
AakashGfude May 5, 2022
f22348c
checkout branch of lecture-python-programming.myst with rhs toc settings
mmcky May 6, 2022
adde74b
checkout correct branch after cloning
mmcky May 6, 2022
c932aa7
checkout inside repo
mmcky May 6, 2022
42da195
sticky_toc
AakashGfude May 12, 2022
3ec412e
sphinx version
AakashGfude May 12, 2022
20c8790
changing install order
AakashGfude May 12, 2022
91f2ec9
fixing sphinx versions
AakashGfude May 12, 2022
d00b16f
Merge branch 'master' into rhs-toc-adjustments
AakashGfude Apr 28, 2023
eb7e422
Merge branch 'master' into rhs-toc-adjustments
AakashGfude Apr 30, 2023
b50aed5
changing to sticky_contents
AakashGfude Apr 30, 2023
be53f5c
input checkbox styling
AakashGfude May 1, 2023
05cd737
updating master
AakashGfude May 1, 2023
0acf72c
keeping it True by deafult
AakashGfude May 3, 2023
9abf43c
resolved merge conflict
AakashGfude May 3, 2023
8416d73
sticky_contents default reverted
AakashGfude May 4, 2023
6f47f6a
Merge branch 'master' into rhs-toc-adjustments
AakashGfude May 4, 2023
06127b2
running pre-commit
AakashGfude May 4, 2023
a75930f
update to python=3.10
mmcky May 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
shell: bash -l {0}
run: |
git clone https://github.com/QuantEcon/lecture-python-programming.myst
cd lecture-python-programming.myst && git checkout rhs-toc-sticky && cd ..
- name: Setup Anaconda
uses: conda-incubator/setup-miniconda@v2
with:
Expand Down
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exclude: >

repos:

- repo: git://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-json
Expand All @@ -22,7 +22,7 @@ repos:
- id: flake8

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black

Expand All @@ -42,3 +42,4 @@ repos:
quantecon_book_theme/static/.*|
quantecon_book_theme/theme.conf
)$
additional_dependencies: ['markupsafe==2.0.1']
2 changes: 1 addition & 1 deletion quantecon_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_static_path(app):


def add_to_context(app, pagename, templatename, context, doctree):
""" Functions and variable additions to context."""
"""Functions and variable additions to context."""

def sbt_generate_nav_html(
level=1,
Expand Down
4 changes: 4 additions & 0 deletions quantecon_book_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@

<div class="qe-page__toc">

{% if theme_sticky_contents is defined and theme_sticky_contents is sameas true %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude is the option called theme_sticky_contents or sticky_contents

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theme_ is appended by sphinx itself for html_theme_options. Unfortunately, it's neither 😬. The correct one is theme_sticky_toc. I have corrected it.

<div class="inner sticky">
{%- else %}
<div class="inner">
{%- endif %}

{% set page_toc = generate_toc_html() %}

Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions quantecon_book_theme/theme.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Note: this should only be changed in src/jinja/theme.conf.j2
[theme]
inherit = pydata_sphinx_theme
stylesheet = quantecon-book-theme.1ef59f8f4e91ec8319176e8479c6af4e.css
stylesheet = quantecon-book-theme.8e803950472302ed98c42444678c3bbd.css

[options]
single_page = False
Expand All @@ -28,4 +28,5 @@ keywords =
twitter =
twitter_logo_url =
og_logo_url =
persistent_sidebar: False
sticky_toc = False
persistent_sidebar = False
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"sphinx_book_theme~=0.1.0",
"beautifulsoup4",
"web-compile",
"markupsafe~=2.0.1",
'importlib-resources>=3.0,<3.5; python_version < "3.7"',
],
extras_require={
Expand All @@ -48,7 +49,7 @@
"sphinxcontrib-bibtex~=2.2",
],
"testing": [
"myst_nb~=0.11.1",
"myst-nb~=0.11.1",
"coverage",
"pytest~=6.0.1",
"pytest-cov",
Expand Down
2 changes: 2 additions & 0 deletions src/jinja/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ keywords =
twitter =
twitter_logo_url =
og_logo_url =
sticky_toc = False
persistent_sidebar = False
3 changes: 2 additions & 1 deletion src/jinja/theme.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ keywords =
twitter =
twitter_logo_url =
og_logo_url =
persistent_sidebar: False
sticky_toc = False
persistent_sidebar = False
8 changes: 7 additions & 1 deletion src/js/quantecon-book-theme.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// ScrollSpy Plugin: https://github.com/r3plica/Scrollspy
!function($,window,document,undefined){$.fn.extend({scrollspy:function(options){var defaults={namespace:"scrollspy",activeClass:"active",animate:!1,duration:1e3,offset:0,container:window,replaceState:!1};options=$.extend({},defaults,options);var add=function(ex1,ex2){return parseInt(ex1,10)+parseInt(ex2,10)},findElements=function(links){for(var elements=[],i=0;i<links.length;i++){var link=links[i],hash=$(link).attr("href"),element=$(hash);if(element.length>0){var top=Math.floor(element.offset().top),bottom=top+Math.floor(element.outerHeight());elements.push({element:element,hash:hash,top:top,bottom:bottom})}}return elements},findLink=function(links,hash){for(var i=0;i<links.length;i++){var link=$(links[i]);if(link.attr("href")===hash)return link}},resetClasses=function(links){for(var i=0;i<links.length;i++)$(links[i]).parent().removeClass(options.activeClass)},scrollArea="";return this.each(function(){for(var element=this,container=$(options.container),links=$(element).find("a"),i=0;i<links.length;i++){var link=links[i];$(link).on("click",function(e){var target=$(this).attr("href"),$target=$(target);if($target.length>0){var top=add($target.offset().top,options.offset);options.animate?$("html, body").animate({scrollTop:top},options.duration):window.scrollTo(0,top),e.preventDefault()}})}resetClasses(links);var elements=findElements(links),trackChanged=function(){for(var link,position={top:add($(this).scrollTop(),Math.abs(options.offset)),left:$(this).scrollLeft()},i=0;i<elements.length;i++){var current=elements[i];if(position.top>=current.top&&position.top<current.bottom){var hash=current.hash;if(link=findLink(links,hash)){options.onChange&&scrollArea!==hash&&(options.onChange(current.element,$(element),position),scrollArea=hash),options.replaceState&&history.replaceState({},"","/"+hash),resetClasses(links),link.parent().addClass(options.activeClass);break}}}!link&&"exit"!==scrollArea&&options.onExit&&(options.onExit($(element),position),resetClasses(links),scrollArea="exit",options.replaceState&&history.replaceState({},"","/"))};container.bind("scroll."+options.namespace,function(){trackChanged()}),$(document).ready(function(e){trackChanged()})})}})}(jQuery,window,document);

document.addEventListener("DOMContentLoaded", function(){

// Avoid `console` errors in browsers that lack a console.
Expand Down Expand Up @@ -293,4 +296,7 @@ document.addEventListener("DOMContentLoaded", function(){
touch: false,
});

});
// Highlight page TOC links as user scrolls
$(".sticky .page__toc-nav ul").scrollspy();

})
14 changes: 12 additions & 2 deletions src/scss/quantecon-book-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ tt {
width: 200px;

.inner {
height: 100%;
&.sticky {
position: sticky;
top: 7rem;
}
}

&-header {
Expand Down Expand Up @@ -500,6 +503,13 @@ tt {
opacity: 1;
}
}

&.active {
>a {
//color: $color-primary;
font-weight: bold;
}
}
}
}
.logo {
Expand Down Expand Up @@ -532,7 +542,7 @@ tt {
}

.nav>.active>ul {
display: block;
// display: block;
}

.nav .nav {
Expand Down