PageSourceSearch

https://ambiente.gob.do/app/plugins/wp-file-download/app/site/assets/js/search_filter.js?ver=6.3.0

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

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.