@hortonstudio/main 1.9.2 → 1.9.4
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/button.js +51 -0
- package/autoInit/site-settings.js +26 -1
- package/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function init() {
|
|
2
|
+
function setupButtonIcons() {
|
|
3
|
+
const buttonWrappers = document.querySelectorAll('[data-site-button="wrapper"]');
|
|
4
|
+
|
|
5
|
+
buttonWrappers.forEach(wrapper => {
|
|
6
|
+
// Check if this wrapper has an icon wrapper
|
|
7
|
+
const iconWrapper = wrapper.querySelector('[data-site-button-icon="wrapper"]');
|
|
8
|
+
|
|
9
|
+
if (!iconWrapper) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Find the main icon and get the first slot
|
|
14
|
+
const mainIcon = iconWrapper.querySelector('[data-site-button-icon="main"]');
|
|
15
|
+
if (!mainIcon) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const mainSlot = mainIcon.querySelector('[data-site-icon="slot"]');
|
|
20
|
+
if (!mainSlot) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Clone the main slot
|
|
25
|
+
const clonedSlot = mainSlot.cloneNode(true);
|
|
26
|
+
|
|
27
|
+
// Find the placeholder icon and get the first slot
|
|
28
|
+
const placeholderIcon = iconWrapper.querySelector('[data-site-button-icon="placeholder"]');
|
|
29
|
+
if (!placeholderIcon) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const placeholderSlot = placeholderIcon.querySelector('[data-site-icon="slot"]');
|
|
34
|
+
if (!placeholderSlot) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Replace the placeholder slot with the cloned main slot
|
|
39
|
+
placeholderSlot.parentNode.replaceChild(clonedSlot, placeholderSlot);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setupButtonIcons();
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
result: "button initialized",
|
|
47
|
+
destroy: () => {
|
|
48
|
+
// No cleanup needed - this module only modifies DOM during init
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -21,8 +21,33 @@ export function init() {
|
|
|
21
21
|
const settingElements = list.querySelectorAll('[data-site-settings]');
|
|
22
22
|
|
|
23
23
|
settingElements.forEach(element => {
|
|
24
|
+
// Clone the element to avoid modifying the original DOM
|
|
25
|
+
const clonedElement = element.cloneNode(true);
|
|
26
|
+
|
|
27
|
+
// Find and remove elements with data-site-settings-hide that match their classes
|
|
28
|
+
const hideElements = clonedElement.querySelectorAll('[data-site-settings-hide]');
|
|
29
|
+
|
|
30
|
+
hideElements.forEach(hideElement => {
|
|
31
|
+
const hideValue = hideElement.getAttribute('data-site-settings-hide');
|
|
32
|
+
|
|
33
|
+
if (hideValue) {
|
|
34
|
+
// Split by spaces to get all class names to check
|
|
35
|
+
const classesToHide = hideValue.split(' ').filter(c => c.trim());
|
|
36
|
+
|
|
37
|
+
// Check if element has any of the classes
|
|
38
|
+
const hasMatchingClass = classesToHide.some(className =>
|
|
39
|
+
hideElement.classList.contains(className)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Remove element if it has a matching class
|
|
43
|
+
if (hasMatchingClass) {
|
|
44
|
+
hideElement.remove();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
24
49
|
const settingName = element.getAttribute('data-site-settings');
|
|
25
|
-
const settingValue =
|
|
50
|
+
const settingValue = clonedElement.textContent.trim();
|
|
26
51
|
|
|
27
52
|
// Only store if both name and value exist (ignore empty elements like images)
|
|
28
53
|
if (settingName && settingValue) {
|
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const initializeHsMain = async () => {
|
|
|
33
33
|
counter: () => import("./autoInit/counter.js"),
|
|
34
34
|
form: () => import("./autoInit/form.js"),
|
|
35
35
|
"site-settings": () => import("./autoInit/site-settings.js"),
|
|
36
|
+
button: () => import("./autoInit/button.js"),
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
let scripts = [
|
|
@@ -73,6 +74,7 @@ const initializeHsMain = async () => {
|
|
|
73
74
|
counter: true,
|
|
74
75
|
form: true,
|
|
75
76
|
"site-settings": true,
|
|
77
|
+
button: true,
|
|
76
78
|
// Only include transition if no-transition attribute is NOT present
|
|
77
79
|
...(hasNoTransition ? {} : { transition: true }),
|
|
78
80
|
};
|