fix board editor drop-in on touch screens

This commit is contained in:
Thibault Duplessis 2016-01-20 13:52:09 +07:00
parent fa1072bdd0
commit 246eebeb82
3 changed files with 10 additions and 4 deletions

View file

@ -9,7 +9,7 @@ net {
ip = "5.196.91.160" ip = "5.196.91.160"
asset { asset {
domain = ${net.domain} domain = ${net.domain}
version = 809 version = 810
} }
} }
play { play {

View file

@ -3,7 +3,7 @@ var util = require('chessground').util;
var drag = require('chessground').drag; var drag = require('chessground').drag;
module.exports = function(ctrl, e) { module.exports = function(ctrl, e) {
if (e.button !== 0) return; // only left click if (e.button !== undefined && e.button !== 0) return; // only touch or left click
var role = e.target.getAttribute('data-role'), var role = e.target.getAttribute('data-role'),
color = e.target.getAttribute('data-color'); color = e.target.getAttribute('data-color');
if (!role || !color) return; if (!role || !color) return;

View file

@ -135,6 +135,8 @@ function sparePieces(ctrl, color, orientation, position) {
})); }));
} }
var eventNames = ['mousedown', 'touchstart'];
module.exports = function(ctrl) { module.exports = function(ctrl) {
var fen = ctrl.computeFen(); var fen = ctrl.computeFen();
var color = ctrl.chessground.data.orientation; var color = ctrl.chessground.data.orientation;
@ -143,9 +145,13 @@ module.exports = function(ctrl) {
config: function(el, isUpdate, context) { config: function(el, isUpdate, context) {
if (isUpdate) return; if (isUpdate) return;
var onstart = partial(drag, ctrl); var onstart = partial(drag, ctrl);
document.addEventListener('mousedown', onstart); eventNames.forEach(function(name) {
document.addEventListener(name, onstart);
});
context.onunload = function() { context.onunload = function() {
document.removeEventListener('mousedown', onstart); eventNames.forEach(function(name) {
document.removeEventListener(name, onstart);
});
}; };
} }
}, [ }, [