2013-11-27 11:12:50 +01:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-01-11 03:26:53 +01:00
|
|
|
(function($) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
if (window.Uhr !== undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.Uhr = {
|
|
|
|
id: 0,
|
|
|
|
start: function(e) {
|
|
|
|
if (!Uhr.isOn(e)) {
|
|
|
|
e.data('timer', window.setInterval(function() {Uhr.update(e);}, 1000));
|
|
|
|
Uhr.update(e);
|
|
|
|
jQuery.cookie('status' + e.data('id'), 'on', {expires: 365, path: '/'});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
stop: function(e) {
|
|
|
|
if (Uhr.isOn(e)) {
|
|
|
|
window.clearInterval(e.data('timer'));
|
|
|
|
e.data('timer', null);
|
|
|
|
Uhr.update(e);
|
|
|
|
jQuery.cookie('status' + e.data('id'), 'off', {expires: 365, path: '/'});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
update: function(e) {
|
|
|
|
if (Uhr.isOn(e)) {
|
|
|
|
var now = new Date();
|
|
|
|
if (now.getMinutes() == e.data('currentMinute')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.data('currentMinute', now.getMinutes());
|
|
|
|
var dotMinute = Uhr.getDotMinute(e, now);
|
|
|
|
var hour = Uhr.getHour(e, now);
|
|
|
|
var coarseMinute = this.getCoarseMinute(e, now);
|
|
|
|
Uhr.clear(e);
|
|
|
|
Uhr.highlight(e, 'on');
|
|
|
|
for (var i = 1; i <= dotMinute; i++) {
|
|
|
|
Uhr.highlight(e, 'dot' + i);
|
|
|
|
}
|
|
|
|
Uhr.highlight(e, 'minute' + coarseMinute);
|
|
|
|
hour = this.normalizeHour(hour);
|
|
|
|
Uhr.highlight(e, 'hour' + hour);
|
|
|
|
if (coarseMinute == 0) {
|
|
|
|
Uhr.highlight(e, 'sharphour');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Uhr.clear(e);
|
|
|
|
e.data('currentMinute', -1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggle: function(e) {
|
|
|
|
if (Uhr.isOn(e)) {
|
|
|
|
Uhr.stop(e);
|
|
|
|
} else {
|
|
|
|
Uhr.start(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clear: function(e) {
|
|
|
|
e.find('.item').removeClass('active');
|
|
|
|
},
|
|
|
|
setLanguage: function(e, language) {
|
2014-01-11 12:18:11 +01:00
|
|
|
var newLanguage = Uhr.layouts[language];
|
|
|
|
if (newLanguage !== undefined && newLanguage != e.data('currentLanguage')) {
|
|
|
|
e.data('currentLanguage', newLanguage);
|
|
|
|
var renderer = new UhrRenderer(newLanguage, e.find('.letterarea'));
|
|
|
|
renderer.render(e);
|
|
|
|
jQuery.cookie('language' + e.data('id'), language, {expires: 365, path: '/'});
|
|
|
|
}
|
2014-01-11 03:26:53 +01:00
|
|
|
},
|
|
|
|
setTheme: function(e, theme) {
|
|
|
|
var currentTheme = e.data('currentTheme');
|
|
|
|
if (theme != currentTheme) {
|
|
|
|
e.removeClass(currentTheme).addClass(theme);
|
|
|
|
e.data('toggleSwitch').removeClass(currentTheme).addClass(theme);
|
|
|
|
e.data('currentTheme', theme);
|
|
|
|
jQuery.cookie('theme' + e.data('id'), theme, {expires: 365, path: '/'});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isOn: function(e) {
|
|
|
|
return e.data('timer') != null;
|
|
|
|
},
|
|
|
|
highlight: function(e, itemClass) {
|
|
|
|
e.find('.item.' + itemClass).addClass('active');
|
|
|
|
},
|
|
|
|
getHour: function(e, date) {
|
2014-01-11 12:18:11 +01:00
|
|
|
//FIXME
|
|
|
|
/*
|
2014-01-11 03:26:53 +01:00
|
|
|
if (typeof e.data('currentLayout').getHour === 'function') {
|
|
|
|
return e.data('currentLayout').getHour(date);
|
|
|
|
}
|
2014-01-11 12:18:11 +01:00
|
|
|
*/
|
2014-01-11 03:26:53 +01:00
|
|
|
var hour = date.getHours();
|
|
|
|
if (date.getMinutes() >= 25) {
|
|
|
|
return hour + 1;
|
|
|
|
}
|
|
|
|
return hour;
|
|
|
|
},
|
|
|
|
getCoarseMinute: function(e, date) {
|
2014-01-11 12:18:11 +01:00
|
|
|
//FIXME
|
|
|
|
/*
|
2014-01-11 03:26:53 +01:00
|
|
|
if (typeof e.data('currentLayout').getCoarseMinute === 'function') {
|
|
|
|
return e.data('currentLayout').getCoarseMinute(date);
|
|
|
|
}
|
2014-01-11 12:18:11 +01:00
|
|
|
*/
|
2014-01-11 03:26:53 +01:00
|
|
|
var minutes = date.getMinutes();
|
|
|
|
return minutes - Uhr.getDotMinute(e, date);
|
|
|
|
},
|
|
|
|
getDotMinute: function(e, date) {
|
2014-01-11 12:18:11 +01:00
|
|
|
//FIXME
|
|
|
|
/*
|
2014-01-11 03:26:53 +01:00
|
|
|
if (typeof e.data('currentLayout').getDotMinute === 'function') {
|
|
|
|
return e.data('currentLayout').getDotMinute(date);
|
|
|
|
}
|
2014-01-11 12:18:11 +01:00
|
|
|
*/
|
2014-01-11 03:26:53 +01:00
|
|
|
var minutes = date.getMinutes();
|
|
|
|
return minutes % 5;
|
|
|
|
},
|
|
|
|
normalizeHour: function(hour) {
|
|
|
|
if (hour > 12) {
|
|
|
|
hour %= 12;
|
|
|
|
}
|
|
|
|
if (hour == 0) {
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
return hour;
|
2014-01-11 12:18:11 +01:00
|
|
|
},
|
|
|
|
registerLanguage: function(languageKey, layout) {
|
|
|
|
this.layouts[languageKey] = layout;
|
|
|
|
},
|
|
|
|
layouts: new Array()
|
2014-01-11 03:26:53 +01:00
|
|
|
}
|
|
|
|
$.fn.uhr = function(options) {
|
|
|
|
var settings = $.extend({
|
|
|
|
width: '100%',
|
|
|
|
force: false,
|
|
|
|
status: 'on',
|
|
|
|
language: 'de_CH',
|
|
|
|
theme: 'black'
|
|
|
|
}, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var e = $(this);
|
|
|
|
var id = window.Uhr.id++;
|
|
|
|
e.data('id', id);
|
|
|
|
e.data('timer', null);
|
|
|
|
|
|
|
|
e.addClass('uhr');
|
|
|
|
e.empty();
|
|
|
|
e.append('<span class="item dot dot1"></span>');
|
|
|
|
e.append('<span class="item dot dot2"></span>');
|
|
|
|
e.append('<span class="item dot dot3"></span>');
|
|
|
|
e.append('<span class="item dot dot4"></span>');
|
|
|
|
e.append('<div class="letterarea"></div>');
|
|
|
|
e.append('<div class="reflection"></div>');
|
|
|
|
e.css('width', settings.width);
|
|
|
|
var realWidth = e.width()
|
|
|
|
e.width(realWidth);
|
|
|
|
e.height(realWidth);
|
|
|
|
e.css('font-size', (realWidth / 40) + 'px');
|
|
|
|
|
|
|
|
var toggleSwitch = jQuery('<div class="onoffswitch"></div>');
|
|
|
|
toggleSwitch.append('<input type="checkbox" name="onoffswitch' + id + '" class="onoffswitch-checkbox" id="onoffswitch' + id + '" checked="checked" />');
|
|
|
|
toggleSwitch.append('<label class="onoffswitch-label" for="onoffswitch' + id + '">'
|
|
|
|
+ '<div class="onoffswitch-inner"></div>'
|
|
|
|
+ '<div class="onoffswitch-switch"></div>'
|
|
|
|
+ '</label>');
|
|
|
|
e.after(toggleSwitch);
|
|
|
|
e.data('toggleSwitch', toggleSwitch);
|
|
|
|
|
|
|
|
var languageSwitch = jQuery('<select></select>')
|
|
|
|
// FIXME handle layouts correctly
|
|
|
|
for (var code in Uhr.layouts) {
|
|
|
|
if (Uhr.layouts.hasOwnProperty(code)) {
|
|
|
|
var language = Uhr.layouts[code];
|
|
|
|
var option = '<option value="' + code + '">' + language.language + '</option>';
|
|
|
|
languageSwitch.append(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.after(languageSwitch);
|
|
|
|
e.data('languageSwitch', languageSwitch);
|
|
|
|
|
|
|
|
var themeSwitch = jQuery('<select></select>');
|
|
|
|
themeSwitch.append('<option value="black">Schwarz</option>');
|
|
|
|
themeSwitch.append('<option value="red">Rot</option>');
|
|
|
|
themeSwitch.append('<option value="blue">Blau</option>');
|
|
|
|
themeSwitch.append('<option value="green">Grün</option>');
|
|
|
|
themeSwitch.append('<option value="white">Weiss</option>');
|
|
|
|
e.after(themeSwitch);
|
|
|
|
e.data('themeSwitch', themeSwitch);
|
|
|
|
|
|
|
|
|
|
|
|
var input = jQuery('#onoffswitch' + id);
|
|
|
|
input.on('click', function() {
|
|
|
|
window.Uhr.toggle(e);
|
|
|
|
});
|
|
|
|
|
|
|
|
var status = jQuery.cookie('status' + id);
|
|
|
|
if (status == undefined || settings.force) {
|
|
|
|
status = settings.status;
|
|
|
|
}
|
|
|
|
if (status == 'on') {
|
|
|
|
window.Uhr.start(e);
|
|
|
|
input.prop('checked', true);
|
|
|
|
} else {
|
|
|
|
window.Uhr.stop(e);
|
|
|
|
input.prop('checked', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.data('languageSwitch').on('change', function() {
|
|
|
|
window.Uhr.setLanguage(e, this.value);
|
|
|
|
});
|
|
|
|
var selectedLanguage = jQuery.cookie('language' + id);
|
|
|
|
if (selectedLanguage == undefined || settings.force) {
|
|
|
|
selectedLanguage = settings.language;
|
|
|
|
}
|
|
|
|
e.data('languageSwitch').val(selectedLanguage);
|
|
|
|
window.Uhr.setLanguage(e, selectedLanguage);
|
|
|
|
|
|
|
|
e.data('themeSwitch').on('change', function() {
|
|
|
|
window.Uhr.setTheme(e, this.value);
|
|
|
|
});
|
|
|
|
var selectedTheme = jQuery.cookie('theme' + id);
|
|
|
|
if (selectedTheme == undefined || settings.force) {
|
|
|
|
selectedTheme = settings.theme;
|
|
|
|
}
|
|
|
|
e.data('themeSwitch').val(selectedTheme);
|
|
|
|
window.Uhr.setTheme(e, selectedTheme);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})(jQuery);
|
|
|
|
(function($){
|
|
|
|
return this;
|
2013-11-26 13:25:50 +01:00
|
|
|
/**
|
|
|
|
* Die Uhr.
|
2013-11-27 15:40:56 +01:00
|
|
|
* @param clockarea Das jQuery-gewrappte HTML-Element, auf dem die Uhr angezeigt werden soll.
|
2013-11-26 13:25:50 +01:00
|
|
|
* @param themeElement Das HTML-Stylesheet-Tag, das das Theme-CSS referenziert.
|
|
|
|
*/
|
2013-12-17 21:50:28 +01:00
|
|
|
//if (typeof Uhr === 'undefined') {
|
2013-11-28 13:31:47 +01:00
|
|
|
function Uhr(clockarea, settings) {
|
2013-11-27 18:16:42 +01:00
|
|
|
this.id = Uhr.id++;
|
2013-11-26 13:25:50 +01:00
|
|
|
this.timer = null;
|
|
|
|
this.currentTheme = null;
|
2013-11-30 19:24:04 +01:00
|
|
|
this.currentLayout = {};
|
2013-11-26 13:25:50 +01:00
|
|
|
this.currentMinute = -1;
|
2013-11-28 13:31:47 +01:00
|
|
|
this.initHTMLElements(clockarea, settings || {});
|
2013-11-27 17:36:05 +01:00
|
|
|
}
|
2013-11-27 18:16:42 +01:00
|
|
|
Uhr.id = 0;
|
2013-11-27 17:36:05 +01:00
|
|
|
Uhr.layouts = new Array();
|
|
|
|
Uhr.register = function (locale, layout) {
|
|
|
|
Uhr.layouts[locale] = layout;
|
2013-11-26 13:25:50 +01:00
|
|
|
}
|
|
|
|
Uhr.prototype.toggle = function() {
|
|
|
|
if (this.isOn()) {
|
|
|
|
this.stop();
|
2013-11-19 16:55:01 +01:00
|
|
|
} else {
|
2013-11-26 13:25:50 +01:00
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Uhr.prototype.start = function() {
|
|
|
|
if (!this.isOn()) {
|
|
|
|
var uhr = this;
|
|
|
|
this.timer = window.setInterval(function() {uhr.update();}, 1000);
|
|
|
|
this.update();
|
2013-12-01 16:42:42 +01:00
|
|
|
jQuery.cookie('status' + this.id, 'on', {expires: 365, path: '/'});
|
2013-11-19 16:55:01 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-26 13:25:50 +01:00
|
|
|
Uhr.prototype.stop = function() {
|
|
|
|
if (this.isOn()) {
|
|
|
|
window.clearInterval(this.timer);
|
|
|
|
this.timer = null;
|
|
|
|
this.update();
|
2013-12-01 16:42:42 +01:00
|
|
|
jQuery.cookie('status' + this.id, 'off', {expires: 365, path: '/'});
|
2013-11-26 13:25:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Uhr.prototype.isOn = function() {
|
|
|
|
return this.timer != null;
|
|
|
|
}
|
|
|
|
Uhr.prototype.setLayout = function(locale) {
|
2013-11-27 17:36:05 +01:00
|
|
|
var newLayout = Uhr.layouts[locale];
|
2013-11-26 13:25:50 +01:00
|
|
|
if (newLayout !== undefined && newLayout != this.currentLayout) {
|
|
|
|
this.currentLayout = newLayout;
|
2013-11-27 15:40:56 +01:00
|
|
|
var renderer = new UhrRenderer(this.currentLayout, this.letterarea);
|
2013-11-26 13:25:50 +01:00
|
|
|
renderer.render(this);
|
2013-12-01 16:42:42 +01:00
|
|
|
jQuery.cookie('layout' + this.id, locale, {expires: 365, path: '/'});
|
2013-11-26 13:25:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Uhr.prototype.setTheme = function(theme) {
|
|
|
|
if (theme != this.currentTheme) {
|
2013-11-28 09:57:50 +01:00
|
|
|
this.clockarea.removeClass(this.currentTheme);
|
|
|
|
this.toggleSwitch.removeClass(this.currentTheme);
|
|
|
|
this.clockarea.addClass(theme);
|
|
|
|
this.toggleSwitch.addClass(theme);
|
2013-11-26 13:25:50 +01:00
|
|
|
this.currentTheme = theme;
|
2013-12-01 16:42:42 +01:00
|
|
|
jQuery.cookie('theme' + this.id, theme, {expires: 365, path: '/'});
|
2013-11-26 13:25:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Uhr.prototype.update = function() {
|
|
|
|
if (this.isOn()) {
|
|
|
|
var now = new Date();
|
2013-12-01 00:30:41 +01:00
|
|
|
if (now.getMinutes() == this.currentMinute) {
|
2013-11-26 13:25:50 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-12-01 00:30:41 +01:00
|
|
|
this.currentMinute = now.getMinutes();
|
|
|
|
var dotMinute = this.getDotMinute(now);
|
2013-11-26 13:25:50 +01:00
|
|
|
var hour = this.getHour(now);
|
|
|
|
var coarseMinute = this.getCoarseMinute(now);
|
|
|
|
this.clear();
|
|
|
|
this.highlight('on');
|
|
|
|
for (var i = 1; i <= dotMinute; i++) {
|
|
|
|
this.highlight('dot' + i);
|
|
|
|
}
|
|
|
|
this.highlight('minute' + coarseMinute);
|
|
|
|
hour = this.normalizeHour(hour);
|
|
|
|
this.highlight('hour' + hour);
|
|
|
|
if (coarseMinute == 0) {
|
|
|
|
this.highlight('sharphour');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.clear();
|
|
|
|
this.currentMinute = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Uhr.prototype.clear = function() {
|
2013-11-27 15:40:56 +01:00
|
|
|
this.clockarea.find('.item').removeClass('active');
|
2013-11-26 13:25:50 +01:00
|
|
|
}
|
|
|
|
Uhr.prototype.highlight = function(itemClass) {
|
2013-11-27 15:40:56 +01:00
|
|
|
this.clockarea.find('.item.' + itemClass).addClass('active');
|
2013-11-25 13:25:02 +01:00
|
|
|
}
|
2013-11-26 13:25:50 +01:00
|
|
|
Uhr.prototype.getHour = function(date) {
|
|
|
|
if (typeof this.currentLayout.getHour === 'function') {
|
|
|
|
return this.currentLayout.getHour(date);
|
|
|
|
}
|
|
|
|
var hour = date.getHours();
|
|
|
|
if (date.getMinutes() >= 25) {
|
|
|
|
return hour + 1;
|
|
|
|
}
|
|
|
|
return hour;
|
|
|
|
}
|
|
|
|
Uhr.prototype.getCoarseMinute = function(date) {
|
|
|
|
if (typeof this.currentLayout.getCoarseMinute === 'function') {
|
|
|
|
return this.currentLayout.getCoarseMinute(date);
|
|
|
|
}
|
|
|
|
var minutes = date.getMinutes();
|
|
|
|
return minutes - this.getDotMinute(date);
|
|
|
|
}
|
|
|
|
Uhr.prototype.getDotMinute = function(date) {
|
|
|
|
if (typeof this.currentLayout.getDotMinute === 'function') {
|
|
|
|
return this.currentLayout.getDotMinute(date);
|
|
|
|
}
|
|
|
|
var minutes = date.getMinutes();
|
|
|
|
return minutes % 5;
|
|
|
|
}
|
|
|
|
Uhr.prototype.normalizeHour = function(hour) {
|
|
|
|
if (hour > 12) {
|
|
|
|
hour %= 12;
|
|
|
|
}
|
|
|
|
if (hour == 0) {
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
return hour;
|
|
|
|
}
|
2013-11-28 13:31:47 +01:00
|
|
|
Uhr.prototype.initHTMLElements = function(clockarea, presets) {
|
2013-11-30 18:51:43 +01:00
|
|
|
this.createHTMLElements(clockarea, presets.width);
|
2013-11-28 13:31:47 +01:00
|
|
|
var force = presets.force || false;
|
|
|
|
this.initToggleSwitch(presets.status, force);
|
|
|
|
this.initLayoutSwitch(presets.layout, force);
|
|
|
|
this.initThemeSwitch(presets.theme, force);
|
2013-11-28 08:51:37 +01:00
|
|
|
}
|
2013-11-30 18:51:43 +01:00
|
|
|
Uhr.prototype.createHTMLElements = function(clockarea, width) {
|
|
|
|
this.createClockarea(clockarea, width)
|
2013-11-28 10:12:52 +01:00
|
|
|
this.letterarea = this.clockarea.find('.letterarea');
|
|
|
|
this.createToggleSwitch();
|
|
|
|
this.createLayoutSwitch();
|
|
|
|
this.createThemeSwitch();
|
2013-11-28 09:57:50 +01:00
|
|
|
}
|
2013-11-30 18:51:43 +01:00
|
|
|
Uhr.prototype.createClockarea = function(clockarea, width) {
|
2013-11-29 14:31:08 +01:00
|
|
|
clockarea.addClass('uhr');
|
2013-11-27 18:13:37 +01:00
|
|
|
clockarea.empty();
|
|
|
|
clockarea.append('<span class="item dot dot1"></span>');
|
|
|
|
clockarea.append('<span class="item dot dot2"></span>');
|
|
|
|
clockarea.append('<span class="item dot dot3"></span>');
|
|
|
|
clockarea.append('<span class="item dot dot4"></span>');
|
|
|
|
clockarea.append('<div class="letterarea"></div>');
|
|
|
|
clockarea.append('<div class="reflection"></div>');
|
2013-11-30 18:51:43 +01:00
|
|
|
if(width == undefined) {
|
|
|
|
width = '100%';
|
|
|
|
}
|
|
|
|
clockarea.css('width', width);
|
|
|
|
var realWidth = clockarea.width()
|
|
|
|
clockarea.width(realWidth);
|
|
|
|
clockarea.height(realWidth);
|
|
|
|
clockarea.css('font-size', (realWidth / 40) + 'px');
|
2013-11-28 10:12:52 +01:00
|
|
|
this.clockarea = clockarea
|
2013-11-27 18:13:37 +01:00
|
|
|
}
|
2013-11-28 10:12:52 +01:00
|
|
|
Uhr.prototype.createToggleSwitch = function() {
|
2013-12-01 16:42:42 +01:00
|
|
|
this.toggleSwitch = jQuery('<div class="onoffswitch"></div>');
|
|
|
|
var input = jQuery('<input type="checkbox" name="onoffswitch' + this.id + '" class="onoffswitch-checkbox" id="onoffswitch' + this.id + '" checked="checked" />');
|
2013-11-28 10:12:52 +01:00
|
|
|
this.toggleSwitch.append(input);
|
|
|
|
this.toggleSwitch.append('<label class="onoffswitch-label" for="onoffswitch' + this.id + '">'
|
|
|
|
+ '<div class="onoffswitch-inner"></div>'
|
|
|
|
+ '<div class="onoffswitch-switch"></div>'
|
|
|
|
+ '</label>');
|
|
|
|
this.clockarea.after(this.toggleSwitch);
|
|
|
|
}
|
|
|
|
Uhr.prototype.createLayoutSwitch = function () {
|
2013-12-01 16:42:42 +01:00
|
|
|
this.layoutSwitch = jQuery('<select></select>')
|
2013-11-28 10:12:52 +01:00
|
|
|
for (var code in Uhr.layouts) {
|
|
|
|
if (Uhr.layouts.hasOwnProperty(code)) {
|
|
|
|
var layout = Uhr.layouts[code];
|
2013-12-01 16:42:42 +01:00
|
|
|
var option = jQuery('<option value="' + code + '">' + layout.language + '</option>')
|
2013-11-28 10:12:52 +01:00
|
|
|
this.layoutSwitch.append(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.clockarea.after(this.layoutSwitch);
|
|
|
|
}
|
|
|
|
Uhr.prototype.createThemeSwitch = function () {
|
2013-12-01 16:42:42 +01:00
|
|
|
this.themeSwitch = jQuery('<select></select>');
|
2013-11-28 10:12:52 +01:00
|
|
|
this.themeSwitch.append('<option value="black">Schwarz</option>');
|
|
|
|
this.themeSwitch.append('<option value="red">Rot</option>');
|
|
|
|
this.themeSwitch.append('<option value="blue">Blau</option>');
|
|
|
|
this.themeSwitch.append('<option value="green">Grün</option>');
|
|
|
|
this.themeSwitch.append('<option value="white">Weiss</option>');
|
|
|
|
this.clockarea.after(this.themeSwitch);
|
|
|
|
}
|
2013-11-28 13:31:47 +01:00
|
|
|
Uhr.prototype.initToggleSwitch = function(defaultValue, overrideCookie) {
|
2013-12-01 16:42:42 +01:00
|
|
|
var input = jQuery('#onoffswitch' + this.id);
|
2013-11-27 18:13:37 +01:00
|
|
|
var uhr = this;
|
|
|
|
input.on('click', function() {
|
|
|
|
uhr.toggle();
|
|
|
|
});
|
2013-12-01 16:42:42 +01:00
|
|
|
var status = jQuery.cookie('status' + this.id);
|
2013-11-28 13:36:56 +01:00
|
|
|
if (status == undefined || (overrideCookie && (defaultValue != undefined))) {
|
2013-11-28 13:31:47 +01:00
|
|
|
status = defaultValue;
|
|
|
|
}
|
|
|
|
if (status == undefined || status == 'undefined') {
|
|
|
|
status = 'on';
|
|
|
|
}
|
2013-11-28 08:51:37 +01:00
|
|
|
if (status == 'on') {
|
|
|
|
this.start();
|
2013-11-28 09:40:04 +01:00
|
|
|
input.prop('checked', true);
|
2013-11-28 08:51:37 +01:00
|
|
|
} else {
|
|
|
|
this.stop();
|
2013-11-28 09:40:04 +01:00
|
|
|
input.prop('checked', false);
|
2013-11-28 08:51:37 +01:00
|
|
|
}
|
2013-11-27 18:13:37 +01:00
|
|
|
}
|
2013-11-28 13:31:47 +01:00
|
|
|
Uhr.prototype.initLayoutSwitch = function(defaultValue, overrideCookie) {
|
2013-11-28 08:51:37 +01:00
|
|
|
var uhr = this;
|
2013-11-28 10:12:52 +01:00
|
|
|
this.layoutSwitch.on('change', function() {
|
2013-11-28 08:51:37 +01:00
|
|
|
uhr.setLayout(this.value);
|
|
|
|
});
|
2013-12-01 16:42:42 +01:00
|
|
|
var selectedLayout = jQuery.cookie('layout' + this.id);
|
2013-11-28 13:36:56 +01:00
|
|
|
if (selectedLayout == undefined || (overrideCookie && (defaultValue != undefined))) {
|
2013-11-28 13:31:47 +01:00
|
|
|
selectedLayout = defaultValue;
|
2013-11-28 08:51:37 +01:00
|
|
|
}
|
2013-11-30 19:24:35 +01:00
|
|
|
if (selectedLayout == undefined) {
|
2013-11-30 19:24:04 +01:00
|
|
|
// FIXME not nice, hardcoded default-value
|
2013-11-28 13:31:47 +01:00
|
|
|
selectedLayout = 'de_CH';
|
|
|
|
}
|
|
|
|
this.layoutSwitch.val(selectedLayout);
|
|
|
|
this.setLayout(selectedLayout);
|
2013-11-27 18:37:38 +01:00
|
|
|
}
|
2013-11-28 13:31:47 +01:00
|
|
|
Uhr.prototype.initThemeSwitch = function(defaultValue, overrideCookie) {
|
2013-11-28 09:57:50 +01:00
|
|
|
var uhr = this;
|
2013-11-28 10:12:52 +01:00
|
|
|
this.themeSwitch.on('change', function() {
|
2013-11-28 09:57:50 +01:00
|
|
|
uhr.setTheme(this.value);
|
|
|
|
});
|
2013-12-01 16:42:42 +01:00
|
|
|
var selectedTheme = jQuery.cookie('theme' + this.id);
|
2013-11-28 13:36:56 +01:00
|
|
|
if (selectedTheme == undefined || (overrideCookie && (defaultValue != undefined))) {
|
2013-11-28 13:31:47 +01:00
|
|
|
selectedTheme = defaultValue;
|
|
|
|
}
|
2013-11-28 10:12:52 +01:00
|
|
|
if (selectedTheme == undefined || selectedTheme == 'undefined') {
|
|
|
|
selectedTheme = 'black';
|
|
|
|
}
|
|
|
|
this.themeSwitch.val(selectedTheme);
|
|
|
|
this.setTheme(selectedTheme);
|
2013-11-28 09:57:50 +01:00
|
|
|
}
|
2013-11-26 13:25:50 +01:00
|
|
|
|
2014-01-11 12:18:11 +01:00
|
|
|
|
|
|
|
//}
|
|
|
|
})(jQuery);
|
2013-11-26 13:25:50 +01:00
|
|
|
/**
|
|
|
|
* Hilfsklasse zum Rendern der Uhr.
|
|
|
|
* @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.layout = layout;
|
|
|
|
this.renderarea = renderarea;
|
|
|
|
}
|
|
|
|
UhrRenderer.prototype.render = function(uhr) {
|
|
|
|
var renderer = this;
|
|
|
|
this.renderarea.fadeOut('fast', function() {
|
|
|
|
renderer.renderarea.empty();
|
|
|
|
for (var y = 0; y < renderer.layout.values.length; y++) {
|
|
|
|
for (var x = 0; x < renderer.layout.values[y].length; x++) {
|
|
|
|
var letter = renderer.layout.values[y][x];
|
|
|
|
renderer.renderarea.append(letter.toString());
|
|
|
|
}
|
|
|
|
if (y < renderer.layout.values.length - 1) {
|
|
|
|
renderer.renderarea.append('<br/>');
|
|
|
|
}
|
|
|
|
}
|
2014-01-11 12:18:11 +01:00
|
|
|
uhr.data('currentMinute', -1);
|
|
|
|
Uhr.update(uhr);
|
2013-11-26 13:25:50 +01:00
|
|
|
renderer.renderarea.fadeIn('fast');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
|
|
|
* @param value Der Buchstabe, der Dargestellt werden soll.
|
|
|
|
* @param style Die CSS-Styleklassen des Buchstabens.
|
|
|
|
*/
|
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() {
|
2013-11-26 13:25:50 +01:00
|
|
|
return 'item letter ' + style;
|
2013-11-25 10:57:30 +01:00
|
|
|
}
|
|
|
|
this.getValue = function() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Letter.prototype.toString = function letterToString() {
|
2013-11-26 13:25:50 +01:00
|
|
|
return '<span class="' + this.getStyle() + '">' + this.getValue() + '</span>';
|
2013-11-25 10:57:30 +01:00
|
|
|
}
|
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);
|
|
|
|
}
|