fix: settings editor not working on touch devices

pull/2669/head
Milan Pikula 2017-11-22 16:04:35 +01:00
parent 325ca46871
commit aeee784901
2 changed files with 40 additions and 0 deletions

View File

@ -36,6 +36,7 @@
echo $this->fetch('script');
echo $this->Html->script('jquery'); // Include jQuery library
echo $this->Html->script('misp-touch'); // touch interface support
?>
</head>

View File

@ -0,0 +1,39 @@
/**
* support for touch devices without the need
*/
$(document).ready(function() {
var touchStartTime = 0;
var touchTarget = null;
document.body.addEventListener('touchstart', function(ev) {
if (touchStartTime == 0) {
touchStartTime = (new Date()).getTime();
touchTarget = ev.target;
}
}, false);
document.body.addEventListener('touchcancel', function(ev) {
// iphone only
touchStartTime = 0;
touchTarget = null;
}, false);
document.body.addEventListener('touchend', function(ev) {
var touchEndTime = (new Date()).getTime();
var canTrigger = (touchStartTime > 0 && (touchEndTime - touchStartTime) > 500 && touchTarget == ev.target);
// reset the variables BEFORE calling the event handler
// so that our code works even if the handler dies
touchStartTime = 0;
touchTarget = null;
if (canTrigger) {
var newEvent = new MouseEvent('dblclick', ev);
try {
ev.target.dispatchEvent(newEvent);
} catch (e) {
// don't care, this was complimentary event anyway
}
}
}, false);
});