autoplay fast and slow
This commit is contained in:
parent
5bc341729f
commit
8bc6dc7661
|
@ -1,3 +1,4 @@
|
|||
var partial = require('chessground').util.partial;
|
||||
var m = require('mithril');
|
||||
|
||||
module.exports = {
|
||||
|
@ -25,11 +26,18 @@ module.exports = {
|
|||
onclick: function() {
|
||||
$.modal($('.continue_with.' + ctrl.data.game.id));
|
||||
}
|
||||
}, ctrl.trans('continueFromHere')),
|
||||
m('a.button[data-icon=G]', {
|
||||
class: 'text' + (ctrl.autoplay.active() ? ' active' : ''),
|
||||
onclick: ctrl.togglePlay
|
||||
}, 'Auto play'),
|
||||
}, ctrl.trans('continueFromHere')), [{
|
||||
name: 'fast',
|
||||
delay: 1000
|
||||
}, {
|
||||
name: 'slow',
|
||||
delay: 5000
|
||||
}].map(function(speed) {
|
||||
return m('a.button[data-icon=G]', {
|
||||
class: 'text' + (ctrl.autoplay.active(speed.delay) ? ' active' : ''),
|
||||
onclick: partial(ctrl.togglePlay, speed.delay)
|
||||
}, 'Auto play ' + speed.name);
|
||||
}),
|
||||
m('div.continue_with.' + ctrl.data.game.id, [
|
||||
m('a.button', {
|
||||
href: ctrl.data.userAnalysis ? '/?fen=' + ctrl.vm.situation.fen + '#ai' : ctrl.router.Round.continue(ctrl.data.game.id, 'ai').url + '?fen=' + ctrl.vm.situation.fen,
|
||||
|
|
|
@ -5,7 +5,8 @@ var m = require('mithril');
|
|||
module.exports = function(ctrl) {
|
||||
|
||||
var interval;
|
||||
var delay = 1000;
|
||||
|
||||
this.delay = null;
|
||||
|
||||
var next = function() {
|
||||
if (control.canGoForward(ctrl)) {
|
||||
|
@ -16,10 +17,10 @@ module.exports = function(ctrl) {
|
|||
} else this.stop();
|
||||
}.bind(this);
|
||||
|
||||
this.start = function() {
|
||||
var start = function(delay) {
|
||||
this.delay = delay;
|
||||
this.stop();
|
||||
next();
|
||||
interval = setInterval(next, delay);
|
||||
interval = setInterval(next, this.delay);
|
||||
}.bind(this);
|
||||
|
||||
this.stop = function() {
|
||||
|
@ -29,12 +30,15 @@ module.exports = function(ctrl) {
|
|||
}
|
||||
}.bind(this);
|
||||
|
||||
this.toggle = function() {
|
||||
if (this.active()) this.stop();
|
||||
else this.start();
|
||||
this.toggle = function(delay) {
|
||||
if (this.active(delay)) this.stop();
|
||||
else {
|
||||
if (!this.active()) next();
|
||||
start(delay);
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
this.active = function() {
|
||||
return !!interval;
|
||||
this.active = function(delay) {
|
||||
return (!delay || delay === this.delay) && !!interval;
|
||||
}.bind(this);
|
||||
};
|
||||
|
|
|
@ -34,8 +34,8 @@ module.exports = function(cfg, router, i18n, onChange) {
|
|||
});
|
||||
}.bind(this);
|
||||
|
||||
this.togglePlay = function() {
|
||||
this.autoplay.toggle();
|
||||
this.togglePlay = function(delay) {
|
||||
this.autoplay.toggle(delay);
|
||||
this.actionMenu.open = false;
|
||||
}.bind(this);
|
||||
|
||||
|
|
Loading…
Reference in a new issue