diff --git a/uhr.js b/uhr.js index bf6dc09..2097aa8 100644 --- a/uhr.js +++ b/uhr.js @@ -141,16 +141,19 @@ Uhr.prototype.normalizeHour = function(hour) { return hour; } Uhr.prototype.initHTMLElements = function(clockarea) { - this.createHTMLElements(); - this.clockarea = this.initClockarea(clockarea); + this.createHTMLElements(clockarea); + this.initToggleSwitch(); + this.initLayoutSwitch(); + this.initThemeSwitch(); +} +Uhr.prototype.createHTMLElements = function(clockarea) { + this.createClockarea(clockarea) this.letterarea = this.clockarea.find('.letterarea'); - this.themeSwitch = this.initThemeSwitch(); - this.layoutSwitch = this.initLayoutSwitch(); - this.toggleSwitch = this.initToggleSwitch(); + this.createToggleSwitch(); + this.createLayoutSwitch(); + this.createThemeSwitch(); } -Uhr.prototype.createHTMLElements = function() { -} -Uhr.prototype.initClockarea = function(clockarea) { +Uhr.prototype.createClockarea = function(clockarea) { clockarea.empty(); clockarea.append(''); clockarea.append(''); @@ -158,22 +161,44 @@ Uhr.prototype.initClockarea = function(clockarea) { clockarea.append(''); clockarea.append('
'); clockarea.append('
'); - return clockarea; + this.clockarea = clockarea +} +Uhr.prototype.createToggleSwitch = function() { + this.toggleSwitch = $('
'); + var input = $(''); + this.toggleSwitch.append(input); + this.toggleSwitch.append(''); + this.clockarea.after(this.toggleSwitch); +} +Uhr.prototype.createLayoutSwitch = function () { + this.layoutSwitch = $('') + for (var code in Uhr.layouts) { + if (Uhr.layouts.hasOwnProperty(code)) { + var layout = Uhr.layouts[code]; + var option = $('') + this.layoutSwitch.append(option); + } + } + this.clockarea.after(this.layoutSwitch); +} +Uhr.prototype.createThemeSwitch = function () { + this.themeSwitch = $(''); + this.themeSwitch.append(''); + this.themeSwitch.append(''); + this.themeSwitch.append(''); + this.themeSwitch.append(''); + this.themeSwitch.append(''); + this.clockarea.after(this.themeSwitch); } Uhr.prototype.initToggleSwitch = function() { - var toggleSwitch = $('
'); - var input = $(''); + var input = $('#onoffswitch' + this.id); var uhr = this; input.on('click', function() { uhr.toggle(); }); - toggleSwitch.append(input); - toggleSwitch.append(''); - this.clockarea.after(toggleSwitch); - var status = $.cookie('status' + this.id); if (status == 'on') { this.start(); @@ -182,45 +207,29 @@ Uhr.prototype.initToggleSwitch = function() { this.stop(); input.prop('checked', false); } - - return toggleSwitch; } Uhr.prototype.initLayoutSwitch = function() { - var layoutSwitch = $('') - - for (var code in Uhr.layouts) { - if (Uhr.layouts.hasOwnProperty(code)) { - var layout = Uhr.layouts[code]; - var option = $('') - layoutSwitch.append(option); - } - } var uhr = this; - layoutSwitch.on('change', function() { + this.layoutSwitch.on('change', function() { uhr.setLayout(this.value); }); - this.clockarea.after(layoutSwitch); - var selectedLayout = $.cookie('layout' + this.id); if (selectedLayout != undefined && selectedLayout != 'undefinded') { - layoutSwitch.val(selectedLayout); + this.layoutSwitch.val(selectedLayout); this.setLayout(selectedLayout); } - return layoutSwitch; } Uhr.prototype.initThemeSwitch = function() { - var themeSwitch = $(''); - themeSwitch.append(''); - themeSwitch.append(''); - themeSwitch.append(''); - themeSwitch.append(''); - themeSwitch.append(''); var uhr = this; - themeSwitch.on('change', function() { + this.themeSwitch.on('change', function() { uhr.setTheme(this.value); }); - this.clockarea.after(themeSwitch); - return themeSwitch; + var selectedTheme = $.cookie('theme' + this.id); + if (selectedTheme == undefined || selectedTheme == 'undefined') { + selectedTheme = 'black'; + } + this.themeSwitch.val(selectedTheme); + this.setTheme(selectedTheme); } Uhr.register('undefined', {