Hello I have problems with a function of the interact.js library what I want is that an action is executed when a box is moved or resized, for this I did the following
interact('.signer-box-update')
.draggable({
inertia: true,
restrict: {
restriction: ".wrapper",
endOnly: false,
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
},
autoScroll: true,
onmove: dragMoveListener
})
.on(['resizeend','dragend'], function (event) {
var idSinger = event.target.getAttribute("idsinger");
var wValue = document.getElementById("widthValue").value ;
var hValue = document.getElementById("heightValue").value ;
var xValue = document.getElementById("coorX").value ;
var yValue = document.getElementById("coorY").value;
if (idSinger!= null) {
$.ajax({
type: "POST",
url: "${pageContext.request.contextPath}" +"/plantillas/plantillasAction_editCoordenadas.action?coorX="+xValue + "&coorY="+yValue +"&heightValue=" +hValue +"&widthValue=" +wValue +"&idSingerDocument="+idSinger,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(data) {
alert(" ok");
},
error: function () {
alert("not ok");
}
});
}
})
.resizable({
onmove: resizeMoveListener,
edges: {left: true, right: true, bottom: true, top: true},
modifiers: [
interact.modifiers.restrictSize({
min: { width: 100, height: 100 },
max: { width: 400, height: 400 }
})
],
inertia: true
});
the idSinger value is assigned once a button is pressed with this I indicate that the call should be made, however what I get is that the call is not made until it has that value, this is correct, but once you have it before making the call is executed and then re-executed, do you have any idea how I can solve it?
this happens when running for the first time
the method is not executed which is correct,the value is subsequently added by executing another method.
once this is done now always two calls are made, the first one is made by entering the function and the second one by entering the if
Just a thought...
Split the "on" function into 2 different functions
.on(['resizeend','dragend'], function (event) {...}
to
.on(['resizeend'], function (event) {
console.log('resize triggered')
})
.on(['dragend'], function (event) {
console.log('drag end triggered')
})
My presumption is that both are actually being triggered causing the function to execute twice.