don't remove blank line

This commit is contained in:
Manuel Friedli 2014-08-12 00:44:29 +02:00
parent dbbfae83b3
commit a3dce2322b

967
js/uhr.js
View file

@ -1,484 +1,485 @@
/* /*
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
(function ($) { (function ($) {
'use strict'; 'use strict';
var uhrGlobals = { var uhrGlobals = {
"id": 0, "id": 0,
"languages": [], "languages": [],
"themes": [], "themes": [],
registerLanguage: function registerLanguage(code, language) { registerLanguage: function registerLanguage(code, language) {
var alreadyExists = uhrGlobals.languages.some(function (element) { var alreadyExists = uhrGlobals.languages.some(function (element) {
if (code === element.code) { if (code === element.code) {
console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + "' because it is already registered for language '" + element.language + "'!"); console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + "' because it is already registered for language '" + element.language + "'!");
return true; return true;
} }
return false; return false;
}); });
if (!alreadyExists) { if (!alreadyExists) {
language.code = code; language.code = code;
uhrGlobals.languages.push(language); uhrGlobals.languages.push(language);
} }
} }
}; };
// auto-detect themes // auto-detect themes
$('link[rel=stylesheet]').each(function (index, item) { $('link[rel=stylesheet]').each(function (index, item) {
var styleSheet = $(item); var styleSheet = $(item);
var styleClass = styleSheet.attr('data-class'); var styleClass = styleSheet.attr('data-class');
if (styleClass !== undefined) { if (styleClass !== undefined) {
var name = styleSheet.attr('data-name'); var name = styleSheet.attr('data-name');
if (name === undefined) { if (name === undefined) {
name = styleClass; name = styleClass;
} }
uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); uhrGlobals.themes.push({'styleClass': styleClass, 'name': name});
} }
}); });
// fall-back if no theme was included // fall-back if no theme was included
if (uhrGlobals.themes.length === 0) { if (uhrGlobals.themes.length === 0) {
uhrGlobals.themes.push({}); uhrGlobals.themes.push({});
} }
// public interface methods (exported later) // public interface methods (exported later)
var start = function start() { var start = function start() {
if (!isOn.bind(this)()) { if (!isOn.bind(this)()) {
this.timer = window.setInterval(function () { this.timer = window.setInterval(function () {
this.options.time = new Date(); this.options.time = new Date();
update.bind(this)(); update.bind(this)();
}.bind(this), 1000); }.bind(this), 1000);
update.bind(this)(); update.bind(this)();
setCookie.bind(this)('uhr-status', 'on'); setCookie.bind(this)('uhr-status', 'on');
} }
}; };
var stop = function stop() { var stop = function stop() {
if (isOn.bind(this)()) { if (isOn.bind(this)()) {
window.clearInterval(this.timer); window.clearInterval(this.timer);
this.timer = null; this.timer = null;
update.bind(this)(); update.bind(this)();
setCookie.bind(this)('uhr-status', 'off'); setCookie.bind(this)('uhr-status', 'off');
} }
}; };
var toggle = function toggle() { var toggle = function toggle() {
if (isOn.bind(this)()) { if (isOn.bind(this)()) {
this.stop(); this.stop();
} else { } else {
this.start(); this.start();
} }
}; };
var setLanguage = function setLanugage(languageKey) { var setLanguage = function setLanugage(languageKey) {
if (languageKey !== this.options.language) { if (languageKey !== this.options.language) {
this.options.language = languageKey; this.options.language = languageKey;
var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea'));
renderer.render.bind(this)(function () { renderer.render.bind(this)(function () {
this.currentMinute = -1; this.currentMinute = -1;
update.bind(this)(); update.bind(this)();
}.bind(this)); }.bind(this));
setCookie.bind(this)('uhr-language', languageKey); setCookie.bind(this)('uhr-language', languageKey);
update.bind(this)(); update.bind(this)();
} }
}; };
var setTheme = function setTheme(theme) { var setTheme = function setTheme(theme) {
if (theme !== this.options.theme) { if (theme !== this.options.theme) {
this.element.removeClass(this.options.theme).addClass(theme); this.element.removeClass(this.options.theme).addClass(theme);
$('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme);
this.options.theme = theme; this.options.theme = theme;
setCookie.bind(this)('uhr-theme', theme); setCookie.bind(this)('uhr-theme', theme);
} }
}; };
var setTime = function setTime(time) { var setTime = function setTime(time) {
this.currentMinute = -1; this.currentMinute = -1;
if (time === null) { if (time === null) {
this.options.time = new Date(); this.options.time = new Date();
} else { } else {
if (this.timer !== null) { if (this.timer !== null) {
window.clearInterval(this.timer); window.clearInterval(this.timer);
} }
this.options.time = time; this.options.time = time;
} }
update.bind(this)(); update.bind(this)();
}; };
var setWidth = function setWidth(width) { var setWidth = function setWidth(width) {
var e = this.element; var e = this.element;
e.css('width', width); e.css('width', width);
var realWidth = e.width(); var realWidth = e.width();
e.width(realWidth); e.width(realWidth);
e.height(realWidth); e.height(realWidth);
e.css('font-size', (realWidth / 40) + 'px'); e.css('font-size', (realWidth / 40) + 'px');
}; };
// private interface methods
var create = function create() { // private interface methods
this.id = uhrGlobals.id++; var create = function create() {
this.timer = null; this.id = uhrGlobals.id++;
this.currentMinute = -1; this.timer = null;
var userTime = this.options.time; this.currentMinute = -1;
if (this.options.time === undefined) { var userTime = this.options.time;
this.options.time = new Date(); if (this.options.time === undefined) {
} this.options.time = new Date();
setupHTML.bind(this)(); }
wireFunctionality.bind(this)(); setupHTML.bind(this)();
if (userTime !== undefined) { wireFunctionality.bind(this)();
this.time(userTime); if (userTime !== undefined) {
} this.time(userTime);
}; }
// private helper methods (not exported) };
var showConfigScreen = function showConfigScreen() { // private helper methods (not exported)
$('#uhr-controlpanel' + this.id).show(); var showConfigScreen = function showConfigScreen() {
}; $('#uhr-controlpanel' + this.id).show();
// set up };
var setupHTML = function setupHTML() { // set up
var e = this.element; var setupHTML = function setupHTML() {
// Base clock area var e = this.element;
e.addClass('uhr'); // Base clock area
e.empty(); e.addClass('uhr');
e.append('<span class="item dot dot1"></span>'); e.empty();
e.append('<span class="item dot dot2"></span>'); e.append('<span class="item dot dot1"></span>');
e.append('<span class="item dot dot3"></span>'); e.append('<span class="item dot dot2"></span>');
e.append('<span class="item dot dot4"></span>'); e.append('<span class="item dot dot3"></span>');
e.append('<div class="letterarea"></div>'); e.append('<span class="item dot dot4"></span>');
e.append('<div class="reflection"></div>'); e.append('<div class="letterarea"></div>');
setWidth.bind(this)(this.options.width); e.append('<div class="reflection"></div>');
setWidth.bind(this)(this.options.width);
if (this.options.controls) {
var configlink = $('<a class="uhr-configlink" id="uhr-configlink' + this.id + '"></a>'); if (this.options.controls) {
configlink.on('click', function () { var configlink = $('<a class="uhr-configlink" id="uhr-configlink' + this.id + '"></a>');
showConfigScreen.bind(this)(); configlink.on('click', function () {
}.bind(this)); showConfigScreen.bind(this)();
e.after(configlink); }.bind(this));
var controlpanel = $('<div class="uhr-controlpanel" id="uhr-controlpanel' + this.id + '"></div>'); e.after(configlink);
var content = $('<div class="content"></div>'); var controlpanel = $('<div class="uhr-controlpanel" id="uhr-controlpanel' + this.id + '"></div>');
controlpanel.append(content); var content = $('<div class="content"></div>');
// on/off switch controlpanel.append(content);
var toggleSwitch = $('<div class="onoffswitch" id="uhr-onoffswitch' + this.id + '"></div>'); // on/off switch
toggleSwitch.append('<input type="checkbox" class="onoffswitch-checkbox" id="uhr-onoffswitch-checkbox' + this.id + '" checked="checked" />'); var toggleSwitch = $('<div class="onoffswitch" id="uhr-onoffswitch' + this.id + '"></div>');
toggleSwitch.append('<label class="onoffswitch-label" for="uhr-onoffswitch-checkbox' + this.id + '">' toggleSwitch.append('<input type="checkbox" class="onoffswitch-checkbox" id="uhr-onoffswitch-checkbox' + this.id + '" checked="checked" />');
+ '<div class="onoffswitch-inner"></div>' toggleSwitch.append('<label class="onoffswitch-label" for="uhr-onoffswitch-checkbox' + this.id + '">'
+ '<div class="onoffswitch-switch"></div>' + '<div class="onoffswitch-inner"></div>'
+ '</label>'); + '<div class="onoffswitch-switch"></div>'
content.append(toggleSwitch); + '</label>');
content.append(toggleSwitch);
// language chooser
if (uhrGlobals.languages.length > 1) { // language chooser
var languageChooser = $('<select id="uhr-languagechooser' + this.id + '"></select>'); if (uhrGlobals.languages.length > 1) {
uhrGlobals.languages.forEach(function (item) { var languageChooser = $('<select id="uhr-languagechooser' + this.id + '"></select>');
languageChooser.append('<option value="' + item.code + '">' + item.language + '</option>'); uhrGlobals.languages.forEach(function (item) {
}); languageChooser.append('<option value="' + item.code + '">' + item.language + '</option>');
content.append(languageChooser); });
} content.append(languageChooser);
}
// theme chooser
if (uhrGlobals.themes.length > 1) { // theme chooser
var themeChooser = $('<select id="uhr-themechooser' + this.id + '"></select>'); if (uhrGlobals.themes.length > 1) {
uhrGlobals.themes.forEach(function (item) { var themeChooser = $('<select id="uhr-themechooser' + this.id + '"></select>');
themeChooser.append('<option value="' + item.styleClass + '">' + item.name + '</option>'); uhrGlobals.themes.forEach(function (item) {
}); themeChooser.append('<option value="' + item.styleClass + '">' + item.name + '</option>');
content.append(themeChooser); });
} content.append(themeChooser);
var closebutton = $('<a class="uhr-closecontrolpanel" id="uhr-closecontrolpanel' + this.id + '"></a>'); }
closebutton.on('click', function () { var closebutton = $('<a class="uhr-closecontrolpanel" id="uhr-closecontrolpanel' + this.id + '"></a>');
$('#uhr-controlpanel' + this.id).hide(); closebutton.on('click', function () {
}.bind(this)); $('#uhr-controlpanel' + this.id).hide();
content.append(closebutton); }.bind(this));
e.after(controlpanel); content.append(closebutton);
controlpanel.hide(); e.after(controlpanel);
} controlpanel.hide();
}; }
var wireFunctionality = function wireFunctionality() { };
// on/off switch var wireFunctionality = function wireFunctionality() {
var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); // on/off switch
toggleSwitch.on('click', function () { var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id);
this.toggle(); toggleSwitch.on('click', function () {
}.bind(this)); this.toggle();
var status = $.cookie('uhr-status' + this.id); }.bind(this));
if (status === undefined || this.options.force) { var status = $.cookie('uhr-status' + this.id);
status = this.options.status; if (status === undefined || this.options.force) {
} status = this.options.status;
toggleSwitch.prop('checked', status === 'on'); }
if (status === 'on') { toggleSwitch.prop('checked', status === 'on');
this.start(); if (status === 'on') {
} else { this.start();
this.stop(); } else {
} this.stop();
}
// language chooser
var languageChooser = $('#uhr-languagechooser' + this.id); // language chooser
languageChooser.on('change', function () { var languageChooser = $('#uhr-languagechooser' + this.id);
var languageKey = $('#uhr-languagechooser' + this.id).val(); languageChooser.on('change', function () {
this.language(languageKey); var languageKey = $('#uhr-languagechooser' + this.id).val();
}.bind(this)); this.language(languageKey);
var selectedLanguage = $.cookie('uhr-language' + this.id); }.bind(this));
if (selectedLanguage === undefined || this.options.force) { var selectedLanguage = $.cookie('uhr-language' + this.id);
selectedLanguage = this.options.language; if (selectedLanguage === undefined || this.options.force) {
} selectedLanguage = this.options.language;
var found = uhrGlobals.languages.some(function (item) { }
return selectedLanguage === item.code; var found = uhrGlobals.languages.some(function (item) {
}); return selectedLanguage === item.code;
if (!found) { });
var fallbackLanguage; if (!found) {
if (uhrGlobals.languages.length > 0) { var fallbackLanguage;
fallbackLanguage = uhrGlobals.languages[0].code; if (uhrGlobals.languages.length > 0) {
} else { fallbackLanguage = uhrGlobals.languages[0].code;
fallbackLanguage = ''; } else {
} fallbackLanguage = '';
console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); }
selectedLanguage = fallbackLanguage; console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'");
} selectedLanguage = fallbackLanguage;
languageChooser.val(selectedLanguage); }
this.options.language = ""; languageChooser.val(selectedLanguage);
this.language(selectedLanguage); this.options.language = "";
this.language(selectedLanguage);
// theme chooser
var themeChooser = $('#uhr-themechooser' + this.id); // theme chooser
themeChooser.on('change', function () { var themeChooser = $('#uhr-themechooser' + this.id);
var themeKey = $('#uhr-themechooser' + this.id).val(); themeChooser.on('change', function () {
this.theme(themeKey); var themeKey = $('#uhr-themechooser' + this.id).val();
}.bind(this)); this.theme(themeKey);
var selectedTheme = $.cookie('uhr-theme' + this.id); }.bind(this));
if (selectedTheme === undefined || this.options.force) { var selectedTheme = $.cookie('uhr-theme' + this.id);
selectedTheme = this.options.theme; if (selectedTheme === undefined || this.options.force) {
} selectedTheme = this.options.theme;
found = uhrGlobals.themes.some(function (item) { }
return selectedTheme === item.styleClass; found = uhrGlobals.themes.some(function (item) {
}); return selectedTheme === item.styleClass;
if (!found) { });
var fallbackTheme = uhrGlobals.themes[0].styleClass; if (!found) {
console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); var fallbackTheme = uhrGlobals.themes[0].styleClass;
selectedTheme = fallbackTheme; console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'");
} selectedTheme = fallbackTheme;
themeChooser.val(selectedTheme); }
this.options.theme = ""; themeChooser.val(selectedTheme);
this.theme(selectedTheme); this.options.theme = "";
}; this.theme(selectedTheme);
var setCookie = function setCookie(cookieName, cookieValue) { };
var options = {}; var setCookie = function setCookie(cookieName, cookieValue) {
if (this.options.cookiePath !== undefined) { var options = {};
options = {expires: 365, path: this.options.cookiePath}; if (this.options.cookiePath !== undefined) {
} else { options = {expires: 365, path: this.options.cookiePath};
options = {expires: 365}; } else {
} options = {expires: 365};
$.cookie(cookieName + this.id, cookieValue, options); }
}; $.cookie(cookieName + this.id, cookieValue, options);
};
// business logic
var isOn = function isOn() { // business logic
return this.timer !== null; var isOn = function isOn() {
}; return this.timer !== null;
var update = function update() { };
if (isOn.bind(this)()) { var update = function update() {
var time = this.options.time; if (isOn.bind(this)()) {
if (!language.bind(this)().hasOwnProperty('seconds')) { var time = this.options.time;
if (time.getMinutes() === this.currentMinute) { if (!language.bind(this)().hasOwnProperty('seconds')) {
return; if (time.getMinutes() === this.currentMinute) {
} return;
this.currentMinute = time.getMinutes(); }
} this.currentMinute = time.getMinutes();
show.bind(this)(time); }
} else { show.bind(this)(time);
clear.bind(this)(); } else {
this.currentMinute = -1; clear.bind(this)();
} this.currentMinute = -1;
}; }
var show = function show(time) { };
var second = getSecond.bind(this)(time); var show = function show(time) {
var dotMinute = getDotMinute.bind(this)(time); var second = getSecond.bind(this)(time);
var hour = getHour.bind(this)(time); var dotMinute = getDotMinute.bind(this)(time);
var coarseMinute = getCoarseMinute.bind(this)(time); var hour = getHour.bind(this)(time);
clear.bind(this)(); var coarseMinute = getCoarseMinute.bind(this)(time);
highlight.bind(this)('on'); clear.bind(this)();
for (var i = 1; i <= dotMinute; i++) { highlight.bind(this)('on');
highlight.bind(this)('dot' + i); for (var i = 1; i <= dotMinute; i++) {
} highlight.bind(this)('dot' + i);
highlight.bind(this)('second' + second); }
highlight.bind(this)('minute' + coarseMinute); highlight.bind(this)('second' + second);
highlight.bind(this)('hour' + hour); highlight.bind(this)('minute' + coarseMinute);
}; highlight.bind(this)('hour' + hour);
var highlight = function highlight(itemClass) { };
this.element.find('.item.' + itemClass).addClass('active'); var highlight = function highlight(itemClass) {
}; this.element.find('.item.' + itemClass).addClass('active');
var clear = function clear() { };
this.element.find('.item').removeClass('active'); var clear = function clear() {
}; this.element.find('.item').removeClass('active');
var getSecond = function getSecond(date) { };
if (typeof language.bind(this)().getSeconds === 'function') { var getSecond = function getSecond(date) {
return language.bind(this)().getSeconds(date); if (typeof language.bind(this)().getSeconds === 'function') {
} return language.bind(this)().getSeconds(date);
return date.getSeconds(); }
}; return date.getSeconds();
var getDotMinute = function getDotMinute(date) { };
if (typeof language.bind(this)().getDotMinute === 'function') { var getDotMinute = function getDotMinute(date) {
return language.bind(this)().getDotMinute(date); if (typeof language.bind(this)().getDotMinute === 'function') {
} return language.bind(this)().getDotMinute(date);
var minutes = date.getMinutes(); }
return minutes % 5; var minutes = date.getMinutes();
}; return minutes % 5;
var getCoarseMinute = function getCoarseMinute(date) { };
if (typeof language.bind(this)().getCoarseMinute === 'function') { var getCoarseMinute = function getCoarseMinute(date) {
return language.bind(this)().getCoarseMinute(date); if (typeof language.bind(this)().getCoarseMinute === 'function') {
} return language.bind(this)().getCoarseMinute(date);
return date.getMinutes(); }
}; return date.getMinutes();
var getHour = function getHour(date) { };
if (typeof language.bind(this)().getHour === 'function') { var getHour = function getHour(date) {
return language.bind(this)().getHour(date); if (typeof language.bind(this)().getHour === 'function') {
} return language.bind(this)().getHour(date);
var hour = date.getHours(); }
if (date.getMinutes() >= 25) { var hour = date.getHours();
return (hour + 1) % 24; if (date.getMinutes() >= 25) {
} return (hour + 1) % 24;
return hour; }
}; return hour;
};
var language = function language() {
var matchingLanguages = uhrGlobals.languages.filter(function (element) { var language = function language() {
return (element.code === this.options.language); var matchingLanguages = uhrGlobals.languages.filter(function (element) {
}, this); return (element.code === this.options.language);
if (matchingLanguages.length > 0) { }, this);
return matchingLanguages[0]; if (matchingLanguages.length > 0) {
} return matchingLanguages[0];
// fallback: return empty object }
return {}; // fallback: return empty object
}; return {};
};
$.widget("fritteli.uhr", {
"options": { $.widget("fritteli.uhr", {
width: '100%', "options": {
status: 'on', width: '100%',
language: 'de_CH', status: 'on',
theme: uhrGlobals.themes[0].styleClass, language: 'de_CH',
force: false, theme: uhrGlobals.themes[0].styleClass,
controls: true, force: false,
cookiePath: undefined controls: true,
}, cookiePath: undefined
"start": start, },
"stop": stop, "start": start,
"toggle": toggle, "stop": stop,
"language": setLanguage, "toggle": toggle,
"theme": setTheme, "language": setLanguage,
"time": setTime, "theme": setTheme,
"width": setWidth, "time": setTime,
// constructor method "width": setWidth,
"_create": create // constructor method
}); "_create": create
$.fritteli.uhr.register = uhrGlobals.registerLanguage; });
/** $.fritteli.uhr.register = uhrGlobals.registerLanguage;
* Hilfsklasse zum Rendern der Uhr. /**
* @param layout Layout-Objekt, das gerendert werden soll. * Hilfsklasse zum Rendern der Uhr.
* @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. * @param layout Layout-Objekt, das gerendert werden soll.
*/ * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll.
function UhrRenderer(layout, renderarea) { */
this.render = function render(beforeshow) { function UhrRenderer(layout, renderarea) {
if (layout.parsed === undefined) { this.render = function render(beforeshow) {
switch (layout.version) { if (layout.parsed === undefined) {
case 2: switch (layout.version) {
var delegate = new UhrRendererV2Delegate(layout); case 2:
var parsedLayout = delegate.parse(); var delegate = new UhrRendererV2Delegate(layout);
Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false}); var parsedLayout = delegate.parse();
break; Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false});
default: break;
console.warn("Unknown layout version: '" + layout.version + "'"); default:
return; console.warn("Unknown layout version: '" + layout.version + "'");
} return;
} }
var letters = layout.parsed; }
renderarea.fadeOut('fast', function () { var letters = layout.parsed;
renderarea.empty(); renderarea.fadeOut('fast', function () {
letters.forEach(function (line, index, array) { renderarea.empty();
line.forEach(function (letter) { letters.forEach(function (line, index, array) {
renderarea.append(letter.toString()); line.forEach(function (letter) {
}); renderarea.append(letter.toString());
if (index < array.length - 1) { });
renderarea.append('<br/>'); if (index < array.length - 1) {
} renderarea.append('<br/>');
}); }
if (typeof beforeshow === 'function') { });
beforeshow(); if (typeof beforeshow === 'function') {
} beforeshow();
renderarea.fadeIn('fast'); }
}); renderarea.fadeIn('fast');
}; });
} };
}
function UhrRendererV2Delegate(layout) {
function parseArrayOrObject(letters, styleClass, input) { function UhrRendererV2Delegate(layout) {
if (typeof input !== 'undefined' && input !== null) { function parseArrayOrObject(letters, styleClass, input) {
if (Array.isArray(input)) { if (typeof input !== 'undefined' && input !== null) {
input.forEach(function (item) { if (Array.isArray(input)) {
parseObject(letters, styleClass, item); input.forEach(function (item) {
}); parseObject(letters, styleClass, item);
} else { });
parseObject(letters, styleClass, input); } else {
} parseObject(letters, styleClass, input);
} }
} }
}
function parseObject(letters, styleClass, object) {
if (typeof object !== 'undefined' && object !== null) { function parseObject(letters, styleClass, object) {
Object.keys(object).forEach(function (y) { if (typeof object !== 'undefined' && object !== null) {
var highlightLetters = object[y]; Object.keys(object).forEach(function (y) {
highlightLetters.forEach(function (x) { var highlightLetters = object[y];
letters[y - 1][x - 1].addStyle(styleClass); highlightLetters.forEach(function (x) {
}); letters[y - 1][x - 1].addStyle(styleClass);
}); });
} });
} }
}
function parseTimeDefinition(letters, styleClass, definition) {
if (typeof definition !== 'undefined' && definition !== null) { function parseTimeDefinition(letters, styleClass, definition) {
Object.keys(definition).forEach(function (listString) { if (typeof definition !== 'undefined' && definition !== null) {
var array = listString.split(','); Object.keys(definition).forEach(function (listString) {
var highlightLetters = definition[listString]; var array = listString.split(',');
array.forEach(function (item) { var highlightLetters = definition[listString];
parseArrayOrObject(letters, styleClass + item, highlightLetters); array.forEach(function (item) {
}); parseArrayOrObject(letters, styleClass + item, highlightLetters);
}); });
} });
} }
}
this.parse = function parse() {
var letters = []; this.parse = function parse() {
layout.letters.forEach(function (string) { var letters = [];
var line = []; layout.letters.forEach(function (string) {
for (var c = 0; c < string.length; c++) { var line = [];
var character = new Letter(string[c]); for (var c = 0; c < string.length; c++) {
line.push(character); var character = new Letter(string[c]);
} line.push(character);
letters.push(line); }
}); letters.push(line);
parseArrayOrObject(letters, 'on', layout.permanent); });
parseTimeDefinition(letters, 'second', layout.seconds); parseArrayOrObject(letters, 'on', layout.permanent);
parseTimeDefinition(letters, 'minute', layout.minutes); parseTimeDefinition(letters, 'second', layout.seconds);
parseTimeDefinition(letters, 'hour', layout.hours); parseTimeDefinition(letters, 'minute', layout.minutes);
return letters; 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. * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
* @param style Die CSS-Styleklassen des Buchstabens. * @param value Der Buchstabe, der Dargestellt werden soll.
*/ * @param style Die CSS-Styleklassen des Buchstabens.
function Letter(value, style) { */
var myValue = value; function Letter(value, style) {
var myStyle = style || ''; var myValue = value;
this.addStyle = function (style) { var myStyle = style || '';
if (myStyle === '') { this.addStyle = function (style) {
myStyle = style; if (myStyle === '') {
} else { myStyle = style;
myStyle += ' ' + style; } else {
} myStyle += ' ' + style;
}; }
this.toString = function () { };
return '<span class="item letter ' + myStyle + '">' + myValue + '</span>'; this.toString = function () {
}; return '<span class="item letter ' + myStyle + '">' + myValue + '</span>';
} };
}
})(jQuery); })(jQuery);