Added relative timestamps

Former-commit-id: 5ea7e7519cbe1059d9595a82229b7c7de3ef17bf
This commit is contained in:
Ziver Koc 2016-01-24 17:37:32 +01:00
parent 73ac1f8208
commit fc41b60386
11 changed files with 3641 additions and 14 deletions

View file

@ -1,5 +1,13 @@
////////////////////////////////////// Definitions
///////////////////////////////// Autostart
$(function(){
$(".toggle-switch").bootstrapSwitch();
$(".timestamp").relTimestamp();
});
////////////////////////////////////// JQuery functions
// $.attr() # returns all attributes of an element
(function(old) {
$.fn.attr = function() {
if(arguments.length === 0) {
@ -20,8 +28,16 @@
};
})($.fn.attr);
$.fn.relTimestamp = function() {
return this.each(function() {
var timestamp = parseInt($(this).text());
var timestampNow = Date.now();
var timeDiff = timestampNow - timestamp;
///////////////////////////////// Autostart
$(function(){
$(".toggle-switch").bootstrapSwitch();
});
if(timeDiff < 24 * 60 * 60 * 1000) // less than 24 hours
$(this).text(moment(timestamp).fromNow());
else
$(this).text(moment(timestamp).format("YYYY-MM-DD HH:mm"));
return this;
});
};