var daram = (function($) { function closeFaq($box) { $box.removeClass("on"); $box.find(".qustion button").attr("aria-expanded", "false"); $box.find(".answer").stop(true, true).slideUp(250); } function openFaq($box) { $box.addClass("on"); $box.find(".qustion button").attr("aria-expanded", "true"); $box.find(".answer").stop(true, true).slideDown(250); } function openFirstFaq($panel) { var $firstBox = $panel.find(".faq_box").first(); $firstBox.addClass("on"); $firstBox.find(".qustion button").attr("aria-expanded", "true"); $firstBox.find(".answer").show(); } function FAQ() { $(".faq_tabs").on("click", ".faq_tab", function(e) { e.preventDefault(); var tabId = $(this).attr("data-tab"); var $targetPanel = $("#" + tabId); $(".faq_tab").removeClass("active").attr("aria-selected", "false"); $(this).addClass("active").attr("aria-selected", "true"); $(".faq_panel").removeClass("active").css("display", "none"); $(".faq_panel .faq_box").removeClass("on"); $(".faq_panel .qustion button").attr("aria-expanded", "false"); $(".faq_panel .answer").stop(true, true).css("display", "none"); $targetPanel.addClass("active").css("display", "block"); openFirstFaq($targetPanel); }); $(".faqList").on("click", ".qustion button", function(e) { e.preventDefault(); var $box = $(this).closest(".faq_box"); var $panel = $box.closest(".faq_panel"); if ($box.hasClass("on")) { closeFaq($box); } else { $panel.find(".faq_box.on").each(function() { closeFaq($(this)); }); openFaq($box); } }); } return { FAQ:FAQ }; })(jQuery); jQuery(function() { daram.FAQ(); });