-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathclient.js
More file actions
59 lines (54 loc) · 1.59 KB
/
Copy pathclient.js
File metadata and controls
59 lines (54 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
hyperbook.learningmap = (function () {
async function init(root) {
const elems = root.getElementsByClassName("directive-learningmap");
for (let elem of elems) {
const map = elem.getElementsByTagName("hyperbook-learningmap")[0];
if (map) {
const result = await store.learningmap.get(elem.id);
if (result) {
map.initialState = result;
}
map.addEventListener("change", function (event) {
store.learningmap
.update(elem.id, {
id: elem.id,
nodes: event.detail.nodes,
x: event.detail.x,
y: event.detail.y,
zoom: event.detail.zoom,
})
.then((updated) => {
if (updated == 0) {
store.learningmap.put({
id: elem.id,
nodes: event.detail.nodes,
x: event.detail.x,
y: event.detail.y,
zoom: event.detail.zoom,
});
}
});
});
}
}
}
// Initialize existing elements on document load
document.addEventListener("DOMContentLoaded", () => {
init(document);
});
// Observe for new elements added to the DOM
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === 1) {
// Element node
init(node);
}
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
return {
init,
};
})();