uhr ist parametrisierbar
This commit is contained in:
parent
6a6d1634dc
commit
a9ee9ec62c
1 changed files with 26 additions and 12 deletions
38
uhr.js
38
uhr.js
|
@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* @param clockarea Das jQuery-gewrappte HTML-Element, auf dem die Uhr angezeigt werden soll.
|
* @param clockarea Das jQuery-gewrappte HTML-Element, auf dem die Uhr angezeigt werden soll.
|
||||||
* @param themeElement Das HTML-Stylesheet-Tag, das das Theme-CSS referenziert.
|
* @param themeElement Das HTML-Stylesheet-Tag, das das Theme-CSS referenziert.
|
||||||
*/
|
*/
|
||||||
function Uhr(clockarea) {
|
function Uhr(clockarea, settings) {
|
||||||
this.id = Uhr.id++;
|
this.id = Uhr.id++;
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
this.currentTheme = null;
|
this.currentTheme = null;
|
||||||
this.currentLayout = Uhr.layouts['undefined'];
|
this.currentLayout = Uhr.layouts['undefined'];
|
||||||
this.currentMinute = -1;
|
this.currentMinute = -1;
|
||||||
this.initHTMLElements(clockarea);
|
this.initHTMLElements(clockarea, settings || {});
|
||||||
}
|
}
|
||||||
Uhr.id = 0;
|
Uhr.id = 0;
|
||||||
Uhr.layouts = new Array();
|
Uhr.layouts = new Array();
|
||||||
|
@ -140,11 +140,12 @@ Uhr.prototype.normalizeHour = function(hour) {
|
||||||
}
|
}
|
||||||
return hour;
|
return hour;
|
||||||
}
|
}
|
||||||
Uhr.prototype.initHTMLElements = function(clockarea) {
|
Uhr.prototype.initHTMLElements = function(clockarea, presets) {
|
||||||
this.createHTMLElements(clockarea);
|
this.createHTMLElements(clockarea);
|
||||||
this.initToggleSwitch();
|
var force = presets.force || false;
|
||||||
this.initLayoutSwitch();
|
this.initToggleSwitch(presets.status, force);
|
||||||
this.initThemeSwitch();
|
this.initLayoutSwitch(presets.layout, force);
|
||||||
|
this.initThemeSwitch(presets.theme, force);
|
||||||
}
|
}
|
||||||
Uhr.prototype.createHTMLElements = function(clockarea) {
|
Uhr.prototype.createHTMLElements = function(clockarea) {
|
||||||
this.createClockarea(clockarea)
|
this.createClockarea(clockarea)
|
||||||
|
@ -193,13 +194,19 @@ Uhr.prototype.createThemeSwitch = function () {
|
||||||
this.themeSwitch.append('<option value="white">Weiss</option>');
|
this.themeSwitch.append('<option value="white">Weiss</option>');
|
||||||
this.clockarea.after(this.themeSwitch);
|
this.clockarea.after(this.themeSwitch);
|
||||||
}
|
}
|
||||||
Uhr.prototype.initToggleSwitch = function() {
|
Uhr.prototype.initToggleSwitch = function(defaultValue, overrideCookie) {
|
||||||
var input = $('#onoffswitch' + this.id);
|
var input = $('#onoffswitch' + this.id);
|
||||||
var uhr = this;
|
var uhr = this;
|
||||||
input.on('click', function() {
|
input.on('click', function() {
|
||||||
uhr.toggle();
|
uhr.toggle();
|
||||||
});
|
});
|
||||||
var status = $.cookie('status' + this.id);
|
var status = $.cookie('status' + this.id);
|
||||||
|
if (overrideCookie && (defaultValue != undefined)) {
|
||||||
|
status = defaultValue;
|
||||||
|
}
|
||||||
|
if (status == undefined || status == 'undefined') {
|
||||||
|
status = 'on';
|
||||||
|
}
|
||||||
if (status == 'on') {
|
if (status == 'on') {
|
||||||
this.start();
|
this.start();
|
||||||
input.prop('checked', true);
|
input.prop('checked', true);
|
||||||
|
@ -208,23 +215,30 @@ Uhr.prototype.initToggleSwitch = function() {
|
||||||
input.prop('checked', false);
|
input.prop('checked', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Uhr.prototype.initLayoutSwitch = function() {
|
Uhr.prototype.initLayoutSwitch = function(defaultValue, overrideCookie) {
|
||||||
var uhr = this;
|
var uhr = this;
|
||||||
this.layoutSwitch.on('change', function() {
|
this.layoutSwitch.on('change', function() {
|
||||||
uhr.setLayout(this.value);
|
uhr.setLayout(this.value);
|
||||||
});
|
});
|
||||||
var selectedLayout = $.cookie('layout' + this.id);
|
var selectedLayout = $.cookie('layout' + this.id);
|
||||||
if (selectedLayout != undefined && selectedLayout != 'undefinded') {
|
if (overrideCookie && (defaultValue != undefined)) {
|
||||||
this.layoutSwitch.val(selectedLayout);
|
selectedLayout = defaultValue;
|
||||||
this.setLayout(selectedLayout);
|
|
||||||
}
|
}
|
||||||
|
if (selectedLayout == undefined || selectedLayout == 'undefined') {
|
||||||
|
selectedLayout = 'de_CH';
|
||||||
|
}
|
||||||
|
this.layoutSwitch.val(selectedLayout);
|
||||||
|
this.setLayout(selectedLayout);
|
||||||
}
|
}
|
||||||
Uhr.prototype.initThemeSwitch = function() {
|
Uhr.prototype.initThemeSwitch = function(defaultValue, overrideCookie) {
|
||||||
var uhr = this;
|
var uhr = this;
|
||||||
this.themeSwitch.on('change', function() {
|
this.themeSwitch.on('change', function() {
|
||||||
uhr.setTheme(this.value);
|
uhr.setTheme(this.value);
|
||||||
});
|
});
|
||||||
var selectedTheme = $.cookie('theme' + this.id);
|
var selectedTheme = $.cookie('theme' + this.id);
|
||||||
|
if (overrideCookie && (defaultValue != undefined)) {
|
||||||
|
selectedTheme = defaultValue;
|
||||||
|
}
|
||||||
if (selectedTheme == undefined || selectedTheme == 'undefined') {
|
if (selectedTheme == undefined || selectedTheme == 'undefined') {
|
||||||
selectedTheme = 'black';
|
selectedTheme = 'black';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue