faq.js 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
$(document).ready(function(){

    $(".faq .faq-item .faq-title").click(function(){        
        var item = $(this).parent('.faq-item');
        
        if(item.hasClass("active"))
            $(this).find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down");
        else
            $(this).find(".fa").removeClass("fa-angle-down").addClass("fa-angle-up");
        
        item.toggleClass("active");
        
        onresize(300);
    });

    $("#faqForm").on("submit",function(){
        var keyword = $("#faqSearchKeyword").val();
        
        if(keyword.length >= 3){
            $(".faq .faq-item").removeClass("active");
            
            $("#faqSearchResult").html("");
            $(".faq").removeHighlight();
            
            var items = $(".faq .faq-text:containsi('"+keyword+"')");
            
            items.highlight(keyword);
            
            items.each(function(){
                $(this).parent(".faq-item").addClass("active");
            });
            
            onresize(300);
            
            $("#faqSearchResult").html("<span class='text-success'>Found in "+items.length+" answers</span>");            
        }else
            $("#faqSearchResult").html("<span class='text-error'>Minimum 3 chars required</span>");
        
        return false;
    });
    
    $("#faqOpenAll").click(function(){
        $(".faq .faq-item").addClass("active");
        onresize(300);
    });
    
    $("#faqCloseAll").click(function(){
        $(".faq .faq-item").removeClass("active");
        onresize(300);
    });
    
    $("#faqRemoveHighlights").click(function(){
        var hl = $(".faq").find(".faq-highlight");
        hl.each(function(){
            var txt = $(this).html();
            $(this).after(txt);
            $(this).remove();
        });
    });
    
    
    
});