hyperbook 0.45.0 → 0.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  hyperbook.scratchblock = (function () {
2
- function init() {
2
+ const init = () => {
3
3
  scratchblocks.renderMatching("pre.directive-scratchblock", {
4
4
  style: "scratch3",
5
5
  languages: [
@@ -24,7 +24,22 @@ hyperbook.scratchblock = (function () {
24
24
  ],
25
25
  scale: 1,
26
26
  });
27
- }
27
+ };
28
28
 
29
- init();
29
+ document.addEventListener("DOMContentLoaded", () => {
30
+ init();
31
+ });
32
+
33
+ // Observe for new elements
34
+ const observer = new MutationObserver((mutations) => {
35
+ mutations.forEach((mutation) => {
36
+ mutation.addedNodes.forEach((node) => {
37
+ if (node.nodeType === 1 && node.matches("pre.directive-scratchblock")) {
38
+ init();
39
+ }
40
+ });
41
+ });
42
+ });
43
+
44
+ observer.observe(document.body, { childList: true, subtree: true });
30
45
  })();
@@ -50,15 +50,36 @@ hyperbook.slideshow = (function () {
50
50
  window.hyperbook.slideshow.update(id);
51
51
  };
52
52
 
53
- const slideshows = document.getElementsByClassName("slideshow");
54
- for (let slideshow of slideshows) {
55
- const id = slideshow.getAttribute("data-id");
56
- update(id);
57
- }
53
+ const init = (root) => {
54
+ const slideshows = root.getElementsByClassName("slideshow");
55
+ for (let slideshow of slideshows) {
56
+ const id = slideshow.getAttribute("data-id");
57
+ update(id);
58
+ }
59
+ };
60
+
61
+ // Initialize existing slideshows on document load
62
+ document.addEventListener("DOMContentLoaded", () => {
63
+ init(document);
64
+ });
65
+
66
+ // Observe for new slideshows added to the DOM
67
+ const observer = new MutationObserver((mutations) => {
68
+ mutations.forEach((mutation) => {
69
+ mutation.addedNodes.forEach((node) => {
70
+ if (node.nodeType === 1) { // Element node
71
+ init(node);
72
+ }
73
+ });
74
+ });
75
+ });
76
+
77
+ observer.observe(document.body, { childList: true, subtree: true });
58
78
 
59
79
  return {
60
80
  update,
61
81
  moveBy,
62
82
  setActive,
83
+ init,
63
84
  };
64
85
  })();
@@ -1,14 +1,15 @@
1
1
  hyperbook.tabs = (function () {
2
- let allTabs = document.querySelectorAll(".directive-tabs .tab[data-tabs-id]");
3
-
4
- allTabs.forEach((tab) =>
5
- tab.addEventListener("click", () => {
6
- selectTab(
7
- tab.getAttribute("data-tabs-id"),
8
- tab.getAttribute("data-tab-id"),
9
- );
10
- }),
11
- );
2
+ const init = (root) => {
3
+ let allTabs = root.querySelectorAll(".directive-tabs .tab[data-tabs-id]");
4
+ allTabs.forEach((tab) =>
5
+ tab.addEventListener("click", () => {
6
+ selectTab(
7
+ tab.getAttribute("data-tabs-id"),
8
+ tab.getAttribute("data-tab-id"),
9
+ );
10
+ }),
11
+ );
12
+ };
12
13
 
13
14
  function selectTab(tabsId, tabId) {
14
15
  let relevantTabButtons = document.querySelectorAll(
@@ -31,7 +32,23 @@ hyperbook.tabs = (function () {
31
32
  });
32
33
  }
33
34
 
35
+ init(document.body);
36
+
37
+ // Observe for new tabs added to the DOM
38
+ const observer = new MutationObserver((mutations) => {
39
+ mutations.forEach((mutation) => {
40
+ mutation.addedNodes.forEach((node) => {
41
+ if (node.nodeType === 1) { // Element node
42
+ init(node);
43
+ }
44
+ });
45
+ });
46
+ });
47
+
48
+ observer.observe(document.body, { childList: true, subtree: true });
49
+
34
50
  return {
35
51
  selectTab,
52
+ init,
36
53
  };
37
54
  })();