2020-10-28 23:56:43 +00:00
|
|
|
(function($) {
|
|
|
|
"use strict"; // Start of use strict
|
2020-11-01 02:05:13 +00:00
|
|
|
|
2020-11-01 01:13:53 +00:00
|
|
|
const min = 60;
|
|
|
|
const hour = min * 60;
|
|
|
|
const day = hour * 24;
|
2020-11-01 02:05:13 +00:00
|
|
|
const week = day * 7;
|
2020-11-01 01:13:53 +00:00
|
|
|
const month = day * 30;
|
|
|
|
const ninemonth = month * 9;
|
2020-10-28 23:56:43 +00:00
|
|
|
|
2020-11-01 02:05:13 +00:00
|
|
|
function addImageLoadHandler() {
|
|
|
|
$('.feeditem img').each(function() {
|
2020-10-28 23:56:43 +00:00
|
|
|
$(this).one('load', () => {
|
|
|
|
$('.masonry').masonry()
|
|
|
|
})
|
|
|
|
})
|
2020-11-01 02:05:13 +00:00
|
|
|
}
|
2020-10-28 23:56:43 +00:00
|
|
|
|
2020-11-01 02:05:13 +00:00
|
|
|
function setFriendlyTime() {
|
2020-11-01 01:13:53 +00:00
|
|
|
// 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
|
2020-11-01 02:05:13 +00:00
|
|
|
|
2020-11-01 01:13:53 +00:00
|
|
|
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'
|
2020-11-01 02:05:13 +00:00
|
|
|
else if (elapsed < week) friendlytime = Math.floor(elapsed/day) + ' days'
|
|
|
|
else if (elapsed < month) friendlytime = Math.floor(elapsed/week) + ' weeks'
|
2020-11-01 01:13:53 +00:00
|
|
|
else if (elapsed < ninemonth) friendlytime = Math.floor(elapsed/month) + ' months'
|
2020-11-01 02:05:13 +00:00
|
|
|
|
2020-11-01 01:13:53 +00:00
|
|
|
if (friendlytime && friendlytime.startsWith('1 ')) friendlytime = friendlytime.slice(0, -1)
|
2020-11-01 02:05:13 +00:00
|
|
|
|
2020-11-01 01:13:53 +00:00
|
|
|
if (friendlytime) $(this).find('.friendlytime').html(friendlytime)
|
|
|
|
})
|
2020-11-01 02:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are feed items present on page load, do the things...
|
|
|
|
if ($('.feeditem').length > 0) {
|
|
|
|
addImageLoadHandler()
|
|
|
|
setFriendlyTime()
|
|
|
|
}
|
|
|
|
|
|
|
|
// If feeditems are added to the page asynchronously, do the things...
|
|
|
|
$(window).on('feedLoaded', () => {
|
|
|
|
if (!feedItemClass) feedItemClass = 'col-sm-12 col-md-6 col-xl-4'
|
|
|
|
$('.feeditem').addClass(feedItemClass)
|
|
|
|
$('.show-onfeedloaded').removeClass('d-none')
|
|
|
|
|
|
|
|
$('.masonry').masonry('reloadItems')
|
|
|
|
$('.masonry').masonry()
|
|
|
|
|
|
|
|
addImageLoadHandler()
|
|
|
|
setFriendlyTime()
|
|
|
|
})
|
|
|
|
|
|
|
|
// When a tag data is loaded, render the cloud
|
|
|
|
$(window).on('tagsLoaded', function(event, data) {
|
|
|
|
var cloudWords = []
|
|
|
|
|
|
|
|
data.responseJSON.forEach((tag) => {
|
|
|
|
cloudWords.push({text: tag.tag, weight: tag.count, link: '/feed/all/' + tag.tag})
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#tagcloud').html('').height($('#tagcloud').width() * 4/3)
|
|
|
|
|
|
|
|
$('#tagcloud').jQCloud(cloudWords, {
|
|
|
|
autoResize: true,
|
|
|
|
removeOverflowing: true,
|
|
|
|
delay: 2
|
|
|
|
})
|
2020-10-28 23:56:43 +00:00
|
|
|
})
|
2020-10-23 22:54:30 +00:00
|
|
|
})(jQuery); // End of use strict
|