time() funktion implementiert; damit kann eine fixe zeit gesetzt werden. noch nicht ganz ausgereift.

This commit is contained in:
Manuel Friedli 2014-01-11 22:54:46 +01:00
parent 9710663b1d
commit 831f1facd7
3 changed files with 75 additions and 33 deletions

View file

@ -30,16 +30,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<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;">
<div id="uhr"></div> <div style="display:inline-block;">
<h3>Uhr mit der aktuellen Zeit</h3>
<div id="uhr"></div>
</div>
<div style="display:inline-block;">
<h3>Uhr mit statischer Zeit</h3>
<div id="uhr-statictime"></div>
</div>
<p id="disclaimer">Created by fritteli, inspired by <a href="http://www.qlocktwo.com/">QLOCKTWO</a>. <p id="disclaimer">Created by fritteli, inspired by <a href="http://www.qlocktwo.com/">QLOCKTWO</a>.
<script type="text/javascript" src="uhr-de_CH.js"></script> <script type="text/javascript" src="uhr-de_CH.js"></script>
<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(); var size = 300;
var width = jQuery(window).width(); $('#uhr').uhr({
var size = height < width ? height : width; width: size + 'px'
$('#uhr').uhr({width:size+'px'}); });
$('#uhr-statictime').uhr({
width: size + 'px',
time: new Date(1982, 2, 22, 0, 12, 0)
});
// Auch möglich:
//$('#uhr-statictime').uhr("time", new Date(1982, 2, 22, 0, 10, 0));
</script> </script>
</body> </body>
</html> </html>

View file

@ -1,19 +1,20 @@
CACHE MANIFEST CACHE MANIFEST
# 4.0.0-alpha1 # 4.0.0-alpha2
COPYING COPYING
favicon.png
index.html index.html
jquery-2.0.3.min.js jquery-2.0.3.min.js
jquery-cookie-1.4.0.js jquery-cookie-1.4.0.js
jquery-ui-1.10.3.custom.min.js jquery-ui-1.10.3.custom.min.js
uhr.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

70
uhr.js
View file

@ -61,7 +61,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (languageKey !== this.options.language) { if (languageKey !== this.options.language) {
this.options.language = languageKey; this.options.language = languageKey;
var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea')); var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea'));
renderer.render(this); var uhr = this;
renderer.render(this, function() {
uhr._currentMinute = -1;
uhr._update();
});
$.cookie('uhr-language' + this._id, languageKey, {expires: 365, path: '/'}); $.cookie('uhr-language' + this._id, languageKey, {expires: 365, path: '/'});
this._update(); this._update();
} }
@ -74,6 +78,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
$.cookie('uhr-theme' + this._id, theme, {expires: 365, path: '/'}); $.cookie('uhr-theme' + this._id, theme, {expires: 365, path: '/'});
} }
}, },
time: function(time) {
this.options.time = time;
if (time == null) {
this._currentMinute = -1;
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);
});
}
},
// private variables // private variables
_id: -1, _id: -1,
_timer: null, _timer: null,
@ -84,30 +105,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}, },
_update: function() { _update: function() {
if (this._isOn()) { if (this._isOn()) {
var now = new Date(); var time = new Date();
if (now.getMinutes() == this._currentMinute) { if (time.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);
}
this._highlight('minute' + coarseMinute);
hour = this._normalizeHour(hour);
this._highlight('hour' + hour);
if (coarseMinute == 0) {
this._highlight('sharphour');
}
},
_language: function() { _language: function() {
return window._uhr.languages[this.options.language]; return window._uhr.languages[this.options.language];
}, },
@ -154,6 +178,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this._id = window._uhr.id++; this._id = window._uhr.id++;
this._setupHTML(); this._setupHTML();
this._wireFunctionality(); this._wireFunctionality();
if (this.options.time !== undefined) {
this.time(this.options.time);
}
}, },
_setupHTML: function() { _setupHTML: function() {
var e = this.element; var e = this.element;
@ -258,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();
@ -271,8 +298,9 @@ 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');
}); });
} }