client: custom date formats (minutes/seconds/full)
This commit is contained in:
parent
c619be5917
commit
4a4e9e694d
@ -118,6 +118,23 @@ function getOffsetTop( elem ) {
|
|||||||
return offsetTop;
|
return offsetTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
var date_format = function(d, format) {
|
||||||
|
var pad = function(s) {
|
||||||
|
return (s < 10) ? '0'+s : ''+s ;
|
||||||
|
};
|
||||||
|
|
||||||
|
var ret = format;
|
||||||
|
ret = ret.replace(/H/g, pad(d.getHours()));
|
||||||
|
ret = ret.replace(/i/g, pad(d.getMinutes()));
|
||||||
|
ret = ret.replace(/s/g, pad(d.getSeconds()));
|
||||||
|
ret = ret.replace(/Y/g, d.getFullYear());
|
||||||
|
ret = ret.replace(/m/g, pad(d.getMonth() + 1));
|
||||||
|
ret = ret.replace(/d/g, pad(d.getDate()));
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
/* Tab writers */
|
/* Tab writers */
|
||||||
|
|
||||||
var write = function(tab) {
|
var write = function(tab) {
|
||||||
@ -140,14 +157,8 @@ var write = function(tab) {
|
|||||||
},
|
},
|
||||||
'time': function() {
|
'time': function() {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
var pad = function(s) {
|
|
||||||
return (s < 10) ? '0'+s : ''+s ;
|
return this.raw('<span class="tx-time">['+ date_format(new Date(), timestamp_formats[timestamp_format_index])+"]</span> ");
|
||||||
};
|
|
||||||
return this.raw(
|
|
||||||
'<span class="tx-time">['+
|
|
||||||
pad(d.getHours()) + ":" + pad(d.getMinutes())+
|
|
||||||
"]</span> "
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
'system': function(s) {
|
'system': function(s) {
|
||||||
return this.time().c('tx-sys', sanitise(s)).raw('<br/>');
|
return this.time().c('tx-sys', sanitise(s)).raw('<br/>');
|
||||||
@ -576,6 +587,7 @@ var menu = new MenuList($("#menubutton"));
|
|||||||
menu.reset = function() {
|
menu.reset = function() {
|
||||||
this.clear();
|
this.clear();
|
||||||
this.add(joinparts_getstr(), toggle_joinparts);
|
this.add(joinparts_getstr(), toggle_joinparts);
|
||||||
|
this.add(timestamp_display(), timestamp_toggle);
|
||||||
};
|
};
|
||||||
|
|
||||||
var usermenu = new MenuList(document.body);
|
var usermenu = new MenuList(document.body);
|
||||||
@ -692,6 +704,21 @@ var STATE_ACTIVE = 2;
|
|||||||
var chat_scrollback = [];
|
var chat_scrollback = [];
|
||||||
var chat_scrollback_index = -1;
|
var chat_scrollback_index = -1;
|
||||||
|
|
||||||
|
var timestamp_formats = [ "H:i", "H:i:s", "Y-m-d H:i:s" ];
|
||||||
|
var timestamp_names = [ "Minutes", "Seconds", "Full" ];
|
||||||
|
var timestamp_format_index = 0;
|
||||||
|
|
||||||
|
var timestamp_display = function() {
|
||||||
|
return "Timestamp format: " + timestamp_names[timestamp_format_index];
|
||||||
|
};
|
||||||
|
|
||||||
|
var timestamp_toggle = function(ev) {
|
||||||
|
var $el = ev.target || ev.srcElement;
|
||||||
|
timestamp_format_index = (timestamp_format_index + 1) % timestamp_formats.length;
|
||||||
|
persistence_set("timestamps", timestamp_format_index);
|
||||||
|
$el.innerHTML = timestamp_display();
|
||||||
|
};
|
||||||
|
|
||||||
var scrollback_move = function(delta) {
|
var scrollback_move = function(delta) {
|
||||||
if (chat_scrollback.length === 0) {
|
if (chat_scrollback.length === 0) {
|
||||||
return; // no effect
|
return; // no effect
|
||||||
@ -817,6 +844,8 @@ window.onload = function() {
|
|||||||
usermenu.hide();
|
usermenu.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
timestamp_format_index = persistence_get("timestamps", 0);
|
||||||
|
|
||||||
menu.reset();
|
menu.reset();
|
||||||
|
|
||||||
tab_addHandlers();
|
tab_addHandlers();
|
||||||
|
Loading…
Reference in New Issue
Block a user