Commit 8dcbe84d authored by Julie Blanc's avatar Julie Blanc
Browse files

[notes-float] check if note already exist in note area

parent 3d305195
......@@ -69,6 +69,7 @@ function addStyleNotesArea({width, positionLeft, positionRight}){
class NotesFloat extends Paged.Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
this.notesId = [];
this.notesConfig = {
positionLeft: 'bottom left',
positionRight: 'bottom right',
......@@ -93,37 +94,58 @@ class NotesFloat extends Paged.Handler {
if (
node.nodeType === 1 &&
(node.querySelector(`.${NOTE_CLASS}`) || node.className.includes(NOTE_CLASS))
// to do here: check if the paragraph with a note is going to be chuncked
// if it's the case : check if the note is on first part of the paragraph or the second
) {
const note = node.querySelector(`.${NOTE_CLASS}`) || node;
// change the positionning of the note
note.style.position = 'relative';
note.style.display = 'block';
// @todo here : store the data-id of the note in a set
// to check if it has already added to the notes-area
// store the data-id of the note in a set
let noteId = note.dataset.id;
if(!this.notesId.includes(noteId)){
this.notesId.push(noteId);
}
// find page content
const parent = node.closest('.pagedjs_page_content');
let notesArea = document.createElement('div');
notesArea.className = 'pagedjs_notes-area';
// if page content has no notes area then create it
if (parent.querySelector('.pagedjs_notes-area') === null) {
parent.insertBefore(notesArea, parent.children[0]);
notesArea.style.width = this.notesConfig.width;
// to check if it has already added to a notes-area
if(!document.querySelectorAll('.pagedjs_notes-area [data-id="' + noteId + '"]').length >= 1){
console.log("note doesn't exist");
// find page content
const parent = node.closest('.pagedjs_page_content');
let notesArea = document.createElement('div');
notesArea.className = 'pagedjs_notes-area';
// if page content has no notes area then create it
if (parent.querySelector('.pagedjs_notes-area') === null) {
parent.insertBefore(notesArea, parent.children[0]);
notesArea.style.width = this.notesConfig.width;
} else {
notesArea = parent.querySelector('.pagedjs_notes-area');
}
// move the note to the container
notesArea.appendChild(note);
// find if we are on the left or right page
const page = node.closest('.pagedjs_page');
const isLeft = page.className.includes('pagedjs_left_page');
// find if this page has position bottom
const pageConf = isLeft ? this.notesConfig['positionLeft'] : this.notesConfig['positionRight'];
// if so displace the height of the element
if (pageConf.includes('bottom')) {
notesArea.style.marginTop = parent.offsetHeight - notesArea.clientHeight + 'px';
}
} else {
notesArea = parent.querySelector('.pagedjs_notes-area');
}
// move the note to the container
notesArea.appendChild(note);
// find if we are on the left or right page
const page = node.closest('.pagedjs_page');
const isLeft = page.className.includes('pagedjs_left_page');
// find if this page has position bottom
const pageConf = isLeft ? this.notesConfig['positionLeft'] : this.notesConfig['positionRight'];
// if so displace the height of the element
if (pageConf.includes('bottom')) {
notesArea.style.marginTop = parent.offsetHeight - notesArea.offsetHeight + 1 + 'px';
// remove the note if already exist
node.remove();
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment