2022-03-28 00:56:00 +02:00
|
|
|
var windowWidth = window.innerWidth;
|
2022-05-10 23:57:53 +02:00
|
|
|
var menu = null;
|
|
|
|
var menuOffcanvas = null;
|
2022-03-30 09:52:09 +02:00
|
|
|
var is_mobile = function() {
|
|
|
|
return !(window.getComputedStyle(document.getElementById('is_mobile')).display === "none");
|
|
|
|
};
|
2022-10-11 02:08:34 +02:00
|
|
|
var hasTouch = function() {
|
|
|
|
return 'ontouchstart' in document.documentElement
|
|
|
|
|| navigator.maxTouchPoints > 0
|
|
|
|
|| navigator.msMaxTouchPoints > 0;
|
|
|
|
}
|
|
|
|
var disabledHoverStyle = function() {
|
|
|
|
try { // prevent exception on browsers not supporting DOM styleSheets properly
|
|
|
|
for (var si in document.styleSheets) {
|
|
|
|
var styleSheet = document.styleSheets[si];
|
|
|
|
if (!styleSheet.rules) continue;
|
|
|
|
|
|
|
|
for (var ri = styleSheet.rules.length - 1; ri >= 0; ri--) {
|
|
|
|
if (!styleSheet.rules[ri].selectorText) continue;
|
|
|
|
|
|
|
|
if (styleSheet.rules[ri].selectorText.match(':hover')) {
|
|
|
|
styleSheet.deleteRule(ri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
}
|
2022-05-10 23:57:53 +02:00
|
|
|
var responsiveDisplay = function() {
|
|
|
|
if(is_mobile()) {
|
|
|
|
document.getElementById('page-organization').style.paddingRight = "inherit";
|
|
|
|
menu.classList.remove('show');
|
|
|
|
menuOffcanvas.hide();
|
|
|
|
document.getElementById('container-pages').classList.remove('vh-100');
|
2022-05-24 00:43:34 +02:00
|
|
|
document.getElementById('container-btn-zoom').style.top = '62px';
|
|
|
|
document.getElementById('container-btn-zoom').style.right = '6px';
|
2022-10-07 23:45:33 +02:00
|
|
|
document.getElementById('container-btn-zoom').classList.add('d-none');
|
2022-05-10 23:57:53 +02:00
|
|
|
} else {
|
|
|
|
menuOffcanvas.show();
|
|
|
|
document.getElementById('page-organization').style.paddingRight = "350px";
|
|
|
|
document.getElementById('container-pages').classList.add('vh-100');
|
2022-05-24 00:43:34 +02:00
|
|
|
document.getElementById('container-btn-zoom').style.top = '6px';
|
|
|
|
document.getElementById('container-btn-zoom').style.right = '368px';
|
2022-10-07 23:45:33 +02:00
|
|
|
document.getElementById('container-btn-zoom').classList.remove('d-none');
|
2022-05-10 23:57:53 +02:00
|
|
|
}
|
|
|
|
menu.classList.remove('d-md-block');
|
|
|
|
menu.classList.remove('d-none');
|
|
|
|
};
|
2022-05-11 00:57:49 +02:00
|
|
|
var isSelectionMode = function() {
|
|
|
|
return document.querySelectorAll('.canvas-container .input-select:checked').length > 0;
|
|
|
|
}
|
2022-05-31 01:27:13 +02:00
|
|
|
var isDraggedMode = function() {
|
|
|
|
return document.querySelectorAll('.canvas-container .input-drag:checked').length > 0;
|
|
|
|
}
|
2022-05-10 23:57:53 +02:00
|
|
|
|
2022-03-30 10:12:57 +02:00
|
|
|
var nbPagePerLine = 5;
|
2022-03-30 09:52:09 +02:00
|
|
|
if(is_mobile()) {
|
2022-10-08 10:57:39 +02:00
|
|
|
nbPagePerLine = 2;
|
2022-03-30 09:52:09 +02:00
|
|
|
}
|
2022-03-31 01:46:45 +02:00
|
|
|
var pdfjsLib = window['pdfjs-dist/build/pdf'];
|
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = '/vendor/pdf.worker.js?legacy';
|
|
|
|
var nbPDF = 0;
|
2022-04-05 01:11:03 +02:00
|
|
|
var pages = [];
|
2022-05-07 02:06:30 +02:00
|
|
|
var pdfRenderTasks = [];
|
2022-03-28 00:56:00 +02:00
|
|
|
|
2022-03-31 01:46:45 +02:00
|
|
|
var loadPDF = async function(pdfBlob, filename, pdfIndex) {
|
2022-03-28 00:56:00 +02:00
|
|
|
let url = await URL.createObjectURL(pdfBlob);
|
|
|
|
|
|
|
|
let dataTransfer = new DataTransfer();
|
2022-04-04 00:53:24 +02:00
|
|
|
let i = 0;
|
|
|
|
for (i = 0; i < document.getElementById('input_pdf').files.length; i++) {
|
2022-03-31 01:46:45 +02:00
|
|
|
dataTransfer.items.add(document.getElementById('input_pdf').files[i]);
|
|
|
|
}
|
2022-03-28 00:56:00 +02:00
|
|
|
dataTransfer.items.add(new File([pdfBlob], filename, {
|
|
|
|
type: 'application/pdf'
|
|
|
|
}));
|
|
|
|
document.getElementById('input_pdf').files = dataTransfer.files;
|
2022-04-28 19:13:45 +02:00
|
|
|
updateListePDF();
|
2022-03-28 00:56:00 +02:00
|
|
|
|
2022-04-04 00:53:24 +02:00
|
|
|
let pdfLetter = String.fromCharCode(96 + i+1).toUpperCase();
|
|
|
|
|
2022-03-31 01:46:45 +02:00
|
|
|
let loadingTask = pdfjsLib.getDocument(url);
|
2022-05-23 23:57:14 +02:00
|
|
|
await loadingTask.promise.then(function(pdf) {
|
2022-03-28 00:56:00 +02:00
|
|
|
for(var pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) {
|
|
|
|
pdf.getPage(pageNumber).then(function(page) {
|
2022-04-05 01:11:03 +02:00
|
|
|
let pageIndex = pdfLetter + "_" + (page.pageNumber - 1);
|
|
|
|
pages[pageIndex] = page;
|
2022-03-28 00:56:00 +02:00
|
|
|
|
2022-05-11 08:04:20 +02:00
|
|
|
let pageHTML = '<div class="position-relative mt-0 ms-1 me-0 mb-1 canvas-container d-flex align-items-center justify-content-center bg-transparent bg-opacity-25 border border-2 border-transparent" id="canvas-container-' + pageIndex +'" draggable="true">';
|
|
|
|
pageHTML += '<canvas class="canvas-pdf shadow-sm"></canvas>';
|
2022-05-18 01:28:00 +02:00
|
|
|
pageHTML += '<div title="Séléctionner cette page" class="position-absolute top-0 start-50 translate-middle-x p-2 ps-3 pe-3 mt-2 rounded-circle btn-select d-none"><i class="bi bi-check-square"></i></div>';
|
|
|
|
pageHTML += '<div title="Supprimer cette page" class="position-absolute top-50 start-0 translate-middle-y p-2 ps-3 pe-3 ms-2 rounded-circle btn-delete d-none"><i class="bi bi-trash"></i></div>';
|
2022-05-18 01:02:09 +02:00
|
|
|
pageHTML += '<div title="Restaurer cette page" class="position-absolute top-50 start-50 translate-middle p-2 ps-3 pe-3 rounded-circle container-resize btn-restore d-none"><i class="bi bi-recycle"></i></div>';
|
2022-05-18 01:28:00 +02:00
|
|
|
pageHTML += '<div title="Déplacer cette page" class="position-absolute top-50 start-50 translate-middle p-2 ps-3 pe-3 rounded-circle container-resize btn-drag d-none"><i class="bi bi-arrows-move"></i></div>';
|
2022-11-20 00:54:48 +01:00
|
|
|
pageHTML += '<div title="Déplacer ici" class="position-absolute start-0 top-50 translate-middle p-2 ps-3 pe-3 rounded-circle container-resize btn-drag-here-left bg-white shadow d-none" style="left: -5px !important;"><i class="bi bi-arrow-up-square"></i></div>';
|
|
|
|
pageHTML += '<div title="Déplacer ici" class="position-absolute start-100 top-50 translate-middle p-2 ps-3 pe-3 rounded-circle container-resize btn-drag-here-right bg-white shadow d-none" style="margin-left: 3px !important;"><i class="bi bi-arrow-up-square"></i></div>';
|
2022-10-08 01:07:49 +02:00
|
|
|
pageHTML += '<div title="Déplacer ici" class="position-absolute top-100 start-50 translate-middle p-2 ps-3 pe-3 rounded-circle container-resize btn-drag-here_mobile bg-white shadow d-none"><i class="bi bi-arrows-collapse"></i></div>';
|
2022-05-18 01:28:00 +02:00
|
|
|
pageHTML += '<div title="Tourner cette page" class="position-absolute top-50 end-0 translate-middle-y p-2 ps-3 pe-3 me-2 rounded-circle container-rotate btn-rotate d-none"><i class="bi bi-arrow-clockwise"></i></div>';
|
2022-05-18 01:39:38 +02:00
|
|
|
pageHTML += '<div title="Télécharger cette page" class="position-absolute bottom-0 start-50 translate-middle-x p-2 ps-3 pe-3 mb-3 rounded-circle btn-download d-none"><i class="bi bi-download"></i></div>';
|
2022-05-12 00:26:35 +02:00
|
|
|
pageHTML += '<p class="page-title position-absolute text-center w-100 ps-2 pe-2 pb-0 pt-0 mb-1 bg-white opacity-75 d-none" style="bottom: -4px; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden;">Page '+page.pageNumber+' - '+filename+'</p>';
|
2022-05-18 01:02:09 +02:00
|
|
|
pageHTML += '<input form="form_pdf" class="checkbox-page d-none" role="switch" type="checkbox" checked="checked" value="'+pdfLetter+page.pageNumber+'" />';
|
2022-05-06 00:18:36 +02:00
|
|
|
pageHTML += '<input type="hidden" class="input-rotate" value="0" id="input_rotate_'+pageIndex+'" />';
|
2022-05-06 00:44:15 +02:00
|
|
|
pageHTML += '<input type="checkbox" class="input-select d-none" value="'+pdfLetter+page.pageNumber+'" id="input_select_'+pageIndex+'" />';
|
2022-05-18 01:28:00 +02:00
|
|
|
pageHTML += '<input type="checkbox" class="input-hover d-none" value="'+pdfLetter+page.pageNumber+'" id="input_select_'+pageIndex+'" />';
|
2022-05-31 01:27:13 +02:00
|
|
|
pageHTML += '<input type="checkbox" class="input-drag d-none" value="'+pdfLetter+page.pageNumber+'" id="input_drag_'+pageIndex+'" />';
|
2022-05-06 00:18:36 +02:00
|
|
|
pageHTML += '</div>';
|
|
|
|
|
|
|
|
document.getElementById('container-pages').insertAdjacentHTML('beforeend', pageHTML);
|
2022-03-28 00:56:00 +02:00
|
|
|
|
2022-04-05 01:11:03 +02:00
|
|
|
let canvasContainer = document.getElementById('canvas-container-' + pageIndex);
|
2022-05-18 01:42:41 +02:00
|
|
|
canvasContainer.addEventListener('click', function(e) {
|
2022-10-07 23:45:33 +02:00
|
|
|
if(isPageDeleted(this) || isPageDragged(this)) {
|
2022-05-18 01:42:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-10-07 23:45:33 +02:00
|
|
|
canvasContainer.querySelector('.btn-select').click();
|
2022-05-18 01:42:41 +02:00
|
|
|
});
|
2022-05-12 00:26:35 +02:00
|
|
|
canvasContainer.addEventListener('mouseenter', function(e) {
|
2022-05-18 01:42:41 +02:00
|
|
|
if(is_mobile()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-18 01:28:00 +02:00
|
|
|
this.querySelector('input[type=checkbox].input-hover').checked = true;
|
|
|
|
updatePageState(this);
|
2022-05-12 00:26:35 +02:00
|
|
|
});
|
|
|
|
canvasContainer.addEventListener('mouseleave', function(e) {
|
2022-05-18 01:28:00 +02:00
|
|
|
this.querySelector('input[type=checkbox].input-hover').checked = false;
|
|
|
|
updatePageState(this);
|
2022-05-12 00:26:35 +02:00
|
|
|
});
|
2022-03-30 02:00:25 +02:00
|
|
|
canvasContainer.addEventListener('dragstart', function(e) {
|
2022-10-08 00:09:41 +02:00
|
|
|
if(is_mobile()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-10-09 01:51:38 +02:00
|
|
|
if(isDraggedMode()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-10-18 00:02:41 +02:00
|
|
|
if(isSelectionMode()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-31 00:25:16 +02:00
|
|
|
this.querySelector('.container-resize').classList.add('d-none');
|
2022-03-30 02:00:25 +02:00
|
|
|
this.querySelector('.canvas-pdf').classList.add('shadow-lg');
|
2022-03-31 00:25:16 +02:00
|
|
|
this.querySelector('.canvas-pdf').style.border = '2px dashed #777';
|
2022-03-30 02:00:25 +02:00
|
|
|
e.dataTransfer.setData('element', this.id);
|
2022-03-31 00:25:16 +02:00
|
|
|
this.style.opacity = 0.4;
|
2022-03-30 02:00:25 +02:00
|
|
|
});
|
|
|
|
canvasContainer.addEventListener('dragend', function(e) {
|
2022-03-31 00:25:16 +02:00
|
|
|
this.querySelector('.container-resize').classList.remove('d-none');
|
2022-03-30 02:00:25 +02:00
|
|
|
this.querySelector('.canvas-pdf').classList.remove('shadow-lg');
|
2022-05-31 01:27:13 +02:00
|
|
|
this.querySelector('.canvas-pdf').style.removeProperty('border');
|
2022-03-31 00:25:16 +02:00
|
|
|
this.style.opacity = 1;
|
2022-05-18 01:02:09 +02:00
|
|
|
updatePageState(this);
|
2022-03-30 02:00:25 +02:00
|
|
|
});
|
|
|
|
canvasContainer.addEventListener('dragover', function(e) {
|
|
|
|
if (e.preventDefault) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2022-10-07 10:47:13 +02:00
|
|
|
let pdfOver = this;
|
|
|
|
let pdfMoving = document.querySelector('#'+e.dataTransfer.getData('element'));
|
|
|
|
|
|
|
|
if(pdfOver.id == pdfMoving.id) {
|
|
|
|
|
|
|
|
return;
|
2022-10-07 01:41:30 +02:00
|
|
|
}
|
2022-10-07 10:47:13 +02:00
|
|
|
|
|
|
|
let leftRight = false;
|
|
|
|
let topBottom = false;
|
|
|
|
|
|
|
|
if(pdfOver.offsetTop < pdfMoving.offsetTop) {
|
|
|
|
topBottom = 'top';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pdfOver.offsetTop > pdfMoving.offsetTop) {
|
|
|
|
topBottom = 'bottom';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pdfOver.offsetLeft > pdfMoving.offsetLeft) {
|
|
|
|
leftRight = 'right';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pdfOver.offsetLeft < pdfMoving.offsetLeft) {
|
|
|
|
leftRight = 'left';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftRight == 'left' || topBottom == 'top') {
|
|
|
|
pdfOver.insertAdjacentElement('beforebegin', pdfMoving);
|
2022-10-07 01:41:30 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 10:47:13 +02:00
|
|
|
if (leftRight == 'right' || topBottom == 'bottom') {
|
|
|
|
pdfOver.insertAdjacentElement('afterend', pdfMoving);
|
2022-03-30 02:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2022-05-06 00:07:57 +02:00
|
|
|
canvasContainer.querySelector('.btn-delete').addEventListener('click', function(e) {
|
2022-10-07 19:50:25 +02:00
|
|
|
e.stopPropagation();
|
2022-05-18 01:02:09 +02:00
|
|
|
toggleDeletePage(this.parentNode);
|
|
|
|
});
|
|
|
|
canvasContainer.querySelector('.btn-restore').addEventListener('click', function(e) {
|
2022-10-07 19:50:25 +02:00
|
|
|
e.stopPropagation();
|
2022-05-18 01:02:09 +02:00
|
|
|
toggleDeletePage(this.parentNode);
|
2022-03-30 02:00:25 +02:00
|
|
|
});
|
2022-05-06 00:44:15 +02:00
|
|
|
canvasContainer.querySelector('.btn-select').addEventListener('click', function(e) {
|
2022-10-07 19:50:25 +02:00
|
|
|
e.stopPropagation();
|
2022-05-18 01:02:09 +02:00
|
|
|
toggleSelectPage(this.parentNode);
|
2022-05-06 00:44:15 +02:00
|
|
|
});
|
2022-05-31 01:27:13 +02:00
|
|
|
canvasContainer.querySelector('.btn-drag').addEventListener('click', function(e) {
|
2022-10-07 19:50:25 +02:00
|
|
|
e.stopPropagation();
|
2022-05-31 01:27:13 +02:00
|
|
|
toggleDragPage(this.parentNode);
|
|
|
|
});
|
2022-10-08 01:07:49 +02:00
|
|
|
canvasContainer.querySelector('.btn-drag-here_mobile').addEventListener('click', function(e) {
|
2022-10-08 01:20:21 +02:00
|
|
|
e.stopPropagation();
|
2022-10-09 00:44:04 +02:00
|
|
|
movePagesDragged(this.parentNode, 'right');
|
2022-10-08 01:07:49 +02:00
|
|
|
});
|
2022-10-09 00:04:44 +02:00
|
|
|
canvasContainer.querySelector('.btn-drag-here-right').addEventListener('click', function(e) {
|
|
|
|
e.stopPropagation();
|
2022-10-09 00:44:04 +02:00
|
|
|
movePagesDragged(this.parentNode, 'right');
|
2022-10-09 00:04:44 +02:00
|
|
|
});
|
|
|
|
canvasContainer.querySelector('.btn-drag-here-left').addEventListener('click', function(e) {
|
2022-10-08 01:07:49 +02:00
|
|
|
e.stopPropagation();
|
2022-10-09 00:44:04 +02:00
|
|
|
movePagesDragged(this.parentNode, 'left');
|
2022-05-31 01:27:13 +02:00
|
|
|
});
|
2022-05-07 01:14:52 +02:00
|
|
|
canvasContainer.querySelector('.btn-download').addEventListener('click', function(e) {
|
2022-10-07 19:50:25 +02:00
|
|
|
e.stopPropagation();
|
2022-05-07 01:14:52 +02:00
|
|
|
let container = this.parentNode;
|
|
|
|
let pageValue = container.querySelector('.checkbox-page').value;
|
|
|
|
let orientation = degreesToOrientation(container.querySelector('.input-rotate').value);
|
|
|
|
if(orientation) {
|
|
|
|
pageValue = pageValue + "-" + orientation;
|
|
|
|
}
|
|
|
|
document.querySelector('#input_pages').value = pageValue;
|
|
|
|
document.querySelector('#form_pdf').submit();
|
|
|
|
});
|
2022-04-05 01:11:03 +02:00
|
|
|
canvasContainer.querySelector('.btn-rotate').addEventListener('click', function(e) {
|
2022-10-07 19:50:25 +02:00
|
|
|
e.stopPropagation();
|
2022-05-11 09:29:46 +02:00
|
|
|
let inputRotate = this.parentNode.querySelector('.input-rotate');
|
|
|
|
inputRotate.value = (parseInt(inputRotate.value) + 90) % 360;
|
|
|
|
pageRender(pageIndex);
|
2022-04-05 01:11:03 +02:00
|
|
|
})
|
2022-03-30 02:00:25 +02:00
|
|
|
|
2022-04-05 01:11:03 +02:00
|
|
|
pageRender(pageIndex);
|
2022-03-28 00:56:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, function (reason) {
|
|
|
|
console.error(reason);
|
|
|
|
});
|
2022-05-23 23:57:14 +02:00
|
|
|
|
|
|
|
return loadingTask;
|
2022-03-28 00:56:00 +02:00
|
|
|
};
|
|
|
|
|
2022-04-07 00:13:22 +02:00
|
|
|
var pageRenderAll = function() {
|
|
|
|
for(pageIndex in pages) {
|
|
|
|
pageRender(pageIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 02:06:30 +02:00
|
|
|
var pageRender = async function(pageIndex) {
|
2022-05-25 01:08:19 +02:00
|
|
|
let scrollWidth = 12;
|
|
|
|
if(is_mobile()) {
|
|
|
|
scrollWidth = -4;
|
|
|
|
}
|
2022-04-05 01:11:03 +02:00
|
|
|
let page = pages[pageIndex];
|
2022-04-07 00:13:22 +02:00
|
|
|
let rotation = parseInt(document.querySelector('#input_rotate_'+pageIndex).value);
|
2022-04-05 01:11:03 +02:00
|
|
|
let viewport = page.getViewport({scale: 1, rotation: rotation});
|
2022-05-25 01:08:19 +02:00
|
|
|
let sizeWidth = Math.floor((document.getElementById('container-pages').offsetWidth - (8*(nbPagePerLine+1)) - scrollWidth) / nbPagePerLine);
|
2022-05-15 01:48:38 +02:00
|
|
|
let sizeHeight = sizeWidth * 1.25;
|
|
|
|
let scaleWidth = sizeWidth / viewport.width;
|
|
|
|
let scaleHeight = sizeHeight / viewport.height;
|
2022-04-06 23:17:27 +02:00
|
|
|
let viewportWidth = page.getViewport({scale: scaleWidth, rotation: rotation});
|
|
|
|
let viewportHeight = page.getViewport({scale: scaleHeight, rotation: rotation});
|
|
|
|
|
2022-05-15 01:48:38 +02:00
|
|
|
if(viewportWidth.height > sizeWidth) {
|
2022-04-06 23:17:27 +02:00
|
|
|
viewport = viewportHeight;
|
|
|
|
} else {
|
|
|
|
viewport = viewportWidth;
|
|
|
|
}
|
|
|
|
|
2022-04-05 01:11:03 +02:00
|
|
|
let canvasContainer = document.getElementById('canvas-container-' + pageIndex);
|
2022-05-15 01:48:38 +02:00
|
|
|
canvasContainer.style.height = (sizeHeight + 4) + "px";
|
|
|
|
canvasContainer.style.width = (sizeWidth + 4) + "px";
|
2022-04-05 01:11:03 +02:00
|
|
|
let canvasPDF = canvasContainer.querySelector('.canvas-pdf');
|
|
|
|
let context = canvasPDF.getContext('2d');
|
|
|
|
canvasPDF.height = viewport.height;
|
|
|
|
canvasPDF.width = viewport.width;
|
|
|
|
|
2022-05-07 02:06:30 +02:00
|
|
|
if(pdfRenderTasks[pageIndex]) {
|
|
|
|
pdfRenderTasks[pageIndex].cancel();
|
|
|
|
}
|
|
|
|
pdfRenderTasks[pageIndex] = await page.render({
|
|
|
|
canvasContext: context,
|
|
|
|
viewport: viewport,
|
2022-04-05 01:11:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-21 01:07:07 +02:00
|
|
|
var getFileIndex = function(page) {
|
|
|
|
|
|
|
|
return page.id.replace('canvas-container-', '').replace(/_.*$/, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
var getFilesStats = function() {
|
|
|
|
let files = [];
|
|
|
|
document.querySelectorAll('.canvas-container').forEach(function(page) {
|
|
|
|
let fileIndex = getFileIndex(page);
|
|
|
|
if(!files[fileIndex]) {
|
|
|
|
files[fileIndex] = { nbPage: 0, nbPageSelected: 0, nbPageDeleted: 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isPageDeleted(page)) {
|
|
|
|
files[fileIndex].nbPageDeleted++;
|
|
|
|
} else {
|
|
|
|
files[fileIndex].nbPage++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isPageSelected(page)) {
|
|
|
|
files[fileIndex].nbPageSelected++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
var updateListePDF = function() {
|
|
|
|
document.querySelector('#list_pdf').innerHTML = "";
|
2022-10-17 00:49:32 +02:00
|
|
|
let nbFiles = document.querySelector('#input_pdf').files.length;
|
|
|
|
for (var i = 0; i < nbFiles; i++) {
|
2022-05-21 01:07:07 +02:00
|
|
|
let pdfLetter = String.fromCharCode(96 + i+1).toUpperCase();
|
|
|
|
const pdfFile = document.querySelector('#input_pdf').files.item(i);
|
2022-05-21 02:19:09 +02:00
|
|
|
document.querySelector('#list_pdf').insertAdjacentHTML('beforeend', '<li id="file_' + pdfLetter + '" class="list-group-item small ps-2 pe-5" title="'+decodeURI(pdfFile.name)+'" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><i class="bi bi-files"></i><span class="ms-2">'+decodeURI(pdfFile.name)+'</span> <input class="form-check-input float-end position-absolute" style="right: 10px;" type="checkbox" /> </li>');
|
2022-05-21 01:07:07 +02:00
|
|
|
let fileItem = document.querySelector('#file_' + pdfLetter);
|
|
|
|
fileItem.querySelector('input[type=checkbox]').addEventListener('change', function(e) {
|
|
|
|
document.querySelectorAll('.canvas-container').forEach(function(page) {
|
|
|
|
if(getFileIndex(page) == pdfLetter && !isPageDeleted(page)) {
|
|
|
|
selectPage(page, e.target.checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updateGlobalState();
|
|
|
|
});
|
2022-10-07 23:45:33 +02:00
|
|
|
document.querySelector('#liste_pdf_titre_mobile').innerText = decodeURI(pdfFile.name);
|
2022-10-17 00:49:32 +02:00
|
|
|
document.querySelector('#btn_liste_pdf_bar span').innerText = nbFiles;
|
|
|
|
if(nbFiles > 1) {
|
|
|
|
document.querySelector('#liste_pdf_titre_mobile').innerText = nbFiles + ' documents PDF';
|
|
|
|
}
|
2022-05-21 01:07:07 +02:00
|
|
|
}
|
|
|
|
updateGlobalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
var getPagesSelected = function() {
|
|
|
|
let pages = [];
|
|
|
|
document.querySelectorAll('.canvas-container .input-select:checked').forEach(function(item) {
|
|
|
|
pages[item.parentNode.id.replace('canvas-container-', '')] = item.parentNode;
|
|
|
|
});
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
var selectPage = function(page, state) {
|
|
|
|
page.querySelector('input[type=checkbox].input-select').checked = state;
|
2022-05-18 01:02:09 +02:00
|
|
|
updatePageState(page);
|
2022-05-21 01:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var toggleSelectPage = function(page) {
|
|
|
|
selectPage(page, !isPageSelected(page));
|
2022-05-18 01:02:09 +02:00
|
|
|
updateGlobalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
var isPageSelected = function(page) {
|
2022-03-30 02:00:25 +02:00
|
|
|
|
2022-05-18 01:02:09 +02:00
|
|
|
return page.querySelector('input[type=checkbox].input-select').checked;
|
|
|
|
}
|
|
|
|
|
2022-05-31 01:27:13 +02:00
|
|
|
var dragPage = function(page, state) {
|
|
|
|
page.querySelector('input[type=checkbox].input-drag').checked = state;
|
|
|
|
updatePageState(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
var toggleDragPage = function(page) {
|
|
|
|
dragPage(page, !isPageDragged(page));
|
|
|
|
updateGlobalState();
|
|
|
|
document.querySelectorAll('.canvas-container').forEach(function(page) {
|
|
|
|
updatePageState(page);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var isPageDragged = function(page) {
|
|
|
|
|
|
|
|
return page.querySelector('input[type=checkbox].input-drag').checked;
|
|
|
|
}
|
|
|
|
|
2022-10-09 00:44:04 +02:00
|
|
|
var movePagesDragged = function(pageHere, position) {
|
|
|
|
document.querySelectorAll('.canvas-container .input-drag:checked').forEach(function(item) {
|
|
|
|
let page = item.parentNode;
|
|
|
|
if(position == 'right') {
|
|
|
|
pageHere.insertAdjacentElement('afterend', page);
|
|
|
|
} else {
|
|
|
|
pageHere.insertAdjacentElement('beforebegin', page);
|
|
|
|
}
|
|
|
|
});
|
2022-10-14 00:22:47 +02:00
|
|
|
bootstrap.Modal.getOrCreateInstance(document.querySelector('#modalDrag')).hide();
|
2022-10-09 00:44:04 +02:00
|
|
|
}
|
|
|
|
|
2022-05-18 01:02:09 +02:00
|
|
|
var toggleDeletePage = function(page) {
|
2022-05-21 01:07:07 +02:00
|
|
|
deletePage(page, isPageDeleted(page))
|
|
|
|
updateGlobalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
var deletePage = function(page, state) {
|
|
|
|
page.querySelector('input[type=checkbox].checkbox-page').checked = state;
|
2022-05-18 01:02:09 +02:00
|
|
|
page.querySelector('input[type=checkbox].input-select').checked = false;
|
|
|
|
updatePageState(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
var isPageDeleted = function(page) {
|
|
|
|
|
|
|
|
return !page.querySelector('input[type=checkbox].checkbox-page').checked;
|
|
|
|
}
|
|
|
|
|
2022-05-18 01:28:00 +02:00
|
|
|
var isPageHover = function(page) {
|
|
|
|
|
|
|
|
return page.querySelector('input[type=checkbox].input-hover').checked;
|
|
|
|
}
|
|
|
|
|
2022-05-18 01:02:09 +02:00
|
|
|
var updatePageState = function(page) {
|
2022-05-18 01:28:00 +02:00
|
|
|
page.classList.remove('border-primary', 'shadow-sm', 'bg-primary', 'border-secondary', 'bg-secondary');
|
2022-05-18 01:02:09 +02:00
|
|
|
page.classList.add('border-transparent', 'bg-transparent');
|
2022-05-31 01:27:13 +02:00
|
|
|
page.querySelector('.canvas-pdf').style.opacity = '1';
|
|
|
|
page.querySelector('.canvas-pdf').style.zIndex = 'inherit';
|
|
|
|
page.querySelector('.canvas-pdf').classList.add('shadow-sm');
|
|
|
|
page.querySelector('.canvas-pdf').classList.remove('shadow');
|
2022-05-18 01:28:00 +02:00
|
|
|
page.querySelector('.btn-rotate').classList.add('d-none');
|
|
|
|
page.querySelector('.btn-download').classList.add('d-none');
|
|
|
|
page.querySelector('.btn-delete').classList.add('d-none');
|
|
|
|
page.querySelector('.btn-select').classList.add('d-none');
|
|
|
|
page.querySelector('.btn-select').classList.remove('text-primary');
|
|
|
|
page.querySelector('.btn-drag').classList.add('d-none');
|
2022-10-09 00:04:44 +02:00
|
|
|
page.querySelector('.btn-drag-here-left').classList.add('d-none');
|
|
|
|
page.querySelector('.btn-drag-here-right').classList.add('d-none');
|
2022-10-08 01:07:49 +02:00
|
|
|
page.querySelector('.btn-drag-here_mobile').classList.add('d-none');
|
2022-05-18 01:02:09 +02:00
|
|
|
page.querySelector('.btn-restore').classList.add('d-none');
|
2022-05-18 01:28:00 +02:00
|
|
|
page.querySelector('.page-title').classList.add('d-none');
|
2022-10-14 00:22:47 +02:00
|
|
|
page.querySelector('.canvas-pdf').classList.remove('opacity-50');
|
|
|
|
page.classList.remove('page-dragged');
|
2022-05-18 01:02:09 +02:00
|
|
|
|
|
|
|
if(isPageDeleted(page)) {
|
|
|
|
page.querySelector('.canvas-pdf').style.opacity = '0.15';
|
2022-05-18 01:28:00 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 10:34:51 +02:00
|
|
|
if(isPageHover(page) && !isPageDeleted(page) && !isPageDragged(page) && !isPageSelected(page) && !isDraggedMode()) {
|
2022-05-18 01:28:00 +02:00
|
|
|
page.querySelector('.page-title').classList.remove('d-none');
|
|
|
|
page.classList.add('border-secondary', 'bg-secondary');
|
|
|
|
page.classList.remove('border-transparent', 'bg-transparent');
|
2022-10-18 00:02:41 +02:00
|
|
|
page.querySelector('.btn-select').classList.remove('d-none')
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isPageHover(page) && !isPageDeleted(page) && !isPageDragged(page) && !isPageSelected(page) && !isDraggedMode() && !isSelectionMode()) {
|
2022-05-18 01:28:00 +02:00
|
|
|
page.querySelector('.btn-rotate').classList.remove('d-none');
|
|
|
|
page.querySelector('.btn-download').classList.remove('d-none');
|
|
|
|
page.querySelector('.btn-delete').classList.remove('d-none');
|
|
|
|
page.querySelector('.btn-drag').classList.remove('d-none');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isPageHover(page) && isPageDeleted(page)) {
|
2022-05-18 01:02:09 +02:00
|
|
|
page.querySelector('.btn-restore').classList.remove('d-none');
|
2022-03-30 02:00:25 +02:00
|
|
|
}
|
2022-05-18 01:02:09 +02:00
|
|
|
|
2022-10-08 00:32:57 +02:00
|
|
|
if(is_mobile() && isPageDeleted(page)) {
|
|
|
|
page.querySelector('.btn-restore').classList.remove('d-none');
|
|
|
|
}
|
|
|
|
|
2022-10-09 00:55:13 +02:00
|
|
|
if(isPageSelected(page) && !isDraggedMode()) {
|
2022-10-08 10:28:18 +02:00
|
|
|
page.querySelector('.page-title').classList.remove('d-none');
|
2022-05-18 01:02:09 +02:00
|
|
|
page.classList.add('border-primary', 'shadow-sm', 'bg-primary');
|
|
|
|
page.classList.remove('border-transparent', 'bg-transparent', 'border-secondary', 'bg-secondary');
|
2022-05-18 01:28:00 +02:00
|
|
|
page.querySelector('.btn-select').classList.add('text-primary');
|
2022-10-09 00:55:13 +02:00
|
|
|
page.querySelector('.btn-select').classList.remove('d-none');
|
2022-05-18 01:02:09 +02:00
|
|
|
}
|
2022-05-31 01:27:13 +02:00
|
|
|
|
|
|
|
if(isPageDragged(page)) {
|
2022-10-14 00:22:47 +02:00
|
|
|
page.classList.add('page-dragged');
|
2022-05-31 01:27:13 +02:00
|
|
|
page.querySelector('.canvas-pdf').classList.remove('shadow-sm');
|
|
|
|
page.querySelector('.canvas-pdf').classList.add('shadow');
|
|
|
|
}
|
|
|
|
|
2022-10-09 00:04:44 +02:00
|
|
|
if(!isPageDragged(page) && isDraggedMode()) {
|
2022-10-14 00:22:47 +02:00
|
|
|
page.querySelector('.canvas-pdf').classList.add('opacity-50');
|
2022-10-09 00:04:44 +02:00
|
|
|
page.querySelector('.btn-drag-here-left').classList.remove('d-none');
|
|
|
|
page.querySelector('.btn-drag-here-right').classList.remove('d-none');
|
2022-10-08 01:07:49 +02:00
|
|
|
}
|
2022-05-18 01:02:09 +02:00
|
|
|
}
|
|
|
|
|
2022-05-21 01:07:07 +02:00
|
|
|
var updateFilesState = function() {
|
|
|
|
let filesStats = getFilesStats();
|
|
|
|
for(fileIndex in filesStats) {
|
|
|
|
let checkbox = document.querySelector('#file_'+fileIndex+' input[type=checkbox]');
|
|
|
|
let fileStat = filesStats[fileIndex];
|
|
|
|
checkbox.checked = (fileStat.nbPageSelected > 0 && fileStat.nbPageSelected == fileStat.nbPage);
|
|
|
|
checkbox.indeterminate = (fileStat.nbPageSelected > 0 && fileStat.nbPageSelected < fileStat.nbPage);
|
|
|
|
document.querySelector('#file_'+fileIndex+' span').classList.remove('text-primary');
|
|
|
|
if(fileStat.nbPageSelected > 0) {
|
|
|
|
document.querySelector('#file_'+fileIndex+' span').classList.add('text-primary');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 01:02:09 +02:00
|
|
|
var updateGlobalState = function() {
|
2022-05-21 01:07:07 +02:00
|
|
|
updateFilesState();
|
2022-10-09 00:04:44 +02:00
|
|
|
if(!is_mobile()) {
|
|
|
|
document.querySelector('#container-btn-zoom').classList.remove('d-none');
|
|
|
|
}
|
2022-05-18 01:02:09 +02:00
|
|
|
document.querySelector('#container_btn_select').classList.add('opacity-50');
|
2022-05-18 10:04:49 +02:00
|
|
|
document.querySelector('#container_btn_select').classList.remove('border-primary');
|
|
|
|
document.querySelector('#container_btn_select .card-header').classList.remove('bg-primary', 'text-white');
|
|
|
|
document.querySelector('#container_btn_select .card-header').classList.add('text-muted');
|
2022-05-21 01:43:49 +02:00
|
|
|
document.querySelectorAll('#container_btn_select .card-body button').forEach(function(button) {
|
2022-05-18 10:04:49 +02:00
|
|
|
button.classList.add('btn-outline-secondary');
|
2022-05-18 01:02:09 +02:00
|
|
|
button.classList.remove('btn-outline-primary');
|
|
|
|
button.setAttribute('disabled', 'disabled');
|
|
|
|
});
|
2022-05-18 10:04:49 +02:00
|
|
|
document.querySelector('#container_btn_select .card-header span').innerText = "Aucune";
|
2022-10-11 00:42:45 +02:00
|
|
|
document.querySelector('#container_btn_select .card-footer').classList.add('d-none');
|
2022-10-07 23:45:33 +02:00
|
|
|
document.querySelector('#top_bar_action').classList.remove('d-none');
|
|
|
|
document.querySelector('#top_bar_action_selection').classList.add('d-none');
|
|
|
|
document.querySelector('#bottom_bar_action').classList.remove('d-none');
|
|
|
|
document.querySelector('#bottom_bar_action_selection').classList.add('d-none');
|
2022-12-07 01:48:36 +01:00
|
|
|
document.querySelector('#save').removeAttribute('disabled');
|
2022-10-09 01:46:17 +02:00
|
|
|
|
2022-05-18 01:02:09 +02:00
|
|
|
if(isSelectionMode()) {
|
2022-05-18 10:04:49 +02:00
|
|
|
document.querySelector('#container_btn_select .card-header span').innerText = document.querySelectorAll('.canvas-container .input-select:checked').length;
|
2022-10-17 00:49:32 +02:00
|
|
|
document.querySelector('#top_bar_action_selection_recap_nb_pages').innerText = document.querySelectorAll('.canvas-container .input-select:checked').length;
|
2022-05-18 01:02:09 +02:00
|
|
|
document.querySelector('#container_btn_select').classList.remove('opacity-50');
|
2022-05-18 10:04:49 +02:00
|
|
|
document.querySelector('#container_btn_select').classList.add('border-primary');
|
|
|
|
document.querySelector('#container_btn_select .card-header').classList.remove('text-muted');
|
|
|
|
document.querySelector('#container_btn_select .card-header').classList.add('bg-primary', 'text-white');
|
2022-05-21 01:43:49 +02:00
|
|
|
document.querySelectorAll('#container_btn_select .card-body button').forEach(function(button) {
|
2022-05-18 01:02:09 +02:00
|
|
|
button.classList.add('btn-outline-primary');
|
2022-05-18 10:04:49 +02:00
|
|
|
button.classList.remove('btn-outline-secondary');
|
2022-05-18 01:02:09 +02:00
|
|
|
button.removeAttribute('disabled');
|
|
|
|
});
|
2022-10-11 00:42:45 +02:00
|
|
|
document.querySelector('#container_btn_select .card-footer').classList.remove('d-none');
|
2022-05-31 01:27:13 +02:00
|
|
|
document.querySelectorAll('.canvas-container .btn-add').forEach(function(button) {
|
|
|
|
button.classList.remove('d-none');
|
|
|
|
});
|
2022-10-07 23:45:33 +02:00
|
|
|
document.querySelector('#top_bar_action_selection').classList.remove('d-none');
|
|
|
|
document.querySelector('#top_bar_action').classList.add('d-none');
|
|
|
|
document.querySelector('#bottom_bar_action_selection').classList.remove('d-none');
|
|
|
|
document.querySelector('#bottom_bar_action').classList.add('d-none');
|
2022-12-07 01:48:36 +01:00
|
|
|
document.querySelector('#save').setAttribute('disabled', 'disabled');
|
2022-05-31 01:27:13 +02:00
|
|
|
}
|
|
|
|
if(isDraggedMode()) {
|
2022-10-14 00:22:47 +02:00
|
|
|
document.querySelector('#modalDrag .modal-body').insertAdjacentElement('afterbegin', document.querySelector('#container-pages'));
|
|
|
|
document.querySelector('#container-pages').style.overflow = 'visible';
|
|
|
|
bootstrap.Modal.getOrCreateInstance(document.querySelector('#modalDrag')).show();
|
2022-05-18 01:02:09 +02:00
|
|
|
}
|
|
|
|
}
|
2022-03-30 02:00:25 +02:00
|
|
|
|
2022-05-07 01:14:52 +02:00
|
|
|
var degreesToOrientation = function(degrees) {
|
|
|
|
if(degrees == 90) { return "east"; }
|
|
|
|
if(degrees == 180) { return "south"; }
|
|
|
|
if(degrees == 270) { return "west"; }
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:56:00 +02:00
|
|
|
var createEventsListener = function() {
|
2022-10-07 23:45:33 +02:00
|
|
|
document.getElementById('save-select_mobile').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('save').click();
|
|
|
|
});
|
2022-05-07 01:14:52 +02:00
|
|
|
document.getElementById('save-select').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('save').click();
|
|
|
|
});
|
2022-03-30 02:00:25 +02:00
|
|
|
document.getElementById('save').addEventListener('click', function(event) {
|
|
|
|
let order = [];
|
2022-05-06 00:44:15 +02:00
|
|
|
|
2022-05-11 00:57:49 +02:00
|
|
|
let selectionMode = isSelectionMode();
|
2022-05-06 00:44:15 +02:00
|
|
|
|
2022-04-08 01:06:35 +02:00
|
|
|
document.querySelectorAll('.canvas-container').forEach(function(canvasContainer) {
|
|
|
|
let checkbox = canvasContainer.querySelector('.checkbox-page');
|
2022-05-06 00:44:15 +02:00
|
|
|
if(selectionMode) {
|
|
|
|
checkbox = canvasContainer.querySelector('.input-select');
|
|
|
|
}
|
2022-04-08 01:06:35 +02:00
|
|
|
let inputRotate = canvasContainer.querySelector('.input-rotate');
|
|
|
|
let pageValue = "";
|
2022-03-30 02:00:25 +02:00
|
|
|
if(checkbox.checked) {
|
2022-04-08 01:06:35 +02:00
|
|
|
pageValue = checkbox.value;
|
|
|
|
}
|
2022-05-07 01:14:52 +02:00
|
|
|
let orientation = degreesToOrientation(inputRotate.value);
|
|
|
|
if(pageValue && orientation) {
|
|
|
|
pageValue = pageValue + "-" + orientation;
|
2022-04-08 01:06:35 +02:00
|
|
|
}
|
|
|
|
if(pageValue) {
|
|
|
|
order.push(pageValue);
|
2022-03-30 02:00:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
document.querySelector('#input_pages').value = order.join(',');
|
|
|
|
});
|
2022-05-21 10:01:17 +02:00
|
|
|
document.getElementById('save_mobile').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('save').click();
|
|
|
|
});
|
2022-03-31 01:46:45 +02:00
|
|
|
document.getElementById('input_pdf_upload_2').addEventListener('change', async function(event) {
|
2022-05-23 23:57:14 +02:00
|
|
|
for (let i = 0; i < this.files.length; i++) {
|
|
|
|
if(this.files[i].size > maxSize) {
|
2022-03-31 01:46:45 +02:00
|
|
|
|
2022-05-23 23:57:14 +02:00
|
|
|
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const cache = await caches.open('pdf');
|
|
|
|
let filename = this.files[i].name;
|
|
|
|
let response = new Response(this.files[i], { "status" : 200, "statusText" : "OK" });
|
|
|
|
let urlPdf = '/pdf/'+filename;
|
|
|
|
await cache.put(urlPdf, response);
|
|
|
|
let pdfBlob = await getPDFBlobFromCache(urlPdf);
|
|
|
|
nbPDF++;
|
|
|
|
await loadPDF(pdfBlob, filename, nbPDF);
|
2022-03-31 01:46:45 +02:00
|
|
|
}
|
|
|
|
this.value = '';
|
|
|
|
});
|
2022-04-07 00:13:22 +02:00
|
|
|
document.getElementById('btn-zoom-decrease').addEventListener('click', function(event) {
|
|
|
|
nbPagePerLine++;
|
|
|
|
pageRenderAll();
|
|
|
|
});
|
|
|
|
document.getElementById('btn-zoom-increase').addEventListener('click', function(event) {
|
|
|
|
nbPagePerLine--;
|
|
|
|
pageRenderAll();
|
|
|
|
});
|
2022-10-11 00:42:45 +02:00
|
|
|
document.getElementById('btn_cancel_select_footer').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('btn_cancel_select').click();
|
|
|
|
});
|
2022-10-07 23:45:33 +02:00
|
|
|
document.getElementById('btn_cancel_select_mobile').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('btn_cancel_select').click();
|
|
|
|
});
|
2022-05-07 00:42:24 +02:00
|
|
|
document.getElementById('btn_cancel_select').addEventListener('click', function(event) {
|
|
|
|
document.querySelectorAll('.input-select:checked').forEach(function(input) {
|
|
|
|
input.parentNode.querySelector('.btn-select').click();
|
|
|
|
});
|
|
|
|
});
|
2022-10-07 23:45:33 +02:00
|
|
|
document.getElementById('btn_delete_select_mobile').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('btn_delete_select').click();
|
|
|
|
});
|
2022-05-11 09:29:46 +02:00
|
|
|
document.getElementById('btn_delete_select').addEventListener('click', function(event) {
|
|
|
|
let pages = getPagesSelected();
|
|
|
|
for(index in pages) {
|
2022-05-21 01:07:07 +02:00
|
|
|
deletePage(pages[index]);
|
2022-05-11 09:29:46 +02:00
|
|
|
}
|
2022-05-21 01:07:07 +02:00
|
|
|
updateGlobalState();
|
2022-05-11 09:29:46 +02:00
|
|
|
});
|
2022-10-07 23:45:33 +02:00
|
|
|
document.getElementById('btn_rotate_select_mobile').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('btn_rotate_select').click();
|
|
|
|
});
|
2022-05-11 09:29:46 +02:00
|
|
|
document.getElementById('btn_rotate_select').addEventListener('click', function(event) {
|
|
|
|
let pages = getPagesSelected();
|
|
|
|
for(index in pages) {
|
|
|
|
let inputRotate = pages[index].querySelector('.input-rotate');
|
|
|
|
inputRotate.value = (parseInt(inputRotate.value) + 90) % 360;
|
|
|
|
pageRender(index);
|
|
|
|
}
|
|
|
|
});
|
2022-10-08 01:07:49 +02:00
|
|
|
document.getElementById('btn_drag_select').addEventListener('click', function(event) {
|
|
|
|
let pages = getPagesSelected();
|
|
|
|
for(index in pages) {
|
|
|
|
toggleDragPage(pages[index]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
document.getElementById('btn_drag_select_mobile').addEventListener('click', function(event) {
|
|
|
|
document.getElementById('btn_drag_select').click();
|
|
|
|
});
|
2022-10-14 00:22:47 +02:00
|
|
|
document.querySelector('#modalDrag').addEventListener('shown.bs.modal', event => {
|
|
|
|
document.querySelector('#modalDrag .modal-body').scrollTop = document.querySelector('.page-dragged').offsetTop;
|
|
|
|
});
|
|
|
|
document.querySelector('#modalDrag').addEventListener('hide.bs.modal', event => {
|
|
|
|
document.querySelector('#container-main').insertAdjacentElement('afterbegin', document.querySelector('#container-pages'));
|
|
|
|
document.querySelector('#container-pages').style.overflowY = 'scroll';
|
|
|
|
document.querySelector('#container-pages').style.overflowX = 'hidden';
|
|
|
|
});
|
|
|
|
document.querySelector('#modalDrag').addEventListener('hidden.bs.modal', event => {
|
|
|
|
if(is_mobile()) {
|
|
|
|
window.scrollTo(0, document.querySelector('.page-dragged').offsetTop);
|
|
|
|
} else {
|
|
|
|
document.querySelector('#container-pages').scrollTop = document.querySelector('.page-dragged').offsetTop;
|
|
|
|
}
|
|
|
|
document.querySelectorAll('.canvas-container .input-drag:checked').forEach(function(item) {
|
|
|
|
let page = item.parentNode;
|
|
|
|
page.querySelector('input[type=checkbox].input-drag').checked = false;
|
|
|
|
});
|
|
|
|
document.querySelectorAll('.canvas-container').forEach(function(page) {
|
|
|
|
page.querySelector('input[type=checkbox].input-hover').checked = false;
|
|
|
|
updatePageState(page);
|
|
|
|
});
|
|
|
|
updateGlobalState();
|
|
|
|
});
|
2022-10-17 00:49:32 +02:00
|
|
|
document.querySelector('#btn_liste_pdf').addEventListener('click', function(event) {
|
|
|
|
bootstrap.Modal.getOrCreateInstance(document.querySelector('#modalFichier')).show();
|
|
|
|
document.querySelector('#modalFichier .modal-body').insertAdjacentElement('afterbegin', document.querySelector('#list_pdf'));
|
|
|
|
});
|
|
|
|
document.querySelector('#btn_liste_pdf_bar').addEventListener('click', function(event) {
|
|
|
|
document.querySelector('#btn_liste_pdf').click();
|
|
|
|
});
|
|
|
|
document.querySelector('#modalDrag').addEventListener('hidden.bs.modal', event => {
|
|
|
|
document.querySelector('#list_pdf_container').insertAdjacentElement('afterbegin', document.querySelector('#list_pdf'));
|
|
|
|
});
|
2022-12-07 00:52:54 +01:00
|
|
|
document.querySelector('body').addEventListener('click', function(event) {
|
|
|
|
if(!event.originalTarget.classList.contains('offcanvas-header') && !event.originalTarget.classList.contains('offcanvas-body') && event.originalTarget.id != 'container-pages' && event.originalTarget.id != 'sidebarToolsLabel' && event.originalTarget.id != 'btn_container') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
document.getElementById('btn_cancel_select').click();
|
|
|
|
});
|
|
|
|
|
2022-03-28 00:56:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getPDFBlobFromCache(cacheUrl) {
|
|
|
|
const cache = await caches.open('pdf');
|
|
|
|
let responsePdf = await cache.match(cacheUrl);
|
|
|
|
|
|
|
|
if(!responsePdf) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pdfBlob = await responsePdf.blob();
|
|
|
|
|
|
|
|
return pdfBlob;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function uploadFromUrl(url) {
|
|
|
|
history.replaceState({}, '', '/organization');
|
|
|
|
var response = await fetch(url);
|
|
|
|
if(response.status != 200) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var pdfBlob = await response.blob();
|
|
|
|
|
|
|
|
if(pdfBlob.type != 'application/pdf' && pdfBlob.type != 'application/octet-stream') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let dataTransfer = new DataTransfer();
|
|
|
|
let filename = url.replace(/^.*\//, '');
|
|
|
|
dataTransfer.items.add(new File([pdfBlob], filename, {
|
|
|
|
type: 'application/pdf'
|
|
|
|
}));
|
|
|
|
document.getElementById('input_pdf_upload').files = dataTransfer.files;
|
|
|
|
document.getElementById('input_pdf_upload').dispatchEvent(new Event("change"));
|
|
|
|
}
|
|
|
|
|
|
|
|
var pageUpload = async function() {
|
2022-05-11 08:04:20 +02:00
|
|
|
document.querySelector('body').classList.remove('bg-light');
|
2022-03-28 00:56:00 +02:00
|
|
|
document.getElementById('input_pdf_upload').value = '';
|
|
|
|
document.getElementById('page-upload').classList.remove('d-none');
|
|
|
|
document.getElementById('page-organization').classList.add('d-none');
|
|
|
|
document.getElementById('input_pdf_upload').focus();
|
2023-05-03 01:34:07 +02:00
|
|
|
let cache;
|
|
|
|
try {
|
|
|
|
cache = await caches.open('pdf');
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
alert("Erreur d'accès au cache. Cette application ne fonctionne pas en mode de navigation privée");
|
|
|
|
return;
|
|
|
|
}
|
2022-03-28 00:56:00 +02:00
|
|
|
document.getElementById('input_pdf_upload').addEventListener('change', async function(event) {
|
|
|
|
if(document.getElementById('input_pdf_upload').files[0].size > maxSize) {
|
|
|
|
|
2022-03-30 02:05:02 +02:00
|
|
|
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
|
2022-03-28 00:56:00 +02:00
|
|
|
document.getElementById('input_pdf_upload').value = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let filename = document.getElementById('input_pdf_upload').files[0].name;
|
|
|
|
let response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" });
|
|
|
|
let urlPdf = '/pdf/'+filename;
|
|
|
|
await cache.put(urlPdf, response);
|
|
|
|
history.pushState({}, '', '/organization#'+filename);
|
|
|
|
pageOrganization(urlPdf)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var pageOrganization = async function(url) {
|
|
|
|
let filename = url.replace('/pdf/', '');
|
|
|
|
document.title = filename + ' - ' + document.title;
|
2022-05-11 08:04:20 +02:00
|
|
|
document.querySelector('body').classList.add('bg-light');
|
2022-03-28 00:56:00 +02:00
|
|
|
document.getElementById('page-upload').classList.add('d-none');
|
|
|
|
document.getElementById('page-organization').classList.remove('d-none');
|
2022-05-10 23:57:53 +02:00
|
|
|
menu = document.getElementById('sidebarTools');
|
|
|
|
menuOffcanvas = new bootstrap.Offcanvas(menu);
|
|
|
|
responsiveDisplay();
|
2022-03-28 00:56:00 +02:00
|
|
|
|
|
|
|
let pdfBlob = await getPDFBlobFromCache(url);
|
|
|
|
if(!pdfBlob) {
|
|
|
|
document.location = '/organization';
|
|
|
|
return;
|
|
|
|
}
|
2022-05-10 23:57:53 +02:00
|
|
|
|
2022-03-28 00:56:00 +02:00
|
|
|
createEventsListener();
|
2022-03-31 01:46:45 +02:00
|
|
|
loadPDF(pdfBlob, filename, nbPDF);
|
2022-03-28 00:56:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
if(window.location.hash && window.location.hash.match(/^\#http/)) {
|
|
|
|
let hashUrl = window.location.hash.replace(/^\#/, '');
|
|
|
|
pageUpload();
|
|
|
|
uploadFromUrl(hashUrl);
|
|
|
|
} else if(window.location.hash) {
|
|
|
|
pageOrganization('/pdf/'+window.location.hash.replace(/^\#/, ''));
|
|
|
|
} else {
|
|
|
|
pageUpload();
|
|
|
|
}
|
|
|
|
window.addEventListener('hashchange', function() {
|
|
|
|
window.location.reload();
|
|
|
|
})
|
2022-10-11 02:08:34 +02:00
|
|
|
|
|
|
|
if (hasTouch()) {
|
|
|
|
disabledHoverStyle();
|
|
|
|
}
|
2022-03-28 00:56:00 +02:00
|
|
|
})();
|