From 2ca6ac03d7c1ebb52bf494dcaccc80817a5066fd Mon Sep 17 00:00:00 2001 From: Wruczek Date: Wed, 21 Oct 2020 16:18:00 +0200 Subject: [PATCH] Replace moment.js with smaller day.js --- src/js/script.js | 10 ++++++---- src/js/viewer.js | 4 ++-- src/private/templates/body.latte | 15 ++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/js/script.js b/src/js/script.js index 8b5e118..f8ed73f 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -15,7 +15,10 @@ $(function () { // END string.format // START Time functions - console.log("Moment.js locale set to " + moment.locale()); + dayjs.extend(window.dayjs_plugin_localizedFormat) + dayjs.extend(window.dayjs_plugin_relativeTime) + + console.log("Day.js locale set to " + dayjs.locale()); updateRelativeTime(); @@ -107,9 +110,8 @@ $(function () { function timestampToDate(timestamp, full) { "use strict" - var ld = moment.localeData() - var fuzzydate = moment.unix(timestamp).fromNow() - var fulldate = moment.unix(timestamp).format(ld.longDateFormat("LLL")) + var fuzzydate = dayjs.unix(timestamp).fromNow() + var fulldate = dayjs.unix(timestamp).format("LLL") return full ? fulldate : fuzzydate } diff --git a/src/js/viewer.js b/src/js/viewer.js index b0f90a8..56bd45c 100644 --- a/src/js/viewer.js +++ b/src/js/viewer.js @@ -141,14 +141,14 @@ function showPopover(el) { } var describeSeconds = function (seconds) { - return moment().seconds(-seconds).fromNow() + return dayjs().subtract(seconds, 'second').fromNow() } var describeTimestamp = function (timestamp, skipSuffix) { if (skipSuffix === undefined) skipSuffix = true - return moment.unix(timestamp).fromNow(skipSuffix) + return dayjs.unix(timestamp).fromNow(skipSuffix) } var time = result.timenow diff --git a/src/private/templates/body.latte b/src/private/templates/body.latte index 3dbee32..9eec450 100644 --- a/src/private/templates/body.latte +++ b/src/private/templates/body.latte @@ -187,15 +187,16 @@ $navActiveIndex = isset($navActiveIndex) ? (int) $navActiveIndex : 0; {$tplutils::includeScript("{cdnjs}/js-cookie/2.2.0/js.cookie.min.js", "sha256-9Nt2r+tJnSd2A2CRUvnjgsD+ES1ExvjbjBNqidm9doI=")} - - -{$tplutils::includeScript("{cdnjs}/moment.js/2.24.0/moment.min.js", "sha256-4iQZ6BVL4qNKlQ27TExEhBN1HFPvAvAMbFavKKosSWQ=")} + +{$tplutils::includeScript("{cdnjs}/dayjs/1.9.3/dayjs.min.js", "sha256-ty2mPrBF/8jcJe1+JfGM5l2HsYs7zEbs+f6X0norebo=")} +{$tplutils::includeScript("{cdnjs}/dayjs/1.9.3/plugin/localizedFormat.min.js", "sha256-kP2eKuLMKEa/YcMNj0kW8qRpNtjAE4rJrS8PPL3vxCc=")} +{$tplutils::includeScript("{cdnjs}/dayjs/1.9.3/plugin/relativeTime.min.js", "sha256-K66CFTJDYaJ07agFxxju12e79nVEG+OuRN+hl9ivxYI=")} -{var $momentjslang = __get("MOMENTJS_LANG", [], true)} -{if $momentjslang !== null && $momentjslang !== "en-us"} - {$tplutils::includeScript("{cdnjs}/moment.js/2.24.0/locale/$momentjslang.js")} +{var $dayjslang = __get("DAYJS_LANG", [], true) ?? __get("MOMENTJS_LANG", [], true)} +{if $dayjslang !== null && $dayjslang !== "en"} + {$tplutils::includeScript("{cdnjs}/dayjs/1.9.3/locale/$dayjslang.js")} {/if}