This class will grow over time, but it's purpose came from running this site on GitHub Pages. Specifically, I didn't want to have to update the year in the footer of each page annually.
So I came up with the idea for an all-purpose class who's responsibility would be limited to looking up elements and performing some basic modifications.
Right now, it's limited to searching for elements with the
attribute [data-lookup="year"]
, and setting the
current year.
But I'd like to extend it for the following use-cases:
-
Searching for any elements like
<tweet id="123" />
and swapping in tweet embed code - Easily setting up a timer
- Swapping in messaging about the time of day. For example, "Good morning" or "Good evening" depending on the time of day relative to the visitor.
It's been open sourced, and is available on GitHub.
Implementation Code
RuntimeUpdater.init();
RuntimeUpdater.updateYears();
Larger Concept
I wanted a small class that I could drop in, and plug-and-play various concepts such that a server-side parser isn't required.
I want it to be limited in scope, and essentially function to "update" pages at "runtime" 😉
Enjoy :)