From 8eab9fe6056ec61f92ead4dde683a3087da91198 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sat, 31 Oct 2020 18:13:53 -0700 Subject: [PATCH] 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. --- .../javascript/{feedlayout.js => feed.js} | 27 ++++++++++++-- www/themes/jason-williamsca/pages/feed.htm | 3 +- www/themes/jason-williamsca/pages/welcome.htm | 36 +++++++++---------- .../partials/feed/template.htm | 8 ++--- 4 files changed, 48 insertions(+), 26 deletions(-) rename www/themes/jason-williamsca/assets/javascript/{feedlayout.js => feed.js} (59%) diff --git a/www/themes/jason-williamsca/assets/javascript/feedlayout.js b/www/themes/jason-williamsca/assets/javascript/feed.js similarity index 59% rename from www/themes/jason-williamsca/assets/javascript/feedlayout.js rename to www/themes/jason-williamsca/assets/javascript/feed.js index 43b555f..ac96425 100644 --- a/www/themes/jason-williamsca/assets/javascript/feedlayout.js +++ b/www/themes/jason-williamsca/assets/javascript/feed.js @@ -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 \ No newline at end of file diff --git a/www/themes/jason-williamsca/pages/feed.htm b/www/themes/jason-williamsca/pages/feed.htm index 6f60546..642e3b0 100644 --- a/www/themes/jason-williamsca/pages/feed.htm +++ b/www/themes/jason-williamsca/pages/feed.htm @@ -20,8 +20,7 @@ function onStart() else $this['channelfilter'] = explode(',', $this->param('channel')); $this->addJs('https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.3/jqcloud.min.js'); - $this->addJs('assets/javascript/feedlayout.js'); - //$this->addCss('https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.3/jqcloud.min.css'); + $this->addJs('assets/javascript/feed.js'); } ?> == diff --git a/www/themes/jason-williamsca/pages/welcome.htm b/www/themes/jason-williamsca/pages/welcome.htm index a0b6c89..6de0f6e 100644 --- a/www/themes/jason-williamsca/pages/welcome.htm +++ b/www/themes/jason-williamsca/pages/welcome.htm @@ -8,25 +8,25 @@ maxItems = 5 renderPartial = "feed/template" == addJs('assets/javascript/feedlayout.js'); +function onStart() +{ + $this->addJs('assets/javascript/feed.js'); } ?> == -
-
-

Welcome

-

Welcome to Ja.son-Williams.ca, the little home on the web of – perhaps unsurprisingly – Jason Williams.

-

Jay is a human male originally from Swansea, UK but last spotted in Calgary, Canada. By day he's a mild-mannered bank employee and by night he's... uh... asleep, mostly.

-

He doesn't keep very much stuff here, but to browse around please make a selection from the menu at the top right of the page.

- -

Available Everywhere

- {% partial 'social' %} -
-
-

Feed

- {% partial 'feed/placeholder' feeditemclass='col-sm-12 col-md-6' %} - View More... -
+
+
+

Welcome

+

Welcome to Ja.son-Williams.ca, the little home on the web of – perhaps unsurprisingly – Jason Williams.

+

Jay is a human male originally from Swansea, UK but last spotted in Calgary, Canada. By day he's a mild-mannered bank employee and by night he's... uh... asleep, mostly.

+

He doesn't keep very much stuff here, but to browse around please make a selection from the menu at the top right of the page.

+ +

Available Everywhere

+ {% partial 'social' %} +
+
+

Feed

+ {% partial 'feed/placeholder' feeditemclass='col-sm-12 col-md-6' %} + View More... +
\ No newline at end of file diff --git a/www/themes/jason-williamsca/partials/feed/template.htm b/www/themes/jason-williamsca/partials/feed/template.htm index f59b1ea..f49b628 100644 --- a/www/themes/jason-williamsca/partials/feed/template.htm +++ b/www/themes/jason-williamsca/partials/feed/template.htm @@ -1,8 +1,8 @@ == {% if feeditemclass is empty %} - {% set feeditemclass = 'masonry-item' %} + {% set feeditemclass = 'feeditem masonry-item' %} {% else %} - {% set feeditemclass = 'masonry-item ' ~ feeditemclass %} + {% set feeditemclass = 'feeditem masonry-item ' ~ feeditemclass %} {% endif %} {% if posts is empty %} @@ -10,7 +10,7 @@ {% endif %} {% for post in posts %} -
+
{% if post.extra.img %} @@ -32,7 +32,7 @@

{{ post.extra.address }}

{% endif %}