cache parsed layouts instead of re-parsing them every time the language

changes
This commit is contained in:
Manuel Friedli 2014-06-27 13:23:10 +02:00
parent a263a1f18c
commit e5ce0ab2bb

12
uhr.js
View file

@ -288,16 +288,18 @@ function UhrRenderer(layout, renderarea) {
}
UhrRenderer.prototype.render = function(uhr, beforeshow) {
var renderer = this;
var letters;
if (this.layout._parsed === undefined) {
switch (this.layout.version) {
case 2:
var delegate = new _UhrRendererV2Delegate(this.layout);
letters = delegate.parse();
this.layout._parsed = delegate.parse();
break;
default:
console.warn("Unknown layout version: '" + this.layout.version + "'");
return;
}
}
var letters = this.layout._parsed;
this.renderarea.fadeOut('fast', function() {
renderer.renderarea.empty();
for (var y = 0; y < letters.length; y++) {
@ -337,7 +339,7 @@ function _UhrRendererV2Delegate(layout) {
}
}
}
this._definitionHelper = function(letters, styleClass, definition) {
this._parseTimeDefinition = function(letters, styleClass, definition) {
for (listString in definition) {
if (definition.hasOwnProperty(listString)) {
var array = listString.split(',');
@ -361,8 +363,8 @@ _UhrRendererV2Delegate.prototype.parse = function() {
letters.push(line);
}
this._parseArrayOrObject(letters, 'on', this.layout.permanent);
this._definitionHelper(letters, 'minute', this.layout.minutes);
this._definitionHelper(letters, 'hour', this.layout.hours);
this._parseTimeDefinition(letters, 'minute', this.layout.minutes);
this._parseTimeDefinition(letters, 'hour', this.layout.hours);
return letters;
};
/**