New functionality to change feed dates to relative dates (e.g. 1 day ago) where the feed items are available on page load. Contributes to #50.

This commit is contained in:
Jason Williams
2020-10-31 18:13:53 -07:00
parent 623d54f307
commit 8eab9fe605
4 changed files with 48 additions and 26 deletions

View File

@@ -1,8 +1,14 @@
(function($) {
"use strict"; // Start of use strict
const min = 60;
const hour = min * 60;
const day = hour * 24;
const month = day * 30;
const ninemonth = month * 9;
// If the feed is loaded immediadely on page load (i.e. we're not using ajax), reset the layout on each image load
$('.masonry img').each(function() {
$('.feeditem img').each(function() {
$(this).one('load', () => {
$('.masonry').masonry()
})
@@ -45,8 +51,8 @@
})
})
// If there's tag data set once the page is loaded, create a tag cloud
$(function() {
// If there's tag data set once the page is loaded, create a tag cloud
if(typeof tagData !== 'undefined') {
var cloudWords = []
@@ -60,5 +66,22 @@
delay: 2
})
}
// Loop through each feeditem (assuming they're loaded when the page loads) and set the friendlytime
var nowts = Math.floor(new Date().getTime() / 1000)
$('.feeditem').each(function() {
var elapsed = nowts - $(this).attr('data-timestamp')
var friendlytime = false
if (elapsed < min) friendlytime = elapsed + ' seconds'
else if (elapsed < hour) friendlytime = Math.floor(elapsed/min) + ' minutes'
else if (elapsed < day) friendlytime = Math.floor(elapsed/hour) + ' hours'
else if (elapsed < month) friendlytime = Math.floor(elapsed/day) + ' days'
else if (elapsed < ninemonth) friendlytime = Math.floor(elapsed/month) + ' months'
if (friendlytime && friendlytime.startsWith('1 ')) friendlytime = friendlytime.slice(0, -1)
if (friendlytime) $(this).find('.friendlytime').html(friendlytime)
})
})
})(jQuery); // End of use strict