Fixed board editor for touch screens.
parent
5dc27d8776
commit
ce1631a211
|
@ -33,7 +33,7 @@ function onMouseEvent(ctrl) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
var sel = ctrl.vm.selected();
|
var sel = ctrl.vm.selected();
|
||||||
|
|
||||||
if (isLeftClick(e)) {
|
if (isLeftClick(e) || e.type === 'touchstart' || e.type === 'touchmove') {
|
||||||
if (
|
if (
|
||||||
sel === 'pointer' ||
|
sel === 'pointer' ||
|
||||||
(
|
(
|
||||||
|
@ -55,13 +55,14 @@ function onMouseEvent(ctrl) {
|
||||||
piece.role = sel[1];
|
piece.role = sel[1];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
e.type === 'mousedown' && existingPiece &&
|
(e.type === 'mousedown' || e.type === 'touchstart') &&
|
||||||
|
existingPiece &&
|
||||||
piece.color === existingPiece.color &&
|
piece.color === existingPiece.color &&
|
||||||
piece.role === existingPiece.role
|
piece.role === existingPiece.role
|
||||||
) {
|
) {
|
||||||
pieces[key] = false;
|
pieces[key] = false;
|
||||||
ctrl.chessground.setPieces(pieces);
|
ctrl.chessground.setPieces(pieces);
|
||||||
} else if (e.type === 'mousedown' || key !== lastKey) {
|
} else if (e.type === 'mousedown' || e.type === 'touchstart' || key !== lastKey) {
|
||||||
pieces[key] = piece;
|
pieces[key] = piece;
|
||||||
ctrl.chessground.cancelMove();
|
ctrl.chessground.cancelMove();
|
||||||
ctrl.chessground.setPieces(pieces);
|
ctrl.chessground.setPieces(pieces);
|
||||||
|
|
|
@ -182,27 +182,32 @@ function sparePieces(ctrl, color, orientation, position) {
|
||||||
|
|
||||||
return m('div', {
|
return m('div', {
|
||||||
class: containerClass,
|
class: containerClass,
|
||||||
onmousedown: function(e) {
|
onmousedown: onSelectSparePiece(ctrl, s, 'mouseup'),
|
||||||
if (['pointer', 'trash'].indexOf(s) !== -1) {
|
ontouchstart: onSelectSparePiece(ctrl, s, 'touchend')
|
||||||
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});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, m('piece', attrs));
|
}, 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) {
|
function makeCursor(selected) {
|
||||||
|
|
||||||
if (selected === 'pointer') return 'pointer';
|
if (selected === 'pointer') return 'pointer';
|
||||||
|
|
Loading…
Reference in New Issue