more JSHinting
This commit is contained in:
parent
cd58ff4ba3
commit
ec8a185dd7
1 changed files with 62 additions and 66 deletions
128
js/uhr.js
128
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,84 +344,80 @@ 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) {
|
case 2:
|
||||||
var renderer = this;
|
var delegate = new _UhrRendererV2Delegate(layout);
|
||||||
if (this.layout._parsed === undefined) {
|
var parsedLayout = delegate.parse();
|
||||||
switch (this.layout.version) {
|
Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false});
|
||||||
case 2:
|
break;
|
||||||
var delegate = new _UhrRendererV2Delegate(this.layout);
|
default:
|
||||||
this.layout._parsed = delegate.parse();
|
console.warn("Unknown layout version: '" + layout.version + "'");
|
||||||
break;
|
return;
|
||||||
default:
|
|
||||||
console.warn("Unknown layout version: '" + this.layout.version + "'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var letters = this.layout._parsed;
|
|
||||||
this.renderarea.fadeOut('fast', function () {
|
|
||||||
renderer.renderarea.empty();
|
|
||||||
letters.forEach(function(line, index, array) {
|
|
||||||
line.forEach(function (letter) {
|
|
||||||
renderer.renderarea.append(letter.toString());
|
|
||||||
});
|
|
||||||
if (index < array.length - 1) {
|
|
||||||
renderer.renderarea.append('<br/>');
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
var letters = layout.parsed;
|
||||||
|
renderarea.fadeOut('fast', function () {
|
||||||
|
renderarea.empty();
|
||||||
|
letters.forEach(function (line, index, array) {
|
||||||
|
line.forEach(function (letter) {
|
||||||
|
renderarea.append(letter.toString());
|
||||||
|
});
|
||||||
|
if (index < array.length - 1) {
|
||||||
|
renderarea.append('<br/>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (typeof beforeshow === 'function') {
|
||||||
|
beforeshow();
|
||||||
|
}
|
||||||
|
renderarea.fadeIn('fast');
|
||||||
});
|
});
|
||||||
if (typeof beforeshow === 'function') {
|
};
|
||||||
beforeshow();
|
}
|
||||||
}
|
|
||||||
renderer.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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
this.parse = function parse() {
|
||||||
|
var letters = [];
|
||||||
|
layout.letters.forEach(function (string) {
|
||||||
|
var line = [];
|
||||||
|
for (var c = 0; c < string.length; c++) {
|
||||||
|
var character = new Letter(string[c]);
|
||||||
|
line.push(character);
|
||||||
|
}
|
||||||
|
letters.push(line);
|
||||||
|
});
|
||||||
|
parseArrayOrObject(letters, 'on', layout.permanent);
|
||||||
|
parseTimeDefinition(letters, 'minute', layout.minutes);
|
||||||
|
parseTimeDefinition(letters, 'hour', layout.hours);
|
||||||
|
return letters;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
_UhrRendererV2Delegate.prototype.parse = function() {
|
|
||||||
var letters = [];
|
|
||||||
this.layout.letters.forEach(function(string) {
|
|
||||||
var line = [];
|
|
||||||
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._parseTimeDefinition(letters, 'minute', this.layout.minutes);
|
|
||||||
this._parseTimeDefinition(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