Skip to content

Commit 7bc4e3d

Browse files
committed
Fix automatic date switching in program
1 parent 454ce5d commit 7bc4e3d

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

_includes/js/program.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,28 @@ window.conference.program = (() => {
66
};
77

88
const init = () => {
9-
if ($("#day-list")) {
10-
// Switch to day if page load with hash
11-
const hash = window.location.hash;
12-
if (hash) {
13-
$('#day-list a[href="' + hash + '"]').tab("show");
14-
}
9+
const $dayList = $('#day-list');
10+
if (!$dayList.length) return;
1511

16-
// Switch to day if today
17-
else {
18-
const now = new Date();
19-
const tsNow = Math.floor(now.getTime() / 1000);
20-
21-
$('a[data-toggle="tab"]').each(function () {
22-
const tsMidnight = new Date($(this).data("ts") * 1000);
23-
24-
if (tsMidnight <= tsNow < tsMidnight + 24 * 60 * 60) {
25-
$(this).tab("show");
26-
updateHash(this.hash);
27-
}
28-
});
29-
}
30-
31-
// Add current selected day as hash to URL while keeping current scrolling position
32-
$('a[data-toggle="tab"]').on("shown.bs.tab", function () {
33-
updateHash(this.hash);
12+
const hash = window.location.hash;
13+
if (hash) {
14+
$(`a[data-toggle="tab"][href="${hash}"]`).tab('show');
15+
} else {
16+
const tsNow = Date.now() / 1000 | 0;
17+
$('a[data-toggle="tab"]').each(function () {
18+
const tsMidnight = $(this).data("ts");
19+
if (tsMidnight && tsMidnight <= tsNow && tsNow < tsMidnight + 24 * 60 * 60) {
20+
$(this).tab('show');
21+
updateHash(this.hash);
22+
return false;
23+
}
3424
});
3525
}
26+
27+
// Add current selected day as hash to URL while keeping current scrolling position
28+
$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
29+
updateHash(this.hash);
30+
});
3631
};
3732

3833
return {

0 commit comments

Comments
 (0)