Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-custom-collapse.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,30 @@ | ||
// ------------------------------------------------------=> CUSTOM COLLAPSE | ||
/** | ||
* @description Show and hide blocks on click | ||
* | ||
* @param {HTMLElement} $blockClick - Element that will be clickable to show or hide | ||
* @param {HTMLElement} $blockTarget - Target element that will be hidden or displayed | ||
* @param {HTMLElement} $class - Class that we will put for to hide or display | ||
* @param {boolean} [collapseAll=true] - Allows to leave open or close by default when clicking on an element. | ||
* - true = close everything by clicking on an element | ||
* - false = always leave the elements open | ||
*/ | ||
function customCollapse($blockClick, $blockTarget, $class, collapseAll = true) { | ||
const blockClick = document.querySelectorAll($blockClick); | ||
blockClick.forEach((item) => { | ||
item.addEventListener('click', function () { | ||
// Closing other collapses | ||
if (collapseAll === true) { | ||
if (!this.closest($blockTarget).classList.contains($class)) { | ||
blockClick.forEach((itemClean) => { | ||
itemClean.closest($blockTarget).classList.remove($class); | ||
}); | ||
} | ||
} | ||
// Opening / Closing of the targeted collapse | ||
this.closest($blockTarget).classList.toggle($class); | ||
}); | ||
}); | ||
} | ||
|
||
export default customCollapse; |
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