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

use vendor libraries from npm and various fixes #3066

Merged
merged 28 commits into from
May 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7002d5e
update Dockerfile to make hadolint happy
haarg Apr 28, 2024
e305ccf
improve asset build script and add clean option
haarg Apr 28, 2024
e7e5226
use explicitly relative paths when loading less files
haarg May 13, 2024
0d8d64c
clean up autocomplete css whitespace
haarg May 12, 2024
d8f4e44
fontawesome from npm
haarg Apr 28, 2024
8f17b6b
bootstrap from npm
haarg Apr 28, 2024
e5b8632
rewrite login, logout, and user data processing javascript
haarg May 12, 2024
0f86e38
rewrite favorite handling to avoid inline code
haarg May 12, 2024
6a530d7
fix favorite error handling
haarg May 12, 2024
d7e1e98
update dropdown navigations to avoid inline scripts
haarg May 12, 2024
da5186f
convert relatizeDate from jQuery to normal required library
haarg May 12, 2024
9c06bdb
move client side storage to a separate library
haarg May 12, 2024
1936eeb
use tablesorter from npm
haarg May 12, 2024
96db561
mousetrap from npm
haarg May 12, 2024
0add62f
autocomplete from npm
haarg May 12, 2024
1703370
qtip2 from npm
haarg May 13, 2024
453cead
use for of loop rather than forEach for dropdown
haarg May 13, 2024
8222408
fix syntax highlighter to work in strict mode
haarg May 13, 2024
7b8db5c
convert javascript code to be an esm
haarg May 13, 2024
82fec3f
syntaxhighlighter from npm
haarg May 13, 2024
8196741
move table of contents and anchor js to separate file
haarg May 13, 2024
67f8e01
move pod2html js to separate file
haarg May 13, 2024
a02c882
remove most uses of jQuery from GitHub popup
haarg May 13, 2024
cc4fc5e
fix profile accept donations checkbox
haarg May 13, 2024
fa5f860
fix changes collapsing/expanding
haarg May 13, 2024
d98d06d
fix contributors display button
haarg May 13, 2024
5b3fc5d
remove extra injections of jQuery that are no longer needed
haarg May 14, 2024
4380596
remove some no longer used js functions
haarg May 14, 2024
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
Prev Previous commit
Next Next commit
move table of contents and anchor js to separate file
haarg committed May 17, 2024
commit 8196741e96e02cef492771d5f346450413a42664
23 changes: 9 additions & 14 deletions root/static/js/cpan.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@
const relatizeDate = require('./relatize_date.js');
const storage = require('./storage.js');
const Mousetrap = require('mousetrap');
const {
formatTOC,
createAnchors
} = require('./document-ui.mjs');

// Store global data in this object
var MetaCPAN = {};
@@ -151,16 +155,7 @@ $(document).ready(function() {
element.insertBefore(start, end);
}

function create_anchors(top) {
top.find('h1,h2,h3,h4,h5,h6,dt').each(function() {
if (this.id) {
$(document.createElement('a')).attr('href', '#' + this.id).addClass('anchor').append(
$(document.createElement('span')).addClass('fa fa-bookmark black')
).prependTo(this);
}
});
}
create_anchors($('.anchors'));
createAnchors(document.querySelectorAll('.anchors'));

for (const favButton of document.querySelectorAll('.breadcrumbs .favorite')) {
setFavTitle(favButton);
@@ -213,9 +208,9 @@ $(document).ready(function() {
});
}

let toc = document.querySelector(".content .toc")
const toc = document.querySelector(".content .toc")
if (toc) {
format_toc(toc);
formatTOC(toc);
}

$('a[href*="/search?"]').on('click', function() {
@@ -340,9 +335,9 @@ $(document).ready(function() {
);
var toc = $("nav", rendered);
if (toc.length) {
format_toc(toc[0]);
formatTOC(toc[0]);
}
create_anchors(rendered);
createAnchors(rendered);
loading.hide();
error.hide();
rendered.show();
67 changes: 67 additions & 0 deletions root/static/js/document-ui.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import storage from './storage.js';

export const createAnchors = (topList) => {
const it = typeof (topList)[Symbol.iterator] === 'function' ? topList : [topList];
for (const top of it) {
for (const heading of top.querySelectorAll(':scope h1,h2,h3,h4,h5,h6,dt')) {
const id = heading.id;
if (!id) {
continue;
}

const link = document.createElement('a');
link.href = '#' + id;
link.classList.add('anchor');

const icon = document.createElement('span');
icon.classList.add('fa', 'fa-bookmark', 'black');
link.append(icon);

heading.prepend(link);
}
}
}

export const formatTOC = (toc) => {
if (storage.getItem('hideTOC') == 1) {
toc.classList.add("hide-toc");
}

const toc_header = toc.querySelector('.toc-header');
const toc_body = toc.querySelector('ul');

toc_header.insertAdjacentHTML('beforeend',
' [ <button class="btn-link toggle-toc"><span class="toggle-show">show</span><span class="toggle-hide">hide</span></button> ]'
);
toc_header.querySelector('.toggle-toc').addEventListener('click', e => {
e.preventDefault();
const currentVisible = !toc.classList.contains('hide-toc');
storage.setItem('hideTOC', currentVisible ? 1 : 0);

const fullHeight = toc_body.scrollHeight;

if (currentVisible) {
const trans = toc_body.style.transition;
toc_body.style.transition = '';

requestAnimationFrame(() => {
toc_body.style.height = fullHeight + 'px';
toc_body.style.transition = trans;
toc.classList.toggle('hide-toc');

requestAnimationFrame(() => {
toc_body.style.height = null;
});
});
} else {
const finish = e => {
toc_body.removeEventListener('transitionend', finish);
toc_body.style.height = null;
};

toc_body.addEventListener('transitionend', finish);
toc_body.style.height = fullHeight + 'px';
toc.classList.toggle('hide-toc');
}
});
};