forked from s3lph/matemat
Touchkey now works on mobile browsers.
This commit is contained in:
parent
45be1930a4
commit
582bef44fd
1 changed files with 8 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue