more JSHinting
This commit is contained in:
parent
cd58ff4ba3
commit
ec8a185dd7
1 changed files with 62 additions and 66 deletions
78
js/uhr.js
78
js/uhr.js
|
@ -205,14 +205,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
return selectedLanguage === item.code;
|
return selectedLanguage === item.code;
|
||||||
});
|
});
|
||||||
if (!found) {
|
if (!found) {
|
||||||
var fallback;
|
var fallbackLanguage;
|
||||||
if (uhrGlobals.languages.length > 0) {
|
if (uhrGlobals.languages.length > 0) {
|
||||||
fallback = uhrGlobals.languages[0].code;
|
fallbackLanguage = uhrGlobals.languages[0].code;
|
||||||
} else {
|
} else {
|
||||||
fallback = '';
|
fallbackLanguage = '';
|
||||||
}
|
}
|
||||||
console.warn("Language " + selectedLanguage + " not found! Using fallback: " + fallback);
|
console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'");
|
||||||
selectedLanguage = fallback;
|
selectedLanguage = fallbackLanguage;
|
||||||
}
|
}
|
||||||
languageChooser.val(selectedLanguage);
|
languageChooser.val(selectedLanguage);
|
||||||
uhr.options.language = "";
|
uhr.options.language = "";
|
||||||
|
@ -231,9 +231,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
return selectedTheme === item.styleClass;
|
return selectedTheme === item.styleClass;
|
||||||
});
|
});
|
||||||
if (!found) {
|
if (!found) {
|
||||||
var fallback = uhrGlobals.themes[0].styleClass;
|
var fallbackTheme = uhrGlobals.themes[0].styleClass;
|
||||||
console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback);
|
console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'");
|
||||||
selectedTheme = fallback;
|
selectedTheme = fallbackTheme;
|
||||||
}
|
}
|
||||||
themeChooser.val(selectedTheme);
|
themeChooser.val(selectedTheme);
|
||||||
uhr.options.theme = "";
|
uhr.options.theme = "";
|
||||||
|
@ -310,7 +310,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
var language = function language(uhr) {
|
var language = function language(uhr) {
|
||||||
var matchingLanguages = uhrGlobals.languages.filter(function (element) {
|
var matchingLanguages = uhrGlobals.languages.filter(function (element) {
|
||||||
return (element.code === this.options.language)
|
return (element.code === this.options.language);
|
||||||
}, uhr);
|
}, uhr);
|
||||||
if (matchingLanguages.length > 0) {
|
if (matchingLanguages.length > 0) {
|
||||||
return matchingLanguages[0];
|
return matchingLanguages[0];
|
||||||
|
@ -344,72 +344,67 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll.
|
* @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll.
|
||||||
*/
|
*/
|
||||||
function UhrRenderer(layout, renderarea) {
|
function UhrRenderer(layout, renderarea) {
|
||||||
this.layout = layout;
|
this.render = function render(uhr, beforeshow) {
|
||||||
this.renderarea = renderarea;
|
if (layout.parsed === undefined) {
|
||||||
}
|
switch (layout.version) {
|
||||||
UhrRenderer.prototype.render = function (uhr, beforeshow) {
|
|
||||||
var renderer = this;
|
|
||||||
if (this.layout._parsed === undefined) {
|
|
||||||
switch (this.layout.version) {
|
|
||||||
case 2:
|
case 2:
|
||||||
var delegate = new _UhrRendererV2Delegate(this.layout);
|
var delegate = new _UhrRendererV2Delegate(layout);
|
||||||
this.layout._parsed = delegate.parse();
|
var parsedLayout = delegate.parse();
|
||||||
|
Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn("Unknown layout version: '" + this.layout.version + "'");
|
console.warn("Unknown layout version: '" + layout.version + "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var letters = this.layout._parsed;
|
var letters = layout.parsed;
|
||||||
this.renderarea.fadeOut('fast', function () {
|
renderarea.fadeOut('fast', function () {
|
||||||
renderer.renderarea.empty();
|
renderarea.empty();
|
||||||
letters.forEach(function (line, index, array) {
|
letters.forEach(function (line, index, array) {
|
||||||
line.forEach(function (letter) {
|
line.forEach(function (letter) {
|
||||||
renderer.renderarea.append(letter.toString());
|
renderarea.append(letter.toString());
|
||||||
});
|
});
|
||||||
if (index < array.length - 1) {
|
if (index < array.length - 1) {
|
||||||
renderer.renderarea.append('<br/>');
|
renderarea.append('<br/>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (typeof beforeshow === 'function') {
|
if (typeof beforeshow === 'function') {
|
||||||
beforeshow();
|
beforeshow();
|
||||||
}
|
}
|
||||||
renderer.renderarea.fadeIn('fast');
|
renderarea.fadeIn('fast');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
}
|
||||||
function _UhrRendererV2Delegate(layout) {
|
function _UhrRendererV2Delegate(layout) {
|
||||||
this.layout = layout;
|
function parseArrayOrObject(letters, styleClass, input) {
|
||||||
this._parseArrayOrObject = function (letters, styleClass, input) {
|
|
||||||
if (Array.isArray(input)) {
|
if (Array.isArray(input)) {
|
||||||
input.forEach(function (item) {
|
input.forEach(function (item) {
|
||||||
this._parseObject(letters, styleClass, item);
|
parseObject(letters, styleClass, item);
|
||||||
}, this);
|
}, this);
|
||||||
} else {
|
} else {
|
||||||
this._parseObject(letters, styleClass, input);
|
parseObject(letters, styleClass, input);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
this._parseObject = function (letters, styleClass, object) {
|
function parseObject(letters, styleClass, object) {
|
||||||
Object.keys(object).forEach(function (y) {
|
Object.keys(object).forEach(function (y) {
|
||||||
var highlightLetters = object[y];
|
var highlightLetters = object[y];
|
||||||
highlightLetters.forEach(function (x) {
|
highlightLetters.forEach(function (x) {
|
||||||
letters[y - 1][x - 1].addStyle(styleClass);
|
letters[y - 1][x - 1].addStyle(styleClass);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
this._parseTimeDefinition = function(letters, styleClass, definition) {
|
function parseTimeDefinition(letters, styleClass, definition) {
|
||||||
var renderer = this;
|
|
||||||
Object.keys(definition).forEach(function (listString) {
|
Object.keys(definition).forEach(function (listString) {
|
||||||
var array = listString.split(',');
|
var array = listString.split(',');
|
||||||
var highlightLetters = definition[listString];
|
var highlightLetters = definition[listString];
|
||||||
array.forEach(function (item) {
|
array.forEach(function (item) {
|
||||||
renderer._parseArrayOrObject(letters, styleClass + item, highlightLetters);
|
parseArrayOrObject(letters, styleClass + item, highlightLetters);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
_UhrRendererV2Delegate.prototype.parse = function() {
|
this.parse = function parse() {
|
||||||
var letters = [];
|
var letters = [];
|
||||||
this.layout.letters.forEach(function(string) {
|
layout.letters.forEach(function (string) {
|
||||||
var line = [];
|
var line = [];
|
||||||
for (var c = 0; c < string.length; c++) {
|
for (var c = 0; c < string.length; c++) {
|
||||||
var character = new Letter(string[c]);
|
var character = new Letter(string[c]);
|
||||||
|
@ -417,11 +412,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
}
|
}
|
||||||
letters.push(line);
|
letters.push(line);
|
||||||
});
|
});
|
||||||
this._parseArrayOrObject(letters, 'on', this.layout.permanent);
|
parseArrayOrObject(letters, 'on', layout.permanent);
|
||||||
this._parseTimeDefinition(letters, 'minute', this.layout.minutes);
|
parseTimeDefinition(letters, 'minute', layout.minutes);
|
||||||
this._parseTimeDefinition(letters, 'hour', this.layout.hours);
|
parseTimeDefinition(letters, 'hour', layout.hours);
|
||||||
return letters;
|
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