Fixed board editor for touch screens.

pull/2799/head
Brandon Evans 2017-03-16 11:09:53 -05:00
parent 5dc27d8776
commit ce1631a211
2 changed files with 26 additions and 20 deletions

View File

@ -33,7 +33,7 @@ function onMouseEvent(ctrl) {
return function(e) {
var sel = ctrl.vm.selected();
if (isLeftClick(e)) {
if (isLeftClick(e) || e.type === 'touchstart' || e.type === 'touchmove') {
if (
sel === 'pointer' ||
(
@ -55,13 +55,14 @@ function onMouseEvent(ctrl) {
piece.role = sel[1];
if (
e.type === 'mousedown' && existingPiece &&
(e.type === 'mousedown' || e.type === 'touchstart') &&
existingPiece &&
piece.color === existingPiece.color &&
piece.role === existingPiece.role
) {
pieces[key] = false;
ctrl.chessground.setPieces(pieces);
} else if (e.type === 'mousedown' || key !== lastKey) {
} else if (e.type === 'mousedown' || e.type === 'touchstart' || key !== lastKey) {
pieces[key] = piece;
ctrl.chessground.cancelMove();
ctrl.chessground.setPieces(pieces);

View File

@ -182,27 +182,32 @@ function sparePieces(ctrl, color, orientation, position) {
return m('div', {
class: containerClass,
onmousedown: function(e) {
if (['pointer', 'trash'].indexOf(s) !== -1) {
ctrl.vm.selected(s);
} else {
ctrl.vm.selected('pointer');
dragNewPiece(ctrl.chessground.state, {
color: s[0],
role: s[1]
}, e, true);
document.addEventListener('mouseup', function() {
ctrl.vm.selected(s);
m.redraw();
}, {once: true});
}
}
onmousedown: onSelectSparePiece(ctrl, s, 'mouseup'),
ontouchstart: onSelectSparePiece(ctrl, s, 'touchend')
}, m('piece', attrs));
}));
}
function onSelectSparePiece(ctrl, s, upEvent) {
return function(e) {
if (['pointer', 'trash'].indexOf(s) !== -1) {
ctrl.vm.selected(s);
} else {
ctrl.vm.selected('pointer');
dragNewPiece(ctrl.chessground.state, {
color: s[0],
role: s[1]
}, e, true);
document.addEventListener(upEvent, function() {
ctrl.vm.selected(s);
m.redraw();
}, {once: true});
}
};
}
function makeCursor(selected) {
if (selected === 'pointer') return 'pointer';