moved parsing of v2-layouts to own class
This commit is contained in:
parent
6d588aa08b
commit
b9473f405f
1 changed files with 54 additions and 67 deletions
121
uhr.js
121
uhr.js
|
@ -285,69 +285,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
function UhrRenderer(layout, renderarea) {
|
function UhrRenderer(layout, renderarea) {
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
this.renderarea = renderarea;
|
this.renderarea = renderarea;
|
||||||
this._parseLayoutV2 = function() {
|
|
||||||
var letters = [];
|
|
||||||
for (var i = 0; i < this.layout.letters.length; i++) {
|
|
||||||
var line = [];
|
|
||||||
var string = this.layout.letters[i];
|
|
||||||
for (var c = 0; c < string.length; c++) {
|
|
||||||
var character = new Letter(string[c]);
|
|
||||||
line.push(character);
|
|
||||||
}
|
|
||||||
letters.push(line);
|
|
||||||
}
|
|
||||||
var permanent = this.layout.permanent;
|
|
||||||
if (Array.isArray(permanent)) {
|
|
||||||
for (var i = 0; i < permanent.length; i++) {
|
|
||||||
this._parseObject(letters, 'on', permanent[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._parseObject(letters, 'on', permanent);
|
|
||||||
}
|
|
||||||
var minuteDefinitions = this.layout.minutes;
|
|
||||||
for (minutes in minuteDefinitions) {
|
|
||||||
if (minuteDefinitions.hasOwnProperty(minutes)) {
|
|
||||||
var highlightLetters = minuteDefinitions[minutes];
|
|
||||||
var minuteArray = minutes.split(',');
|
|
||||||
if (Array.isArray(highlightLetters)) {
|
|
||||||
for (var i = 0; i < highlightLetters.length; i++) {
|
|
||||||
for (var j = 0; j < minuteArray.length; j++) {
|
|
||||||
this._parseObject(letters, 'minute' + minuteArray[j], highlightLetters[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (var i = 0; i < minuteArray.length; i++) {
|
|
||||||
this._parseObject(letters, 'minute' + minuteArray[i], highlightLetters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var hours = this.layout.hours;
|
|
||||||
for (hour in hours) {
|
|
||||||
if (hours.hasOwnProperty(hour)) {
|
|
||||||
var highlightLetters = hours[hour];
|
|
||||||
if (Array.isArray(highlightLetters)) {
|
|
||||||
for (var i = 0; i < highlightLetters.length; i++) {
|
|
||||||
this._parseObject(letters, 'hour' + hour, highlightLetters[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._parseObject(letters, 'hour' + hour, highlightLetters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return letters;
|
|
||||||
}
|
|
||||||
this._parseObject = function(letters, styleClass, object) {
|
|
||||||
for (line in object) {
|
|
||||||
if (object.hasOwnProperty(line)) {
|
|
||||||
var highlightLetters = object[line];
|
|
||||||
for (var i = 0; i < highlightLetters.length; i++) {
|
|
||||||
var x = highlightLetters[i] - 1;
|
|
||||||
letters[line - 1][x].addStyle(styleClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
UhrRenderer.prototype.render = function(uhr, beforeshow) {
|
UhrRenderer.prototype.render = function(uhr, beforeshow) {
|
||||||
var renderer = this;
|
var renderer = this;
|
||||||
|
@ -355,12 +292,11 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) {
|
||||||
if (this.layout.version !== undefined) {
|
if (this.layout.version !== undefined) {
|
||||||
switch (this.layout.version) {
|
switch (this.layout.version) {
|
||||||
case 2:
|
case 2:
|
||||||
letters = this._parseLayoutV2();
|
var delegate = new UhrRendererV2Delegate(this.layout);
|
||||||
|
letters = delegate.parse();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (console !== undefined && typeof console.log == 'function') {
|
console.error("Unknown layout version: " + this.layout.version);
|
||||||
console.error("Unknown layout version: " + this.layout.version);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -383,6 +319,57 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) {
|
||||||
renderer.renderarea.fadeIn('fast');
|
renderer.renderarea.fadeIn('fast');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function UhrRendererV2Delegate(layout) {
|
||||||
|
this.layout = layout;
|
||||||
|
this._parseArrayOrObject = function(letters, styleClass, input) {
|
||||||
|
if (Array.isArray(input)) {
|
||||||
|
for (var i = 0; i < input.length; i++) {
|
||||||
|
this._parseObject(letters, styleClass, input[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._parseObject(letters, styleClass, input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._parseObject = function(letters, styleClass, object) {
|
||||||
|
for (line in object) {
|
||||||
|
if (object.hasOwnProperty(line)) {
|
||||||
|
var highlightLetters = object[line];
|
||||||
|
for (var i = 0; i < highlightLetters.length; i++) {
|
||||||
|
var x = highlightLetters[i] - 1;
|
||||||
|
letters[line - 1][x].addStyle(styleClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._definitionHelper = function(letters, styleClass, definition) {
|
||||||
|
for (listString in definition) {
|
||||||
|
if (definition.hasOwnProperty(listString)) {
|
||||||
|
var array = listString.split(',');
|
||||||
|
var highlightLetters = definition[listString];
|
||||||
|
for (var index = 0; index < array.length; index++) {
|
||||||
|
this._parseArrayOrObject(letters, styleClass + array[index], highlightLetters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UhrRendererV2Delegate.prototype.parse = function() {
|
||||||
|
var letters = [];
|
||||||
|
for (var i = 0; i < this.layout.letters.length; i++) {
|
||||||
|
var line = [];
|
||||||
|
var string = this.layout.letters[i];
|
||||||
|
for (var c = 0; c < string.length; c++) {
|
||||||
|
var character = new Letter(string[c]);
|
||||||
|
line.push(character);
|
||||||
|
}
|
||||||
|
letters.push(line);
|
||||||
|
}
|
||||||
|
this._parseArrayOrObject(letters, 'on', this.layout.permanent);
|
||||||
|
this._definitionHelper(letters, 'minute', this.layout.minutes);
|
||||||
|
this._definitionHelper(letters, 'hour', this.layout.hours);
|
||||||
|
return letters;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
||||||
* @param value Der Buchstabe, der Dargestellt werden soll.
|
* @param value Der Buchstabe, der Dargestellt werden soll.
|
||||||
|
|
Loading…
Reference in a new issue