Skip to content

Commit 9747e59

Browse files
authored
Merge pull request #62 from ErliSoares/patch-2
Update timeago_mkdocs_material.js
2 parents 9c6dd76 + a0011a7 commit 9747e59

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
// Script to ensure timeago keeps working when
22
// used with mkdocs-material's instant loading feature
33

4-
if (
5-
typeof app !== "undefined" &&
6-
typeof app.document$ !== "undefined"
7-
) {
8-
app.document$.subscribe(function() {
4+
if (typeof document$ !== "undefined") {
5+
document$.subscribe(function() {
96
var nodes = document.querySelectorAll('.timeago');
10-
var locale = nodes[0].getAttribute('locale');
11-
timeago.render(nodes, locale);
7+
if (nodes.length > 0) {
8+
var locale = nodes[0].getAttribute('locale');
9+
timeago.render(nodes, locale);
10+
}
1211
})
1312
} else {
1413
var nodes = document.querySelectorAll('.timeago');
15-
var locale = nodes[0].getAttribute('locale');
16-
timeago.render(nodes, locale);
14+
if (nodes.length > 0) {
15+
var locale = nodes[0].getAttribute('locale');
16+
timeago.render(nodes, locale);
17+
}
1718
}

0 commit comments

Comments
 (0)