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-en.js"></script>
<script type="text/javascript">
var uhr = new Uhr($('#uhr'));
new Uhr($('#uhr'), {
layout: 'de_CH',
theme: 'black',
status: 'on'
});
</script>
</body>
</html>

View File

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

38
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 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('<option value="white">Weiss</option>');
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';
}