mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
Drag and drop with only detecting change and direction more easier et
reliable
This commit is contained in:
parent
ebc92a17e5
commit
eb758a1b9a
@ -120,24 +120,39 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
|
|||||||
if (e.preventDefault) {
|
if (e.preventDefault) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
let element = this;
|
let pdfOver = this;
|
||||||
// vers le haut
|
let pdfMoving = document.querySelector('#'+e.dataTransfer.getData('element'));
|
||||||
if(this.offsetTop < document.querySelector('#'+e.dataTransfer.getData('element')).offsetTop && e.layerX <= element.clientWidth / 2) {
|
|
||||||
element = this.previousSibling;
|
if(pdfOver.id == pdfMoving.id) {
|
||||||
}
|
|
||||||
// vers le bas
|
return;
|
||||||
if(this.offsetTop > document.querySelector('#'+e.dataTransfer.getData('element')).offsetTop && e.layerX > element.clientWidth / 2) {
|
|
||||||
element = this.nextSibling;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!element.draggable && !this.previousSibling.draggable) {
|
let leftRight = false;
|
||||||
this.insertAdjacentElement('beforebegin', document.querySelector('#'+e.dataTransfer.getData('element')));
|
let topBottom = false;
|
||||||
} else if(!element.draggable && !this.nextSibling.draggable) {
|
|
||||||
this.insertAdjacentElement('beforebegin', document.querySelector('#'+e.dataTransfer.getData('element')));
|
if(pdfOver.offsetTop < pdfMoving.offsetTop) {
|
||||||
} else if (e.layerX > element.clientWidth / 2) {
|
topBottom = 'top';
|
||||||
element.insertAdjacentElement('beforebegin', document.querySelector('#'+e.dataTransfer.getData('element')));
|
}
|
||||||
} else {
|
|
||||||
element.insertAdjacentElement('afterend', document.querySelector('#'+e.dataTransfer.getData('element')));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftRight == 'right' || topBottom == 'bottom') {
|
||||||
|
pdfOver.insertAdjacentElement('afterend', pdfMoving);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -103,6 +103,6 @@
|
|||||||
<script>
|
<script>
|
||||||
var maxSize = <?php echo $maxSize ?>;
|
var maxSize = <?php echo $maxSize ?>;
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/organization.js?202210070140"></script>
|
<script src="/js/organization.js?2022100701047"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user