diff --git a/app/assets/javascripts/initializePage.js.erb b/app/assets/javascripts/initializePage.js.erb index ac7fda265..f5e91a7ed 100644 --- a/app/assets/javascripts/initializePage.js.erb +++ b/app/assets/javascripts/initializePage.js.erb @@ -28,6 +28,7 @@ function callInitalizers(){ initializeCommentsPage(); initEditorResize(); initLeaveEditorWarning(); + initializeArticleDate(); initializeArticleReactions(); initNotifications(); initializeSplitTestTracking(); diff --git a/app/assets/javascripts/initializers/initializeArticleDate.js b/app/assets/javascripts/initializers/initializeArticleDate.js new file mode 100644 index 000000000..eaf52f5f0 --- /dev/null +++ b/app/assets/javascripts/initializers/initializeArticleDate.js @@ -0,0 +1,10 @@ +/* Show article date/time according to user's locale */ +/* global addLocalizedDateTimeToElementsTitles */ + +function initializeArticleDate() { + var articlesDates = document.querySelectorAll( + '.single-article time, article time, .single-other-article time', + ); + + addLocalizedDateTimeToElementsTitles(articlesDates, 'datetime'); +} diff --git a/app/assets/javascripts/initializers/initializeCommentDate.js b/app/assets/javascripts/initializers/initializeCommentDate.js index f9c871ea6..f7e201a10 100644 --- a/app/assets/javascripts/initializers/initializeCommentDate.js +++ b/app/assets/javascripts/initializers/initializeCommentDate.js @@ -1,50 +1,8 @@ /* Show comment date/time according to user's locale */ -/* global timestampToLocalDateTime */ +/* global addLocalizedDateTimeToElementsTitles */ function initializeCommentDate() { - // example: "Wednesday, April 3, 2019, 2:55:14 PM" - var hoverTimeOptions = { - weekday: 'long', - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - second: 'numeric', - }; + var commentsDates = document.querySelectorAll('.comment-date time'); - // example: "Apr 3" - var visibleDateOptions = { - month: 'short', - day: 'numeric', - }; - - var commentDates = document.getElementsByClassName('comment-date'); - for (var i = 0; i < commentDates.length; i += 1) { - // get UTC timestamp set by the server - var ts = commentDates[i].getAttribute('data-published-timestamp'); - - // add a full datetime to the comment date string, visible on hover - // `navigator.language` is used for full date times to allow the hover date - // to be localized according to the user's locale - var hoverTime = timestampToLocalDateTime( - ts, - navigator.language, - hoverTimeOptions, - ); - commentDates[i].setAttribute('title', hoverTime); - - // replace the comment short visible date with the equivalent localized one - var visibleDate = commentDates[i].querySelector('a'); - if (visibleDate) { - var localVisibleDate = timestampToLocalDateTime( - ts, - 'en-US', // en-US because for now we want all users to see `Apr 3` - visibleDateOptions, - ); - if (localVisibleDate) { - visibleDate.innerHTML = localVisibleDate; - } - } - } + addLocalizedDateTimeToElementsTitles(commentsDates, 'datetime'); } diff --git a/app/assets/javascripts/utilities/buildArticleHTML.js.erb b/app/assets/javascripts/utilities/buildArticleHTML.js.erb index d8f525070..31ba2921c 100644 --- a/app/assets/javascripts/utilities/buildArticleHTML.js.erb +++ b/app/assets/javascripts/utilities/buildArticleHTML.js.erb @@ -90,7 +90,11 @@ function buildArticleHTML(article) { var publishDate = ''; if (article.readable_publish_date) { - publishDate = '・'+article.readable_publish_date + if (article.published_timestamp) { + publishDate = '・' + ''; + } else { + publishDate = '・' + ''; + } } var readingTimeHTML = ''; if (article.reading_time && article.class_name === "Article") { diff --git a/app/assets/javascripts/utilities/buildCommentHTML.js.erb b/app/assets/javascripts/utilities/buildCommentHTML.js.erb index 8156ff29e..5748ac56c 100644 --- a/app/assets/javascripts/utilities/buildCommentHTML.js.erb +++ b/app/assets/javascripts/utilities/buildCommentHTML.js.erb @@ -43,8 +43,12 @@ function buildCommentHTML(comment) { \ '+twitterIcon+'\ '+githubIcon+'\ -