Touchkey now works on mobile browsers.

This commit is contained in:
s3lph 2018-07-14 22:30:04 +02:00
parent 45be1930a4
commit 582bef44fd

View file

@ -57,11 +57,11 @@ initTouchkey = (keepPattern, svgid, formid, formfieldid) => {
});
};
svg.onmousedown = (ev) => {
svg.ontouchstart = svg.onmousedown = (ev) => {
clearTouchkey();
const svgrect = svg.getBoundingClientRect();
const trX = ev.x - svgrect.left;
const trY = ev.y - svgrect.top;
const trX = (typeof ev.touches !== 'undefined' ? ev.touches[0].pageX : ev.x) - svgrect.left;
const trY = (typeof ev.touches !== 'undefined' ? ev.touches[0].pageY : ev.y) - svgrect.top;
let minId = '';
let minDist = Infinity;
let minx = 0;
@ -83,7 +83,7 @@ initTouchkey = (keepPattern, svgid, formid, formfieldid) => {
enteredKey += minId;
};
svg.onmouseup = (ev) => {
svg.ontouchend = svg.onmouseup = (ev) => {
endPath();
formfield.value = enteredKey;
if (keepPattern !== true) {
@ -94,10 +94,11 @@ initTouchkey = (keepPattern, svgid, formid, formfieldid) => {
}
};
svg.onmousemove = (ev) => {
svg.ontouchmove = svg.onmousemove = (ev) => {
const svgrect = svg.getBoundingClientRect();
const trX = ev.x - svgrect.left;
const trY = ev.y - svgrect.top;
const trX = (typeof ev.touches !== 'undefined' ? ev.touches[0].pageX : ev.x) - svgrect.left;
const trY = (typeof ev.touches !== 'undefined' ? ev.touches[0].pageY : ev.y) - svgrect.top;
console.log(trY);
if (currentStroke != null) {
let minId = '';
let minDist = Infinity;