more JSHinting

This commit is contained in:
Manuel Friedli 2014-07-04 00:42:05 +02:00
parent cd58ff4ba3
commit ec8a185dd7

128
js/uhr.js
View file

@ -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,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.
*/
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) {
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();
letters.forEach(function(line, index, array) {
line.forEach(function (letter) {
renderer.renderarea.append(letter.toString());
});
if (index < array.length - 1) {
renderer.renderarea.append('<br/>');
this.render = function render(uhr, beforeshow) {
if (layout.parsed === undefined) {
switch (layout.version) {
case 2:
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: '" + layout.version + "'");
return;
}
}
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) {
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);
});
});
};
}
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.
* @param value Der Buchstabe, der Dargestellt werden soll.