Example #1
0
function renderButtons(ctrl) {
  var firstPly = ctrl.firstPly();
  var lastPly = ctrl.lastPly();
  var flipAttrs = {
    class: 'button flip hint--top' + (ctrl.vm.flip ? ' active' : ''),
    'data-hint': ctrl.trans('flipBoard'),
  };
  if (ctrl.data.tv) flipAttrs.href = '/tv' + (ctrl.data.tv.flip ? '' : '?flip=1');
  else if (ctrl.data.player.spectator) flipAttrs.href = ctrl.router.Round.watcher(ctrl.data.game.id, ctrl.data.opponent.color).url;
  else flipAttrs.onclick = ctrl.flip;
  return m('div.buttons', [
    m('a', flipAttrs, m('span[data-icon=B]')), [
      ['first', 'W', ctrl.firstPly()],
      ['prev', 'Y', ctrl.vm.ply - 1],
      ['next', 'X', ctrl.vm.ply + 1],
      ['last', 'V', lastPly]
    ].map(function(b) {
      var enabled = ctrl.vm.ply !== b[2] && b[2] >= firstPly && b[2] <= lastPly;
      return m('a', {
        class: 'button ' + b[0] + ' ' + classSet({
          disabled: (ctrl.broken || !enabled),
          glowing: b[0] === 'last' && ctrl.isLate()
        }),
        'data-icon': b[1],
        onclick: enabled ? partial(ctrl.jump, b[2]) : null
      });
    }), (game.userAnalysable(ctrl.data) ? m('a', {
      class: 'button hint--top analysis',
      'data-hint': ctrl.trans('analysis'),
      href: ctrl.router.UserAnalysis.game(ctrl.data.game.id, ctrl.data.player.color).url + '#' + ctrl.vm.ply,
    }, m('span[data-icon="A"]')) : null)
  ]);
}