diff --git a/index.html b/index.html index 0172462..526f116 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,11 @@ along with this program. If not, see . diff --git a/manifest.appcache b/manifest.appcache index 69b3ada..c306af8 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# 3.0.1 +# 3.0.2 COPYING index.html diff --git a/uhr.js b/uhr.js index 2097aa8..ee06939 100644 --- a/uhr.js +++ b/uhr.js @@ -17,13 +17,13 @@ along with this program. If not, see . * @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. */ -function Uhr(clockarea) { +function Uhr(clockarea, settings) { this.id = Uhr.id++; this.timer = null; this.currentTheme = null; this.currentLayout = Uhr.layouts['undefined']; this.currentMinute = -1; - this.initHTMLElements(clockarea); + this.initHTMLElements(clockarea, settings || {}); } Uhr.id = 0; Uhr.layouts = new Array(); @@ -140,11 +140,12 @@ Uhr.prototype.normalizeHour = function(hour) { } return hour; } -Uhr.prototype.initHTMLElements = function(clockarea) { +Uhr.prototype.initHTMLElements = function(clockarea, presets) { this.createHTMLElements(clockarea); - this.initToggleSwitch(); - this.initLayoutSwitch(); - this.initThemeSwitch(); + var force = presets.force || false; + this.initToggleSwitch(presets.status, force); + this.initLayoutSwitch(presets.layout, force); + this.initThemeSwitch(presets.theme, force); } Uhr.prototype.createHTMLElements = function(clockarea) { this.createClockarea(clockarea) @@ -193,13 +194,19 @@ Uhr.prototype.createThemeSwitch = function () { this.themeSwitch.append(''); this.clockarea.after(this.themeSwitch); } -Uhr.prototype.initToggleSwitch = function() { +Uhr.prototype.initToggleSwitch = function(defaultValue, overrideCookie) { var input = $('#onoffswitch' + this.id); var uhr = this; input.on('click', function() { uhr.toggle(); }); var status = $.cookie('status' + this.id); + if (status == undefined || (overrideCookie && (defaultValue != undefined))) { + status = defaultValue; + } + if (status == undefined || status == 'undefined') { + status = 'on'; + } if (status == 'on') { this.start(); input.prop('checked', true); @@ -208,23 +215,30 @@ Uhr.prototype.initToggleSwitch = function() { input.prop('checked', false); } } -Uhr.prototype.initLayoutSwitch = function() { +Uhr.prototype.initLayoutSwitch = function(defaultValue, overrideCookie) { var uhr = this; this.layoutSwitch.on('change', function() { uhr.setLayout(this.value); }); var selectedLayout = $.cookie('layout' + this.id); - if (selectedLayout != undefined && selectedLayout != 'undefinded') { - this.layoutSwitch.val(selectedLayout); - this.setLayout(selectedLayout); + if (selectedLayout == undefined || (overrideCookie && (defaultValue != undefined))) { + selectedLayout = defaultValue; } + 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; this.themeSwitch.on('change', function() { uhr.setTheme(this.value); }); var selectedTheme = $.cookie('theme' + this.id); + if (selectedTheme == undefined || (overrideCookie && (defaultValue != undefined))) { + selectedTheme = defaultValue; + } if (selectedTheme == undefined || selectedTheme == 'undefined') { selectedTheme = 'black'; }