forked from brooksbingham/theme-elegance
refactor: update accordion plugin
parent
f76e01989c
commit
bcf8a02213
|
@ -124,20 +124,28 @@ $(function () {
|
|||
root: ".th-accordion",
|
||||
item: ".th-accordion-item",
|
||||
trigger: ".th-accordion-item-trigger",
|
||||
svg: ".th-accordion-item-trigger-svg",
|
||||
content: ".th-accordion-item-content",
|
||||
};
|
||||
let selection = null;
|
||||
let items = this.find(selectors.item);
|
||||
let rotateClass = "rotate-90 duration-500";
|
||||
|
||||
function collapseAll() {
|
||||
items.each(function () {
|
||||
$(this).find(selectors.content).hide(500);
|
||||
$(this).find(selectors.svg).removeClass(rotateClass);
|
||||
});
|
||||
}
|
||||
function close() {
|
||||
$(selection).find(selectors.content).hide(500);
|
||||
$(selection).find(selectors.svg).removeClass("rotate-90");
|
||||
}
|
||||
|
||||
function open() {
|
||||
collapseAll();
|
||||
$(selection).find(selectors.content).show(500);
|
||||
$(selection).find(selectors.svg).addClass(rotateClass);
|
||||
}
|
||||
|
||||
function isOpen(item) {
|
||||
|
@ -152,7 +160,11 @@ $(function () {
|
|||
.find(selectors.trigger)
|
||||
.on("click", function () {
|
||||
if (selection === self) {
|
||||
selection = null;
|
||||
if (isOpen(selection)) {
|
||||
close();
|
||||
} else {
|
||||
open();
|
||||
}
|
||||
} else {
|
||||
selection = self;
|
||||
if (!isOpen(selection)) {
|
||||
|
|
Loading…
Reference in New Issue