PageSourceSearch

https://www.rfebm.com/wp-content/plugins/wp-file-download/app/site/assets/js/search_filter.js?ver=6.3.11

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

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.