walter-boente_book-collection/js/addPagesNotes.js

90 lines
3.4 KiB
JavaScript
Raw Normal View History

2026-04-16 10:35:30 +02:00
import { Handler } from '/csspageweaver/lib/paged.esm.js';
export default class addPagesNotes extends Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
2026-04-16 16:00:53 +02:00
afterParsed(parsed){
let notes = parsed.querySelectorAll(".inline-note");
notes.forEach(function (note, index) {
2026-04-16 18:15:07 +02:00
// console.log(note);
2026-04-16 16:00:53 +02:00
note.style.position = "absolute";
note.style.top = "0px";
note.style.left = "0px";
note.style.height = "0px";
let counter = note.getAttribute('data-counter-note');
let call = document.createElement('span');
call.classList.add('note_call');
call.textContent = counter;
note.insertAdjacentElement('beforebegin', call);
note.classList.replace('inline-note', 'body-note');
let marker = document.createElement('span');
marker.classList.add('note_marker');
marker.textContent = counter + ". ";
note.prepend(marker);
});
}
2026-04-16 10:35:30 +02:00
afterPageLayout(pageElement, page, breakToken, chunker) {
2026-04-16 16:00:53 +02:00
2026-04-16 18:15:07 +02:00
// add class if page contains h1
if (pageElement.querySelector('h1')) {
pageElement.classList.add('page-with-h1');
}
2026-04-16 16:00:53 +02:00
// move notes into previous page
let notes = pageElement.querySelectorAll(".body-note");
if(notes){
let container = document.createElement('div');
container.classList.add('container-note');
notes.forEach(function (note, index) {
2026-04-16 17:42:46 +02:00
container.appendChild(note);
2026-04-16 16:00:53 +02:00
note.style.position = "relative";
note.style.height = "auto";
2026-04-16 17:42:46 +02:00
if (note.getAttribute('data-counter-note') === '1') {
container.classList.add('container-note-first');
}
2026-04-16 16:00:53 +02:00
});
let pageNum = parseInt(pageElement.getAttribute('data-page-number'));
let prevPage = document.querySelector('[data-page-number="' + (pageNum - 1) + '"]');
if (prevPage) {
2026-04-16 18:15:07 +02:00
let content = prevPage.querySelector('[data-id="section__content"]');
let contentId = prevPage.querySelector('#section__content');
2026-04-16 16:00:53 +02:00
if(content){
content.appendChild(container);
2026-04-16 18:15:07 +02:00
}else if(contentId){
contentId.appendChild(container);
2026-04-16 16:00:53 +02:00
}else{
prevPage.querySelector('.pagedjs_page_content').appendChild(container);
}
}
}
// create blank left page
if (
page.element.classList.contains('pagedjs_right_page') &&
2026-04-16 18:15:07 +02:00
page.element.querySelector('[data-id="section__content"]') &&
!pageElement.querySelector('.before-h1')
2026-04-16 16:00:53 +02:00
) {
let notesPage = chunker.addPage();
notesPage.element.classList.add('page-notes');
// Make margin boxes visible (hasContent is set during polishing, which skips added pages)
notesPage.element.querySelector('.pagedjs_margin-bottom-left')?.classList.add('hasContent');
notesPage.element.querySelector('.pagedjs_margin-bottom-center')?.classList.add('hasContent');
2026-04-16 10:35:30 +02:00
}
}
}