1
0
Fork 0
forked from s3lph/matemat

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