(function ($) {
    $.fn.customDropdown = function (data) {
        this.each((index, value) => {
            generateCustomDropdown($(value));
        });
    };

    function generateCustomDropdown($element) {
        var $submenuButtons = $element.find(".dropdown-submenu a");

        $submenuButtons.off("click.customDropdown");
        $submenuButtons.on("click.customDropdown", function (e) {
            if ($(this).parent().hasClass("submenu-open")) {
                $(this).closest("ul").find(".submenu-open").removeClass("submenu-open");
            } else {
                $(this).closest("ul").find(".submenu-open").removeClass("submenu-open");
                $(this).parent().addClass("submenu-open");
            }

            e.preventDefault();
        });
    }
}(jQuery));

$(document).ready(function () {
    $(".custom-dropdown").customDropdown();
});