-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclock.js
executable file
·140 lines (133 loc) · 4.16 KB
/
clock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Generated by CoffeeScript 1.7.1
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
(function($) {
var Clock, date, pad;
if (!(typeof STUDIP === 'object' && typeof $ === 'function')) {
throw 'No Stud.IP environment';
}
if (!(($.fn != null) && ($.fn.jquery != null) && $.fn.jquery >= '1.4.3')) {
throw 'Invalid jQuery version, required version is 1.4.3';
}
pad = function(what, length) {
if (length == null) {
length = 2;
}
return ('0000' + what).slice(-length);
};
date = function(format, timestamp) {
var days, mapping;
if (format == null) {
format = 'H:i:s';
}
if (timestamp == null) {
timestamp = null;
}
if (typeof timestamp !== 'object') {
timestamp = new Date(timestamp);
}
days = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
mapping = {
d: 'getDate',
H: 'getHours',
i: 'getMinutes',
s: 'getSeconds'
};
return format.replace(/[dHilmsY]/g, function(token) {
var method;
method = mapping[token];
switch (token) {
case 'l':
return days[timestamp.getDay()].toLocaleString();
case 'm':
return pad(timestamp.getMonth() + 1);
case 'Y':
return (timestamp.getYear() % 100) + 2000;
default:
if (method != null) {
return pad(timestamp[method]());
} else {
return token;
}
}
});
};
Clock = (function() {
function Clock(element, offset, format) {
var metadata, tokens, _ref;
if (element == null) {
element = '.clockip';
}
this.offset = offset != null ? offset : 0;
this.format = format != null ? format : 'H:i:s';
this.stop = __bind(this.stop, this);
this.start = __bind(this.start, this);
this.display = __bind(this.display, this);
this.adjust = __bind(this.adjust, this);
this.element = $(element);
this.interval = null;
metadata = (_ref = this.element.data()) != null ? _ref : {};
if (metadata.format != null) {
this.format = metadata.format;
}
if (__indexOf.call(window, 'matchMedia') >= 0) {
if (metadata.mediumformat != null) {
tokens = metadata.mediumformat.split(')');
if (window.matchMedia(tokens[0] + ')').matches) {
this.format = tokens[1];
}
}
if (metadata.smallformat != null) {
tokens = metadata.smallformat.split(')');
if (window.matchMedia(tokens[0] + ')').matches) {
this.format = tokens[1];
}
}
}
if (metadata.timestamp != null) {
this.adjust(metadata.timestamp);
}
}
Clock.prototype.adjust = function(timestamp) {
return this.offset = timestamp ? timestamp - (new Date()).getTime() : 0;
};
Clock.prototype.display = function() {
var now, time;
now = (new Date()).getTime();
time = date(this.format, now + this.offset);
if (time !== this.last) {
this.element.text(time);
this.last = time;
}
return this.element.show();
};
Clock.prototype.start = function() {
this.stop();
return this.interval = setInterval(this.display, 100);
};
Clock.prototype.stop = function() {
this.element.hide();
if (this.interval != null) {
clearInterval(this.interval);
}
this.interval = null;
return this.last = null;
};
return Clock;
})();
return $(function() {
var clock, infobox_clock;
clock = new Clock;
if (clock.element.hasClass('uni-oldenburg') && $('header').length === 0) {
clock.element.hide();
return;
}
if (clock.element.hasClass('uni-augsburg')) {
infobox_clock = $("<b>Aktuelle Serverzeit:</b><br>");
clock.element.addClass('sidebar').appendTo(infobox_clock);
infobox_clock.appendTo('.infoboxrahmen');
}
_(clock.start).defer();
return STUDIP.CLOCK = clock;
});
})(jQuery);