Commit e195fc24 authored by Julie Blanc's avatar Julie Blanc
Browse files

[notes-float] check if note exist already to a previous note-area

parent 977a070d
......@@ -187,30 +187,47 @@ class NotesFloat extends Paged.Handler {
return;
}
// Check if note already exists for overflow
let existing = notesArea.querySelector(`[data-ref="${node.dataset.ref}"]`);
if (existing) {
// Remove the note from the flow but no need to render it again
node.remove();
return;
// store the data-id of the note in a set
let noteId = node.dataset.id;
if(!this.notesId.includes(noteId)){
this.notesId.push(noteId);
}
// Add the note node
let noteContainer = parent.querySelector('.pagedjs_notes-area_content');
noteContainer.appendChild(node);
// change the positionning of the note
node.style.position = 'relative';
node.style.display = 'block';
// 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';
// to check if it has already added to a previous note-area
if(!document.querySelectorAll('.pagedjs_notes-area [data-id="' + noteId + '"]').length >= 1){
// Check if note already exists for overflow
let existing = notesArea.querySelector(`[data-ref="${node.dataset.ref}"]`);
if (existing) {
// Remove the note from the flow but no need to render it again
node.remove();
return;
}
// Add the note node
let noteContainer = parent.querySelector('.pagedjs_notes-area_content');
noteContainer.appendChild(node);
// change the positionning of the note
node.style.position = 'relative';
node.style.display = 'block';
// 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{
// 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