PageSourceSearch

https://www.foxcharleston.com/wp-content/plugins/wp-file-download/…/site/assets/js/search_filter.js?ver=6.3.8

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

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.