summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
authorHaocen Xu <haocen.xu@gmail.com>2018-07-06 12:48:46 -0400
committerHaocen Xu <haocen.xu@gmail.com>2018-07-06 12:48:46 -0400
commit43d86d7d5d3f3b34b0500f6d5d3afe7bd86b0060 (patch)
tree53a76eabbc909075bb4ad8f514aa6d67d2eee5ad /client/lib
parent6c7eab4456f8608ae3893d2200b759d426863cd2 (diff)
downloadwekan-43d86d7d5d3f3b34b0500f6d5d3afe7bd86b0060.tar.gz
wekan-43d86d7d5d3f3b34b0500f6d5d3afe7bd86b0060.tar.bz2
wekan-43d86d7d5d3f3b34b0500f6d5d3afe7bd86b0060.zip
Hotfix for mobile device
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/utils.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/client/lib/utils.js b/client/lib/utils.js
index 1f44c60d..7e2651d2 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -95,6 +95,52 @@ Utils = {
increment,
};
},
+
+ // Detect touch device
+ isTouchDevice() {
+ const isTouchable = (() => {
+ const prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
+ const mq = function(query) {
+ return window.matchMedia(query).matches;
+ };
+
+ if (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch) {
+ return true;
+ }
+
+ // include the 'heartz' as a way to have a non matching MQ to help terminate the join
+ // https://git.io/vznFH
+ const query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join('');
+ return mq(query);
+ })();
+ return isTouchable;
+ },
+
+ calculateTouchDistance(touchA, touchB) {
+ return Math.sqrt(
+ Math.pow(touchA.screenX - touchB.screenX, 2) +
+ Math.pow(touchA.screenY - touchB.screenY, 2)
+ );
+ },
+
+ enableClickOnTouch(element) {
+ let touchStart = null;
+ let lastTouch = null;
+ element.addEventListener('touchstart', function(e) {
+ touchStart = e.touches[0];
+ }, false);
+ element.addEventListener('touchmove', function(e) {
+ const touches = e.touches;
+ lastTouch = touches[touches.length - 1];
+ }, true);
+ element.addEventListener('touchend', function() {
+ if (touchStart && lastTouch && Utils.calculateTouchDistance(touchStart, lastTouch) <= 20) {
+ const clickEvent = document.createEvent('MouseEvents');
+ clickEvent.initEvent('click', true, true);
+ this.dispatchEvent(clickEvent);
+ }
+ }, false);
+ },
};
// A simple tracker dependency that we invalidate every time the window is