From 5205eeac73cd2d4482dbcf6677a7cd636c62e8b3 Mon Sep 17 00:00:00 2001 From: Jacques Supcik Date: Sat, 31 Aug 2019 23:52:30 +0200 Subject: Add `timeRefresh` for periodic localtime update and allow for multilingual time format (#177) --- assets/js/initMoment.js | 11 +++++++++-- layouts/index.html | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/js/initMoment.js b/assets/js/initMoment.js index e638cf1..9b7cb33 100644 --- a/assets/js/initMoment.js +++ b/assets/js/initMoment.js @@ -1,4 +1,11 @@ $(document).ready(function() { - var time = moment().tz("{{ .Site.Params.home.timeZone }}").format("{{ .Site.Params.home.timeFormat }}"); - $("#time").html(time); + const tnode = $("#time") + const update_localtime = function(){ + var time = moment() + .tz(tnode.attr("data-time-zone")) + .format(tnode.attr("data-time-format")); + tnode.html(time); + } + update_localtime(); + setInterval(update_localtime, 1000); }) diff --git a/layouts/index.html b/layouts/index.html index 3de991a..209ba78 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -106,7 +106,7 @@ {{ .Content }} {{ if .Site.Params.home.localTime }} -

{{ i18n "index_currentTime" . }} .

+

{{ i18n "index_currentTime" . }} .

{{ end }} {{ with .Site.Params.email }}

@@ -135,7 +135,7 @@ {{ $momentjs := resources.Get "vendor/momentjs/moment.min.js" }} {{ $momentTimezone := resources.Get "vendor/momentjs/moment-timezone.min.js" }} {{ $momentTimezoneWithData := resources.Get "vendor/momentjs/moment-timezone-with-data-2012-2022.min.js" }} - {{ $initMomentjs := resources.Get "js/initMoment.js" | resources.ExecuteAsTemplate "js/initMoment.tmp.js" . }} + {{ $initMomentjs := resources.Get "js/initMoment.js" }} {{ $bundleMoment := slice $momentjs $momentTimezone $momentTimezoneWithData $initMomentjs | resources.Concat "js/bundleMoment.js" | fingerprint }} {{ end }} -- cgit v1.2.3