From e5ce0ab2bbdd742353bb033394233df2e970a912 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 13:23:10 +0200 Subject: [PATCH] cache parsed layouts instead of re-parsing them every time the language changes --- uhr.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/uhr.js b/uhr.js index eef10c5..0a1ede0 100644 --- a/uhr.js +++ b/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; }; /**