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" />
</head>
<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>.
<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-en.js"></script>
<script type="text/javascript">
var height = jQuery(window).height();
var width = jQuery(window).width();
var size = height < width ? height : width;
$('#uhr').uhr({width:size+'px'});
var size = 300;
$('#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>
</body>
</html>

View file

@ -1,19 +1,20 @@
CACHE MANIFEST
# 4.0.0-alpha1
# 4.0.0-alpha2
COPYING
favicon.png
index.html
jquery-2.0.3.min.js
jquery-cookie-1.4.0.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-red.css
uhr-blue.css
uhr-de.js
uhr-de_CH.js
uhr-en.js
uhr-green.css
uhr-red.css
uhr-white.css
uhr.css
uhr.js
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) {
this.options.language = languageKey;
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: '/'});
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: '/'});
}
},
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
_id: -1,
_timer: null,
@ -84,30 +105,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
},
_update: function() {
if (this._isOn()) {
var now = new Date();
if (now.getMinutes() == this._currentMinute) {
var time = new Date();
if (time.getMinutes() == this._currentMinute) {
return;
}
this._currentMinute = now.getMinutes();
var dotMinute = this._getDotMinute(now);
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');
}
this._currentMinute = time.getMinutes();
this._show(time);
} else {
this._clear();
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() {
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._setupHTML();
this._wireFunctionality();
if (this.options.time !== undefined) {
this.time(this.options.time);
}
},
_setupHTML: function() {
var e = this.element;
@ -258,7 +285,7 @@ function UhrRenderer(layout, renderarea) {
this.layout = layout;
this.renderarea = renderarea;
}
UhrRenderer.prototype.render = function(uhr) {
UhrRenderer.prototype.render = function(uhr, beforeshow) {
var renderer = this;
this.renderarea.fadeOut('fast', function() {
renderer.renderarea.empty();
@ -271,8 +298,9 @@ UhrRenderer.prototype.render = function(uhr) {
renderer.renderarea.append('<br/>');
}
}
uhr._currentMinute = -1;
uhr._update();
if (typeof beforeshow === 'function') {
beforeshow();
}
renderer.renderarea.fadeIn('fast');
});
}