diff --git a/ui/editor/src/chessground.js b/ui/editor/src/chessground.js index 7537d3740e..45cfd5c98e 100644 --- a/ui/editor/src/chessground.js +++ b/ui/editor/src/chessground.js @@ -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); diff --git a/ui/editor/src/view.js b/ui/editor/src/view.js index a968c0e41e..93dd12fbfa 100644 --- a/ui/editor/src/view.js +++ b/ui/editor/src/view.js @@ -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';