From 48e372c4bc734792019359b29e19a2fd8877e51a Mon Sep 17 00:00:00 2001 From: northeastprince Date: Fri, 1 Dec 2023 11:14:01 -0500 Subject: [PATCH 1/2] Reprocess time elements on mutation --- lib/assets/javascripts/src/local-time/controller.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/assets/javascripts/src/local-time/controller.coffee b/lib/assets/javascripts/src/local-time/controller.coffee index db4682e..ac7c085 100644 --- a/lib/assets/javascripts/src/local-time/controller.coffee +++ b/lib/assets/javascripts/src/local-time/controller.coffee @@ -56,6 +56,15 @@ class LocalTime.Controller when "weekday-or-date" relative(time).toWeekdayString() or relative(time).toDateString() + @observeMutations() + + observeMutations: -> + new MutationObserver((mutations) => + for mutation in mutations + if mutation.target.matches(SELECTOR) + @processElement(mutation.target) + ) + markAsLocalized = (element) -> element.setAttribute("data-localized", "") From 4d9e49cdc9b1ee23f4c542297e10061a7f5d23bb Mon Sep 17 00:00:00 2001 From: Matt Almeida Date: Sat, 2 Dec 2023 11:07:15 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=92=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/src/local-time/controller.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/assets/javascripts/src/local-time/controller.coffee b/lib/assets/javascripts/src/local-time/controller.coffee index ac7c085..149d75c 100644 --- a/lib/assets/javascripts/src/local-time/controller.coffee +++ b/lib/assets/javascripts/src/local-time/controller.coffee @@ -22,7 +22,9 @@ class LocalTime.Controller @timer ?= setInterval(@processElements, interval) processElements: (elements = document.querySelectorAll(SELECTOR)) => - @processElement(element) for element in elements + for element in elements + @processElement(element) + observeMutations(element) elements.length processElement: (element) -> @@ -56,14 +58,12 @@ class LocalTime.Controller when "weekday-or-date" relative(time).toWeekdayString() or relative(time).toDateString() - @observeMutations() - - observeMutations: -> + observeMutations = (element) -> new MutationObserver((mutations) => for mutation in mutations if mutation.target.matches(SELECTOR) @processElement(mutation.target) - ) + ).observe(element) markAsLocalized = (element) -> element.setAttribute("data-localized", "")