2013-11-19 16:55:01 +01:00
|
|
|
var clock = null;
|
|
|
|
var currentMinute = -1;
|
2013-11-25 13:25:02 +01:00
|
|
|
var layout = new Array();
|
|
|
|
layout['default'] = {
|
|
|
|
language: 'Undefined',
|
|
|
|
values: []
|
|
|
|
};
|
|
|
|
var currentLayout = layout['default'];
|
2013-11-19 16:55:01 +01:00
|
|
|
|
|
|
|
function highlightCurrentTime() {
|
|
|
|
var now = new Date();
|
2013-11-25 12:53:54 +01:00
|
|
|
var dotMinute = getDotMinute(now);
|
|
|
|
if (dotMinute == currentMinute) {
|
2013-11-19 16:55:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-11-25 12:53:54 +01:00
|
|
|
currentMinute = dotMinute;
|
|
|
|
var hour = getHour(now);
|
|
|
|
var coarseMinute = getCoarseMinute(now);
|
2013-11-19 16:55:01 +01:00
|
|
|
resetItems();
|
|
|
|
for (var i = 1; i <= dotMinute; i++) {
|
|
|
|
highlight('dot' + i);
|
|
|
|
}
|
|
|
|
highlight('minute' + coarseMinute);
|
|
|
|
hour = normalizeHour(hour);
|
2013-11-25 11:09:57 +01:00
|
|
|
highlight('hour' + hour);
|
2013-11-25 14:06:18 +01:00
|
|
|
if (coarseMinute == 0) {
|
|
|
|
highlight('sharphour');
|
|
|
|
}
|
2013-11-19 16:55:01 +01:00
|
|
|
}
|
2013-11-25 12:53:54 +01:00
|
|
|
function getHour(date) {
|
2013-11-25 13:25:02 +01:00
|
|
|
if (typeof currentLayout.getHour === 'function') {
|
|
|
|
return currentLayout.getHour(date);
|
2013-11-25 12:53:54 +01:00
|
|
|
}
|
|
|
|
var hour = date.getHours();
|
|
|
|
if (date.getMinutes() >= 25) {
|
|
|
|
return hour + 1;
|
|
|
|
}
|
|
|
|
return hour;
|
|
|
|
}
|
|
|
|
function getCoarseMinute(date) {
|
2013-11-25 13:25:02 +01:00
|
|
|
if (typeof currentLayout.getCoarseMinute === 'function') {
|
|
|
|
return currentLayout.getCoarseMinute(date);
|
2013-11-25 12:53:54 +01:00
|
|
|
}
|
|
|
|
var minutes = date.getMinutes();
|
|
|
|
return minutes - getDotMinute(date);
|
|
|
|
}
|
|
|
|
function getDotMinute(date) {
|
2013-11-25 13:25:02 +01:00
|
|
|
if (typeof currentLayout.getDotMinute === 'function') {
|
|
|
|
return currentLayout.getDotMinute(date);
|
2013-11-25 12:53:54 +01:00
|
|
|
}
|
|
|
|
var minutes = date.getMinutes();
|
|
|
|
return minutes % 5;
|
|
|
|
}
|
2013-11-19 16:55:01 +01:00
|
|
|
function clearDisplay() {
|
|
|
|
$('.item').removeClass('active');
|
|
|
|
}
|
|
|
|
function resetItems() {
|
|
|
|
clearDisplay()
|
2013-11-25 12:53:54 +01:00
|
|
|
highlight('on');
|
2013-11-19 16:55:01 +01:00
|
|
|
}
|
|
|
|
function highlight(itemClass) {
|
|
|
|
$('.item.' + itemClass).addClass('active');
|
|
|
|
}
|
|
|
|
function normalizeHour(hour) {
|
|
|
|
if (hour > 12) {
|
|
|
|
hour %= 12;
|
|
|
|
}
|
|
|
|
if (hour == 0) {
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
return hour;
|
|
|
|
}
|
|
|
|
function startClock() {
|
|
|
|
if (clock == null) {
|
2013-11-25 12:53:54 +01:00
|
|
|
highlightCurrentTime();
|
2013-11-19 16:55:01 +01:00
|
|
|
clock = window.setInterval(highlightCurrentTime, 1000);
|
|
|
|
}
|
2013-11-25 14:38:25 +01:00
|
|
|
$.cookie('status', 'on');
|
2013-11-19 16:55:01 +01:00
|
|
|
}
|
|
|
|
function stopClock() {
|
|
|
|
if (clock != null) {
|
|
|
|
window.clearInterval(clock);
|
|
|
|
clock = null;
|
|
|
|
currentMinute = -1;
|
|
|
|
clearDisplay();
|
|
|
|
}
|
2013-11-25 14:38:25 +01:00
|
|
|
$.cookie('status', 'off');
|
2013-11-19 16:55:01 +01:00
|
|
|
}
|
|
|
|
function updateClockState() {
|
2013-11-25 13:25:02 +01:00
|
|
|
if (isOn()) {
|
2013-11-19 16:55:01 +01:00
|
|
|
startClock();
|
|
|
|
} else {
|
|
|
|
stopClock();
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 13:25:02 +01:00
|
|
|
function isOn() {
|
|
|
|
return $('#onoffswitch').is(':checked');
|
|
|
|
}
|
|
|
|
function switchTheme(theme) {
|
2013-11-19 16:55:01 +01:00
|
|
|
$('#theme').attr('href', 'uhr-' + theme + '.css');
|
2013-11-25 14:38:25 +01:00
|
|
|
$.cookie('theme', theme);
|
2013-11-19 16:55:01 +01:00
|
|
|
}
|
2013-11-25 13:25:02 +01:00
|
|
|
function switchLayout(locale) {
|
|
|
|
stopClock();
|
|
|
|
currentLayout = layout[locale];
|
2013-11-25 13:42:03 +01:00
|
|
|
if (currentLayout == undefined) {
|
|
|
|
currentLayout = layout['default'];
|
|
|
|
}
|
2013-11-25 13:25:02 +01:00
|
|
|
renderLayout();
|
|
|
|
if (isOn()) {
|
|
|
|
startClock();
|
|
|
|
}
|
2013-11-25 14:38:25 +01:00
|
|
|
$.cookie('layout', locale);
|
2013-11-25 13:25:02 +01:00
|
|
|
}
|
|
|
|
function renderLayout() {
|
2013-11-25 10:57:30 +01:00
|
|
|
var container = $('#renderarea');
|
2013-11-25 13:25:02 +01:00
|
|
|
container.empty();
|
|
|
|
for (var y = 0; y < currentLayout.values.length; y++) {
|
|
|
|
for (var x = 0; x < currentLayout.values[y].length; x++) {
|
|
|
|
var letter = currentLayout.values[y][x];
|
2013-11-24 19:31:14 +01:00
|
|
|
container.append(letter.toString());
|
|
|
|
}
|
2013-11-25 13:25:02 +01:00
|
|
|
if (y < currentLayout.values.length - 1) {
|
2013-11-24 19:31:14 +01:00
|
|
|
container.append('<br/>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 16:58:21 +01:00
|
|
|
function Letter(value, style) {
|
2013-11-25 10:57:30 +01:00
|
|
|
this.value = value;
|
2013-11-25 16:58:21 +01:00
|
|
|
this.style = style || '';
|
2013-11-25 10:57:30 +01:00
|
|
|
this.getStyle = function() {
|
|
|
|
return "item letter " + style;
|
|
|
|
}
|
|
|
|
this.getValue = function() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Letter.prototype.toString = function letterToString() {
|
|
|
|
return "<span class=\"" + this.getStyle() + "\">" + this.getValue() + "</span>";
|
|
|
|
}
|
2013-11-25 11:05:25 +01:00
|
|
|
/**
|
|
|
|
* Hilfsfunktion, um einen Buchstaben zu erzeugen.
|
|
|
|
*
|
|
|
|
* @param letter string: Der Buchstabe, der angezeigt werden soll
|
|
|
|
* @example l('I', 'is') erzeugt den Buchstaben 'I' mit der CSS-Styleklasse 'is'
|
|
|
|
*/
|
2013-11-25 10:57:30 +01:00
|
|
|
function l(letter, style) {
|
|
|
|
return new Letter(letter, style);
|
|
|
|
}
|
2013-11-25 11:05:25 +01:00
|
|
|
/**
|
|
|
|
* Hilfsfunktion, um einen Buchstaben zu erzeugen, der zu einem Stunden-Wort gehört.
|
|
|
|
*
|
2013-11-25 12:53:54 +01:00
|
|
|
* @param letter string: Der Buchstabe, der angezeigt werden soll
|
|
|
|
* @param hours... integer: Eine Aufzählung von Stundenwerten, zu welchen der Buchstabe als aktiv angezeigt werden soll
|
|
|
|
* @example h('Z', 2), 11 erzeugt den Buchstaben 'Z', der um 2:xx, 11:xx, 14:xx und 23:xx aktiv angezeigt wird
|
2013-11-25 11:05:25 +01:00
|
|
|
*/
|
2013-11-25 12:53:54 +01:00
|
|
|
function h(letter) {
|
|
|
|
var style = '';
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
style += ' hour' + arguments[i];
|
|
|
|
}
|
|
|
|
return l(letter, style);
|
2013-11-25 10:57:30 +01:00
|
|
|
}
|
2013-11-25 11:05:25 +01:00
|
|
|
/**
|
|
|
|
* Hilfsfunktion, um einen Buchstaben zu erzeugen, der zu einem Minuten-Wort gehört.
|
|
|
|
*
|
|
|
|
* @param letter string: Der Buchstabe, der angezeigt werden soll
|
2013-11-25 12:53:54 +01:00
|
|
|
* @param minutes... integer: Eine Aufzählung von Minutenwerten, zu welchen der Buchstabe als aktiv angezeigt werden soll
|
2013-11-25 11:05:25 +01:00
|
|
|
* @example m('A', 5, 10, 15, 20, 35) erzeugt den Buchstaben 'A' der um :05, :10, :15, :20 und :35 aktiv angezeigt wird
|
|
|
|
*/
|
2013-11-25 10:57:30 +01:00
|
|
|
function m(letter) {
|
|
|
|
var style = '';
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
style += ' minute' + arguments[i];
|
|
|
|
}
|
|
|
|
return l(letter, style);
|
|
|
|
}
|
|
|
|
|