bind <f> to board flip in play, analysis, and editor

pull/407/head
Thibault Duplessis 2015-04-14 08:12:57 +02:00
parent 0ff7a32b14
commit 32b3c3f421
4 changed files with 30 additions and 1 deletions

View File

@ -49,4 +49,5 @@ module.exports = function(ctrl) {
m.redraw();
}));
k.bind(['esc'], ctrl.chessground.cancelMove);
k.bind('f', preventing(ctrl.flip));
};

View File

@ -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);
};

View File

@ -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();
}));
};

View File

@ -45,5 +45,6 @@ module.exports = {
ctrl.replay.jump(ctrl.data.game.moves.length);
m.redraw();
}));
k.bind('f', preventing(ctrl.flip));
}
};