@hortonstudio/main 1.6.6 → 1.6.7

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/form.js CHANGED
@@ -571,6 +571,12 @@ export function init() {
571
571
  return isValid;
572
572
  };
573
573
 
574
+ // Helper function to parse comma-separated config values
575
+ const parseFormConfig = (configString) => {
576
+ if (!configString) return [];
577
+ return configString.split(',').map(config => config.trim());
578
+ };
579
+
574
580
  const handleFormSubmit = (event) => {
575
581
  const form = event.target;
576
582
 
@@ -596,12 +602,63 @@ export function init() {
596
602
  removeError(input);
597
603
  });
598
604
 
605
+ // Handle text replacement if this form has replace fields
606
+ const replaceFieldElements = form.querySelectorAll('input[data-hs-form^="replace-field-"], textarea[data-hs-form^="replace-field-"], select[data-hs-form^="replace-field-"]');
607
+ if (replaceFieldElements.length > 0) {
608
+ replaceFieldElements.forEach(field => {
609
+ const dataHsForm = field.getAttribute('data-hs-form');
610
+ const suffix = dataHsForm.replace('replace-field-', '');
611
+ const value = field.value;
612
+
613
+ // Find all matching text elements
614
+ const textElements = document.querySelectorAll(`[data-hs-form="replace-text-${suffix}"]`);
615
+
616
+ textElements.forEach(element => {
617
+ element.textContent = value;
618
+ });
619
+ });
620
+ }
621
+
622
+ // Handle form configuration
623
+ const formWrapper = form.closest('[data-hs-form="wrapper"]');
624
+ let shouldPreventSubmit = false;
625
+
626
+ if (formWrapper && formWrapper.hasAttribute('data-hs-config')) {
627
+ const configString = formWrapper.getAttribute('data-hs-config');
628
+ const configs = parseFormConfig(configString);
629
+
630
+ // Check for prevent-submit config
631
+ if (configs.includes('prevent-submit')) {
632
+ shouldPreventSubmit = true;
633
+ }
634
+
635
+ // Check for click-trigger configs
636
+ configs.forEach(config => {
637
+ if (config.startsWith('click-trigger-')) {
638
+ const trigger = document.querySelector(`[data-hs-form="trigger"][data-hs-config*="${config}"]`);
639
+ if (trigger) {
640
+ setTimeout(() => {
641
+ trigger.click();
642
+ }, 100);
643
+ }
644
+ }
645
+ });
646
+ }
647
+
599
648
  // Trigger final animation if it exists
600
649
  const finalAnimElement = form.querySelector(config.selectors.finalAnim);
601
650
  if (finalAnimElement) {
602
651
  finalAnimElement.click();
603
652
  }
604
653
 
654
+ // Prevent submission if configured to do so
655
+ if (shouldPreventSubmit) {
656
+ event.preventDefault();
657
+ event.stopPropagation();
658
+ event.stopImmediatePropagation();
659
+ return false;
660
+ }
661
+
605
662
  // Don't prevent default - let the form submit naturally with its action/method
606
663
  }
607
664
  };
@@ -739,6 +796,7 @@ export function init() {
739
796
  window.removeEventListener('resize', handleResize);
740
797
  };
741
798
 
799
+
742
800
  // Initialize the form validation system
743
801
  const initializeFormValidation = () => {
744
802
  try {
@@ -27,16 +27,12 @@ function setupDynamicDropdowns() {
27
27
  };
28
28
 
29
29
  dropdownWrappers.forEach((wrapper) => {
30
- const toggle = wrapper.querySelector("a");
31
- const allElements = wrapper.querySelectorAll("*");
32
- let dropdownList = null;
33
-
34
- for (const element of allElements) {
35
- const links = element.querySelectorAll("a");
36
- if (links.length >= 2 && !element.contains(toggle)) {
37
- dropdownList = element;
38
- break;
39
- }
30
+ const toggle = wrapper.querySelector('[data-hs-nav="dropdown-toggle"]');
31
+ const dropdownList = wrapper.querySelector('[data-hs-nav="dropdown-list"]');
32
+
33
+ if (!toggle || !dropdownList) {
34
+ console.warn("Dropdown wrapper missing required elements:", wrapper);
35
+ return;
40
36
  }
41
37
 
42
38
  const toggleText = toggle.textContent?.trim() || "dropdown";
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Version:1.6.6
1
+ // Version:1.6.7
2
2
  const API_NAME = "hsmain";
3
3
 
4
4
  const initializeHsMain = async () => {
@@ -16,6 +16,7 @@ const initializeHsMain = async () => {
16
16
 
17
17
  const utilityModules = {
18
18
  "data-hs-util-ba": true,
19
+ "data-hs-util-slider": true,
19
20
  };
20
21
 
21
22
  const autoInitModules = {
@@ -38,6 +39,7 @@ const initializeHsMain = async () => {
38
39
  const moduleMap = {
39
40
  transition: () => import("./autoInit/transition.js"),
40
41
  "data-hs-util-ba": () => import("./utils/before-after.js"),
42
+ "data-hs-util-slider": () => import("./utils/slider.js"),
41
43
  "smooth-scroll": () => import("./autoInit/smooth-scroll.js"),
42
44
  navbar: () => import("./autoInit/navbar.js"),
43
45
  accessibility: () => import("./autoInit/accessibility.js"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hortonstudio/main",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "Animation and utility library for client websites",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,95 @@
1
+ export const init = () => {
2
+ // Null checks for DOM elements
3
+ const wrapper = document.querySelector('[data-hs-slider="wrapper"]');
4
+ const nextBtn = document.querySelector('[data-hs-slider="next"]');
5
+ const prevBtn = document.querySelector('[data-hs-slider="previous"]');
6
+
7
+ // Early return if required elements don't exist
8
+ if (!wrapper || !nextBtn || !prevBtn) {
9
+ return;
10
+ }
11
+
12
+ // Validate slides exist and have length
13
+ const slides = wrapper.children;
14
+ if (!slides || slides.length === 0) {
15
+ return;
16
+ }
17
+
18
+ // Check if gsap is available globally
19
+ if (typeof gsap === 'undefined') {
20
+ return;
21
+ }
22
+
23
+ const totalSlides = slides.length;
24
+ let currentIndex = 0;
25
+ let isAnimating = false;
26
+
27
+ const firstClone = slides[0].cloneNode(true);
28
+ const lastClone = slides[slides.length - 1].cloneNode(true);
29
+
30
+ wrapper.appendChild(firstClone);
31
+ wrapper.insertBefore(lastClone, slides[0]);
32
+
33
+ currentIndex = 1;
34
+ gsap.set(wrapper, { xPercent: -100 });
35
+
36
+ nextBtn.addEventListener('click', () => {
37
+ if (isAnimating) return;
38
+ isAnimating = true;
39
+
40
+ if (currentIndex === totalSlides) {
41
+ currentIndex++;
42
+ gsap.to(wrapper, {
43
+ xPercent: -currentIndex * 100,
44
+ duration: 0.5,
45
+ ease: "power2.inOut",
46
+ onComplete: () => {
47
+ gsap.set(wrapper, { xPercent: -100 });
48
+ currentIndex = 1;
49
+ isAnimating = false;
50
+ }
51
+ });
52
+ } else {
53
+ currentIndex++;
54
+ gsap.to(wrapper, {
55
+ xPercent: -currentIndex * 100,
56
+ duration: 0.5,
57
+ ease: "power2.inOut",
58
+ onComplete: () => {
59
+ isAnimating = false;
60
+ }
61
+ });
62
+ }
63
+ });
64
+
65
+ prevBtn.addEventListener('click', () => {
66
+ if (isAnimating) return;
67
+ isAnimating = true;
68
+
69
+ if (currentIndex === 1) {
70
+ currentIndex--;
71
+ gsap.to(wrapper, {
72
+ xPercent: -currentIndex * 100,
73
+ duration: 0.5,
74
+ ease: "power2.inOut",
75
+ onComplete: () => {
76
+ gsap.set(wrapper, { xPercent: -totalSlides * 100 });
77
+ currentIndex = totalSlides;
78
+ isAnimating = false;
79
+ }
80
+ });
81
+ } else {
82
+ currentIndex--;
83
+ gsap.to(wrapper, {
84
+ xPercent: -currentIndex * 100,
85
+ duration: 0.5,
86
+ ease: "power2.inOut",
87
+ onComplete: () => {
88
+ isAnimating = false;
89
+ }
90
+ });
91
+ }
92
+ });
93
+ };
94
+
95
+ export const version = "1.0.0";