bind <f> to board flip in play, analysis, and editor
parent
0ff7a32b14
commit
32b3c3f421
|
@ -49,4 +49,5 @@ module.exports = function(ctrl) {
|
|||
m.redraw();
|
||||
}));
|
||||
k.bind(['esc'], ctrl.chessground.cancelMove);
|
||||
k.bind('f', preventing(ctrl.flip));
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ var chessground = require('chessground');
|
|||
var partial = chessground.util.partial;
|
||||
var editor = require('./editor');
|
||||
var m = require('mithril');
|
||||
var keyboard = require('./keyboard');
|
||||
|
||||
module.exports = function(cfg) {
|
||||
|
||||
|
@ -54,11 +55,16 @@ module.exports = function(cfg) {
|
|||
}.bind(this);
|
||||
|
||||
this.positionLooksLegit = function() {
|
||||
var kings = {white: 0, black: 0};
|
||||
var kings = {
|
||||
white: 0,
|
||||
black: 0
|
||||
};
|
||||
var pieces = this.chessground.data.pieces;
|
||||
for (var pos in pieces) {
|
||||
if (pieces[pos] && pieces[pos].role === 'king') kings[pieces[pos].color]++;
|
||||
}
|
||||
return kings.white === 1 && kings.black === 1;
|
||||
}.bind(this);
|
||||
|
||||
keyboard(this);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
var k = Mousetrap;
|
||||
var m = require('mithril');
|
||||
|
||||
function preventing(f) {
|
||||
return function(e) {
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
// internet explorer
|
||||
e.returnValue = false;
|
||||
}
|
||||
f();
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = function(ctrl) {
|
||||
k.bind('f', preventing(function() {
|
||||
ctrl.chessground.toggleOrientation();
|
||||
m.redraw();
|
||||
}));
|
||||
};
|
|
@ -45,5 +45,6 @@ module.exports = {
|
|||
ctrl.replay.jump(ctrl.data.game.moves.length);
|
||||
m.redraw();
|
||||
}));
|
||||
k.bind('f', preventing(ctrl.flip));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue