@hortonstudio/main 1.9.0 → 1.9.2
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.
- package/autoInit/accessibility.js +22 -0
- package/autoInit/site-settings.js +109 -0
- package/index.js +2 -0
- package/package.json +1 -1
|
@@ -12,6 +12,27 @@ export function init() {
|
|
|
12
12
|
cleanup.handlers.push({ element, event, handler, options });
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
function setupBlogListCleanup() {
|
|
16
|
+
const wrappers = document.querySelectorAll('[data-site-blog="wrapper"]');
|
|
17
|
+
|
|
18
|
+
wrappers.forEach(wrapper => {
|
|
19
|
+
// Check if wrapper has the delete-if-no-list config
|
|
20
|
+
const shouldDelete = wrapper.getAttribute('data-site-blog-config') === 'delete-if-no-list';
|
|
21
|
+
|
|
22
|
+
if (!shouldDelete) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Check if there's a descendant with data-site-blog="list"
|
|
27
|
+
const hasList = wrapper.querySelector('[data-site-blog="list"]') !== null;
|
|
28
|
+
|
|
29
|
+
// Delete wrapper if it doesn't have a list
|
|
30
|
+
if (!hasList) {
|
|
31
|
+
wrapper.remove();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
function setupGeneralAccessibility() {
|
|
16
37
|
setupListAccessibility();
|
|
17
38
|
setupRemoveListAccessibility();
|
|
@@ -24,6 +45,7 @@ export function init() {
|
|
|
24
45
|
setupCustomValuesReplacement();
|
|
25
46
|
setupClickForwarding(addHandler);
|
|
26
47
|
setupTextSynchronization(addObserver);
|
|
48
|
+
setupBlogListCleanup();
|
|
27
49
|
}
|
|
28
50
|
|
|
29
51
|
function setupListAccessibility() {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export function init() {
|
|
2
|
+
function setupSiteSettings() {
|
|
3
|
+
const wrapper = document.querySelector('[data-site-settings-element="wrapper"]');
|
|
4
|
+
|
|
5
|
+
if (!wrapper) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Find all lists inside the wrapper
|
|
10
|
+
const lists = wrapper.querySelectorAll('[data-site-settings-element="list"]');
|
|
11
|
+
|
|
12
|
+
if (lists.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Collect all site settings data
|
|
17
|
+
const siteSettings = {};
|
|
18
|
+
|
|
19
|
+
lists.forEach(list => {
|
|
20
|
+
// Find all descendants with data-site-settings attribute
|
|
21
|
+
const settingElements = list.querySelectorAll('[data-site-settings]');
|
|
22
|
+
|
|
23
|
+
settingElements.forEach(element => {
|
|
24
|
+
const settingName = element.getAttribute('data-site-settings');
|
|
25
|
+
const settingValue = element.textContent.trim();
|
|
26
|
+
|
|
27
|
+
// Only store if both name and value exist (ignore empty elements like images)
|
|
28
|
+
if (settingName && settingValue) {
|
|
29
|
+
siteSettings[settingName] = settingValue;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// If no site settings found, exit early
|
|
35
|
+
if (Object.keys(siteSettings).length === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Replace text content efficiently using TreeWalker
|
|
40
|
+
const walker = document.createTreeWalker(
|
|
41
|
+
document.body,
|
|
42
|
+
NodeFilter.SHOW_TEXT,
|
|
43
|
+
{
|
|
44
|
+
acceptNode: (node) => {
|
|
45
|
+
// Check if any site setting names exist in the text content
|
|
46
|
+
const text = node.textContent;
|
|
47
|
+
for (const name in siteSettings) {
|
|
48
|
+
if (text.includes(`{{${name}}}`)) {
|
|
49
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return NodeFilter.FILTER_SKIP;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const textNodes = [];
|
|
58
|
+
let node;
|
|
59
|
+
while (node = walker.nextNode()) {
|
|
60
|
+
textNodes.push(node);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Replace text in collected nodes
|
|
64
|
+
textNodes.forEach(textNode => {
|
|
65
|
+
let newText = textNode.textContent;
|
|
66
|
+
let hasChanges = false;
|
|
67
|
+
|
|
68
|
+
for (const name in siteSettings) {
|
|
69
|
+
const placeholder = `{{${name}}}`;
|
|
70
|
+
if (newText.includes(placeholder)) {
|
|
71
|
+
newText = newText.replace(new RegExp(placeholder, 'g'), siteSettings[name]);
|
|
72
|
+
hasChanges = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (hasChanges) {
|
|
77
|
+
textNode.textContent = newText;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Replace link hrefs
|
|
82
|
+
const links = document.querySelectorAll('a[href]');
|
|
83
|
+
links.forEach(link => {
|
|
84
|
+
let href = link.getAttribute('href');
|
|
85
|
+
let hasChanges = false;
|
|
86
|
+
|
|
87
|
+
for (const name in siteSettings) {
|
|
88
|
+
const placeholder = `{{${name}}}`;
|
|
89
|
+
if (href.includes(placeholder)) {
|
|
90
|
+
href = href.replace(new RegExp(placeholder, 'g'), siteSettings[name]);
|
|
91
|
+
hasChanges = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (hasChanges) {
|
|
96
|
+
link.setAttribute('href', href);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setupSiteSettings();
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
result: "site-settings initialized",
|
|
105
|
+
destroy: () => {
|
|
106
|
+
// No cleanup needed - this module only modifies DOM during init
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
package/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const initializeHsMain = async () => {
|
|
|
32
32
|
accessibility: () => import("./autoInit/accessibility.js"),
|
|
33
33
|
counter: () => import("./autoInit/counter.js"),
|
|
34
34
|
form: () => import("./autoInit/form.js"),
|
|
35
|
+
"site-settings": () => import("./autoInit/site-settings.js"),
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
let scripts = [
|
|
@@ -71,6 +72,7 @@ const initializeHsMain = async () => {
|
|
|
71
72
|
accessibility: true,
|
|
72
73
|
counter: true,
|
|
73
74
|
form: true,
|
|
75
|
+
"site-settings": true,
|
|
74
76
|
// Only include transition if no-transition attribute is NOT present
|
|
75
77
|
...(hasNoTransition ? {} : { transition: true }),
|
|
76
78
|
};
|