PageSourceSearch

https://varsovia.study/wp-content/plugins/wp-file-download/app/site/assets/js/search_filter.js?ver=6.3.2

js varsovia.study collected 2026-10-06 04:47:57 UTC 66,762 bytes, 1,618 lines download raw bytes

1function initSorting() {
2    var $ = jQuery;
3    $('.orderingCol').click(function (e) {
4        e.preventDefault();
5        var formID = '#' + $(this).closest('form').attr('id');
6        var ordering = $(this).data('ordering');
7        var direction = $(this).data('direction');
8        ajaxSearch(formID, ordering, direction);
9    });
10
11
12    if (jQuery(".list-results .wpfd-pagination").length) {
13        jQuery(".list-results .wpfd-pagination a.page-numbers:not('.wpfd-form-search-file-category .list-results .wpfd-pagination')").on('click', function (e) {
14            e.preventDefault();
15            jQuery('[name="wpfd_search_page"]').val(jQuery(this).data('page'));
16            var formID = '#' + jQuery(this).closest('form').attr('id');
17            ajaxSearch(formID);
18            return false;
19        });
20    }
21
22    $(".list-results #limit:not('.wpfd-form-search-file-category .list-results #limit')").change(function (e) {
23        e.preventDefault();
24        var formID = '#' + $(this).closest('form').attr('id');
25        $(formID).find('[name="limit"]').val($(this).val());
26        ajaxSearch(formID);
27        return false;
28    });
29}
30
31function showDefautTags() {
32    var $ = jQuery;
33    if (typeof defaultAllTags !== 'undefined' && defaultAllTags.length > 0) {
34        $('.chk-tags-filtering ul').empty();
35        defaultAllTags.sort(function (a, b) {
36            if (a > b) {
37                return 1
38            }
39            if (a < b) {
40                return -1
41            }
42            return 0;
43        });
44        var checklable1 = $('<label class="labletags">' + wpfdvars.msg_filter_by_tags + '</label>');
45        $('.chk-tags-filtering ul').append(checklable1);
46        $.each(defaultAllTags, function (index, tag) {
47            var key = 'wpfd' + tag.replace(/-/g, '');
48            var element = $('<li class="tags-item"><span> ' + tagsLabel[key] + ' </span> <input title="" type="checkbox" name="chk_ftags[]" onclick="fillInputTags();" class="ju-input chk_ftags" id="ftags' + index + '" value="' + tag + '"></li>');
49            $('.chk-tags-filtering ul').append(element);
50        });
51        $(".input_tags").val("");
52        selectdChecktags();
53    }
54}
55
56function catChange(filterCatElem) {
57    var $ = jQuery;
58    var catId = filterCatElem.val();
59    var catType = filterCatElem.attr('data-cattype');
60    var catSlug = filterCatElem.attr('data-slug');
61    if (!catType) {
62        catType = 'default';
63    }
64    if (!catSlug) {
65        catSlug = '';
66    }
67
68    // Kill file tag ajax is running
69    var prevFileTagAjax = window.file_tag_ajax_on_search;
70    if (prevFileTagAjax !== null) {
71        prevFileTagAjax.abort();
72    }
73
74    var boxSearchFilter = $(filterCatElem).parents('.box-search-filter').get(0);
75    if (parseInt(catId) === 0) {
76        if (typeof availTags !== 'undefined' && availTags.length > 0 && availTags[catId].length > 0) {
77            $(boxSearchFilter).find('.chk-tags-filtering ul').empty();
78            $.each(availTags[catId], function (index, value) {
79                var tagKey = value['id'];
80                var tagLabel = value['label'];
81                var tagVal = value['value'];
82                var element = $('<li class="tags-item"><span> ' + tagLabel + ' </span> <input title="" type="checkbox" name="chk_ftags[]" class="ju-input chk_ftags" id="ftags' + tagKey + '" value="' + tagLabel + '"></li>');
83                $(boxSearchFilter).find('.chk-tags-filtering ul').append(element);
84            });
85            $(boxSearchFilter).find(".input_tags").val("");
86            selectdChecktags();
87        }
88        showDefautTags();
89        $(boxSearchFilter).find('.chk_ftags').parent().show();
90        return;
91    }
92    if ($(boxSearchFilter).find('.chk-tags-filtering ul').length === 0) {
93        return;
94    }
95
96    window.file_tag_ajax_on_search = $.ajax({
97        type: "GET",
98        url: wpfdajaxurl + "task=search.getTagByCatId",
99        data: {
100            catId: catId,
101            catType: catType,
102            catSlug: catSlug
103        }
104    }).done(function (tags) {
105        if (tags === '0') {
106            $(boxSearchFilter).find('.chk-tags-filtering ul').empty();
107            var message = $('<li>' + wpfdvars.msg_no_tag_in_this_category_found + '</li>');
108            $(boxSearchFilter).find('.chk-tags-filtering ul').append(message);
109            $(boxSearchFilter).find(".input_tags").val("");
110            $('#Category_container').trigger('wpfd_search_engine_without_available_tags');
111        } else {
112            if (tags.success === true) {
113                $(boxSearchFilter).find('.chk-tags-filtering ul').empty();
114                $.each(tags.tags, function (index, tag) {
115                    var element = $('<li class="tags-item"><input title="" type="checkbox" name="chk_ftags[]" onclick="fillInputTags();" class="ju-input chk_ftags" id="ftags' + index + '" value="' + tag['name'] + '"> <span>' + tag['name'].replace(/-/g, ' ') + '</span></li>');
116                    $(boxSearchFilter).find('.chk-tags-filtering ul').append(element);
117                });
118                $(boxSearchFilter).find(".input_tags").val("");
119                selectdChecktags();
120                $('#Category_container').trigger('wpfd_search_engine_with_available_tags');
121            } else {
122                $(boxSearchFilter).find('.chk-tags-filtering ul').empty();
123                var message = $('<li>' + tags.message + '</li>');
124                $(boxSearchFilter).find('.chk-tags-filtering ul').append(message);
125                $(boxSearchFilter).find(".input_tags").val("");
126                $('#Category_container').trigger('wpfd_search_engine_without_available_tags');
127            }
128        }
129    });
130}
131
132function fillInputTags() {
133    var tagVal = [];
134    jQuery('.chk_ftags').each(function () {
135        if (this.checked && jQuery(this).is(":visible")) {
136            tagVal.push(jQuery(this).val());
137        }
138    });
139    if (tagVal.length > 0) {
140        jQuery(".input_tags").val(tagVal.join(","));
141    } else {
142        jQuery(".input_tags").val("");
143    }
144}
145
146function getSearchParams(k) {
147    var p = {};
148    location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (s, k, v) {
149        p[k] = v
150    });
151    return k ? p[k] : p;
152}
153
154function ajaxSearch(element, ordering, direction, pushState = true) {
155    var $ = jQuery;
156    var sform = element;
157    var filterType = ($(sform).find('select[name=extension]').length && $(sform).find('select[name=extension]').val() !== null) ? true : false;
158    var isTypeFilter = (filterType && $(sform).find('select[name=extension]').val() !== '0') ? true : false;
159    var isFromWeightFilter = ($(sform).find('input[name=from_weight]').length
160        && $(sform).find('input[name=from_weight]').val() !== '' && $(sform).find('input[name=from_weight]').val() !== 'NaN') ? true : false;
161    var isFromWeightUnitFilter = ($(sform).find('select[name=from_weight_unit]').length && $(sform).find('select[name=from_weight_unit]').val() !== 'kb') ? true : false;
162    var isToWeightFilter = ($(sform).find('input[name=to_weight]').length
163        && $(sform).find('input[name=to_weight]').val() !== '' && $(sform).find('input[name=to_weight]').val() !== 'NaN') ? true : false;
164    var isToWeightUnitFilter = ($(sform).find('select[name=to_weight_unit]').length && $(sform).find('select[name=to_weight_unit]').val() !== 'kb') ? true : false;
165    var $key = $(sform).find('input[name=q]').val();
166    var $placeholder = $(sform).find('input[name=q]').attr('placeholder');
167    var $paged = $(sform).find('input[name=wpfd_search_page]').length ? $(sform).find('input[name=wpfd_search_page]').val() : 1;
168    var isSearchAll = ($(sform).find('input[name=wpfd_search_all]').length && $(sform).find('input[name=wpfd_search_all]').val() !== null) ? parseInt($(sform).find('input[name=wpfd_search_all]').val()) : 1;
169
170    // Avoid conflict key search
171    if (($key || '') === ($placeholder || '')) {
172        $key = '';
173    }
174
175    if (parseInt($(sform).find('[name=catid]').val()) == 0 && isSearchAll == 0) {
176        return false;
177    }
178    // Get the form data
179    var formData = {
180        'q': $key,
181        'catid': $(sform).find('[name=catid]').val(),
182        'exclude': $(sform).find('[name=exclude]').val(),
183        'theme': $(sform).find('[name=theme]').val(),
184        'ftags': $(sform).find('input[name=ftags]').val(),
185        'cfrom': $(sform).find('input[name=cfrom]').val(),
186        'cto': $(sform).find('input[name=cto]').val(),
187        'ufrom': $(sform).find('input[name=ufrom]').val(),
188        'uto': $(sform).find('input[name=uto]').val(),
189        'show_pagination': $(sform).find('input[name=show_pagination]').val(),
190        'paged': $paged,
191        'limit': $(sform).find('[name=limit]').val(),
192        'theme_column': $(sform).find('input[name=theme_column]').val(),
193        'wpfd_search_nonce': $(sform).find('input[name=wpfd_search_nonce]').val()
194    };
195
196    if (isTypeFilter) {
197        const extensionValue = $(sform).find('select[name=extension]').val();
198
199        if (Array.isArray(extensionValue)) {
200            formData.type = extensionValue.join(',');
201        } else if (extensionValue && extensionValue !== '0') {
202            formData.type = extensionValue;
203        }
204    }
205
206    if (isFromWeightFilter) {
207        formData.wfrom = $(sform).find('input[name=from_weight]').val();
208    }
209
210    if (isFromWeightUnitFilter) {
211        formData.wfromunit = $(sform).find('select[name=from_weight_unit]').val();
212    }
213
214    if (isToWeightFilter) {
215        formData.wto = $(sform).find('input[name=to_weight]').val();
216    }
217
218    if (isToWeightUnitFilter) {
219        formData.wtounit = $(sform).find('select[name=to_weight_unit]').val();
220    }
221
222    formData = cleanObj(formData);
223
224    if (jQuery.isEmptyObject(formData) ||
225        (typeof (formData.q) === 'undefined' &&
226            typeof (formData.ftags) === 'undefined' &&
227            typeof (formData.cfrom) === 'undefined' &&
228            typeof (formData.cto) === 'undefined' &&
229            typeof (formData.ufrom) === 'undefined' &&
230            typeof (formData.uto) === 'undefined' &&
231            typeof (formData.type) === 'undefined' &&
232            typeof (formData.wfrom) === 'undefined' &&
233            typeof (formData.wto) === 'undefined' &&
234            (typeof (formData.catid) === 'undefined'
235                || (typeof (formData.catid) !== 'undefined' && parseInt(formData.catid) === 0 && typeof (wpfdvars.verify_key_search) !== 'undefined' && parseInt(wpfdvars.verify_key_search) === 1)))) {
236        $(element).find(".txtfilename").focus();
237        return false;
238    }
239
240    if (typeof (wpfdvars.check_empty_key_search) !== 'undefined' && parseInt(wpfdvars.check_empty_key_search) === 1 && $key === '') {
241        $(element).find('.txtfilename').focus();
242        return false;
243    }
244
245    if (isFromWeightFilter && formData.wfrom !== '') {
246        if (parseInt(formData.wfrom) < 0) {
247            alert('Weight from is positive integer.');
248            return false;
249        }
250
251        switch (formData.wfromunit) {
252            case 'mb':
253                formData.wfrom = parseFloat(formData.wfrom) * 1024 * 1024;
254                break;
255            case 'gb':
256                formData.wfrom = parseFloat(formData.wfrom) * 1024 * 1024 * 1024;
257                break;
258            default:
259                formData.wfrom = parseFloat(formData.wfrom) * 1024;
260                break;
261        }
262    }
263
264    if (isToWeightFilter && formData.wto !== '') {
265        if (parseInt(formData.wto) < 0) {
266            alert('Weight to is positive integer.');
267            return false;
268        }
269
270        switch (formData.wtounit) {
271            case 'mb':
272                formData.wto = parseFloat(formData.wto) * 1024 * 1024;
273                break;
274            case 'gb':
275                formData.wto = parseFloat(formData.wto) * 1024 * 1024 * 1024;
276                break;
277            default:
278                formData.wto = parseFloat(formData.wto) * 1024;
279                break;
280        }
281    }
282
283    if (isFromWeightFilter && formData.wfrom !== '' && isToWeightFilter && formData.wto !== ''
284        && parseFloat(formData.wfrom) > parseFloat(formData.wto)) {
285        alert('Weight from must be less than weight to.');
286        return false;
287    }
288
289    // Not search in category filters
290    if ($(sform).parent('.wpfd-content').length) {
291        return false;
292    }
293
294    if ((typeof ordering !== 'undefined') && ordering) formData.ordering = ordering;
295    if ((typeof direction !== 'undefined') && direction) formData.dir = direction;
296
297    // Pagination
298    if (pushState) {
299        var filter_url = jQuery.param(formData);
300        var currentUrl = window.location.search;
301        var pushUrl;
302        if (typeof URLSearchParams !== 'undefined') {
303            var currentFilters = new URLSearchParams(currentUrl.substring(1));
304            Object.keys(formData).forEach(function (key) {
305                if (currentFilters.has(key)) {
306                    currentFilters.delete(key);
307                }
308                if (key === 'theme_column') {
309                    delete formData.theme_column;
310                    // currentFilters.delete(key);
311                }
312            });
313            filter_url = jQuery.param(formData);
314            if (currentUrl.substring(1) === '?' && currentFilters.toString() !== '') {
315                pushUrl = currentFilters.toString() + '&' + filter_url;
316
317            } else {
318                pushUrl = '?' + filter_url;
319            }
320
321            window.history.pushState(formData, "", pushUrl);
322        }
323    }
324
325    var theme_column = $(sform).find('input[name=theme_column]').val();
326    if (typeof (theme_column) !== 'undefined') {
327        formData.theme_column = theme_column
328    }
329
330    var wpfdSearchUrl = wpfdajaxurl + "task=search.display";
331    if (typeof wpfdvars.locale !== "undefined" && wpfdvars.locale) {
332        wpfdSearchUrl += "&lang=" + wpfdvars.locale;
333    }
334    window.ajax_search_handler = $.ajax({
335        method: "POST",
336        url: wpfdSearchUrl,
337        data: formData,
338        beforeSend: function () {
339            $(element).find(".wpfd-results").html('');
340            $(element).find(".wpfd-results").prepend($(element).find("#loader").clone().show());
341            $(element).find(".wpfd_search_file_suggestion").html('');
342            $(element).find(".wpfd_search_file_suggestion").fadeOut(300);
343            $(element).find('.wpfd-icon-search').show();
344            $(element).find('.wpfd-icon-search-loading').hide();
345        },
346        success: function (result) {
347            $(element).find(".wpfd_search_file_suggestion").html('');
348            $(element).find(".wpfd_search_file_suggestion").fadeOut(300);
349
350            if (parseInt(wpfdvars.downloadSelected) === 1) {
351                var dls_contents = '<div class="wpfd-search-result-download-files-section">';
352                dls_contents += '<a type="button" id="search_download_selected_btn" class="search-download-selected" style="display: none">';
353                dls_contents += wpfdvars.translates.download_selected + ' <i class="zmdi zmdi-check-all wpfd-download-category"></i></a>';
354                dls_contents += '<input type="hidden" id="search_result_download_selected_list" class="search_result_download_selected_list" />';
355                dls_contents += '<input type="hidden" id="search_result_download_selected_file_with_category_list" class="search_result_download_selected_file_with_category_list" /></div>';
356                result = dls_contents + result;
357            }
358
359            $(element).find(".wpfd-results").html(result);
360            if ($(element).find('.wpfd_search_page').length) {
361                $(element).find('.wpfd_search_page').val(1);
362            }
363            initSorting();
364            if (typeof wpfdColorboxInit !== 'undefined') {
365                wpfdColorboxInit();
366            }
367            preSearchDownloadSelectedFiles();
368            searchDownloadSelectedFiles();
369
370            if ($(element).find('.wpfd-results .cbox_file_download').length) {
371                $(element).find('.wpfd-results .cbox_file_download').addClass('search-download-checkbox');
372            }
373
374            window.ajax_search_handler = null;
375
376            $(element).find('.wpfd-icon-search').show();
377            $(element).find('.wpfd-icon-search-loading').hide();
378
379            // Safe actions
380            if (typeof formData.theme !== "undefined" && formData.theme === 'ggd') {
381                wpfdSearchGGDThemeActions();
382            }
383
384            if (typeof formData.theme !== "undefined" && formData.theme === 'preview') {
385                wpfdSearchPreviewThemeActions();
386            }
387
388            wpfdWooCommerceAddToCart();
389
390            wpfdViewMoreFileDescription();
391        }
392    });
393}
394
395var activeSearchForm = null;
396
397function makeFileSuggestion(element, ordering, direction, pushState = true) {
398    var $ = jQuery;
399    var sform = element;
400    var $placeholder = '<div class="wpfd_file_suggestion_placeholder"></div>';
401    var $keySearch = $(sform).find('input[name=q]').val();
402
403    // Check key search valid for making file suggestion
404    if ($keySearch.length < 3) {
405        return;
406    }
407
408    // Get the form data
409    var formData = {
410        'q': $keySearch,
411        'catid': $(sform).find('[name=catid]').val(),
412        'exclude': $(sform).find('[name=exclude]').val(),
413        'make_file_suggestion': '1',
414        'wpfd_search_nonce': $(sform).find('input[name=wpfd_search_nonce]').val()
415    };
416
417    formData = cleanObj(formData);
418
419    if ((typeof ordering !== 'undefined') && ordering) {
420        formData.ordering = ordering;
421    }
422
423    if ((typeof direction !== 'undefined') && direction) {
424        formData.dir = direction;
425    }
426
427    // Do not make file suggestion when searching
428    if (window.ajax_search_handler !== null) {
429        return;
430    }
431
432    // Kill file suggestion ajax is running
433    var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search;
434
435    if (prevFileSuggestionAjax !== null && activeSearchForm === sform) {
436        prevFileSuggestionAjax.abort();
437    }
438    activeSearchForm = sform;
439    var wpfdSearchUrl = wpfdajaxurl + "task=search.display";
440    if (typeof wpfdvars.locale !== "undefined" && wpfdvars.locale) {
441        wpfdSearchUrl += "&lang=" + wpfdvars.locale;
442    }
443    window.file_suggestion_ajax_on_search = $.ajax({
444        method: "POST",
445        url: wpfdSearchUrl,
446        data: formData,
447        beforeSend: function () {
448            var $placeholder = '<div class="ph-item"><div class="ph-col-12"><div class="ph-picture"></div><div class="ph-row"><div class="ph-col-6 big"></div><div class="ph-col-4 empty big"></div><div class="ph-col-2 big"></div><div class="ph-col-4"></div><div class="ph-col-8 empty"></div><div class="ph-col-6"></div><div class="ph-col-6 empty"></div><div class="ph-col-12"></div></div></div></div>';
449            $(element).find(".wpfd_search_file_suggestion").html('');
450            $(element).find(".wpfd_search_file_suggestion").append($(element).findplaceholder).fadeIn('slow');
451            $(element).find(".wpfd_search_file_suggestion").addClass('placeholder');
452            $(element).find('.wpfd-icon-search').hide();
453            $(element).find('.wpfd-icon-search-loading').show();
454            $(element).find('.txtfilename').addClass('is-file-suggestion');
455        },
456        success: function (result) {
457            $(element).find(".wpfd_search_file_suggestion").html(result);
458            $(element).find(".wpfd_search_file_suggestion").removeClass('placeholder');
459            $(element).find('.wpfd-icon-search').show();
460            $(element).find('.wpfd-icon-search-loading').hide();
461
462            if ($(element).find(".wpfd_search_file_suggestion .table").length) {
463                $(element).find(".wpfd_search_file_suggestion .table thead").remove();
464                $(element).find(".wpfd_search_file_suggestion .table .file_desc").remove();
465                $(element).find(".wpfd_search_file_suggestion .table .file_category").remove();
466                $(element).find(".wpfd_search_file_suggestion .table .wpfd_checkbox").remove();
467                $(element).find(".wpfd_search_file_suggestion .table .file_version").remove();
468                $(element).find(".wpfd_search_file_suggestion .table .file_size").remove();
469                $(element).find(".wpfd_search_file_suggestion .table .file_hits").remove();
470                $(element).find(".wpfd_search_file_suggestion .table .file_created").remove();
471                $(element).find(".wpfd_search_file_suggestion .wpfd-num").remove();
472                $(element).find(".wpfd_search_file_suggestion .table .wpfd-file-link").attr('href', '');
473                $(element).find(".wpfd_search_file_suggestion").fadeIn('slow').slideDown('slow');
474
475                $(element).find(".wpfd_search_file_suggestion .table td.file_title").on('click', function (e) {
476                    e.preventDefault();
477                    var selected_file_name = $(this).find('.wpfd-file-link').attr('title');
478                    if (selected_file_name && selected_file_name !== '') {
479                        $(element).find('.txtfilename').val(selected_file_name);
480                        ajaxSearch(element);
481                        $(element).find('.wpfd_search_file_suggestion').fadeOut(300);
482                        $(element).find('.txtfilename').removeClass('is-file-suggestion');
483
484                        return false;
485                    }
486                });
487
488                $(element).find(".wpfd_search_file_suggestion .protected-title").on('click', function (e) {
489                    e.preventDefault();
490                    var selected_file_name = $(this).attr('title');
491                    if (selected_file_name && selected_file_name !== '') {
492                        $(element).find('.txtfilename').val(selected_file_name);
493                        ajaxSearch(element);
494                        $(element).find('.wpfd_search_file_suggestion').fadeOut(300);
495                        $(element).find('.txtfilename').removeClass('is-file-suggestion');
496
497                        return false;
498                    }
499                });
500            } else {
501                // Return default search
502                $(element).find('.txtfilename').removeClass('is-file-suggestion');
503                $(element).find(".wpfd_search_file_suggestion").fadeOut(300);
504            }
505
506            if (typeof wpfdColorboxInit !== 'undefined') {
507                wpfdColorboxInit();
508            }
509
510            // Close suggestion list on click outside
511            $(document).click(function (e) {
512                var $target = $(e.target);
513                if ((!$target.closest('.wpfd_search_file_suggestion').length && $('.wpfd_search_file_suggestion').is(":visible"))
514                    && (!$target.closest('.txtfilename').length && !$target.closest('.categories-filtering-selection').length && $('.wpfd_search_file_suggestion').is(":visible"))) {
515                    $('.wpfd_search_file_suggestion').hide();
516                    $('.txtfilename').removeClass('is-file-suggestion');
517                }
518            });
519        }
520    });
521}
522
523function openSearchfilter(evt, searchName) {
524    evt.preventDefault();
525
526    var $ = jQuery;
527    var $this = $(evt.target);
528
529    $this.parent().find('.tablinks').removeClass('active');
530    $this.addClass('active');
531
532    $this.parent().parent().find('.wpfd_tabcontainer .wpfd_tabcontent').removeClass('active');
533    $this.parent().parent().find('.wpfd_tabcontainer #' + searchName).addClass('active');
534
535    return false;
536}
537
538function clearFilterTypes() {
539    var $ = jQuery;
540
541    if ($('#wpfd-search-file-type').length <= 0) {
542        return;
543    }
544
545    var $extension = $('#wpfd-search-file-type').val();
546    var $echo = $('#wpfd-search-file-type + .chzn-container .chzn-single > span');
547    if ($extension === '0') {
548        $echo.addClass('normal');
549    } else {
550        $echo.removeClass('normal');
551    }
552}
553
554function selectdChecktags() {
555    var $ = jQuery;
556    var captured = /ftags=([^&]+)/.exec(window.location.search);
557    var tags = typeof captured !== "null" ? decodeURIComponent(captured).split(',') : false;
558
559    $('li.tags-item').off("click");
560    $('li.tags-item').on('click', function () {
561        $(this).toggleClass("active");
562        if ($(this).hasClass("active")) {
563            $(this).children("input[type='checkbox']").prop('checked', true);
564        } else {
565            $(this).children("input[type='checkbox']").prop('checked', false);
566        }
567        var tagVal = [];
568        $(this).parent('ul').find(".chk_ftags").each(function () {
569            if ($(this).prop("checked") == true) {
570                tagVal.push($(this).val());
571            }
572        });
573        if (tagVal.length > 0) {
574            $(this).parents('.wpfd-tags').find(".input_tags").val(tagVal.join(","));
575        } else {
576            $(this).parents('.wpfd-tags').find(".input_tags").val("");
577        }
578    });
579
580    // Check load/reload url has tag(s) selected
581    $('li.tags-item').each(function () {
582        var currentname = $(this).find('input').val();
583        if (tags.indexOf(currentname) > -1) {
584            $(this).click();
585        }
586    });
587}
588
589function wpfdshowCateReload() {
590    var $, SelectedCateReloadCase, wpfddisplayCateReloadCase;
591    $ = jQuery;
592    SelectedCateReloadCase = $(".categories-filtering .cate-item.choosed label").text();
593    wpfddisplayCateReloadCase = $(".categories-filtering .cate-lab");
594    var selectedCatecontentReloadCase = "<label>" + SelectedCateReloadCase + "</label>";
595    if ($(".cate-item.choosed").length > 0) {
596        wpfddisplayCateReloadCase.addClass('display-cate');
597        wpfddisplayCateReloadCase.empty();
598        wpfddisplayCateReloadCase.append(selectedCatecontentReloadCase);
599        if (wpfddisplayCateReloadCase.text() !== null) {
600            wpfddisplayCateReloadCase.append('<a class="cancel"></a>');
601        }
602    }
603    // wpfdcancelSelectedCate();
604}
605
606function showCategory() {
607    var $ = jQuery;
608    $(".categories-filtering .categories-filtering-overlay").unbind('click').on('click', function (e) {
609        e.preventDefault();
610        var $this = $(this);
611        $('.wpfd_search_input').css('z-index', '1');
612        if ($this.closest('.box-search-filter').height() < 600 && $this.closest('.box-search-filter').height() > 200) {
613            var listCateHeight = parseInt($this.closest('.box-search-filter').height()) - 40;
614            $this.closest('.box-search-filter').find('.wpfd-listCate').css('max-height', listCateHeight + 'px');
615        } else {
616            $this.closest('.box-search-filter').find('.wpfd-listCate').css('max-height', '600px');
617        }
618        if (!$this.closest('.box-search-filter').find('.wpfd-listCate-opened').length) {
619            var width_listCate = parseInt($this.closest('.box-search-filter').find('.wpfd-listCate').width()) + 26;
620            $this.closest('.box-search-filter').find('.wpfd-listCate').css('width', width_listCate + 'px').addClass('wpfd-listCate-opened');
621        }
622        $this.closest('.wpfd_search_input').css('z-index', '12');
623        var $container = $this.parent();
624        $('.wpfd-listCate', $container).toggle();
625
626        selectCategoriesActions($container);
627    });
628}
629
630function selectCategoriesActions($container) {
631    var $ = jQuery;
632    if (typeof $container === 'undefined') {
633        $container = $('.categories-filtering');
634    }
635    $('li.cate-item', $container).unbind('click').on('click', function () {
636        $('li.cate-item.checked', $container).removeClass("checked");
637        $('li.cate-item', $container).removeClass("choosed");
638
639        $(this).addClass("checked");
640        if ($(".filter_catid", $container).val().toString() !== $(this).data('catid').toString()) {
641            $(".filter_catid", $container).val($(this).data('catid'));
642            $(".filter_catid", $container).attr('data-cattype', $(this).data('cattype'));
643            $(".filter_catid", $container).attr('data-slug', $(this).data('slug')).trigger("change");
644        }
645        $('.wpfd-listCate', $container).hide();
646
647        // Show selected category
648        var wpfdSelectedCatename = $(".cate-item.checked label", $container).text();
649        var wpfddisplayCate = $('.cate-lab', $container);
650        if ($('.showitems', $container).length > 0) {
651            $('.show-selected-cate', $container).css("display", "");
652        } else {
653            var selectedCatecontent = "<label title='" + wpfdSelectedCatename + "' class='ju-setting-label'>" + wpfdSelectedCatename + "</label>";
654            $('.show-selected-cate', $container).css("display", "block");
655            if ($('.cate-item.checked', $container).length === 1) {
656                wpfddisplayCate.addClass('display-cate');
657                wpfddisplayCate.empty();
658                wpfddisplayCate.append(selectedCatecontent);
659                if (wpfddisplayCate.text() !== null) {
660                    wpfddisplayCate.append('<a class="cancel"></a>');
661                }
662            }
663        }
664
665        $('#btnsearchbelow').trigger('wpfd_search_new_selected_category');
666    });
667
668    $(document).mouseup(function (e) {
669        if (!$(".categories-filtering > .ui-widget").is(e.target) // If the target of the click isn't the container...
670            && !$(".categories-filtering .categories-filtering-overlay").is(e.target)
671            && $(".categories-filtering > .ui-widget").has(e.target).length === 0) // ... nor a descendant of the container
672        {
673            $(".categories-filtering > .ui-widget").hide();
674        }
675    });
676}
677
678function wpfdAddPlaceholder() {
679    var $ = jQuery;
680    if ($(".tags-filtering .tagit-new input").length) {
681        $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder);
682    } else {
683        setTimeout(function () {
684            jQuery(".tagit.input_tags").tagit({allowSpaces: true});
685            if ($(".tags-filtering .tagit-new input").length) {
686                $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder);
687            }
688        }, 3000);
689    }
690
691    if ($('.fusion-builder-live').length || $('.et_divi_theme.et-fb').length) {
692        setInterval(function () {
693            if ($(".wpfd-adminForm").length) {
694                if ($(".input_tags").length) {
695                    if ($(".tags-filtering .tagit-new input").length) {
696                        $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder);
697                    } else {
698                        if ($('.fusion-builder-live').length) {
699                            $('.wpfd-tags .tags-filtering .input_tags').remove();
700                            var inputField = $('<input>').attr({
701                                'type': 'text',
702                                'name': 'ftags'
703                            }).addClass('tagit input_tags');
704                            $('.wpfd-tags .tags-filtering').append(inputField);
705                            inputField.tagit({allowSpaces: true});
706                        } else {
707                            setTimeout(function () {
708                                jQuery(".tagit.input_tags").tagit({allowSpaces: true});
709                                if ($(".tags-filtering .tagit-new input").length) {
710                                    $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder);
711                                }
712                            }, 3000);
713                        }
714
715                    }
716                }
717            }
718        }, 1000);
719    }
720}
721
722// Add class to search button
723function addtoSearchbuttonbelow() {
724    var $ = jQuery;
725    var searchbox = $("#Tags").children();
726    if (searchbox.hasClass("tags-filtering")) {
727        $(".box-btngroup-below").addClass("searchboxClass");
728    }
729}
730
731function parentFolderIcon() {
732    var $ = jQuery;
733    $("li.cate-item").each(function () {
734        var count = $(this).find('span.child-cate').length;
735        var prelevel = $(this).prev().attr("data-catlevel");
736        var catelevel = $(this).attr("data-catlevel");
737        if ((count == 1 && catelevel > prelevel) || (count == 1 && prelevel == 9)) {
738            $(this).prev().addClass("parent-cate");
739        }
740    });
741}
742
743function noTagscase() {
744    var $ = jQuery;
745    if ($("#Tags .no-tags").length > 0) {
746        $("#Tags .no-tags").each(function () {
747            $(this).parents('.box-search-filter').find('.box-btngroup-below').addClass("notags-case");
748        });
749    } else {
750        $(".feature .box-btngroup-below").removeClass("notags-case");
751    }
752}
753
754function wpfdSingleDateTimePicker(input, sform) {
755    var $ = jQuery;
756    var timer = $(input);
757    var dateType = $(input).attr('name');
758    if (!timer.length) {
759        return;
760    }
761
762    var $options = {
763        locale: wpfdLocaleSettings,
764        "alwaysShowCalendars": true,
765        autoApply: true,
766        autoUpdateInput: false,
767        singleDatePicker: true
768    };
769
770    if (timer.val() !== '') {
771        $options.startDate = timer.val();
772    }
773
774    var is_filter_create_date_from = $(sform).find('.cfrom').length ? true : false;
775    var is_filter_create_date_to = $(sform).find('.cto').length ? true : false;
776    var is_filter_update_date_from = $(sform).find('.ufrom').length ? true : false;
777    var is_filter_update_date_to = $(sform).find('.uto').length ? true : false;
778
779    timer.daterangepicker($options, function (start, end, label) {
780        // Let update the fields manually this event fires on selection of range
781        var time = start.format(wpfdvars.dateFormat);
782        var char = time.charAt(2);// Return '/' or '-'
783        var timeNumber = Date.parse(time.split(char).reverse().join(char));
784
785        switch (dateType) {
786            case 'cfrom':
787                var cToDate = $(sform).find('.cto').val();
788                var ctoTimeNumber = Date.parse(cToDate.split(char).reverse().join(char));
789                var timeValid = timeNumber < ctoTimeNumber ? true : false;
790                if (is_filter_create_date_to && cToDate.toString() !== '' && cToDate.toString() !== time.toString() && !timeValid) {
791                    wpfdFilterMessages(sform);
792
793                    return;
794                }
795                break;
796            case 'cto':
797                var cFromDate = $(sform).find('.cfrom').val();
798                var cfromTimeNumber = Date.parse(cFromDate.split(char).reverse().join(char));
799                var timeValid = timeNumber > cfromTimeNumber ? true : false;
800                if (is_filter_create_date_from && cFromDate.toString() !== '' && cFromDate.toString() !== time.toString() && !timeValid) {
801                    wpfdFilterMessages(sform);
802
803                    return;
804                }
805                break;
806            case 'ufrom':
807                var uToDate = $(sform).find('.uto').val();
808                var utoTimeNumber = Date.parse(uToDate.split(char).reverse().join(char));
809                var timeValid = timeNumber < utoTimeNumber ? true : false;
810                if (is_filter_update_date_to && uToDate.toString() !== '' && uToDate.toString() !== time.toString() && !timeValid) {
811                    wpfdFilterMessages(sform);
812
813                    return;
814                }
815                break;
816            case 'uto':
817                var uFromDate = $(sform).find('.ufrom').val();
818                var ufromTimeNumber = Date.parse(uFromDate.split(char).reverse().join(char));
819                var timeValid = timeNumber > ufromTimeNumber ? true : false;
820                if (is_filter_update_date_from && uFromDate.toString() !== '' && uFromDate.toString() !== time.toString() && !timeValid) {
821                    wpfdFilterMessages(sform);
822
823                    return;
824                }
825                break;
826            default:
827                break;
828        }
829
830        timer.val(time);
831
832        // Setting the selection of dates on calender on check field
833        var checkInPicker = timer.data('daterangepicker');
834        checkInPicker.setStartDate(time);
835    });
836    timer.next().on('click', function (e) {
837        $(this).prev().trigger('click')
838    });
839}
840
841function wpfdFilterMessages(sform) {
842    var $ = jQuery;
843
844    if (!$(sform).find('.wpfd-search-date-filter-message-container').length) {
845        return;
846    }
847
848    $(sform).find('.wpfd-search-date-filter-message-container').empty();
849    $(sform).find('.wpfd-search-date-filter-message-container').append(wpfdvars.msg_to_date_greater_than_from_date).removeClass('hidden');
850
851    setTimeout(function () {
852        $(sform).find('.wpfd-search-date-filter-message-container').addClass('hidden');
853    }, 3000);
854}
855
856function fullWidthSearch() {
857    var $ = jQuery;
858    var $inputSearchContainer = $('.wpfd_search_input');
859
860    if ($inputSearchContainer.parent().prev().hasClass('categories-filter
860ing')) {
861        $inputSearchContainer.addClass("fullwidth");
862    } else {
863        $inputSearchContainer.removeClass("fullwidth");
864    }
865}
866
867function preSearchDownloadSelectedFiles() {
868    var $ = jQuery;
869    if ($('#wpfd-results input.cbox_file_download').length) {
870        $('#wpfd-results input.cbox_file_download').each(function () {
871            var fileId = $(this).data('id');
872            if (!$.isNumeric(fileId)) {
873                $(this).parent().hide();
874            }
875        });
876    }
877
878    $('#wpfd-results input.cbox_file_download').on('change', function () {
879        var filesId = [];
880        var filesWithCategoryId = {};
881        var selectedFiles = $("#wpfd-results input.cbox_file_download:checked");
882        var selectedCategory = $('#cate-list .cate-item.checked').data('catid');
883        if (selectedFiles.length) {
884            selectedFiles.each(function (index, file) {
885                filesId.push($(file).data('id'));
886                if (typeof (selectedCategory) === 'undefined' || selectedCategory === '') {
887                    filesWithCategoryId[$(file).data('id')] = $(file).data('catid');
888                }
889            });
890        }
891
892        if (filesId.length > 0) {
893            $('.search-download-selected').show();
894            $('#search_result_download_selected_list').val('');
895            $('#search_result_download_selected_list').val(filesId.join(','));
896
897            if (!$.isEmptyObject(filesWithCategoryId)) {
898                var values = JSON.stringify(filesWithCategoryId);
899                $('#search_result_download_selected_file_with_category_list').val(values);
900            }
901        } else {
902            $('.search-download-selected').hide();
903        }
904    });
905}
906
907function searchDownloadSelectedFiles() {
908    var $ = jQuery;
909    $('#search_download_selected_btn').on('click', function () {
910        var current_category = $('.cate-list .cate-item.checked').data('catid');
911        var category_name = 'wp-file-download-search';
912        var selectedFilesId = $('#search_result_download_selected_list').val();
913
914        if (typeof (current_category) !== 'undefined' && current_category !== '') {
915            $.ajax({
916                url: wpfdajaxurl + "task=files.zipSeletedFiles&filesId=" + selectedFilesId + "&wpfd_category_id=" + current_category,
917                dataType: "json",
918            }).done(function (results) {
919                if (results.success) {
920                    var hash = results.data.hash;
921                    window.location.href = wpfdajaxurl + "task=files.downloadZipedFile&hash=" + hash + "&wpfd_category_id=" + current_category + "&wpfd_category_name=" + category_name;
922                } else {
923                    alert(results.data.message);
924                }
925            })
926        } else {
927            var selectedFileWithCategoryIds = $('#search_result_download_selected_file_with_category_list').val();
928            if (selectedFilesId !== '' && selectedFileWithCategoryIds !== '') {
929                selectedFileWithCategoryIds = $.parseJSON(selectedFileWithCategoryIds);
930                $.ajax({
931                    url: wpfdajaxurl + "task=files.zipSeletedFilesMultipleCategories",
932                    type: "POST",
933                    data: {
934                        filesId: selectedFilesId,
935                        selectedFileWithCategoryIds: selectedFileWithCategoryIds
936                    },
937                    success: function (results) {
938                        if (results.success) {
939                            var hash = results.data.hash;
940                            window.location.href = wpfdajaxurl + "task=files.downloadZipedFileMultipleCategories&hash=" + hash + "&wpfd_search_name=" + category_name;
941                        } else {
942                            alert(results.data.message);
943                        }
944                    }
945                });
946            } else {
947                return;
948            }
949        }
950    });
951}
952
953function wpfdSearchGGDThemeActions() {
954    var $ = jQuery;
955    var sourcefile = $("#wpfd-template-ggd-box").html();
956    $('.wpfd-content .wpfd-file-link').unbind('click').click(function (e) {
957        e.preventDefault();
958        var fileid = $(this).data('id');
959        var categoryid = $(this).data('category_id');
960        var ggd_root_cat = $(this).data('category_id');
961        $.ajax({
962            url: wpfdajaxurl + "task=file.display&view=file&id=" + fileid + "&categoryid=" + categoryid + "&rootcat=" + ggd_root_cat,
963            dataType: "json",
964            beforeSend: function () {
965                // setting a timeout
966                if ($('body').has('wpfd-ggd-box-loader') !== true) {
967                    $('body').append('<div class="wpfd-ggd-box-loader"></div>');
968                }
969            }
970        }).done(function (file) {
971            var template = Handlebars.compile(sourcefile);
972            var html = template(file);
973            var box = $("#wpfd-ggd-box");
974            $('.wpfd-ggd-box-loader').each(function () {
975                $(this).remove();
976            });
977            if (box.length === 0) {
978                $('body').append('<div id="wpfd-ggd-box" style="display: none;"></div>');
979                box = $("#wpfd-ggd-box");
980            }
981            box.empty();
982            box.prepend(html);
983            box.click(function (e) {
984                if ($(e.target).is('#wpfd-ggd-box')) {
985                    box.hide();
986                }
987                $('#wpfd-ggd-box').unbind('click.box').bind('click.box', function (e) {
988                    if ($(e.target).is('#wpfd-ggd-box')) {
989                        box.hide();
990                    }
991                });
992            });
993            $('#wpfd-ggd-box .wpfd-close').click(function (e) {
994                e.preventDefault();
995                box.hide();
996            });
997
998            box.show();
999
1000            var dropblock = box.find('.dropblock');
1001            if ($(window).width() < 400) {
1002                dropblock.css('margin-top', '0');
1003                dropblock.css('margin-left', '0');
1004                dropblock.css('top', '0');
1005                dropblock.css('left', '0');
1006                dropblock.height($(window).height() - parseInt(dropblock.css('padding-top'), 10) - parseInt(dropblock.css('padding-bottom'), 10));
1007                dropblock.width($(window).width() - parseInt(dropblock.css('padding-left'), 10) - parseInt(dropblock.css('padding-right'), 10));
1008            } else {
1009                dropblock.css('margin-top', (-(dropblock.height() / 2) - 20) + 'px');
1010                dropblock.css('margin-left', (-(dropblock.width() / 2) - 20) + 'px');
1011                dropblock.css('height', '');
1012                dropblock.css('width', '');
1013                dropblock.css('top', '');
1014                dropblock.css('left', '');
1015            }
1016
1017            if (typeof wpfdColorboxInit !== 'undefined') {
1018                wpfdColorboxInit();
1019            }
1020            // wpfdTrackDownload();
1021
1022            $('body.elementor-default #wpfd-ggd-box a.wpfd_downloadlink').on('click', function (e) {
1023                e.preventDefault();
1024                e.stopPropagation();
1025                var link = $(this).attr('href');
1026                window.location.href = link;
1027            });
1028        });
1029    });
1030}
1031
1032function wpfdSearchPreviewThemeActions() {
1033    var $ = jQuery;
1034    var sourcefile = $("#wpfd-template-preview-box").html();
1035    $('.wpfd-content .wpfd-file-link').unbind('click').click(function (e) {
1036        e.preventDefault();
1037        var fileid = $(this).data('id');
1038        var categoryid = $(this).data('category_id');
1039        var preview_root_cat = $(this).data('category_id');
1040        $.ajax({
1041            url: wpfdparams.wpfdajaxurl + "task=file.display&view=file&id=" + fileid + "&categoryid=" + categoryid + "&rootcat=" + preview_root_cat,
1042            dataType: "json",
1043            beforeSend: function () {
1044                // setting a timeout
1045                if ($('body').has('wpfd-preview-box-loader') !== true) {
1046                    $('body').append('<div class="wpfd-preview-box-loader"></div>');
1047                }
1048            }
1049        }).done(function (file) {
1050            var template = Handlebars.compile(sourcefile);
1051            var html = template(file);
1052            var box = $("#wpfd-preview-box");
1053            $('.wpfd-preview-box-loader').each(function () {
1054                $(this).remove();
1055            });
1056            if (box.length === 0) {
1057                $('body').append('<div id="wpfd-preview-box" style="display: none;"></div>');
1058                box = $("#wpfd-preview-box");
1059            }
1060            box.empty();
1061            box.prepend(html);
1062            box.attr('data-id', fileid);
1063            box.attr('data-catid', categoryid);
1064            box.attr('class', 'wpfd-preview-box wpfd-download-box wpfd-search-preview-box');
1065            if (typeof (file.file.ext) !== 'undefined') {
1066                box.attr('data-type', file.file.ext);
1067                box.addClass(file.file.ext);
1068            }
1069            box.click(function (e) {
1070                if ($(e.target).is('#wpfd-preview-box')) {
1071                    box.hide();
1072                }
1073                $('#wpfd-preview-box').unbind('click.box').bind('click.box', function (e) {
1074                    if ($(e.target).is('#wpfd-preview-box')) {
1075                        box.hide();
1076                    }
1077                });
1078            });
1079
1080            if ($("#wpfd-preview-box .file-custom-field.file-url").length) {
1081                var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link';
1082                $("#wpfd-preview-box .file-custom-field.file-url").each(function () {
1083                    var label = $(this).attr('data-field-label');
1084                    var url = $(this).attr('data-field-val');
1085                    var urlContents = '<div><span>
1085' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>';
1086                    $(this).empty().append(urlContents);
1087                });
1088            }
1089
1090            if (typeof (file.file.linkdownload) !== 'undefined') {
1091                var previewLinkDownload = '<input type="hidden" class="wpfd_file_preview_link_download" value="' + file.file.linkdownload + '" data-filetitle="' + file.file.post_title + '" />';
1092                box.prepend(previewLinkDownload);
1093            }
1094
1095            $('#wpfd-preview-box .wpfd-close').click(function (e) {
1096                e.preventDefault();
1097                box.hide();
1098            });
1099
1100            box.show();
1101
1102            var dropblock = box.find('.dropblock');
1103            if ($(window).width() < 400) {
1104                dropblock.css('margin-top', '0');
1105                dropblock.css('margin-left', '0');
1106                dropblock.css('top', '0');
1107                dropblock.css('left', '0');
1108                dropblock.height($(window).height() - parseInt(dropblock.css('padding-top'), 10) - parseInt(dropblock.css('padding-bottom'), 10));
1109                dropblock.width($(window).width() - parseInt(dropblock.css('padding-left'), 10) - parseInt(dropblock.css('padding-right'), 10));
1110            } else {
1111                dropblock.css('margin-top', (-(dropblock.height() / 2) - 20) + 'px');
1112                dropblock.css('margin-left', (-(dropblock.width() / 2) - 20) + 'px');
1113                dropblock.css('height', '');
1114                dropblock.css('width', '');
1115                dropblock.css('top', '');
1116                dropblock.css('left', '');
1117            }
1118
1119            if (dropblock && typeof (file.file.ID) !== 'undefined') {
1120                dropblock.attr('data-id', file.file.ID);
1121            }
1122
1123            if (typeof wpfdColorboxInit !== 'undefined') {
1124                wpfdColorboxInit();
1125            }
1126
1127            $('body.elementor-default #wpfd-preview-box a.wpfd_downloadlink').on('click', function (e) {
1128                e.preventDefault();
1129                e.stopPropagation();
1130                var link = $(this).attr('href');
1131                window.location.href = link;
1132            });
1133
1134            if (typeof (wpfdparams.wpfd_directly_preview_on_popup) !== 'undefined'
1135                && parseInt(wpfdparams.wpfd_directly_preview_on_popup) === 1 && $('#wpfd-preview-box.wpfd-search-preview-box .wpfd_previewlink').length) {
1136                $('#wpfd-preview-box.wpfd-search-preview-box .wpfd_previewlink').click();
1137                $('#wpfd-preview-box.wpfd-search-preview-box').hide();
1138            }
1139        });
1140    });
1141}
1142
1143function wpfdWooCommerceAddToCart() {
1144    if (typeof ('wc_add_to_cart_params') === "undefined") {
1145        return false;
1146    }
1147
1148    var $ = jQuery;
1149    $('.wpfd_downloadlink:has(.wpfd-add-to-cart)').unbind('click').click(function (e) {
1150        var $this = $(this);
1151
1152        if (!$this.attr('data-product_id')) {
1153            return true;
1154        }
1155
1156        e.preventDefault();
1157
1158        var url = $this.attr('href');
1159        var data = {};
1160        $.each($this.data(), function (key, value) {
1161            data[key] = value;
1162        });
1163
1164        jQuery.ajax({
1165            url: wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'add_to_cart'),
1166            method: 'POST',
1167            data: data,
1168            success: function (response, status, xhr) {
1169                if (!response) {
1170                    return;
1171                }
1172
1173                if (response.error && response.product_url) {
1174                    window.location = response.product_url;
1175                    return;
1176                }
1177
1178                // Redirect to cart option
1179                if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') {
1180                    window.location = wc_add_to_cart_params.cart_url;
1181                    return;
1182                }
1183
1184                // Trigger event so themes can refresh other areas.
1185                $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $this]);
1186
1187                // Fallback, made sure added to cart button added.
1188                if (!wc_add_to_cart_params.is_cart && $this.parent().find('.added_to_cart').length === 0) {
1189                    $this.removeClass('loading');
1190                    $this.addClass('added');
1191                    $this.after(' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' +
1192                        wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>');
1193                }
1194            },
1195        });
1196        return false;
1197    });
1198}
1199
1200function wpfdViewMoreFileDescription() {
1201    var $ = jQuery;
1202    $('.wpfd-file-view-more-description').unbind('click').click(function (e) {
1203        var $this = $(this);
1204
1205        e.preventDefault();
1206
1207        var description = '';
1208        if ($(this).parent().find('.wpfd-file-description')) {
1209            description = $(this).parent().find('.wpfd-file-description').val();
1210        }
1211
1212        var box = $("#wpfd-file-description-box");
1213        if (box.length === 0) {
1214            $('body').append('<div id="wpfd-file-description-box" style="display: none;"></div>');
1215            box = $("#wpfd-file-description-box");
1216        }
1217        box.empty();
1218        box.prepend('<p class="files-desc-contents">' + description + '</p>');
1219        box.append('<button title="Close (Esc)" type="button" class="wpfd-close">×</button>');
1220
1221        box.click(function (e) {
1222            if ($(e.target).is('#wpfd-file-description-box')) {
1223                box.hide();
1224            }
1225            $('#wpfd-file-description-box').unbind('click.box').bind('click.box', function (e) {
1226                if ($(e.target).is('#wpfd-file-description-box')) {
1227                    box.hide();
1228                }
1229            });
1230        });
1231
1232        $('#wpfd-file-description-box .wpfd-close').click(function (e) {
1233            e.preventDefault();
1234            box.hide();
1235        });
1236
1237        box.show();
1238
1239        var dropblock = box.find('.dropblock');
1240        if ($(window).width() < 400) {
1241            dropblock.css('margin-top', '0');
1242            dropblock.css('margin-left', '0');
1243            dropblock.css('top', '0');
1244            dropblock.css('left', '0');
1245            dropblock.height($(window).height() - parseInt(dropblock.css('padding-top'), 10) - parseInt(dropblock.css('padding-bottom'), 10));
1246            dropblock.width($(window).width() - parseInt(dropblock.css('padding-left'), 10) - parseInt(dropblock.css('padding-right'), 10));
1247        } else {
1248            dropblock.css('margin-top', (-(dropblock.height() / 2) - 20) + 'px');
1249            dropblock.css('margin-left', (-(dropblock.width() / 2) - 20) + 'px');
1250            dropblock.css('height', '');
1251            dropblock.css('width', '');
1252            dropblock.css('top', '');
1253            dropblock.css('left', '');
1254        }
1255    });
1256}
1257
1258// Prevent manually typing into the input (date filter), but allow to delete old value
1259function wpfdCheckInput(event) {
1260    var key = event.keyCode || event.charCode;
1261    // detect backspace or del key
1262    if (key != 8 && key != 46) {
1263        return false;
1264    }
1265}
1266
1267// Validate number input for weight filter, but allow to delete old value
1268function wpfdValidateNumberInput(e) {
1269    var key = e.keyCode || e.charCode;
1270    // detect backspace or del key
1271    if (key != 8 && key != 46 && isNaN(e.key)) {
1272        return false;
1273    }
1274}
1275
1276jQuery(document).ready(function ($) {
1277    window.file_suggestion_ajax_on_search = null;
1278    window.ajax_search_handler = null;
1279    window.file_tag_ajax_on_search = null;
1280    var suggestionEventId;
1281    initSorting();
1282
1283    // Init tags
1284    $(".chk_ftags").click(function () {
1285        fillInputTags();
1286    });
1287
1288    // Call filter type chosen
1289    if ($('select[name="extension"]').length) {
1290        $('select[name="extension"]').chosen({width: '100%', search_contains: true});
1291    } else {
1292        setTimeout(function () {
1293            if ($('select[name="extension"]').length) {
1294                $('select[name="extension"]').chosen({width: '100%', search_contains: true});
1295            }
1296        }, 3000);
1297    }
1298    if ($('.fusion-builder-live').length || $('.et_divi_theme.et-fb').length) {
1299        setInterval(function () {
1300            if ($(".wpfd-adminForm").length) {
1301                if ($('select[name="extension"]').length) {
1302                    if ($('.et_divi_theme.et-fb').length) {
1303                        $('select[name="extension"]').chosen({width: '100%', search_contains: true});
1304                    } else {
1305                        $('select[name="extension"]').empty();
1306                        var newOption = $('<option value="1">test</option>');
1307                        $('select[name="extension"]').append(newOption);
1308                        $('select[name="extension"]').trigger("chosen:updated");
1309                    }
1310                } else {
1311                    setTimeout(function () {
1312                        if ($('select[name="extension"]').length) {
1313                            if ($('.et_divi_theme.et-fb').length) {
1314                                $('select[name="extension"]').chosen({width: '100%', search_contains: true});
1315                            } else {
1316                                $('select[name="extension"]').empty();
1317                                var newOption = $('<option value="1">test</option>');
1318                                $('select[name="extension"]').append(newOption);
1319                                $('select[name="extension"]').trigger("chosen:updated");
1320                            }
1321                        }
1322                    }, 3000);
1323                }
1324            }
1325        }, 1000);
1326    }
1327
1328    $(".filter_catid").change(function () {
1329        // Clear search
1330        var $ = jQuery;
1331        var categoryId = $(this).val();
1332        var cateType = $(this).parent().find('.cate-list .cate-item[data-catid="' + categoryId + '"]').data('cattype');
1333        catChange($(this));
1334    });
1335
1336    $('.qCatesearch').on('keydown keyup', function (e) {
1337        if (e.keyCode === 13 || e.which === 13 || e.key === 'Enter') {
1338            e.preventDefault();
1339            return;
1340        }
1341        var scateList, filter, labl, txtValue;
1342        var $this = $(this);
1343        scateList = $("li.cate-item", $this.parent().parent());
1344
1345        filter = $this.val().toUpperCase();
1346        scateList.each(function () {
1347            labl = $(this).find("label");
1348            txtValue = labl.text().toUpperCase();
1349            if (txtValue.indexOf(filter) > -1) {
1350                $(this).css("display", "");
1351            } else {
1352                $(this).css("display", "none");
1353            }
1354        });
1355    });
1356    $(".wpfd-adminForm").submit(function (e) {
1357        e.preventDefault();
1358        return false;
1359    });
1360    $('.txtfilename:not(".wpfd-form-search-file-category .txtfilename")').on('keyup', function (e) {
1361        var $this = $(this);
1362        if (e.keyCode === 13 || e.which === 13 || e.key === 'Enter') {
1363            e.preventDefault();
1364
1365            if ($this.val() === '') {
1366                return;
1367            }
1368
1369            var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search;
1370            if (prevFileSuggestionAjax !== null) {
1371                prevFileSuggestionAjax.abort();
1372            }
1373
1374            $this.closest('form').find('.wpfd-icon-search').show();
1375            $this.closest('form').find('.wpfd-icon-search-loading').hide();
1376
1377            var formID = '#' + $this.closest('form').attr('id');
1378            ajaxSearch(formID);
1379
1380            return;
1381        }
1382    });
1383
1384    // Make file suggestion handler
1385    $('.txtfilename:not(".wpfd-form-search-file-category .txtfilename")').on('input', function (e) {
1386        // Only make file suggestion on search engine when enabling option
1387        if (!parseInt(wpfdvars.search_file_suggestion)) {
1388            return;
1389        }
1390
1391        var keySearch = $(this).val();
1392        var searchLength = keySearch.replace(/ /g, '').length;
1393        var doFilterSuggestion = searchLength >= 3 ? true : false;
1394        var formID = '#' + $(this).closest('form').attr('id');
1395        $(this).closest('form').find(".wpfd_search_file_suggestion").hide();
1396
1397        if (doFilterSuggestion) {
1398            clearTimeout(suggestionEventId);
1399            suggestionEventId = setTimeout(function () {
1400                makeFileSuggestion(formID);
1401            }, 800);
1402        } else {
1403            var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search;
1404
1405            if (prevFileSuggestionAjax !== null && activeSearchForm === formID) {
1406                prevFileSuggestionAjax.abort();
1407            }
1408
1409            $(this).closest('form').find('.wpfd-icon-search').show();
1410            $(this).closest('form').find('.wpfd-icon-search-loading').hide();
1411        }
1412    });
1413
1414    jQuery('.icon-date').click(function () {
1415        var txt = jQuery(this).attr('data-id');
1416        if (txt !== 'cfrom' && txt !== 'cto' && txt !== 'ufrom' && txt !== 'uto') {
1417            jQuery('#' + txt).datetimepicker('show');
1418        }
1419    });
1420
1421    // Date time picker
1422    jQuery('.wpfd-adminForm').each(function () {
1423        $sForm = $(this);
1424        wpfdSingleDateTimePicker($sForm.find('.cfrom'), $sForm);
1425        wpfdSingleDateTimePicker($sForm.find('.cto'), $sForm);
1426        wpfdSingleDateTimePicker($sForm.find('.ufrom'), $sForm);
1427        wpfdSingleDateTimePicker($sForm.find('.uto'), $sForm);
1428    });
1429
1430    jQuery('.feature-toggle').click(function () {
1431        var containerId = jQuery(this).parents('.wpfd-adminForm').attr('id');
1432        var container = '#' + containerId;
1433        jQuery(container).find('.feature').slideToggle('slow', function () {
1434            jQuery(container).find('.feature-toggle').toggleClass(function () {
1435                if (jQuery(this).is(".toggle-arrow-up-alt")) {
1436                    return "toggle-arrow-down-alt";
1437                } else {
1438                    return "toggle-arrow-up-alt";
1439                }
1440            });
1441        });
1442    });
1443
1444    // Ajax filters
1445    $(".btnsearchbelow:not('.wpfd-form-search-file-category .btnsearchbelow'):not('#btnReset'), .btnsearch:not('.wpfd-form-search-file-category .btnsearchbelow')").on('click', function (e) {
1446        e.preventDefault();
1447        var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search;
1448        if (prevFileSuggestionAjax !== null) {
1449            prevFileSuggestionAjax.abort();
1450        }
1451
1452        $(this).closest('form').find('.wpfd-icon-search').show();
1453        $(this).closest('form').find('.wpfd-icon-search-loading').hide();
1454        var formID = '#' + $(this).closest('form').attr('id');
1455        ajaxSearch(formID);
1456        return false;
1457    });
1458
1459    $('#btnReset').on('click', function (e) {
1460        e.preventDefault();
1461        resetFilters('.wpfd-adminForm');
1462        $('#wpfd-results').html('');
1463        return false;
1464    });
1465
1466    $("#widget_btnReset").on('click', function (e) {
1467        e.preventDefault();
1468        resetFilters('#widget_search');
1469    });
1470
1471    // Get checkbox tags
1472    selectdChecktags();
1473
1474    // Show category
1475    showCategory();
1476
1477    // Select categories actions
1478    selectCategoriesActions();
1479
1480    // Display selected category when reload.
1481    wpfdshowCateReload();
1482
1483    // Set folder icon for parent-folder
1484    parentFolderIcon();
1485
1486    // Add placeholder when tag search box is selected
1487    wpfdAddPlaceholder();
1488
1489    // Get search full width
1490    fullWidthSearch();
1491
1492    // Get searchbox
1493    addtoSearchbuttonbelow();
1494
1495    noTagscase();
1496
1497    jQuery('.list-results table tr td a.file-item').click(function (e) {
1498        return true;
1499    });
1500
1501    resetFilters = function (formSelect) {
1502        var sform = $("#adminForm");
1503        if (formSelect !== null && formSelect !== undefined) {
1504            sform = $(formSelect);
1505        }
1506        var inputs = $(sform).find('input:not([name="catid"]):not([name="theme"]), select:not([name="from_weight_unit"]):not([name="to_weight_unit"])');
1507
1508        $.each(inputs, function (i, el) {
1509            var eType = $(el).attr('type');
1510            if (eType === 'checkbox') {
1511                $(el).prop('checked', false);
1512            } else {
1513                $(el).val('');
1514                if ($(el).hasClass("tagit")) {
1515                    $(el).tagit("removeAll");
1516                }
1517            }
1518        });
1519
1520        if ($('select[name="from_weight_unit"]').length) {
1521            $('select[name="from_weight_unit"]').val('kb');
1522        }
1523
1524        if ($('select[name="to_weight_unit"]').length) {
1525            $('select[name="to_weight_unit"]').val('kb');
1526        }
1527
1528        if ($('select[name="extension"]').length) {
1529            $('select[name="extension"]').val('');
1530            $('select[name="extension"] + .chzn-container .chzn-single > span').html('-- Select type --');
1531            $('select[name="extension"] + .chzn-container .chzn-choices .search-choice').remove();
1532        }
1533
1534        if (!$('.wpfd-listCate').is(':hidden')) {
1535            $('#filter_catid').val('');
1536        }
1537
1538        $('.tags-item').removeClass('active');
1539        if ($('.categories-filtering-selection .cate-lab').length) {
1540            $('.cate-item').removeClass('checked');
1541            var wpfdlCurrentselectedCate = $(".categories-filtering .cate-lab");
1542            if (wpfdlCurrentselectedCate.hasClass('display-cate')) {
1543                wpfdlCurrentselectedCate.removeClass('display-cate');
1544            }
1545            wpfdlCurrentselectedCate.empty();
1546            var rootCateId = $('.categories-filtering-selection #cate-list > .search-cate + li.cate-item').data('catid');
1547            var rootSearchCategoryLabel = $('.categories-filtering-selection #cate-list > .search-cate + li.cate-item').find('label').html();
1548            rootSearchCategoryLabel = rootSearchCategoryLabel !== '' ? rootSearchCategoryLabel : wpfdvars.msg_file_category;
1549            $('.categories-filtering-selection #filter_catid').val(rootCateId);
1550            wpfdlCurrentselectedCate.append("<label id='root-cate'>" + rootSearchCategoryLabel + "</label>");
1551        }
1552    };
1553
1554    populateFilters = function (filters) {
1555        var sform = $("#adminForm");
1556        $.each(filters, function (f, v) {
1557            var els = $('[name=' + f + ']', sform);
1558            if (els.length > 0) {
1559                if ($(els).hasClass("tagit")) {
1560                    $(els).tagit("removeAll");
1561                    if (v !== "") {
1562                        var tgs = v.split(",");
1563                        for (var i = 0; i < tgs.length; i++) {
1564                            $(els).tagit("createTag", tgs[i]);
1565                        }
1566                    }
1567                } else {
1568                    $(els).val(v);
1569                }
1570                $(els).trigger('change').trigger("liszt:updated").trigger("chosen:updated");
1571            }
1572        });
1573    };
1574
1575    // Remove property with empty value
1576    cleanObj = function (obj) {
1577        for (var k in obj) {
1578            if (obj.hasOwnProperty(k)) {
1579                if (!obj[k]) delete obj[k];
1580            }
1581        }
1582        return obj;
1583    };
1584
1585    // Back on browser
1586    jQuery(window).on('popstate', function (event) {
1587        var state = event.originalEvent && typeof event.originalEvent.state !== 'undefined' ? event.originalEvent.state : event.state;
1588        resetFilters();
1589        if (state !== null) {
1590            var params = getSearchParams();
1591            if (typeof params === 'object' && !jQuery.isEmptyObject(params)) {
1592                var formData = state;
1593                populateFilters(formData);
1594                ajaxSearch('.wpfd-adminForm', false, false, false);
1595            } else {
1596                $("#wpfd-results").html("");
1597            }
1598        } else {
1599            $("#wpfd-results").html("");
1600        }
1601    });
1602    var params = getSearchParams();
1603    if (params.q !== undefined ||
1604        params.catid !== undefined ||
1605        params.ftags !== undefined ||
1606        params.cfrom !== undefined ||
1607        params.cto !== undefined ||
1608        params.ufrom !== undefined ||
1609        params.uto !== undefined
1610    ) {
1611        ajaxSearch('.wpfd-adminForm');
1612    }
1613
1614    preSearchDownloadSelectedFiles();
1615    searchDownloadSelectedFiles();
1616    wpfdSearchGGDThemeActions();
1617    wpfdViewMoreFileDescription();
1618});

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.