Add the Chronological
This commit is contained in:
38
js/main.js
38
js/main.js
@@ -8,6 +8,7 @@
|
||||
var OpenService = Luxtools.OpenService;
|
||||
var GalleryThumbnails = Luxtools.GalleryThumbnails;
|
||||
var Scratchpads = Luxtools.Scratchpads;
|
||||
var CalendarWidget = Luxtools.CalendarWidget;
|
||||
|
||||
// ============================================================
|
||||
// Click Handlers
|
||||
@@ -79,12 +80,49 @@
|
||||
});
|
||||
}
|
||||
|
||||
function initChronologicalEventTimes() {
|
||||
var nodes = document.querySelectorAll('.luxtools-event-time[data-luxtools-start]');
|
||||
if (!nodes || nodes.length === 0) return;
|
||||
|
||||
var formatter;
|
||||
try {
|
||||
formatter = new Intl.DateTimeFormat(undefined, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
} catch (e) {
|
||||
formatter = null;
|
||||
}
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
var raw = node.getAttribute('data-luxtools-start') || '';
|
||||
if (!raw) continue;
|
||||
|
||||
var date = new Date(raw);
|
||||
if (isNaN(date.getTime())) continue;
|
||||
|
||||
var label;
|
||||
if (formatter) {
|
||||
label = formatter.format(date);
|
||||
} else {
|
||||
var hh = String(date.getHours()).padStart(2, '0');
|
||||
var mm = String(date.getMinutes()).padStart(2, '0');
|
||||
label = hh + ':' + mm;
|
||||
}
|
||||
|
||||
node.textContent = label;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Initialize
|
||||
// ============================================================
|
||||
document.addEventListener('click', onClick, false);
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if (GalleryThumbnails && GalleryThumbnails.init) GalleryThumbnails.init();
|
||||
initChronologicalEventTimes();
|
||||
if (CalendarWidget && CalendarWidget.init) CalendarWidget.init();
|
||||
}, false);
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if (Scratchpads && Scratchpads.init) Scratchpads.init();
|
||||
|
||||
Reference in New Issue
Block a user