improved handling of explicit time()-setting: no re-rendering, just update

the time and call _update(). that avoids flashing of the letters.
This commit is contained in:
Manuel Friedli 2014-06-26 14:13:21 +02:00
parent 3e8252fa13
commit f9b6acf8b6
1 changed files with 8 additions and 12 deletions

20
uhr.js
View File

@ -30,12 +30,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
language: 'de_CH', language: 'de_CH',
theme: 'black', theme: 'black',
force: false, force: false,
controls: true controls: true,
time: new Date()
}, },
start: function() { start: function() {
if (!this._isOn()) { if (!this._isOn()) {
var uhr = this; var uhr = this;
this._timer = window.setInterval(function() { this._timer = window.setInterval(function() {
uhr.options.time = new Date();
uhr._update(); uhr._update();
}, 1000); }, 1000);
this._update(); this._update();
@ -80,21 +82,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
}, },
time: function(time) { time: function(time) {
this.options.time = time;
if (time == null) { if (time == null) {
this._currentMinute = -1; this._currentMinute = -1;
this._update(); this.options.time = new Date();
} else { } else {
if (this._timer != null) { if (this._timer != null) {
window.clearInterval(this._timer); window.clearInterval(this._timer);
} }
var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea')); this.options.time = time;
var uhr = this;
renderer.render(this, function() {
uhr._show(time);
});
} }
this._update();
}, },
// private variables // private variables
_id: -1, _id: -1,
@ -106,7 +103,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}, },
_update: function() { _update: function() {
if (this._isOn()) { if (this._isOn()) {
var time = new Date(); var time = this.options.time;
if (time.getMinutes() == this._currentMinute) { if (time.getMinutes() == this._currentMinute) {
return; return;
} }
@ -355,7 +352,7 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) {
break; break;
default: default:
if (console !== undefined && typeof console.log == 'function') { if (console !== undefined && typeof console.log == 'function') {
console.log("Unknown layout version: " + this.layout.version); console.error("Unknown layout version: " + this.layout.version);
} }
return; return;
} }
@ -399,7 +396,6 @@ function Letter(value, style) {
} else { } else {
this.style += ' ' + style; this.style += ' ' + style;
} }
console.log(this.getStyle());
} }
} }
Letter.prototype.toString = function letterToString() { Letter.prototype.toString = function letterToString() {