javascript - touchEnd and onMouseUp BOTH firing from iPad -
i'm building page used on laptops , ipads. so, majority of code (it's drag/drop heavy) duplicated across mouse events , touch events. i'm finding strange behavior: when used on laptop, fine, when used on ipad, periodically touchend fires mouseup...and because overall goal of page sequence of events, throws whole thing off track (step 'n' achieved, mouseup function re-tests it, , since it's done, fails)
it took quite awhile figure out (since didn't think possible) putting unique log message in different versions, can see in logs on ipad, 'mouse mistake' message.
because cross event behavior isn't logical me i'm not sure how continue debugging, appreciate whatever advice can give. here primary pieces of code, followed sample log ipad. again.
function touchend(event) { console.log('touchend fired\n'); if (_dragelement != null) { if((extractnumber(_dragelement.style.left)<-30)&&(extractnumber(_dragelement.style.top)<200)&&(event.touches.length==0)){ console.log(_dragelement.id+' in hand\n'); if(process[correct].indexof(_dragelement.id)>=0){ console.log('--correct--\n'); hide(_dragelement.id); //hide('hand'); correct++; document.getelementbyid('speech').innerhtml=phrases[correct]; _dragelement = null; return false; } else{ console.log('--wrong--\n'); document.getelementbyid(_dragelement.id).style.top = document.getelementbyid(_dragelement.id).defaulttop+'px'; document.getelementbyid(_dragelement.id).style.left = document.getelementbyid(_dragelement.id).defaultleft+'px'; mistakecounter++; if(mistakecounter==10){ console.log('ejection\n'); ejection(); } else if(mistakecounter==9){ document.getelementbyid('speech').innerhtml='if again i\'ll have ask leave'; console.log('warning text\n'); } else if(mistakecounter<9&&mistakecounter>5){ document.getelementbyid('speech').innerhtml=bigmistakes[math.floor(math.random()*bigmistakes.length)]; console.log('big mistake text\n'); } else{ document.getelementbyid('speech').innerhtml=mistakes[math.floor(math.random()*mistakes.length)]; console.log('mistake text\n'); } _dragelement = null; } } } //interactions(); } function onmouseup(e) { if (_dragelement != null) { _dragelement.style.zindex = _oldzindex; document.onmousemove = null; document.onselectstart = null; _dragelement.ondragstart = null; _dragelement = null; for(i=0;i<tools.length;i++){ if((extractnumber(document.getelementbyid(tools[i].id).style.left)<-30)&&(extractnumber(document.getelementbyid(tools[i].id).style.top)<200)&&(extractnumber(document.getelementbyid(tools[i].id).style.top)>-800)&&(extractnumber(document.getelementbyid(tools[i].id).style.left)>-800)){ if(process[correct].indexof(tools[i].id)>=0){ hide(tools[i].id); //hide('hand'); correct++; document.getelementbyid('speech').innerhtml=phrases[correct]; } else{ document.getelementbyid(tools[i].id).style.top = document.getelementbyid(tools[i].id).defaulttop+'px'; document.getelementbyid(tools[i].id).style.left = document.getelementbyid(tools[i].id).defaultleft+'px'; mistakecounter++; if(mistakecounter==10){ console.log('mouse ejection\n'); ejection(); } else if(mistakecounter==9){ console.log('mouse warning text\n'); document.getelementbyid('speech').innerhtml='if again i\'ll have ask leave'; } else if(9>mistakecounter&&mistakecounter>5){ console.log('mouse big mistake text\n'); document.getelementbyid('speech').innerhtml=bigmistakes[math.floor(math.random()*bigmistakes.length)]; } else{ console.log('mouse mistake text\n'); document.getelementbyid('speech').innerhtml=mistakes[math.floor(math.random()*mistakes.length)]; } } } } } //check positions //interactions(); }
log:
touchend fired safetyawl in hand --correct-- touchend fired curvedprobe in hand --correct-- touchend fired tap55 in hand --correct-- mouse mistake text
i 'solved' changing first onmouseup if statement test whether ios device:
if ((_dragelement != null)&&(!navigator.useragent.match('ipad'))&&(!navigator.useragent.match('iphone')))
and while works, still seems strange me tries fire i'm skeptical best answer
Comments
Post a Comment