mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
Déduplication de code
This commit is contained in:
parent
6de8cdfe46
commit
c8cb4edfda
137
public/js/app.js
137
public/js/app.js
@ -70,19 +70,41 @@ loadingTask.promise.then(function(pdf) {
|
|||||||
fontCaveat = font;
|
fontCaveat = font;
|
||||||
});
|
});
|
||||||
|
|
||||||
var getHtmlSvg = function(svg, i) {
|
var svgClick = function(label, event) {
|
||||||
var inputRadio = document.createElement('input');
|
if(event.detail == 1) {
|
||||||
inputRadio.type = "radio";
|
label.dataset.lock = parseInt(addLock*1);
|
||||||
inputRadio.classList.add("btn-check");
|
}
|
||||||
inputRadio.id="radio_svg_"+i;
|
if(event.detail > 1){
|
||||||
inputRadio.name = "svg_2_add";
|
stateAddLock(parseInt(label.dataset.lock*1) != 1);
|
||||||
inputRadio.autocomplete = "off";
|
}
|
||||||
inputRadio.value = svg.svg;
|
if(event.detail > 1) {
|
||||||
inputRadio.addEventListener('change', function() {
|
return;
|
||||||
if(this.checked) {
|
}
|
||||||
|
if(!document.getElementById(label.htmlFor).checked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
document.getElementById(label.htmlFor).checked = false;
|
||||||
|
document.getElementById(label.htmlFor).dispatchEvent(new Event("change"));
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
var svgDblClick = function(label, event) {
|
||||||
|
if(parseInt(label.dataset.lock*1) == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stateAddLock(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var svgDragStart = function(label, event) {
|
||||||
|
document.getElementById(label.htmlFor).checked = true;
|
||||||
|
document.getElementById(label.htmlFor).dispatchEvent(new Event("change"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var svgChange = function(input, event) {
|
||||||
|
if(input.checked) {
|
||||||
document.getElementById('btn_svn_select').classList.add('d-none');
|
document.getElementById('btn_svn_select').classList.add('d-none');
|
||||||
document.getElementById('svg_selected_container').classList.remove('d-none');
|
document.getElementById('svg_selected_container').classList.remove('d-none');
|
||||||
document.getElementById('svg_selected').src = this.value;
|
document.getElementById('svg_selected').src = input.value;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('btn_svn_select').classList.remove('d-none');
|
document.getElementById('btn_svn_select').classList.remove('d-none');
|
||||||
document.getElementById('svg_selected_container').classList.add('d-none');
|
document.getElementById('svg_selected_container').classList.add('d-none');
|
||||||
@ -121,6 +143,18 @@ loadingTask.promise.then(function(pdf) {
|
|||||||
if(is_mobile()) {
|
if(is_mobile()) {
|
||||||
menuOffcanvas.hide();
|
menuOffcanvas.hide();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var getHtmlSvg = function(svg, i) {
|
||||||
|
var inputRadio = document.createElement('input');
|
||||||
|
inputRadio.type = "radio";
|
||||||
|
inputRadio.classList.add("btn-check");
|
||||||
|
inputRadio.id="radio_svg_"+i;
|
||||||
|
inputRadio.name = "svg_2_add";
|
||||||
|
inputRadio.autocomplete = "off";
|
||||||
|
inputRadio.value = svg.svg;
|
||||||
|
inputRadio.addEventListener('change', function() {
|
||||||
|
svgChange(this, event);
|
||||||
});
|
});
|
||||||
var svgButton = document.createElement('label');
|
var svgButton = document.createElement('label');
|
||||||
svgButton.id = "label_svg_"+i;
|
svgButton.id = "label_svg_"+i;
|
||||||
@ -144,30 +178,13 @@ loadingTask.promise.then(function(pdf) {
|
|||||||
svgButton.innerHTML += '<a title="Supprimer" data-index="'+i+'" class="btn-svg-list-suppression opacity-50 link-dark position-absolute" style="right: 6px; top: 2px;"><i class="bi bi-trash"></i></a>';
|
svgButton.innerHTML += '<a title="Supprimer" data-index="'+i+'" class="btn-svg-list-suppression opacity-50 link-dark position-absolute" style="right: 6px; top: 2px;"><i class="bi bi-trash"></i></a>';
|
||||||
svgButton.draggable = true;
|
svgButton.draggable = true;
|
||||||
svgButton.addEventListener('dragstart', function(event) {
|
svgButton.addEventListener('dragstart', function(event) {
|
||||||
document.getElementById(this.htmlFor).checked = true;
|
svgDragStart(this, event);
|
||||||
document.getElementById(this.htmlFor).dispatchEvent(new Event("change"));
|
|
||||||
});
|
});
|
||||||
svgButton.addEventListener('click', function(event) {
|
svgButton.addEventListener('click', function(event) {
|
||||||
if(event.detail == 1) {
|
svgClick(this, event);
|
||||||
this.dataset.lock = parseInt(addLock*1);
|
|
||||||
}
|
|
||||||
if(event.detail > 1){
|
|
||||||
stateAddLock(parseInt(this.dataset.lock*1) != 1);
|
|
||||||
}
|
|
||||||
if(event.detail > 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!document.getElementById(this.htmlFor).checked) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
document.getElementById(this.htmlFor).checked = false;
|
|
||||||
document.getElementById(this.htmlFor).dispatchEvent(new Event("change"));
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
});
|
||||||
svgButton.addEventListener('dblclick', function(event) {
|
svgButton.addEventListener('dblclick', function(event) {
|
||||||
if(parseInt(this.dataset.lock*1) != 1) {
|
svgDblClick(this, event);
|
||||||
stateAddLock(true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var svgImg = document.createElement('img');
|
var svgImg = document.createElement('img');
|
||||||
svgImg.src = svg.svg;
|
svgImg.src = svg.svg;
|
||||||
@ -259,63 +276,19 @@ loadingTask.promise.then(function(pdf) {
|
|||||||
|
|
||||||
document.querySelectorAll('label.btn-svg').forEach(function(item) {
|
document.querySelectorAll('label.btn-svg').forEach(function(item) {
|
||||||
item.addEventListener('dragstart', function(event) {
|
item.addEventListener('dragstart', function(event) {
|
||||||
document.getElementById(this.htmlFor).checked = true;
|
svgDragStart(this, event);
|
||||||
document.getElementById(this.htmlFor).dispatchEvent(new Event("change"));
|
|
||||||
});
|
});
|
||||||
item.addEventListener('click', function(event) {
|
item.addEventListener('click', function(event) {
|
||||||
if(event.detail > 1 && document.getElementById(this.htmlFor).checked){
|
svgClick(this, event);
|
||||||
stateAddLock(true);
|
});
|
||||||
}
|
item.addEventListener('dblclick', function(event) {
|
||||||
if(event.detail > 1 && !document.getElementById(this.htmlFor).checked){
|
svgDblClick(this, event);
|
||||||
stateAddLock(false);
|
|
||||||
}
|
|
||||||
if(event.detail > 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!document.getElementById(this.htmlFor).checked) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
document.getElementById(this.htmlFor).checked = false;
|
|
||||||
document.getElementById(this.htmlFor).dispatchEvent(new Event("change"));
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll('input[name="svg_2_add"]').forEach(function (item) {
|
document.querySelectorAll('input[name="svg_2_add"]').forEach(function (item) {
|
||||||
item.addEventListener('change', function() {
|
item.addEventListener('change', function(event) {
|
||||||
if(this.checked) {
|
svgChange(this, event);
|
||||||
document.getElementById('btn_svn_select').classList.add('d-none');
|
|
||||||
document.getElementById('svg_selected_container').classList.remove('d-none');
|
|
||||||
document.getElementById('svg_selected').src = (this.dataset.svg) ? this.dataset.svg : this.value;
|
|
||||||
} else {
|
|
||||||
document.getElementById('btn_svn_select').classList.remove('d-none');
|
|
||||||
document.getElementById('svg_selected_container').classList.add('d-none');
|
|
||||||
document.getElementById('svg_selected').src = null;
|
|
||||||
}
|
|
||||||
stateAddLock(false);
|
|
||||||
var input_selected = document.querySelector('input[name="svg_2_add"]:checked');
|
|
||||||
if(input_selected) {
|
|
||||||
document.body.style.setProperty('cursor', 'copy');
|
|
||||||
} else {
|
|
||||||
document.body.style.removeProperty('cursor');
|
|
||||||
}
|
|
||||||
document.querySelectorAll('.btn-svg').forEach(function(item) {
|
|
||||||
if(input_selected && item.htmlFor == input_selected.id) {
|
|
||||||
item.style.setProperty('cursor', 'copy');
|
|
||||||
} else {
|
|
||||||
item.style.removeProperty('cursor');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
canvasEditions.forEach(function(canvasEdition, index) {
|
|
||||||
if(input_selected) {
|
|
||||||
canvasEdition.defaultCursor = 'copy';
|
|
||||||
} else {
|
|
||||||
canvasEdition.defaultCursor = 'default';
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if(is_mobile()) {
|
|
||||||
menuOffcanvas.hide();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user