PageSourceSearch

https://www.quickreviewer.com/wp-content/plugins/advanced-faq-mana…/public/js/thfaqf-public.js?ver=1.5.4

js quickreviewer.com collected 2026-09-30 22:10:03 UTC 12,511 bytes, 348 lines download raw bytes

1var thfaqf_public = (function($, window, document){
2    'use strict';
3
4    function initialize_thfaqf(){
5        setup_faq_accordion();
6        setup_share_icons();
7        activate_faq_group_url_search();
8
9        $('input[name="form_time"]').val(Math.floor(Date.now() / 1000));
10    }
11
12    $(document).on('focus click', 'input[name="user_name"], textarea[name="user_msg"]', function(){
13        var $form = $(this).closest('form');
14        var $timeField = $form.find('input[name="form_time"]');
15
16        if ($timeField.length) {
17            $timeField.val(Math.floor(Date.now() / 1000));
18        }
19    });
20
21    function setup_faq_accordion(){
22        var open_multiple = thfaqf_public_var.open_multiple_faqs;
23        var faq_wrapper = $('.thfaqf-faq-list');
24
25        open_first_faq_tab(faq_wrapper);
26
27        $('.thfaqf-faq-item-title').click(function(){
28            if(open_multiple != 'yes'){
29                var wrapper = $(this).closest('.thfaqf-faq-list');
30                close_all_other_faq_tabs($(this), wrapper);
31            }
32            toggle_faq_tab($(this));
33        });
34    }
35
36    function close_all_other_faq_tabs(elm, wrapper){
37        var faq_item = elm.closest('.thfaqf-faq-item');
38        var other_faq_items = faq_item.siblings('.thfaqf-faq-item');
39        other_faq_items.find('.thfaqf-faq-item-content').slideUp('fast');
40        other_faq_items.removeClass("thfaqf-active");
41    }
42
43    function toggle_faq_tab(elm){
44        elm.next().slideToggle('fast');
45        elm.closest('.thfaqf-faq-item').toggleClass("thfaqf-active");
46    }
47
48    function open_faq_tab(elm){
49        elm.find('.thfaqf-faq-item-content').slideDown();
50        if(!elm.hasClass("thfaqf-active")){
51            elm.addClass("thfaqf-active");
52        }
53    }
54
55    function open_first_faq_tab(wrapper){
56        wrapper.each(function() {
57            var active_item = $(this).find('.thfaqf-faq-item.thfaqf-active');
58            open_faq_tab(active_item);
59        });
60    }
61
62    function setup_share_icons(){
63        $('a.thfaqf-share-icon').click(function(e){
64            e.preventDefault(); 
65            var url = $(this).attr('data-url'); 
66            window.open(url, 'new-window','width=600, height=400');
67        });
68    }
69
70    function like_dislike_option(elm){
71        Like_and_dislike_option($(elm),event);
72    }
73
74    function Like_and_dislike_option(click,evnt){
75        var wrapper = click.closest('.th-like-wrapper'),
76            id = click.data('user_id');  
77
78        if(id<1){
79            confirm('Please login to like or dislike FAQs.') == true ? '': evnt.preventDefault(evnt);
80        }else{
81            evnt.preventDefault(evnt)
82        } 
83 
84        var dataset = click.data();
85        var data = [];
86
87        for(var key in dataset){
88            if (dataset.hasOwnProperty(key)) {
89                data.push({name:key, value:dataset[key]});
90            }
91        }
92
93        jQuery.ajax({
94            type : "POST",
95            dataType : "json",
96            url : thfaqf_public_var.ajax_url,
97            data : data,
98 
99            beforeSend : function(){
100            },
101            success: function(response){
102
103                if(response.verify_nonce){
104                    $(wrapper).html(response.verify_nonce);
105                }else {
106                    var like_count = Object.keys(response.like_user_ids).length,
107                        dislike_count = Object.keys(response.dislike_user_ids) !== 'undefined'? Object.keys(response.dislike_user_ids).length : '',
108                        like_array = $.map(response.like_user_ids, function(value, index) {return [value];}),
109                        dislike_array = $.map(response.dislike_user_ids, function(value, index) {return [value];}),
110                        like_status = jQuery.inArray(response.current_user_id,like_array) !== -1,
111                        dislike_status = jQuery.inArray(response.current_user_id,dislike_array) !== -1;
112
113                    $(wrapper).find('.thfaq-like-count').html(like_count);
114                    $(wrapper).find('.thfaq-dislike-count').html(dislike_count);
115                    dislike_status == true ? click.find('.thfaq-icomoon').css('color','black'):click.closest('.th-like-wrapper').find('.thfaq-thums-down .thfaq-icomoon').css('color','white');
116                    like_status == true ? click.find('.thfaq-icomoon').css('color','black'):click.closest('.th-like-wrapper').find('.thfaq-thums-up .thfaq-icomoon').css('color','white');
117                }
118            },
119
120            fail: function() {
121               alert('fail');
122            },
123        });
124    }
125
126    function faq_search_option(elm){
127        var wrapper = $(elm).closest('.thfaqf-faq-list'),
128            filter = $(elm).val().trim().toLowerCase(),
129            visible =  wrapper.find('.thfaqf-faq-item:visible').addClass('thfaqf-search'),
130            faq_item = wrapper.find('.thfaqf-faq-item.thfaqf-search');
131
132        for(var i = 0; i< faq_item.length; i++){
133            var each_faq =  $(faq_item[i]),
134                title = $(each_faq).find('.thfaqf-faq-item-title').text(), 
135                title_html = $(each_faq).find('.thfaqf-faq-item-title').html(),
136                content = $(each_faq).find('.thfaqf-faq-item-content').text();
137            (title.toString().toLowerCase().indexOf(filter) > -1 || content.toString().toLowerCase().indexOf(filter) > -1 ) ? $(each_faq).show() : $(each_faq).hide();          
138        }
139    }
140
141    function submit_faq_comments(elm){
142        preppare_faq_comments($(elm),event);
143    }
144
145    function preppare_faq_comments(elm,event){
146        setTimeout(function(){ $(".thfaqf-error-submt,.thfaqf-success-submt").fadeOut(1000); },4000);
147        var clicks = $(elm),
148            click = clicks.closest('.thfaqf-comment-wrapper');
149        event.preventDefault(event);
150        var form  =  clicks.closest('form'),
151            Usercmnt = $(form).serializeArray(),
152            name = click.find('.thfaqf-uname').val(),
153            comment = click.find('.thfaqf-ucomment').val();
154
155        jQuery.ajax({
156            type : "POST",
157            dataType : "json",
158            url : thfaqf_public_var.ajax_url,
159            data : Usercmnt,
160            beforeSend : function(){
161
162            },
163            success: function(response){
164                click.find('.threq-name').html(response.data.name);
165                click.find('.threq-comment').html(response.data.comment);
166                click.find('.thfaqf-comment-validetion').html(response.data.message);
167                
168                if(name && comment){
169                    click.find('.thfaqf-comment-box').val('');
170                }
171
172                if(!response.success){
173                    if(response.data.code === 'nonce_error'){
174                        console.log('Nonce failed');
175                    }
176
177                    click.find('.thfaqf-comment-validetion').html(response.data.message);
178                }
179            },
180            fail: function() {
181               alert('fail');
182            },
183        });
184
185    }
186
187    function add_new_comment(elm){
188        var click = $(elm);
189        var wrapper = click.closest('.thfaqf-faq-item-content');
190        $(wrapper).find('.thfaq-enable-comment-box').toggleClass('thfaqf-hide');
191    }
192
193    function faq_tab(elm,tab_name){
194        var wrapper = $(elm).closest('.thfaqf-layout-wrapper'),
195            items = wrapper.find('.thfaqf-tabcontent-wrapper');
196        wrapper.find('.thfaqf-tablinks').removeClass('active');    
197        for (var i = 0; i < items.length; i++) {
198           $(items[i]).css('display','none');
199        }
200        wrapper.find('.'+tab_name).css('display','block');
201        $(elm).addClass('active');
202    }
203
204    function preppare_pagination(elm,load_page){
205        faq_pagination(elm,load_page,event);
206    }
207
208    function faq_pagination(elm,load_page,event){
209        event.preventDefault(event);
210        if(load_page == 'next_page'){
211            const last = $(elm).siblings().children().last();
212            if (!last.hasClass('current')) {
213                const current = $(elm).siblings().children('.current'),
214                    closest = $(elm).closest('.thfaqf-pagination'),
215                    nextItem = current.parent().next().children(); 
216                current.text() == $(elm).data('page_count') ? $(elm).addClass('thfaqf-div-none'): '';
217                current.removeClass('current');
218                (nextItem.parent().hasClass('thfaqf-hidden-no')) ? 
219                nextItem.parent().next().children().addClass('current').trigger("click") 
220                : nextItem.addClass('current');
221
222                if(nextItem.parent().hasClass('thfaqf-div-none')){
223                    current.parent().addClass('thfaqf-div-none');
224                    nextItem.parent().removeClass('thfaqf-div-none');
225                }
226                if(closest.find('.thfaqf-prev-page').data('number') == 1) {
227                    closest.find().removeClass('thfaqf-div-none')
228                }
229                nextItem.trigger("click");   
230            } 
231        }else{
232            const first = $(elm).siblings().children().first();
233            if (!first.hasClass('current')){
234                const current = $(elm).siblings().children('.current'),
235                    prevItem = current.parent().prev();
236                current.removeClass('current');
237                if(prevItem.hasClass('thfaqf-hidden-no')){
238                    prevItem.addClass('thfaqf-div-none'); 
239                    prevItem.prev().removeClass('thfaqf-div-none');
240                    prevItem.prev().children().addClass('current').trigger("click");
241                }else{
242                    prevItem.children().addClass('current');
243                }
244
245                if(prevItem.hasClass('thfaqf-div-none')&& !prevItem.hasClass('thfaqf-hidden-no')){
246                    current.parent().addClass('thfaqf-div-none');
247                    prevItem.removeClass('thfaqf-div-none'); 
248                }
249                prevItem.children().trigger( "click");
250            }
251        }
252
253    }
254
255    function showPage(page,pageSize,faq_items){
256        $(faq_items).addClass('thfaqf-div-none');
257        $(faq_items).each(function(n){
258            if (n >= pageSize * (page - 1) && n < pageSize * page){
259                $(this).removeClass('thfaqf-div-none');
260            }
261        });        
262    }
263
264    function thfaq_page_number(elm){
265        $(elm).text() >'1' ? $(elm).closest('.thfaqf-pagination').find('.thfaqf-prev-page').removeClass('thfaqf-hidden-no') : '';
266        var closest = $(elm).closest('.thfaqf-faq-list'),
267            count = closest.find('.thfaqf-count-faq-number').val(),
268            faq_items = closest.find('.thfaqf-faq-item');
269        
270        event.preventDefault(event);
271        $(elm).closest('.thfaqf-faq-list').find(".thfaqf-pnumber").removeClass("current");
272        $(elm).addClass("current");
273        showPage(parseInt($(elm).text()),count,faq_items); 
274    }
275
276    function activate_faq_group_url_search(){
277        var searchParams =  new URLSearchParams(window.location.search);
278        var category = searchParams.get('category');
279        var qstn_tab = searchParams.get('qstn_tab');
280        var elm_categry = document.querySelector(".thfaqf-tablinks-"+category);
281        var tab_name = 'thfaqf-tab-id_'+category;
282        if(category){
283            faq_tab(elm_categry,tab_name);
284        }
285        if(qstn_tab){
286            activate_faq_qstn_url(qstn_tab);
287        }
288    }
289
290    function activate_faq_qstn_url(qstn_tab){
291        var elm_qstn = $("#thfaqf-faq-item-"+qstn_tab);
292        open_faq_tab(elm_qstn);
293    }
294
295    /***----- INIT -----***/
296    initialize_thfaqf();
297
298    return {
299        likeDislike : like_dislike_option,
300        FaqSearch   : faq_search_option,
301        SubmitNewComment: submit_faq_comments,
302        postFaqComment  : add_new_comment,
303        TabClick : faq_tab,
304        FaqPagination : preppare_pagination,
305        ThfaqEachPageNumber : thfaq_page_number,
306    }
307
308}(window.jQuery, window, document));
309
310function likeDislikeOption(elm){
311    thfaqf_public.likeDislike(elm);
312}
313
314function faq_search_option(elm){
315    thfaqf_public.FaqSearch(elm);
316}
317
318function submitFaqfComment(elm){
319    thfaqf_public.SubmitNewComment(elm);
320}
321
322function clickFaqComment(elm){
323    thfaqf_public.postFaqComment(elm);
324}
325
326function FaqTabOnClick(elm,tab_name){
327    thfaqf_public.TabClick(elm,tab_name);
328}
329
330function ThfaqPagination(elm,load_page){
331    thfaqf_public.FaqPagination(elm,load_page);
332}
333
334function ThfaqEachPage(elm,load_page){
335    thfaqf_public.ThfaqEachPageNumber(elm);
336}
337
338
339
340
341
342
343
344
345
346
347
348

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.