forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/main_ctas_sticky_buttons
- Loading branch information
Showing
64 changed files
with
450 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
decidim-core/app/packs/src/decidim/abide_form_validator_fixer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* This script modifies the behavior of Abide form validation to address the issue of form validation errors | ||
* appearing prematurely in input fields. | ||
* | ||
* The primary goal is to hide error messages until the input field loses focus. | ||
*/ | ||
|
||
class AbideFormValidatorFixer { | ||
initialize() { | ||
const forms = document.querySelectorAll("main [data-live-validate='true']"); | ||
|
||
forms.forEach((form) => { | ||
if (this.isElementVisible(form)) { | ||
this.setupForm(form); | ||
} | ||
}); | ||
} | ||
|
||
isElementVisible(element) { | ||
return element.offsetParent !== null && getComputedStyle(element).display !== "none"; | ||
} | ||
|
||
setupForm(form) { | ||
const inputs = form.querySelectorAll("input"); | ||
|
||
inputs.forEach((input) => { | ||
const errorElement = input.closest("label")?.querySelector(".form-error") || input.parentElement.querySelector(".form-error"); | ||
if (!errorElement) { | ||
return; | ||
} | ||
form.removeAttribute("data-live-validate"); | ||
input.addEventListener("input", this.hideErrorElement.bind(this, errorElement)); | ||
}); | ||
} | ||
|
||
hideErrorElement(errorElement) { | ||
errorElement.classList.remove("is-visible"); | ||
} | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const validatorFixer = new AbideFormValidatorFixer(); | ||
validatorFixer.initialize(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
// This script implements a sticky header that hides when participants scroll down and shows when they scroll up. | ||
// Sticky headers allow users to quickly access the navigation, search, and utility-navigation elements without scrolling up to the top of the page. | ||
// They increase the discoverability of the elements in the header. | ||
let prevScroll = window.scrollY; | ||
const stickyHeader = document.getElementById("sticky-header"); | ||
const stickyHeader = document.querySelector("[data-sticky-header]"); | ||
|
||
if (stickyHeader) { | ||
document.addEventListener("scroll", () => { | ||
// if a subelement is not visible it has no offsetParent | ||
const header = document.getElementById("main-bar").offsetParent; | ||
if (header) { | ||
let currentScroll = window.scrollY; | ||
if (prevScroll > currentScroll || currentScroll < stickyHeader.offsetHeight) { | ||
stickyHeader.style.top = 0; | ||
} else { | ||
stickyHeader.style.top = `-${stickyHeader.offsetHeight}px`; | ||
let goingDown = prevScroll > currentScroll; | ||
let change = Math.abs(prevScroll - currentScroll); | ||
if (change > 5) { | ||
if (goingDown || currentScroll < stickyHeader.offsetHeight) { | ||
stickyHeader.style.top = 0; | ||
} else { | ||
stickyHeader.style.top = `-${stickyHeader.offsetHeight}px`; | ||
} | ||
prevScroll = currentScroll; | ||
} | ||
prevScroll = currentScroll; | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ | |
</div> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.