Merge branch 'feature/jqueryplugin' of /var/lib/git/repositories/manuel/uhr into develop
This commit is contained in:
commit
22deff86f7
10 changed files with 329 additions and 279 deletions
45
README.md
45
README.md
|
@ -1,13 +1,15 @@
|
||||||
Bärneruhr
|
Bärneruhr
|
||||||
=========
|
=========
|
||||||
|
|
||||||
Du willst Bärneruhr auf deiner Website verwenden? Das geht ganz einfach.
|
Du willst Bärneruhr auf deiner Website verwenden? Dank des jQuery-Plugins geht das so einfach, dass es sogar deine Grossmutter tun könnte!
|
||||||
|
|
||||||
1. Benötigte Dateien einbinden
|
1. Benötigte Dateien einbinden
|
||||||
------------------------------
|
------------------------------
|
||||||
* Binde folgende Javascript-Dateien im HTML-Dokument ein:
|
* Binde folgende Javascript-Dateien im HTML-Dokument ein:
|
||||||
* jquery-2.0.3.min.js (Falls nicht bereits vorhanden)
|
* jquery-2.0.3.min.js (Falls nicht bereits vorhanden)
|
||||||
* jquery.cookie.js (Falls nicht bereits vorhanden)
|
* jquery-ui-1.10.3.custom.min.js (Falls nicht bereits vorhanden)
|
||||||
|
* Von jquery-ui werden die Komponenten 'core' und 'widget' benötigt.
|
||||||
|
* jquery-cookie-1.4.0.js (Falls nicht bereits vorhanden)
|
||||||
* uhr.js
|
* uhr.js
|
||||||
* Binde mindestens eine der folgenden Javascript-Dateien im HTML ein, je nach dem, welche Sprachen deine Uhr unterstützen soll:
|
* Binde mindestens eine der folgenden Javascript-Dateien im HTML ein, je nach dem, welche Sprachen deine Uhr unterstützen soll:
|
||||||
* uhr-de_CH.js
|
* uhr-de_CH.js
|
||||||
|
@ -26,14 +28,14 @@ Du willst Bärneruhr auf deiner Website verwenden? Das geht ganz einfach.
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
Erstelle ein leeres `<div>` mit einer ID:
|
Erstelle ein leeres `<div>` mit einer ID:
|
||||||
|
|
||||||
<div id="meineuhr"></div>
|
<div id="uhrcontainer"></div>
|
||||||
3. Uhr per Javascript konfigurieren
|
3. Uhr per Javascript konfigurieren
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
Initialisiere die Uhr mit einer einzigen Zeile Javascript:
|
Initialisiere die Uhr mit einer einzigen Zeile Javascript:
|
||||||
|
|
||||||
new Uhr(jQuery('#meineuhr'));
|
jQuery('#uhrcontainer').uhr();
|
||||||
|
|
||||||
Als Parameter wird ein jQuery-gewrapptes HTML-Element erwartet. Dies erzeugt eine Uhr in der Standardkonfiguration. Das heisst:
|
Damit wird eine Uhr in der Standardkonfiguration erzeugt. Das heisst:
|
||||||
|
|
||||||
* Breite ist 100% des Eltenelements
|
* Breite ist 100% des Eltenelements
|
||||||
* Farbe ist Schwarz
|
* Farbe ist Schwarz
|
||||||
|
@ -42,17 +44,38 @@ Als Parameter wird ein jQuery-gewrapptes HTML-Element erwartet. Dies erzeugt ein
|
||||||
|
|
||||||
Wie du diese Optionen ändern kannst, verrät der nächte Abschnitt.
|
Wie du diese Optionen ändern kannst, verrät der nächte Abschnitt.
|
||||||
|
|
||||||
|
Es kann natürlich auch eine Collection von Elementen übergeben werden. Mit
|
||||||
|
|
||||||
|
jQuery('div').uhr();
|
||||||
|
|
||||||
|
würde also jedes `<div>`-Element der Seite in eine Uhr umgewandelt
|
||||||
|
|
||||||
4. Weitere Optionen
|
4. Weitere Optionen
|
||||||
-------------------
|
-------------------
|
||||||
Der Uhr()-Methode kann ein Options-Objekt mitgegeben werden:
|
Der uhr()-Methode kann ein Options-Objekt mitgegeben werden:
|
||||||
|
|
||||||
new Uhr(jQuery('#uhrcontainer'), {
|
jQuery('#uhrcontainer').uhr({
|
||||||
status: 'on', // 'on' oder 'off'
|
status: 'on', // 'on' (default) oder 'off'
|
||||||
theme: 'red', // 'black', 'red', 'blue', 'green' oder 'white'
|
theme: 'black', // 'black' (default), 'red', 'blue', 'green' oder 'white'
|
||||||
layout: 'en', // 'de_DE', 'de' oder 'en' (je nach eingebundenen Sprachdateien)
|
language: 'de_CH', // 'de_CH' (default), 'de' oder 'en' (je nach eingebundenen Sprachdateien)
|
||||||
width: '20em' // eine CSS-Grössenangabe
|
width: '100%', // eine CSS-Grössenangabe (default: 100%)
|
||||||
|
force: false, // false (default): Falls ein Cookie im Browser besteht, werden dessen Konfigurationswerte übernommen;
|
||||||
|
// true: immer die angegebene Konfiguration verwenden
|
||||||
});
|
});
|
||||||
|
|
||||||
|
5. Sonderfunktionen
|
||||||
|
-------------------
|
||||||
|
Es gibt noch einen zusätzlichen Konfigurationsparameter. Mit
|
||||||
|
|
||||||
|
{
|
||||||
|
time: new Date()
|
||||||
|
}
|
||||||
|
kann die Uhr auf eine fixe Zeit eingestellt werden. Sie bleibt dann statisch und aktualisiert sich nicht, sondern zeigt immer diese Zeit an. Beim Klick auf den On/Off-Schalter oder beim Wechsel der Sprache wird dies allerdings rückgängig gemacht und die Uhr nimmt das Standardverhalten mit der aktuellen Systemzeit an.
|
||||||
|
|
||||||
|
Die Zeit kann auch über einen Methodenaufruf dynamisch eingestellt werden:
|
||||||
|
|
||||||
|
jQuery('#uhrcontainer').uhr("time", new Date());
|
||||||
|
|
||||||
Viel Spass!
|
Viel Spass!
|
||||||
|
|
||||||
A. Lizenzbestimmungen
|
A. Lizenzbestimmungen
|
||||||
|
|
BIN
favicon.png
Normal file
BIN
favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
19
index.html
19
index.html
|
@ -17,7 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
<head>
|
<head>
|
||||||
<title>Die Zeit als Wort - in HTML, CSS und JS</title>
|
<title>Die Zeit als Wort - in HTML, CSS und JS</title>
|
||||||
<script type="text/javascript" src="jquery-2.0.3.min.js"></script>
|
<script type="text/javascript" src="jquery-2.0.3.min.js"></script>
|
||||||
<script type="text/javascript" src="jquery.cookie.js"></script>
|
<script type="text/javascript" src="jquery-ui-1.10.3.custom.min.js"></script>
|
||||||
|
<script type="text/javascript" src="jquery-cookie-1.4.0.js"></script>
|
||||||
<script type="text/javascript" src="uhr.js"></script>
|
<script type="text/javascript" src="uhr.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="uhr.css" />
|
<link rel="stylesheet" type="text/css" href="uhr.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="uhr-black.css" />
|
<link rel="stylesheet" type="text/css" href="uhr-black.css" />
|
||||||
|
@ -25,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
<link rel="stylesheet" type="text/css" href="uhr-green.css" />
|
<link rel="stylesheet" type="text/css" href="uhr-green.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="uhr-red.css" />
|
<link rel="stylesheet" type="text/css" href="uhr-red.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="uhr-white.css" />
|
<link rel="stylesheet" type="text/css" href="uhr-white.css" />
|
||||||
|
<link rel="shortcut icon" type="image/png" href="favicon.png" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||||
</head>
|
</head>
|
||||||
<body style="padding:0;margin:0;">
|
<body style="padding:0;margin:0;">
|
||||||
|
@ -34,15 +36,14 @@ 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 height = jQuery(window).height();
|
(function($) {
|
||||||
var width = jQuery(window).width();
|
var width = $(window).width();
|
||||||
var size = height < width ? height : width;
|
var height = $(window).height();
|
||||||
new Uhr(jQuery('#uhr'), {
|
var size = (width < height ? width : height) + 'px';
|
||||||
layout: 'de_CH',
|
$('#uhr').uhr({
|
||||||
theme: 'black',
|
width: size
|
||||||
status: 'on',
|
|
||||||
width: size + 'px'
|
|
||||||
});
|
});
|
||||||
|
})(jQuery);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
6
jquery-ui-1.10.3.custom.min.js
vendored
Normal file
6
jquery-ui-1.10.3.custom.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,18 +1,20 @@
|
||||||
CACHE MANIFEST
|
CACHE MANIFEST
|
||||||
# 3.0.8
|
# 4.0.0
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
favicon.png
|
||||||
index.html
|
index.html
|
||||||
jquery-2.0.3.min.js
|
jquery-2.0.3.min.js
|
||||||
jquery.cookie.js
|
jquery-cookie-1.4.0.js
|
||||||
uhr.js
|
jquery-ui-1.10.3.custom.min.js
|
||||||
uhr-de_CH.js
|
|
||||||
uhr-de.js
|
|
||||||
uhr-en.js
|
|
||||||
uhr.css
|
|
||||||
uhr-black.css
|
uhr-black.css
|
||||||
uhr-red.css
|
|
||||||
uhr-blue.css
|
uhr-blue.css
|
||||||
|
uhr-de.js
|
||||||
|
uhr-de_CH.js
|
||||||
|
uhr-en.js
|
||||||
uhr-green.css
|
uhr-green.css
|
||||||
|
uhr-red.css
|
||||||
uhr-white.css
|
uhr-white.css
|
||||||
|
uhr.css
|
||||||
|
uhr.js
|
||||||
uhr.woff
|
uhr.woff
|
||||||
|
|
|
@ -27,4 +27,4 @@ var layout = {
|
||||||
[h('Z', 10), h('E', 10),h('H', 10),h('N', 9, 10),h('E', 9),h('U', 9),h('N', 9),l('K'),l('U'),l('H'),l('R')]
|
[h('Z', 10), h('E', 10),h('H', 10),h('N', 9, 10),h('E', 9),h('U', 9),h('N', 9),l('K'),l('U'),l('H'),l('R')]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
Uhr.register('de', layout);
|
window._uhr.languages['de'] = layout;
|
||||||
|
|
|
@ -27,4 +27,4 @@ var layout = {
|
||||||
[h('Z', 12), h('W', 12),h('Ö', 12),h('U', 12),h('F', 12),h('I', 12),l('N'),l('A'),l('U'),l('H'),l('R')]
|
[h('Z', 12), h('W', 12),h('Ö', 12),h('U', 12),h('F', 12),h('I', 12),l('N'),l('A'),l('U'),l('H'),l('R')]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
Uhr.register('de_CH', layout);
|
window._uhr.languages['de_CH'] = layout;
|
||||||
|
|
|
@ -34,4 +34,4 @@ var layout = {
|
||||||
return hour;
|
return hour;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Uhr.register('en', layout);
|
window._uhr.languages['en'] = layout;
|
||||||
|
|
408
uhr.js
408
uhr.js
|
@ -12,127 +12,160 @@ GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
(function($) {
|
||||||
* Die Uhr.
|
"use strict";
|
||||||
* @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.
|
if (window._uhr !== undefined) {
|
||||||
*/
|
return;
|
||||||
//if (typeof Uhr === 'undefined') {
|
|
||||||
function Uhr(clockarea, settings) {
|
|
||||||
this.id = Uhr.id++;
|
|
||||||
this.timer = null;
|
|
||||||
this.currentTheme = null;
|
|
||||||
this.currentLayout = {};
|
|
||||||
this.currentMinute = -1;
|
|
||||||
this.initHTMLElements(clockarea, settings || {});
|
|
||||||
}
|
}
|
||||||
Uhr.id = 0;
|
|
||||||
Uhr.layouts = new Array();
|
window._uhr = {
|
||||||
Uhr.register = function (locale, layout) {
|
id: 0,
|
||||||
Uhr.layouts[locale] = layout;
|
languages: new Array()
|
||||||
|
};
|
||||||
|
$.widget("fritteli.uhr", {
|
||||||
|
options: {
|
||||||
|
width: '100%',
|
||||||
|
status: 'on',
|
||||||
|
language: 'de_CH',
|
||||||
|
theme: 'black',
|
||||||
|
force: false
|
||||||
|
},
|
||||||
|
start: function() {
|
||||||
|
if (!this._isOn()) {
|
||||||
|
var uhr = this;
|
||||||
|
this._timer = window.setInterval(function() {
|
||||||
|
uhr._update();
|
||||||
|
}, 1000);
|
||||||
|
this._update();
|
||||||
|
$.cookie('uhr-status' + this._id, 'on', {expires: 365, path: '/'});
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
Uhr.prototype.toggle = function() {
|
},
|
||||||
if (this.isOn()) {
|
stop: function() {
|
||||||
|
if(this._isOn()) {
|
||||||
|
window.clearInterval(this._timer);
|
||||||
|
this._timer = null;
|
||||||
|
this._update();
|
||||||
|
$.cookie('uhr-status' + this._id, 'off', {expires: 365, path: '/'});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggle: function() {
|
||||||
|
if(this._isOn()) {
|
||||||
this.stop();
|
this.stop();
|
||||||
} else {
|
} else {
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
Uhr.prototype.start = function() {
|
language: function(languageKey) {
|
||||||
if (!this.isOn()) {
|
if (languageKey !== this.options.language) {
|
||||||
|
this.options.language = languageKey;
|
||||||
|
var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea'));
|
||||||
var uhr = this;
|
var uhr = this;
|
||||||
this.timer = window.setInterval(function() {uhr.update();}, 1000);
|
renderer.render(this, function() {
|
||||||
this.update();
|
uhr._currentMinute = -1;
|
||||||
jQuery.cookie('status' + this.id, 'on', {expires: 365, path: '/'});
|
uhr._update();
|
||||||
|
});
|
||||||
|
$.cookie('uhr-language' + this._id, languageKey, {expires: 365, path: '/'});
|
||||||
|
this._update();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
theme: function(theme) {
|
||||||
|
if (theme != this.options.theme) {
|
||||||
|
this.element.removeClass(this.options.theme).addClass(theme);
|
||||||
|
$('#uhr-onoffswitch' + this._id).removeClass(this.options.theme).addClass(theme);
|
||||||
|
this.options.theme = theme;
|
||||||
|
$.cookie('uhr-theme' + this._id, theme, {expires: 365, path: '/'});
|
||||||
}
|
}
|
||||||
Uhr.prototype.stop = function() {
|
},
|
||||||
if (this.isOn()) {
|
time: function(time) {
|
||||||
window.clearInterval(this.timer);
|
this.options.time = time;
|
||||||
this.timer = null;
|
if (time == null) {
|
||||||
this.update();
|
this._currentMinute = -1;
|
||||||
jQuery.cookie('status' + this.id, 'off', {expires: 365, path: '/'});
|
this._update();
|
||||||
|
} else {
|
||||||
|
if (this._timer != null) {
|
||||||
|
window.clearInterval(this._timer);
|
||||||
}
|
}
|
||||||
|
var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea'));
|
||||||
|
var uhr = this;
|
||||||
|
renderer.render(this, function() {
|
||||||
|
uhr._show(time);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
Uhr.prototype.isOn = function() {
|
},
|
||||||
return this.timer != null;
|
// private variables
|
||||||
}
|
_id: -1,
|
||||||
Uhr.prototype.setLayout = function(locale) {
|
_timer: null,
|
||||||
var newLayout = Uhr.layouts[locale];
|
_currentMinute: -1,
|
||||||
if (newLayout !== undefined && newLayout != this.currentLayout) {
|
// private methods
|
||||||
this.currentLayout = newLayout;
|
_isOn: function() {
|
||||||
var renderer = new UhrRenderer(this.currentLayout, this.letterarea);
|
return this._timer !== null;
|
||||||
renderer.render(this);
|
},
|
||||||
jQuery.cookie('layout' + this.id, locale, {expires: 365, path: '/'});
|
_update: function() {
|
||||||
}
|
if (this._isOn()) {
|
||||||
}
|
var time = new Date();
|
||||||
Uhr.prototype.setTheme = function(theme) {
|
if (time.getMinutes() == this._currentMinute) {
|
||||||
if (theme != this.currentTheme) {
|
|
||||||
this.clockarea.removeClass(this.currentTheme);
|
|
||||||
this.toggleSwitch.removeClass(this.currentTheme);
|
|
||||||
this.clockarea.addClass(theme);
|
|
||||||
this.toggleSwitch.addClass(theme);
|
|
||||||
this.currentTheme = theme;
|
|
||||||
jQuery.cookie('theme' + this.id, theme, {expires: 365, path: '/'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Uhr.prototype.update = function() {
|
|
||||||
if (this.isOn()) {
|
|
||||||
var now = new Date();
|
|
||||||
if (now.getMinutes() == this.currentMinute) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.currentMinute = now.getMinutes();
|
this._currentMinute = time.getMinutes();
|
||||||
var dotMinute = this.getDotMinute(now);
|
this._show(time);
|
||||||
var hour = this.getHour(now);
|
|
||||||
var coarseMinute = this.getCoarseMinute(now);
|
|
||||||
this.clear();
|
|
||||||
this.highlight('on');
|
|
||||||
for (var i = 1; i <= dotMinute; i++) {
|
|
||||||
this.highlight('dot' + i);
|
|
||||||
}
|
|
||||||
this.highlight('minute' + coarseMinute);
|
|
||||||
hour = this.normalizeHour(hour);
|
|
||||||
this.highlight('hour' + hour);
|
|
||||||
if (coarseMinute == 0) {
|
|
||||||
this.highlight('sharphour');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.clear();
|
this._clear();
|
||||||
this.currentMinute = -1;
|
this._currentMinute = -1;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_show: function(time) {
|
||||||
|
var dotMinute = this._getDotMinute(time);
|
||||||
|
var hour = this._getHour(time);
|
||||||
|
var coarseMinute = this._getCoarseMinute(time);
|
||||||
|
this._clear();
|
||||||
|
this._highlight('on');
|
||||||
|
for (var i = 1; i <= dotMinute; i++) {
|
||||||
|
this._highlight('dot' + i);
|
||||||
}
|
}
|
||||||
Uhr.prototype.clear = function() {
|
this._highlight('minute' + coarseMinute);
|
||||||
this.clockarea.find('.item').removeClass('active');
|
hour = this._normalizeHour(hour);
|
||||||
|
this._highlight('hour' + hour);
|
||||||
|
if (coarseMinute == 0) {
|
||||||
|
this._highlight('sharphour');
|
||||||
}
|
}
|
||||||
Uhr.prototype.highlight = function(itemClass) {
|
},
|
||||||
this.clockarea.find('.item.' + itemClass).addClass('active');
|
_language: function() {
|
||||||
}
|
return window._uhr.languages[this.options.language];
|
||||||
Uhr.prototype.getHour = function(date) {
|
},
|
||||||
if (typeof this.currentLayout.getHour === 'function') {
|
_highlight: function(itemClass) {
|
||||||
return this.currentLayout.getHour(date);
|
this.element.find('.item.' + itemClass).addClass('active');
|
||||||
|
},
|
||||||
|
_clear: function() {
|
||||||
|
this.element.find('.item').removeClass('active');
|
||||||
|
},
|
||||||
|
_getHour: function(date) {
|
||||||
|
if (typeof this._language().getHour === 'function') {
|
||||||
|
return this._language().getHour(date);
|
||||||
}
|
}
|
||||||
var hour = date.getHours();
|
var hour = date.getHours();
|
||||||
if (date.getMinutes() >= 25) {
|
if (date.getMinutes() >= 25) {
|
||||||
return hour + 1;
|
return hour + 1;
|
||||||
}
|
}
|
||||||
return hour;
|
return hour;
|
||||||
}
|
},
|
||||||
Uhr.prototype.getCoarseMinute = function(date) {
|
_getCoarseMinute: function(date) {
|
||||||
if (typeof this.currentLayout.getCoarseMinute === 'function') {
|
if (typeof this._language().getCoarseMinute === 'function') {
|
||||||
return this.currentLayout.getCoarseMinute(date);
|
return this._language().getCoarseMinute(date);
|
||||||
}
|
}
|
||||||
var minutes = date.getMinutes();
|
var minutes = date.getMinutes();
|
||||||
return minutes - this.getDotMinute(date);
|
return minutes - this._getDotMinute(date);
|
||||||
}
|
},
|
||||||
Uhr.prototype.getDotMinute = function(date) {
|
_getDotMinute: function(date) {
|
||||||
if (typeof this.currentLayout.getDotMinute === 'function') {
|
if (typeof this._language().getDotMinute === 'function') {
|
||||||
return this.currentLayout.getDotMinute(date);
|
return this._language().getDotMinute(date);
|
||||||
}
|
}
|
||||||
var minutes = date.getMinutes();
|
var minutes = date.getMinutes();
|
||||||
return minutes % 5;
|
return minutes % 5;
|
||||||
}
|
},
|
||||||
Uhr.prototype.normalizeHour = function(hour) {
|
_normalizeHour: function(hour) {
|
||||||
if (hour > 12) {
|
if (hour > 12) {
|
||||||
hour %= 12;
|
hour %= 12;
|
||||||
}
|
}
|
||||||
|
@ -140,122 +173,108 @@ Uhr.prototype.normalizeHour = function(hour) {
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
return hour;
|
return hour;
|
||||||
|
},
|
||||||
|
_create: function() {
|
||||||
|
this._id = window._uhr.id++;
|
||||||
|
this._setupHTML();
|
||||||
|
this._wireFunctionality();
|
||||||
|
if (this.options.time !== undefined) {
|
||||||
|
this.time(this.options.time);
|
||||||
}
|
}
|
||||||
Uhr.prototype.initHTMLElements = function(clockarea, presets) {
|
},
|
||||||
this.createHTMLElements(clockarea, presets.width);
|
_setupHTML: function() {
|
||||||
var force = presets.force || false;
|
var e = this.element;
|
||||||
this.initToggleSwitch(presets.status, force);
|
// Base clock area
|
||||||
this.initLayoutSwitch(presets.layout, force);
|
e.addClass('uhr');
|
||||||
this.initThemeSwitch(presets.theme, force);
|
e.empty();
|
||||||
}
|
e.append('<span class="item dot dot1"></span>');
|
||||||
Uhr.prototype.createHTMLElements = function(clockarea, width) {
|
e.append('<span class="item dot dot2"></span>');
|
||||||
this.createClockarea(clockarea, width)
|
e.append('<span class="item dot dot3"></span>');
|
||||||
this.letterarea = this.clockarea.find('.letterarea');
|
e.append('<span class="item dot dot4"></span>');
|
||||||
this.createToggleSwitch();
|
e.append('<div class="letterarea"></div>');
|
||||||
this.createLayoutSwitch();
|
e.append('<div class="reflection"></div>');
|
||||||
this.createThemeSwitch();
|
e.css('width', this.options.width);
|
||||||
}
|
var realWidth = e.width()
|
||||||
Uhr.prototype.createClockarea = function(clockarea, width) {
|
e.width(realWidth);
|
||||||
clockarea.addClass('uhr');
|
e.height(realWidth);
|
||||||
clockarea.empty();
|
e.css('font-size', (realWidth / 40) + 'px');
|
||||||
clockarea.append('<span class="item dot dot1"></span>');
|
|
||||||
clockarea.append('<span class="item dot dot2"></span>');
|
// on/off switch
|
||||||
clockarea.append('<span class="item dot dot3"></span>');
|
var toggleSwitch = $('<div class="onoffswitch" id="uhr-onoffswitch' + this._id + '"></div>');
|
||||||
clockarea.append('<span class="item dot dot4"></span>');
|
toggleSwitch.append('<input type="checkbox" class="onoffswitch-checkbox" id="uhr-onoffswitch-checkbox' + this._id + '" checked="checked" />');
|
||||||
clockarea.append('<div class="letterarea"></div>');
|
toggleSwitch.append('<label class="onoffswitch-label" for="uhr-onoffswitch-checkbox' + this._id + '">'
|
||||||
clockarea.append('<div class="reflection"></div>');
|
|
||||||
if(width == undefined) {
|
|
||||||
width = '100%';
|
|
||||||
}
|
|
||||||
clockarea.css('width', width);
|
|
||||||
var realWidth = clockarea.width()
|
|
||||||
clockarea.width(realWidth);
|
|
||||||
clockarea.height(realWidth);
|
|
||||||
clockarea.css('font-size', (realWidth / 40) + 'px');
|
|
||||||
this.clockarea = clockarea
|
|
||||||
}
|
|
||||||
Uhr.prototype.createToggleSwitch = function() {
|
|
||||||
this.toggleSwitch = jQuery('<div class="onoffswitch"></div>');
|
|
||||||
var input = jQuery('<input type="checkbox" name="onoffswitch' + this.id + '" class="onoffswitch-checkbox" id="onoffswitch' + this.id + '" checked="checked" />');
|
|
||||||
this.toggleSwitch.append(input);
|
|
||||||
this.toggleSwitch.append('<label class="onoffswitch-label" for="onoffswitch' + this.id + '">'
|
|
||||||
+ '<div class="onoffswitch-inner"></div>'
|
+ '<div class="onoffswitch-inner"></div>'
|
||||||
+ '<div class="onoffswitch-switch"></div>'
|
+ '<div class="onoffswitch-switch"></div>'
|
||||||
+ '</label>');
|
+ '</label>');
|
||||||
this.clockarea.after(this.toggleSwitch);
|
e.after(toggleSwitch);
|
||||||
}
|
|
||||||
Uhr.prototype.createLayoutSwitch = function () {
|
// language chooser
|
||||||
this.layoutSwitch = jQuery('<select></select>')
|
var languageChooser = $('<select id="uhr-languagechooser' + this._id + '"></select>')
|
||||||
for (var code in Uhr.layouts) {
|
for (var code in window._uhr.languages) {
|
||||||
if (Uhr.layouts.hasOwnProperty(code)) {
|
if (window._uhr.languages.hasOwnProperty(code)) {
|
||||||
var layout = Uhr.layouts[code];
|
var language = window._uhr.languages[code];
|
||||||
var option = jQuery('<option value="' + code + '">' + layout.language + '</option>')
|
languageChooser.append('<option value="' + code + '">' + language.language + '</option>');
|
||||||
this.layoutSwitch.append(option);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.clockarea.after(this.layoutSwitch);
|
e.after(languageChooser);
|
||||||
}
|
|
||||||
Uhr.prototype.createThemeSwitch = function () {
|
// theme chooser
|
||||||
this.themeSwitch = jQuery('<select></select>');
|
var themeChooser = $('<select id="uhr-themechooser' + this._id + '"></select>');
|
||||||
this.themeSwitch.append('<option value="black">Schwarz</option>');
|
themeChooser.append('<option value="black">Schwarz</option>');
|
||||||
this.themeSwitch.append('<option value="red">Rot</option>');
|
themeChooser.append('<option value="red">Rot</option>');
|
||||||
this.themeSwitch.append('<option value="blue">Blau</option>');
|
themeChooser.append('<option value="blue">Blau</option>');
|
||||||
this.themeSwitch.append('<option value="green">Grün</option>');
|
themeChooser.append('<option value="green">Grün</option>');
|
||||||
this.themeSwitch.append('<option value="white">Weiss</option>');
|
themeChooser.append('<option value="white">Weiss</option>');
|
||||||
this.clockarea.after(this.themeSwitch);
|
e.after(themeChooser);
|
||||||
}
|
},
|
||||||
Uhr.prototype.initToggleSwitch = function(defaultValue, overrideCookie) {
|
_wireFunctionality: function() {
|
||||||
var input = jQuery('#onoffswitch' + this.id);
|
var e = this.element;
|
||||||
var uhr = this;
|
var uhr = this;
|
||||||
input.on('click', function() {
|
|
||||||
|
// on/off switch
|
||||||
|
var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this._id);
|
||||||
|
toggleSwitch.on('click', function() {
|
||||||
uhr.toggle();
|
uhr.toggle();
|
||||||
});
|
});
|
||||||
var status = jQuery.cookie('status' + this.id);
|
var status = $.cookie('uhr-status' + this._id);
|
||||||
if (status == undefined || (overrideCookie && (defaultValue != undefined))) {
|
if (status == undefined || this.options.force) {
|
||||||
status = defaultValue;
|
status = this.options.status;
|
||||||
}
|
|
||||||
if (status == undefined || status == 'undefined') {
|
|
||||||
status = 'on';
|
|
||||||
}
|
}
|
||||||
|
toggleSwitch.prop('checked', status == 'on');
|
||||||
if (status == 'on') {
|
if (status == 'on') {
|
||||||
this.start();
|
this.start();
|
||||||
input.prop('checked', true);
|
|
||||||
} else {
|
} else {
|
||||||
this.stop();
|
this.stop();
|
||||||
input.prop('checked', false);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Uhr.prototype.initLayoutSwitch = function(defaultValue, overrideCookie) {
|
// language chooser
|
||||||
var uhr = this;
|
var languageChooser = $('#uhr-languagechooser' + this._id);
|
||||||
this.layoutSwitch.on('change', function() {
|
languageChooser.on('change', function() {
|
||||||
uhr.setLayout(this.value);
|
uhr.language(this.value);
|
||||||
});
|
});
|
||||||
var selectedLayout = jQuery.cookie('layout' + this.id);
|
var selectedLanguage = $.cookie('uhr-language' + this._id);
|
||||||
if (selectedLayout == undefined || (overrideCookie && (defaultValue != undefined))) {
|
if (selectedLanguage == undefined || this.options.force) {
|
||||||
selectedLayout = defaultValue;
|
selectedLanguage = this.options.language;
|
||||||
}
|
}
|
||||||
if (selectedLayout == undefined) {
|
languageChooser.val(selectedLanguage);
|
||||||
// FIXME not nice, hardcoded default-value
|
this.options.language = "";
|
||||||
selectedLayout = 'de_CH';
|
this.language(selectedLanguage);
|
||||||
}
|
|
||||||
this.layoutSwitch.val(selectedLayout);
|
// theme chooser
|
||||||
this.setLayout(selectedLayout);
|
var themeChooser = $('#uhr-themechooser' + this._id);
|
||||||
}
|
themeChooser.on('change', function() {
|
||||||
Uhr.prototype.initThemeSwitch = function(defaultValue, overrideCookie) {
|
uhr.theme(this.value);
|
||||||
var uhr = this;
|
|
||||||
this.themeSwitch.on('change', function() {
|
|
||||||
uhr.setTheme(this.value);
|
|
||||||
});
|
});
|
||||||
var selectedTheme = jQuery.cookie('theme' + this.id);
|
var selectedTheme = $.cookie('uhr-theme' + this._id);
|
||||||
if (selectedTheme == undefined || (overrideCookie && (defaultValue != undefined))) {
|
if (selectedTheme == undefined || this.options.force) {
|
||||||
selectedTheme = defaultValue;
|
selectedTheme = this.options.theme;
|
||||||
}
|
}
|
||||||
if (selectedTheme == undefined || selectedTheme == 'undefined') {
|
themeChooser.val(selectedTheme);
|
||||||
selectedTheme = 'black';
|
this.options.theme = "";
|
||||||
}
|
this.theme(selectedTheme);
|
||||||
this.themeSwitch.val(selectedTheme);
|
|
||||||
this.setTheme(selectedTheme);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
})(jQuery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hilfsklasse zum Rendern der Uhr.
|
* Hilfsklasse zum Rendern der Uhr.
|
||||||
|
@ -266,7 +285,7 @@ function UhrRenderer(layout, renderarea) {
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
this.renderarea = renderarea;
|
this.renderarea = renderarea;
|
||||||
}
|
}
|
||||||
UhrRenderer.prototype.render = function(uhr) {
|
UhrRenderer.prototype.render = function(uhr, beforeshow) {
|
||||||
var renderer = this;
|
var renderer = this;
|
||||||
this.renderarea.fadeOut('fast', function() {
|
this.renderarea.fadeOut('fast', function() {
|
||||||
renderer.renderarea.empty();
|
renderer.renderarea.empty();
|
||||||
|
@ -279,12 +298,12 @@ UhrRenderer.prototype.render = function(uhr) {
|
||||||
renderer.renderarea.append('<br/>');
|
renderer.renderarea.append('<br/>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uhr.currentMinute = -1;
|
if (typeof beforeshow === 'function') {
|
||||||
uhr.update();
|
beforeshow();
|
||||||
|
}
|
||||||
renderer.renderarea.fadeIn('fast');
|
renderer.renderarea.fadeIn('fast');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
||||||
* @param value Der Buchstabe, der Dargestellt werden soll.
|
* @param value Der Buchstabe, der Dargestellt werden soll.
|
||||||
|
@ -317,7 +336,7 @@ function l(letter, style) {
|
||||||
*
|
*
|
||||||
* @param letter string: Der Buchstabe, der angezeigt werden soll
|
* @param letter string: Der Buchstabe, der angezeigt werden soll
|
||||||
* @param hours... integer: Eine Aufzählung von Stundenwerten, zu welchen der Buchstabe als aktiv angezeigt werden soll
|
* @param hours... integer: Eine Aufzählung von Stundenwerten, zu welchen der Buchstabe als aktiv angezeigt werden soll
|
||||||
* @example h('Z', 2), 11 erzeugt den Buchstaben 'Z', der um 2:xx, 11:xx, 14:xx und 23:xx aktiv angezeigt wird
|
* @example h('Z', 2, 11) erzeugt den Buchstaben 'Z', der um 2:xx, 11:xx, 14:xx und 23:xx aktiv angezeigt wird
|
||||||
*/
|
*/
|
||||||
function h(letter) {
|
function h(letter) {
|
||||||
var style = '';
|
var style = '';
|
||||||
|
@ -340,4 +359,3 @@ function m(letter) {
|
||||||
}
|
}
|
||||||
return l(letter, style);
|
return l(letter, style);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
|
Loading…
Reference in a new issue