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