summaryrefslogtreecommitdiff
path: root/js/local-time.js
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-07-02 21:09:05 -0400
committerMichael Foster <savetheinternet@tinyboard.org>2013-07-31 04:35:29 -0400
commit46ebcbf51d99cd439906cf63a5bf4cefe5ddce45 (patch)
treee6b1956de6460be7c036811869a1f4df73c69b0d /js/local-time.js
parentf98d5bdd180d7452e82d7e35dcd7e3372ccd2aab (diff)
local-time.js: make it work with thread expand etc; BEWARE IT NOW NEEDS JQUERY TO BE LOADED BEFORE
Diffstat (limited to 'js/local-time.js')
-rw-r--r--js/local-time.js36
1 files changed, 23 insertions, 13 deletions
diff --git a/js/local-time.js b/js/local-time.js
index bb81c83a..aee26ed2 100644
--- a/js/local-time.js
+++ b/js/local-time.js
@@ -6,6 +6,7 @@
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
*
* Usage:
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/local-time.js';
*
*/
@@ -21,23 +22,32 @@ onready(function(){
var zeropad = function(num, count) {
return [Math.pow(10, count - num.toString().length), num].join('').substr(1);
};
+
+ var do_localtime = function(elem) {
+ var times = elem.getElementsByTagName('time');
- var times = document.getElementsByTagName('time');
-
- for(var i = 0; i < times.length; i++) {
- if(typeof times[i].getAttribute('data-local') == 'undefined')
- continue;
+ for(var i = 0; i < times.length; i++) {
+ if(typeof times[i].getAttribute('data-local') == 'undefined')
+ continue;
- var t = iso8601(times[i].getAttribute('datetime'));
+ var t = iso8601(times[i].getAttribute('datetime'));
- times[i].setAttribute('data-local', 'true');
- times[i].innerHTML =
- // date
- zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
- " (" + ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][t.getDay()] + ") " +
- // time
- zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
+ times[i].setAttribute('data-local', 'true');
+ times[i].innerHTML =
+ // date
+ zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
+ " (" + ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][t.getDay()] + ") " +
+ // time
+ zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
+ };
};
+
+ do_localtime(document);
+
+ // allow to work with auto-reload.js, etc.
+ $(document).bind('new_post', function(e, post) {
+ do_localtime(post);
+ });
});