show tenths of seconds

This commit is contained in:
Thibault Duplessis 2013-10-07 00:20:43 +02:00
parent 65d64d011f
commit f1145af88a
2 changed files with 16 additions and 8 deletions

View file

@ -1564,7 +1564,6 @@ var storage = {
$.widget("lichess.clock", { $.widget("lichess.clock", {
_create: function() { _create: function() {
var self = this;
this.options.time = parseFloat(this.options.time) * 1000; this.options.time = parseFloat(this.options.time) * 1000;
this.options.emerg = parseFloat(this.options.emerg) * 1000; this.options.emerg = parseFloat(this.options.emerg) * 1000;
$.extend(this.options, { $.extend(this.options, {
@ -1572,6 +1571,7 @@ var storage = {
state: 'ready' state: 'ready'
}); });
this.element.addClass('clock_enabled'); this.element.addClass('clock_enabled');
this._show();
}, },
destroy: function() { destroy: function() {
this.stop(); this.stop();
@ -1599,7 +1599,7 @@ var storage = {
clearInterval(self.options.interval); clearInterval(self.options.interval);
} }
}, },
1000); 100);
}, },
setTime: function(time) { setTime: function(time) {
@ -1615,14 +1615,22 @@ var storage = {
}, },
_show: function() { _show: function() {
this.element.text(this._formatDate(new Date(this.options.time))); var text = this._formatDate(new Date(this.options.time));
this.element.toggleClass('emerg', this.options.time < this.options.emerg); if (text != this.element.text()) {
this.element.text(text);
this.element.toggleClass('emerg', this.options.time < this.options.emerg);
}
}, },
_formatDate: function(date) { _formatDate: function(date) {
minutes = this._prefixInteger(date.getUTCMinutes(), 2); minutes = this._prefixInteger(date.getUTCMinutes(), 2);
seconds = this._prefixInteger(date.getSeconds(), 2); seconds = this._prefixInteger(date.getSeconds(), 2);
return minutes + ':' + seconds; if (this.options.time < 5 * 1000) {
tenths = Math.floor(date.getMilliseconds() / 100);
return minutes + ':' + seconds + ':' + tenths;
} else {
return minutes + ':' + seconds;
}
}, },
_prefixInteger: function(num, length) { _prefixInteger: function(num, length) {

View file

@ -289,9 +289,9 @@ div.lichess_table a.button.strong {
font-size: 1.2em; font-size: 1.2em;
} }
div.clock { div.clock {
width: 70px; display: inline-block;
border: 1px solid #ccc; border: 1px solid #ccc;
padding: 4px 0 2px 10px; padding: 4px 10px 2px 10px;
font-size: 22px; font-size: 22px;
font-family: monospace; font-family: monospace;
font-weight: bold; font-weight: bold;
@ -321,7 +321,7 @@ div.clock_bottom {
div.lichess_table_wrap a.moretime { div.lichess_table_wrap a.moretime {
opacity: 0.4; opacity: 0.4;
position: absolute; position: absolute;
left: 87px; left: 111px;
top: 6px; top: 6px;
width: 32px; width: 32px;
height: 32px; height: 32px;