diff --git a/lib/assets/javascripts/src/local-time/controller.coffee b/lib/assets/javascripts/src/local-time/controller.coffee index db4682e..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,6 +58,13 @@ class LocalTime.Controller when "weekday-or-date" relative(time).toWeekdayString() or relative(time).toDateString() + 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", "")