Dynamically load Jquery.js and Bootstrap.js

This commit is contained in:
2020-12-01 17:20:53 +01:00
parent f9efb73c87
commit 2d266366bb
5 changed files with 340 additions and 261 deletions

View File

@@ -1,7 +1,3 @@
// var $ = require('jquery');
// window.$ = $;
// require('bootstrap');
//
// Blocks
docReady(function() {
var boxesNames = {
@@ -76,6 +72,51 @@ function docReady(fn) {
}
}
// Load Jquery
var scr = document.createElement('script'),
head = document.head || document.getElementsByTagName('head')[0];
scr.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js';
scr.async = false; // optionally
head.insertBefore(scr, head.firstChild);
// Load Bootstrap.js
var scr = document.createElement('script'),
head = document.head || document.getElementsByTagName('head')[0];
scr.src = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js';
scr.async = false; // optionally
head.insertBefore(scr, head.firstChild);
// After it is loaded
scr.addEventListener('load', () => {
$(document).ready(function() {
$('#text-table-of-contents ul').first().addClass('nav');
// ScrollSpy also requires that we use
// a Bootstrap nav component.
$('body').scrollspy({target: '#text-table-of-contents'});
// set the height of tableOfContents
var $postamble = $('#postamble');
var $tableOfContents = $('#table-of-contents');
$tableOfContents.css({paddingBottom: $postamble.outerHeight()});
// add TOC button
var toggleSidebar = $('<div id="toggle-sidebar"><a href="#table-of-contents"><h2>Table of Contents</h2></a></div>');
$('#content').prepend(toggleSidebar);
// add close button when sidebar showed in mobile screen
var closeBtn = $('<a class="close-sidebar" href="#">Close</a>');
var tocTitle = $('#table-of-contents').find('h2');
tocTitle.append(closeBtn);
});
})
// function collapse_toc_elements_on_click (nav_li_a){
// /*
// When an `a' element in the TOC is clicked, its parent
@@ -121,9 +162,6 @@ function docReady(fn) {
// // a Bootstrap nav component.
// $('body').scrollspy({target: '#text-table-of-contents'});
// // DON'T add sticky table headers (Fix issue #69?)
// // $('table').stickyTableHeaders();
// // set the height of tableOfContents
// var $postamble = $('#postamble');
// var $tableOfContents = $('#table-of-contents');