Merge branch 'feature/uhrmodul' of /var/lib/git/repositories/manuel/uhr into develop

This commit is contained in:
Manuel Friedli 2013-11-28 13:43:03 +01:00
commit 3a651019a4
3 changed files with 32 additions and 14 deletions

View File

@ -34,7 +34,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script type="text/javascript" src="uhr-de.js"></script> <script type="text/javascript" src="uhr-de.js"></script>
<script type="text/javascript" src="uhr-en.js"></script> <script type="text/javascript" src="uhr-en.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var uhr = new Uhr($('#uhr')); new Uhr($('#uhr'), {
layout: 'de_CH',
theme: 'black',
status: 'on'
});
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,5 +1,5 @@
CACHE MANIFEST CACHE MANIFEST
# 3.0.1 # 3.0.2
COPYING COPYING
index.html index.html

36
uhr.js
View File

@ -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 (status == undefined || (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 (selectedLayout == undefined || (overrideCookie && (defaultValue != undefined))) {
selectedLayout = defaultValue;
}
if (selectedLayout == undefined || selectedLayout == 'undefined') {
selectedLayout = 'de_CH';
}
this.layoutSwitch.val(selectedLayout); this.layoutSwitch.val(selectedLayout);
this.setLayout(selectedLayout); this.setLayout(selectedLayout);
} }
} Uhr.prototype.initThemeSwitch = function(defaultValue, overrideCookie) {
Uhr.prototype.initThemeSwitch = function() {
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 (selectedTheme == undefined || (overrideCookie && (defaultValue != undefined))) {
selectedTheme = defaultValue;
}
if (selectedTheme == undefined || selectedTheme == 'undefined') { if (selectedTheme == undefined || selectedTheme == 'undefined') {
selectedTheme = 'black'; selectedTheme = 'black';
} }