more JSHinting
This commit is contained in:
parent
cd58ff4ba3
commit
ec8a185dd7
1 changed files with 62 additions and 66 deletions
80
js/uhr.js
80
js/uhr.js
|
@ -205,14 +205,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
return selectedLanguage === item.code;
|
||||
});
|
||||
if (!found) {
|
||||
var fallback;
|
||||
var fallbackLanguage;
|
||||
if (uhrGlobals.languages.length > 0) {
|
||||
fallback = uhrGlobals.languages[0].code;
|
||||
fallbackLanguage = uhrGlobals.languages[0].code;
|
||||
} else {
|
||||
fallback = '';
|
||||
fallbackLanguage = '';
|
||||
}
|
||||
console.warn("Language " + selectedLanguage + " not found! Using fallback: " + fallback);
|
||||
selectedLanguage = fallback;
|
||||
console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'");
|
||||
selectedLanguage = fallbackLanguage;
|
||||
}
|
||||
languageChooser.val(selectedLanguage);
|
||||
uhr.options.language = "";
|
||||
|
@ -231,9 +231,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
return selectedTheme === item.styleClass;
|
||||
});
|
||||
if (!found) {
|
||||
var fallback = uhrGlobals.themes[0].styleClass;
|
||||
console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback);
|
||||
selectedTheme = fallback;
|
||||
var fallbackTheme = uhrGlobals.themes[0].styleClass;
|
||||
console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'");
|
||||
selectedTheme = fallbackTheme;
|
||||
}
|
||||
themeChooser.val(selectedTheme);
|
||||
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 matchingLanguages = uhrGlobals.languages.filter(function (element) {
|
||||
return (element.code === this.options.language)
|
||||
return (element.code === this.options.language);
|
||||
}, uhr);
|
||||
if (matchingLanguages.length > 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.
|
||||
*/
|
||||
function UhrRenderer(layout, renderarea) {
|
||||
this.layout = layout;
|
||||
this.renderarea = renderarea;
|
||||
}
|
||||
UhrRenderer.prototype.render = function (uhr, beforeshow) {
|
||||
var renderer = this;
|
||||
if (this.layout._parsed === undefined) {
|
||||
switch (this.layout.version) {
|
||||
this.render = function render(uhr, beforeshow) {
|
||||
if (layout.parsed === undefined) {
|
||||
switch (layout.version) {
|
||||
case 2:
|
||||
var delegate = new _UhrRendererV2Delegate(this.layout);
|
||||
this.layout._parsed = delegate.parse();
|
||||
var delegate = new _UhrRendererV2Delegate(layout);
|
||||
var parsedLayout = delegate.parse();
|
||||
Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false});
|
||||
break;
|
||||
default:
|
||||
console.warn("Unknown layout version: '" + this.layout.version + "'");
|
||||
console.warn("Unknown layout version: '" + layout.version + "'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
var letters = this.layout._parsed;
|
||||
this.renderarea.fadeOut('fast', function () {
|
||||
renderer.renderarea.empty();
|
||||
letters.forEach(function(line, index, array) {
|
||||
var letters = layout.parsed;
|
||||
renderarea.fadeOut('fast', function () {
|
||||
renderarea.empty();
|
||||
letters.forEach(function (line, index, array) {
|
||||
line.forEach(function (letter) {
|
||||
renderer.renderarea.append(letter.toString());
|
||||
renderarea.append(letter.toString());
|
||||
});
|
||||
if (index < array.length - 1) {
|
||||
renderer.renderarea.append('<br/>');
|
||||
renderarea.append('<br/>');
|
||||
}
|
||||
});
|
||||
if (typeof beforeshow === 'function') {
|
||||
beforeshow();
|
||||
}
|
||||
renderer.renderarea.fadeIn('fast');
|
||||
renderarea.fadeIn('fast');
|
||||
});
|
||||
};
|
||||
}
|
||||
function _UhrRendererV2Delegate(layout) {
|
||||
this.layout = layout;
|
||||
this._parseArrayOrObject = function (letters, styleClass, input) {
|
||||
function parseArrayOrObject(letters, styleClass, input) {
|
||||
if (Array.isArray(input)) {
|
||||
input.forEach(function (item) {
|
||||
this._parseObject(letters, styleClass, item);
|
||||
parseObject(letters, styleClass, item);
|
||||
}, this);
|
||||
} 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) {
|
||||
var highlightLetters = object[y];
|
||||
highlightLetters.forEach(function (x) {
|
||||
letters[y - 1][x - 1].addStyle(styleClass);
|
||||
});
|
||||
});
|
||||
};
|
||||
this._parseTimeDefinition = function(letters, styleClass, definition) {
|
||||
var renderer = this;
|
||||
}
|
||||
function parseTimeDefinition(letters, styleClass, definition) {
|
||||
Object.keys(definition).forEach(function (listString) {
|
||||
var array = listString.split(',');
|
||||
var highlightLetters = definition[listString];
|
||||
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 = [];
|
||||
this.layout.letters.forEach(function(string) {
|
||||
layout.letters.forEach(function (string) {
|
||||
var line = [];
|
||||
for (var c = 0; c < string.length; 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);
|
||||
});
|
||||
this._parseArrayOrObject(letters, 'on', this.layout.permanent);
|
||||
this._parseTimeDefinition(letters, 'minute', this.layout.minutes);
|
||||
this._parseTimeDefinition(letters, 'hour', this.layout.hours);
|
||||
parseArrayOrObject(letters, 'on', layout.permanent);
|
||||
parseTimeDefinition(letters, 'minute', layout.minutes);
|
||||
parseTimeDefinition(letters, 'hour', layout.hours);
|
||||
return letters;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
||||
* @param value Der Buchstabe, der Dargestellt werden soll.
|
||||
|
|
Loading…
Reference in a new issue