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