show timestamps in local date/locale

this adds a helper script to rewrite all time elements with a proper
datetime attribute into the users locale via the browser
navigator.language.

collection, collection-post and chorus-collection-post templates now
include this script
pull/191/head
Rob Loranger 5 years ago
parent 3759f16ed3
commit caca8f0ae2
No known key found for this signature in database
GPG Key ID: D6F1633A4F0903B8
  1. 9
      static/js/localdate.js
  2. 1
      templates/chorus-collection-post.tmpl
  3. 1
      templates/collection-post.tmpl
  4. 1
      templates/collection.tmpl

@ -0,0 +1,9 @@
function toLocalDate(el) {
var d = new Date(el.getAttribute("datetime"));
el.textContent = d.toLocaleDateString(navigator.language || "en-US", { year: 'numeric', month: 'long', day: 'numeric' });
}
var $dates = document.querySelectorAll("time");
for (var i=0; i < $dates.length; i++) {
toLocalDate($dates[i]);
}

@ -90,6 +90,7 @@ article time.dt-published {
{{range .Collection.ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}} {{range .Collection.ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}}
{{if .Collection.Script}}<script type="text/javascript">{{.Collection.ScriptDisplay}}</script>{{end}} {{if .Collection.Script}}<script type="text/javascript">{{.Collection.ScriptDisplay}}</script>{{end}}
{{end}} {{end}}
<script src="/js/localdate.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var pinning = false; var pinning = false;

@ -70,6 +70,7 @@
{{range .Collection.ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}} {{range .Collection.ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}}
{{if .Collection.Script}}<script type="text/javascript">{{.Collection.ScriptDisplay}}</script>{{end}} {{if .Collection.Script}}<script type="text/javascript">{{.Collection.ScriptDisplay}}</script>{{end}}
{{end}} {{end}}
<script src="/js/localdate.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var pinning = false; var pinning = false;

@ -113,6 +113,7 @@
{{end}} {{end}}
<script src="/js/h.js"></script> <script src="/js/h.js"></script>
<script src="/js/postactions.js"></script> <script src="/js/postactions.js"></script>
<script src="/js/localdate.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var deleting = false; var deleting = false;
function delPost(e, id, owned) { function delPost(e, id, owned) {

Loading…
Cancel
Save