PageSourceSearch

https://kme.hu/wp-content/plugins/advanced-faq-manager/assets/public/js/thfaqf-public.js?ver=1.5.5

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

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.