diff --git a/static/js/touchkey.js b/static/js/touchkey.js index 12a945f..d0f91ad 100644 --- a/static/js/touchkey.js +++ b/static/js/touchkey.js @@ -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;