-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set jquery as external to allow cdn version plugin attachment (#179)
- Loading branch information
1 parent
60964c5
commit 4a33ff5
Showing
3 changed files
with
49 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
require('jquery/dist/jquery'); | ||
require('popper.js/dist/umd/popper'); | ||
require("bootstrap/dist/js/bootstrap.bundle"); | ||
|
||
|
||
/** | ||
* This file should be edited in ./src/js/index.js. After bundling the resulting file in ./pydata_sphinx_theme/static/js/index.js should never be manually changed. | ||
* Edit ./src/js/index.js and run yarn build:dev or yarn build:production. | ||
*/ | ||
|
||
// TOC sidebar - add "active" class to parent list | ||
// | ||
// Bootstrap's scrollspy adds the active class to the <a> link, | ||
// but for the automatic collapsing we need this on the parent list item. | ||
// | ||
// The event is triggered on "window" (and not the nav item as documented), | ||
// see https://github.com/twbs/bootstrap/issues/20086 | ||
$(window).on('activate.bs.scrollspy', function() { | ||
const navLinks = document.querySelectorAll('#bd-toc-nav a'); | ||
/* Sphinx injects the html output with jquery and other javascript files. | ||
* To enable Popper.js (and other jQuery plugins) to hook into the same instancce of jQuery, | ||
* jQuery is defined as a Webpack external, thus this import uses the externally defined jquery dependency. | ||
*/ | ||
import 'jquery'; | ||
|
||
import 'popper.js'; | ||
import 'bootstrap'; | ||
|
||
import './../scss/index.scss'; | ||
|
||
function addTOCInteractivity() { | ||
// TOC sidebar - add "active" class to parent list | ||
// | ||
// Bootstrap's scrollspy adds the active class to the <a> link, | ||
// but for the automatic collapsing we need this on the parent list item. | ||
// | ||
// The event is triggered on "window" (and not the nav item as documented), | ||
// see https://github.com/twbs/bootstrap/issues/20086 | ||
$(window).on('activate.bs.scrollspy', function () { | ||
const navLinks = document.querySelectorAll('#bd-toc-nav a'); | ||
|
||
navLinks.forEach((navLink) => { | ||
navLink.parentElement.classList.remove('active'); | ||
}); | ||
|
||
navLinks.forEach(navLink => { | ||
navLink.parentElement.classList.remove('active'); | ||
}) | ||
const activeNavLinks = document.querySelectorAll('#bd-toc-nav a.active'); | ||
activeNavLinks.forEach((navLink) => { | ||
navLink.parentElement.classList.add('active'); | ||
}); | ||
}); | ||
} | ||
|
||
const activeNavLinks = document.querySelectorAll('#bd-toc-nav a.active'); | ||
activeNavLinks.forEach(navLink => { | ||
navLink.parentElement.classList.add('active'); | ||
}) | ||
$(document).ready(() => { | ||
addTOCInteractivity(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters