cache parsed layouts instead of re-parsing them every time the language
changes
This commit is contained in:
parent
a263a1f18c
commit
e5ce0ab2bb
1 changed files with 14 additions and 12 deletions
26
uhr.js
26
uhr.js
|
@ -288,16 +288,18 @@ function UhrRenderer(layout, renderarea) {
|
|||
}
|
||||
UhrRenderer.prototype.render = function(uhr, beforeshow) {
|
||||
var renderer = this;
|
||||
var letters;
|
||||
switch (this.layout.version) {
|
||||
case 2:
|
||||
var delegate = new _UhrRendererV2Delegate(this.layout);
|
||||
letters = delegate.parse();
|
||||
break;
|
||||
default:
|
||||
console.warn("Unknown layout version: '" + this.layout.version + "'");
|
||||
return;
|
||||
if (this.layout._parsed === undefined) {
|
||||
switch (this.layout.version) {
|
||||
case 2:
|
||||
var delegate = new _UhrRendererV2Delegate(this.layout);
|
||||
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;
|
||||
};
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue