123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- // passage des notes du texte à la fin de la partie
- if (debug) console.log('start footnotes');
- (function() {
- // détecter la partie des notes
- function findH3InAncestorsAndSiblings(element, findNext) {
- let currentElement = element;
- let siblingSelector = findNext ? 'nextElementSibling' : 'previousElementSibling';
-
- while (currentElement !== null) {
- if (currentElement.tagName === 'H3') {
- return currentElement;
- }
- currentElement = currentElement.parentElement;
- }
-
- currentElement = element;
-
- while (currentElement !== null) {
- let sibling = currentElement[siblingSelector];
- while (sibling !== null) {
- if (sibling.tagName === 'H3') {
- return sibling;
- }
- let descendantH3 = sibling.querySelector('h3');
- if (descendantH3 !== null) {
- return descendantH3;
- }
- sibling = sibling[siblingSelector];
- }
- currentElement = currentElement.parentElement;
- }
-
- return null;
- }
-
- // note dans le texte ou note d'image
- function isImgNote(note) {
- if (
- note.parentElement.classList.contains('imgsmall') ||
- note.parentElement.classList.contains('imgsmallsmall') ||
- note.parentElement.classList.contains('imgsmall_bottom') ||
- note.parentElement.classList.contains('fullpage2imgs') ||
- note.parentElement.classList.contains('fullpageimage') ||
- note.parentElement.classList.contains('tripleimgs') ||
- note.parentElement.classList.contains('tripleimgs_bottom') ||
- note.parentElement.classList.contains('tripleimgs2') ||
- note.parentElement.classList.contains('tripleimgs2_bottom') ||
- note.parentElement.classList.contains('bottomimg') ||
- note.parentElement.classList.contains('imgfullspreadleft') ||
- note.parentElement.classList.contains('imgfullspreadright') ||
- note.parentElement.classList.contains('imgfullspreadright_bleedtop') ||
- note.parentElement.classList.contains('imgfullspreadright_bleed') ||
- note.parentElement.classList.contains('doublepage_bigright') ||
- note.parentElement.classList.contains('doublepage_bigleft')
- ) {
- return true;
- } else {
- return false;
- }
- }
-
- // notes
- let noteNumber = 1;
- let prevPartie;
- let partie = 0;
- let notes = document.querySelectorAll('.note');
- let noteTitleNextEl;
- let notesContent = [];
-
- for (let note of notes) {
- let currentPartie = findH3InAncestorsAndSiblings(note, false);
- let noteContent = note.innerText;
-
- if (currentPartie === prevPartie) {
- noteNumber++;
- } else {
- // créer la page des notes
- let notePageTitle = document.createElement('h4');
- notePageTitle.innerText = "Notes";
- // insert before the next partie page
- findH3InAncestorsAndSiblings(note, true).parentNode.insertBefore(notePageTitle, findH3InAncestorsAndSiblings(note, true));
- noteNumber = 1;
- notesContent = [];
- partie++;
- notePageTitle.setAttribute('id', 'note_page_title_' + partie);
- noteTitleNextEl = document.getElementById(`note_page_title_${partie}`).nextElementSibling;
- let notesContentEl = document.createElement('div');
- notesContentEl.setAttribute('id', `notes_content_${partie}`);
- notesContentEl.classList.add('note_text');
- noteTitleNextEl.parentNode.insertBefore(notesContentEl, noteTitleNextEl);
- }
- if (!notesContent.includes(noteContent)) {
- notesContent.push(noteContent);
- let noteTextEl = document.createElement('p');
- noteTextEl.setAttribute('class', 'note_text');
- noteTextEl.innerHTML = `<p class="note_content_${ notesContent.length }"><span class="note_texte_number">` + noteNumber + '</span><span> ' + noteContent + '</span></p>';
- let notesContentEl = document.getElementById(`notes_content_${partie}`);
- notesContentEl.append(noteTextEl);
- } else {
- let notesPageEl = document.querySelector(`#notes_content_${partie}`);
- let noteContentEl = notesPageEl.querySelector(`.note_content_${notesContent.indexOf(noteContent) + 1}`);
- console.log(noteContentEl);
- let spanToAdd = document.createElement('span');
- spanToAdd.classList.add('note_texte_number');
- spanToAdd.innerText = `, ${ noteNumber }`;
- let lastSpan = noteContentEl.lastElementChild.previousElementSibling;
- console.log(lastSpan, spanToAdd, noteContent);
- lastSpan.append(spanToAdd);
- }
- prevPartie = currentPartie;
-
- if (isImgNote(note)) {
- note.innerText = '';
- note.classList.add('note_img');
- note.setAttribute('id', `note_img_${noteNumber}`);
- } else {
- note.innerText = noteNumber;
- }
- }
- })();
- if (debug) console.log('end footnotes');
|