feat: created a jQuery accordion plugin for the filters

staging
Tejas Chari 2023-11-08 13:22:17 +05:30
parent 3d1ef1b400
commit d6c622a60a
2 changed files with 100 additions and 37 deletions

View File

@ -85,28 +85,67 @@ $(function () {
allowPageScroll: "vertical", allowPageScroll: "vertical",
}); });
$("#products_top_sidebar").offcanvas({ // $("#products_top_sidebar").offcanvas({
effect: "slide-in-over", // effect: "slide-in-over",
overlay: true, // overlay: true,
classes: { // classes: {
element: "absolute top-0 z-50", // element: "absolute top-0 z-50",
}, // },
// });
//
// $("#show_filters").on("click", function () {
// $("#products_top_sidebar").offcanvas("toggle");
// });
function ThAccordion() {}
$.extend(ThAccordion.prototype, {
init() {},
}); });
$("#show_filters").on("click", function () { $.fn["thaccordion"] = function () {
$("#products_top_sidebar").offcanvas("toggle"); var selectors = {
}); root: ".th-accordion",
item: ".th-accordion-item",
trigger: ".th-accordion-item-trigger",
content: ".th-accordion-item-content",
};
let selection = null;
let items = this.find(selectors.item);
$("button[id^=show-filters-]").on("click", function () { function collapseAll() {
var filterName = $(this).data("filter-name"); items.each(function () {
$(this).find(selectors.content).hide(500);
});
}
//hide all the other sections and display the current chosen filter function open() {
$("div[id^=filter-section-]").hide(); collapseAll();
$("#filter-section-" + filterName).show(); $(selection).find(selectors.content).show(500);
}); }
$("#show-sort-by").on("click", function () { function isOpen(item) {
$("div[id^=filter-section-]").hide(); return $(item).find(selectors.content).is(":visible");
$("#filter-section-sort-by").toggle(); }
});
collapseAll();
items.each(function () {
var self = this;
$(this)
.find(selectors.trigger)
.on("click", function () {
if (selection === self) {
selection = null;
} else {
selection = self;
if (!isOpen(selection)) {
open();
}
}
});
});
};
$(".th-accordion").thaccordion();
}); });

File diff suppressed because one or more lines are too long