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

[DISC-18903] Remove jquery and hanging javascript assets. #22014

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
98 changes: 0 additions & 98 deletions docs/_assets/css/toolbar.css

This file was deleted.

6 changes: 0 additions & 6 deletions docs/_assets/js/sidebar.js

This file was deleted.

26 changes: 0 additions & 26 deletions docs/_assets/js/toolbar.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/_spec/_layouts/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
<!-- need to use include to see value of page.chapter variable -->
<style type="text/css">
Expand Down
1 change: 0 additions & 1 deletion docs/_spec/_layouts/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<link rel="icon" type="image/png" href="public/favicon.ico">
<link rel="shortcut icon" type="image/png" href="public/favicon.ico">

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<title>{{ page.title }} | Scala {{ site.thisScalaVersion }}</title>

<link rel="stylesheet" type="text/css" href="public/stylesheets/screen.css">
Expand Down
18 changes: 11 additions & 7 deletions docs/_spec/public/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function currentChapter() {
return parseInt(document.location.pathname.split('/').pop().substr(0, 2), 10);
}

function heading(i, heading, $heading) {
function heading(i, heading) {
const currentLevel = parseInt(heading.tagName.substring(1));

if (currentLevel === this.headerLevel) {
Expand All @@ -19,12 +19,12 @@ function heading(i, heading, $heading) {
this.headerCounts[this.headerLevel] = 1;
}
}
return `${this.headerCounts[this.headerLevel]} ${$heading.text()}`;
return `${this.headerCounts[this.headerLevel]} ${heading.innerText}`;
}

// ignore when using wkhtmltopdf, or it won't work...
if (window.jekyllEnv !== 'spec-pdf') {
$('#toc').toc(
addTOC(document.getElementById('toc'),
{
'selectors': 'h1,h2,h3',
'smoothScrolling': false,
Expand Down Expand Up @@ -53,12 +53,16 @@ document.addEventListener("DOMContentLoaded", function() {
// syntax highlighting after KaTeX is loaded,
// so that math can be used in code blocks
hljs.initHighlighting();
$("pre nobr").addClass("fixws");
document.querySelectorAll("pre nobr").forEach((element) => {
element.classList.add("fixws")
});

// point when all necessary js is done, so PDF to be rendered
window.status = "loaded";
});

$("#chapters a").each(function (index) {
const href = $(this).attr("href");
$(this).toggleClass("chapter-active", document.location.pathname.endsWith(href));
document.querySelectorAll("#chapters a").forEach(function (element) {
const href = element.attributes.getNamedItem("href");
const toggle = href != null && document.location.pathname.endsWith(href.value);
element.classList.toggle("chapter-active", toggle);
});
128 changes: 63 additions & 65 deletions docs/_spec/public/scripts/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,94 @@
* copyright Greg Allen 2014
* MIT License
*/
(function($) {
var verboseIdCache = {};
$.fn.toc = function(options) {
var self = this;
var opts = $.extend({}, jQuery.fn.toc.defaults, options);

var container = $(opts.container);
var headings = $(opts.selectors, container);
/* The following ports the jquery plugin to modern javascript. */

/***
* Add table of contents links to the given TOC container.
* @param {HTMLElement} domElement - The DOM element to manipulate
* @param {Object} options - A list of options to change TOC_DEFAULTS.
* @return {HTMLElement} - The same tocContainer for chaining.
*/
function addTOC(tocContainer, options) {
var verboseIdCache = {};
// Since options are only one level of nesting deep,
// we use the spread syntax to merge.
var opts = {...TOC_DEFAULTS, ...options};
var container = document.querySelector(opts.container);
var headings = container.querySelectorAll(opts.selectors);
var headingOffsets = [];
var activeClassName = opts.activeClass;

var scrollTo = function(e, callback) {
$('li', self).removeClass(activeClassName);
$(e.target).parent().addClass(activeClassName);
tocContainer.querySelectorAll('li').forEach(function (element) {
element.classList.remove(activeClassName);
});
e.parentNode.classList.add(activeClassName);
};

//highlight on scroll
var timeout;
var highlightOnScroll = function(e) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
var top = $(window).scrollTop(),
var top = window.pageYOffset,
highlighted, closest = Number.MAX_VALUE, index = 0;

for (var i = 0, c = headingOffsets.length; i < c; i++) {
var currentClosest = Math.abs(headingOffsets[i] - top);
if (currentClosest < closest) {
index = i;
closest = currentClosest;
}
}

$('li', self).removeClass(activeClassName);
highlighted = $('li:eq('+ index +')', self).addClass(activeClassName);
opts.onHighlight(highlighted);
tocContainer.querySelectorAll('li').forEach(function (element) {
element.classList.remove(activeClassName);
});
highlighted = tocContainer.querySelector('li:nth-child(' + index + ')')
if (highlighted != null) { highlighted.classList.add(activeClassName); }
opts.onHighlight(highlighted);
}, 50);
};

if (opts.highlightOnScroll) {
$(window).on('scroll', highlightOnScroll);
window.addEventListener('scroll', highlightOnScroll);
highlightOnScroll();
}

return this.each(function() {
//build TOC
var el = $(this);
var ul = $(opts.listType);

headings.each(function(i, heading) {
var $h = $(heading);
headingOffsets.push($h.offset().top - opts.highlightOffset);

var anchorName = opts.anchorName(i, heading, opts.prefix);

//add anchor
if(heading.id !== anchorName) {
var anchor = $('<span/>').attr('id', anchorName).insertBefore($h);
}

//build TOC item
var a = $('<a/>')
.text(opts.headerText(i, heading, $h))
.attr('href', '#' + anchorName)
.on('click', function(e) {
$(window).off('scroll', highlightOnScroll);
scrollTo(e, function() {
$(window).on('scroll', highlightOnScroll);
});
el.trigger('selected', $(this).attr('href'));
});

var li = $('<li/>')
.addClass(opts.itemClass(i, heading, $h, opts.prefix))
.append(a);
const listTypeRegex = new RegExp("<(.*)/>");
const listTypeToTagName = listTypeRegex.exec(opts.listType);
if (listTypeToTagName == null) { return tocContainer; }
var ul = document.createElement(listTypeToTagName[1]);
headings.forEach(function(heading, i) {
headingOffsets.push(heading.getBoundingClientRect().top - opts.highlightOffset);
var anchorName = opts.anchorName(i, heading, opts.prefix);
if(heading.id !== anchorName) {
var anchor = document.createElement("span");
anchor.setAttribute('id', anchorName);
heading.parentNode.insertBefore(anchor, heading);
}

ul.append(li);
var a = document.createElement("a");
a.textContent = opts.headerText(i, heading);
a.setAttribute('href', '#' + anchorName);
a.addEventListener('click', () => {
window.removeEventListener('scroll', highlightOnScroll);
scrollTo(a, function() {
// Kept bug from jquery version: callback isn't called, so scroll event listener not re-attached.
window.addEventListener('scroll', highlightOnScroll);
});
// Research suggests this is a now unused custom event. Won't translate.
// el.trigger('selected', $(this).attr('href'))
});
el.html(ul);
var li = document.createElement('li');
li.classList.add(opts.itemClass(i, heading, opts.prefix));
li.append(a);
ul.append(li);
});
};

tocContainer.replaceChildren(ul);
}

jQuery.fn.toc.defaults = {
const TOC_DEFAULTS = {
container: 'body',
listType: '<ul/>',
selectors: 'h1,h2,h3',
Expand All @@ -101,28 +105,22 @@ jQuery.fn.toc.defaults = {
if(heading.id.length) {
return heading.id;
}

var candidateId = $(heading).text().replace(/[^a-z0-9]/ig, ' ').replace(/\s+/g, '-').toLowerCase();
var candidateId = heading.innerText.replace(/[^a-z0-9]/ig, ' ').replace(/\s+/g, '-').toLowerCase();
if (verboseIdCache[candidateId]) {
var j = 2;

while(verboseIdCache[candidateId + j]) {
j++;
}
candidateId = candidateId + '-' + j;

}
verboseIdCache[candidateId] = true;

return prefix + '-' + candidateId;
},
headerText: function(i, heading, $heading) {
return $heading.text();
headerText: function(i, heading) {
return heading.innerText();
},
itemClass: function(i, heading, $heading, prefix) {
return prefix + '-' + $heading[0].tagName.toLowerCase();
itemClass: function(i, heading, prefix) {
return prefix + '-' + heading.tagName.toLowerCase();
}

};

})(jQuery);
Loading
Loading