PageSourceSearch

https://www.ammersbek.de/wp-content/wp-file-download/themes/wpfd-downloadlist/js/script.js?ver=6.3.4

js ammersbek.de collected 2026-10-02 21:33:52 UTC 101,405 bytes, 1,961 lines download raw bytes

1/**
2 * Wpfd
3 *
4 * We developed this code with our hearts and passion.
5 * We hope you found it useful, easy to understand and to customize.
6 * Otherwise, please feel free to contact us at [email protected] *
7 * @package WP File Download
8 * @copyright Copyright (C) 2013 JoomUnited (http://www.joomunited.com). All rights reserved.
9 * @copyright Copyright (C) 2013 Damien Barrère (http://www.crac-design.com). All rights reserved.
10 * @license GNU General Public License version 2 or later; http://www.gnu.org/licenses/gpl-2.0.html
11 */
12
13jQuery(document).ready(function ($) {
14    var downloadlist_tree = $('.wpfd-foldertree-downloadlist');
15    var downloadlist_hash = window.location.hash;
16    var downloadlist_root_cat = $('.wpfd-content-downloadlist').data('category');
17    var allCategoriesBreadcrumbs = '<li><a class="catlink" data-idcat="all_0" href="javascript:void(0);">' + wpfdparams.translates.wpfd_all_categories + '</a></li>';
18    var allCategoriesDividerBreadcrumbs = '<li><a class="catlink" data-idcat="all_0" href="javascript:void(0);">' + wpfdparams.translates.wpfd_all_categories + '</a><span class="divider"> &gt; </span></li>';
19    var downloadlist_cParents = {};
20    if (window.wpfdAjax === undefined) {
21        window.wpfdAjax = {};
22    }
23    window.wpfdAjax[downloadlist_root_cat] = {category: null, file: null};
24    $(".wpfd-content-downloadlist").each(function () {
25        var downloadlist_topCat = $(this).data('category');
26        var topCatName = $(this).find('.head-category-downloadlist li:first-child').text();
27        var currentCatName = $(this).find("h2").text();
28        if (currentCatName !== '') {
29            topCatName = currentCatName;
30        }
31        if (downloadlist_topCat == 'all_0') {
32            downloadlist_cParents[downloadlist_topCat] = {parent: 0, term_id: 0, name: topCatName.trim()};
33        } else {
34            downloadlist_cParents[downloadlist_topCat] = {parent: 0, term_id: downloadlist_topCat, name: topCatName.trim()};
35        }
36        $(this).find(".wpfdcategory.catlink").each(function () {
37            var tempidCat = $(this).data('idcat');
38            downloadlist_cParents[tempidCat] = {parent: downloadlist_topCat, term_id: tempidCat, name: $(this).text().trim()};
39        });
40        initInputSelected(downloadlist_topCat);
41        initDownloadSelected(downloadlist_topCat);
42    });
43
44    //load media tables
45    $('.wpfd-content .mediaTable').mediaTable();
46
47    Handlebars.registerHelper('bytesToSize', function (bytes) {
48        if (typeof bytes === "undefined") {
49            return 'n/a';
50        }
51
52        return bytes.toString().toLowerCase() === 'n/a' ? bytes : bytesToSize(parseInt(bytes));
53    });
54
55    function downloadlist_initClick() {
56        $(document).off('click', '.wpfd-content-downloadlist .catlink').on('click', '.wpfd-content-downloadlist .catlink', function(e) {
57            e.preventDefault();
58
59            if ($(this).parents('.wpfd-content').find('.wpfd-form-search-file-category').length) {
60                $(this).parents('.wpfd-content').find('.wpfd-form-search-file-category').remove();
61            }
62
63            var ctheme = $(this).parents('.wpfd-content').find('.wpfd_root_category_theme').val();
64            var c_root_cat = $(this).parents('.wpfd-content').find('.wpfd_root_category_id').val();
65            var rootCat = ".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + c_root_cat + "]";
66            var current_category = $(rootCat).find('#current_category_' + c_root_cat).val();
67            $(".wpfd-content[data-category=" + $(this).parents('.wpfd-content-' + ctheme).data('category') + "] .wpfd-container-" + ctheme).find('.wpfd-categories .wpfdcategory.catlink').each(function () {
68                var tempidCat = $(this).data('idcat');
69                var catName = '';
70                if ($(this).attr('title') !== undefined) {
71                    catName = $(this).attr('title').trim();
72                } else if ($(this).data('title') !== undefined) {
73                    catName = $(this).data('title').trim();
74                }
75                downloadlist_cParents[tempidCat] = {parent: current_category, term_id: tempidCat, name: catName};
76            });
77            e.preventDefault();
78            downloadlist_load(c_root_cat, $(this).data('idcat'));
79        })
80    }
81
82    function initInputSelected(sc) {
83        $(document).on('change', ".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sc + "] input.cbox_file_download", function () {
84            var rootCat = ".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sc + "]";
85            var selectedFiles = $(rootCat + " input.cbox_file_download:checked");
86            var filesId = [];
87            if (selectedFiles.length) {
88                selectedFiles.each(function (index, file) {
89                    filesId.push($(file).data('id'));
90                });
91            }
92            if (filesId.length > 0) {
93                $(rootCat + " .wpfdSelectedFiles").remove();
94                $('<input type="hidden" class="wpfdSelectedFiles" value="' + filesId.join(',') + '" />')
95                    .insertAfter($(rootCat).find(" #current_category_slug_" + sc));
96                hideDownloadAllBtn(sc, true);
97                $(rootCat + " .downloadlist-download-selected").remove();
98                var downloadSelectedBtn = $('<a href="javascript:void(0);" class="downloadlist-download-selected" style="display: block;">
98' + wpfdparams.translates.download_selected + '<i class="zmdi zmdi-check-all wpfd-download-category"></i></a>');
99                if ($(rootCat).find("ul.breadcrumbs").length) {
100                    downloadSelectedBtn.insertBefore($(rootCat).find("ul.breadcrumbs"));
101                } else {
102                    downloadSelectedBtn.insertBefore($(rootCat).find("div.wpfd-container"));
103                }
104            } else {
105                $(rootCat + " .wpfdSelectedFiles").remove();
106                $(rootCat + " .downloadlist-download-selected").remove();
107                hideDownloadAllBtn(sc, false);
108            }
109        });
110    }
111
112    function hideDownloadAllBtn(sc, hide) {
113        var rootCat = ".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sc + "]";
114        var downloadCatButton = $(rootCat + " .downloadlist-download-category");
115        if (downloadCatButton.length === 0 || downloadCatButton.hasClass('display-download-category')) {
116            return;
117        }
118        if (hide) {
119            $(rootCat + " .downloadlist-download-category").hide();
120        } else {
121            $(rootCat + " .downloadlist-download-category").show();
122        }
123    }
124
125    function initDownloadSelected(sc) {
126        var rootCat = ".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sc + "]";
127        $(document).on('click', rootCat + ' .downloadlist-download-selected', function () {
128            if ($(rootCat).find('.wpfdSelectedFiles').length > 0) {
129                var current_category = $(rootCat).find('#current_category_' + sc).val();
130                var category_name = $(rootCat).find('#current_category_slug_' + sc).val();
131                var selectedFilesId = $(rootCat).find('.wpfdSelectedFiles').val();
132                $.ajax({
133                    url: wpfdparams.wpfdajaxurl + "?action=wpfd&task=files.zipSeletedFiles&filesId=" + selectedFilesId + "&wpfd_category_id=" + current_category,
134                    dataType: "json",
135                }).done(function (results) {
136                    if (results.success) {
137                        var hash = results.data.hash;
138                        window.location.href = wpfdparams.wpfdajaxurl + "?action=wpfd&task=files.downloadZipedFile&hash=" + hash + "&wpfd_category_id=" + current_category + "&wpfd_category_name=" + category_name;
139                    } else {
140                        alert(results.data.message);
141                    }
142                })
143            }
144        });
145    }
146
147    downloadlist_initClick();
148
149    if (typeof wpfdColorboxInit !== 'undefined') {
150        wpfdColorboxInit();
151    }
152
153    function wpfd_downloadlist_menu_category_link_handlers() {
154        if ($('.wpfd_menu_category_links .elementor-icon-list-item').length) {
155            $('.wpfd_menu_category_links .elementor-icon-list-item').unbind('click').on('click', function (e) {
156                var hashSubUrl = $(this).find('a').attr('href');
157                var hashGoId = '';
158
159                if (hashSubUrl.indexOf('/') !== -1) {
160                    var hashParams = hashSubUrl.split('/');
161                    hashGoId = hashParams[hashParams.length - 1];
162                    hashGoId = hashGoId.replace('#', '');
163
164                    if (hashGoId !== '') {
165                        var hashGoIda = hashGoId.split('-');
166                        var hashGoIda_sourcecat = hashGoIda[0];
167                        var hashGoIda_category_id = hashGoIda[1];
168
169                        setTimeout(function () {
170                            downloadlist_load(hashGoIda_sourcecat, hashGoIda_category_id, null);
171                            if ($('#e-n-menu-content-1872').length) {
172                                $('#e-n-menu-content-1872').hide();
173                            }
174                        }, 100);
175                    }
176                }
177            });
178        }
179    }
180
181    wpfd_downloadlist_menu_category_link_handlers();
182
183    downloadlist_hash = downloadlist_hash.replace('#', '');
184    if (downloadlist_hash !== '') {
185        var hasha = downloadlist_hash.split('-');
186        var re = new RegExp("^(p[0-9]+)$");
187        var page = null;
188        var stringpage = hasha.pop();
189
190        if (re.test(stringpage)) {
191            page = stringpage.replace('p', '');
192        }
193        var hash_category_id = hasha[1];
194        var hash_sourcecat = hasha[0];
195
196        if (parseInt(hash_category_id) > 0 || hash_category_id === 'all_0') {
197            if (hash_category_id == 'all_0') {
198                hash_category_id = 0;
199            }
200
201            setTimeout(function () {
202                downloadlist_load(hash_sourcecat, hash_category_id, page);
203            }, 100);
204
205        }
206    }
207
208
209    _wpfd_text = function (text) {
210        if (typeof (l10n) !== 'undefined') {
211            return l10n[text];
212        }
213        return text;
214    };
215
216    function toMB(mb) {
217        return mb * 1024 * 1024;
218    }
219
220    var allowedExt = wpfdparams.allowed;
221    allowedExt = allowedExt.split(',');
222    allowedExt.sort();
223
224    var initUploader = function (currentContainer) {
225        var upload_type = 'file';
226        // Init the uploader
227        var uploader = new Resumable({
228            target: wpfdparams.wpfduploadajax + '?action=wpfd&&task=files.upload&upload_from=front',
229            query: {
230                id_category: $(currentContainer).find('input[name=id_category]').val(),
231            },
232            fileParameterName: 'file_upload',
233            simultaneousUploads: 1,
234            maxChunkRetries: 1,
235            maxFileSize: toMB(wpfdparams.maxFileSize),
236            maxFileSizeErrorCallback: function (file) {
237                alert(file.name + ' ' + _wpfd_text('is too large, please upload file(s) less than ') + wpfdparams.maxFileSize + 'Mb!');
238            },
239            chunkSize: wpfdparams.serverUploadLimit - 50 * 1024, // Reduce 50KB to avoid error
240            forceChunkSize: true,
241            fileType: allowedExt,
242            fileTypeErrorCallback: function (file) {
243                alert(file.name + ' cannot upload!\n\n' + _wpfd_text('This type of file is not allowed to be uploaded. You can add new file types in the plugin configuration'));
244            },
245            generateUniqueIdentifier: function (file, event) {
246                var relativePath = file.webkitRelativePath || file.fileName || file.name;
247                var size = file.size;
248                var prefix = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
249                return (prefix + size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''));
250            }
251        });
252
253        if (!uploader.support) {
254            alert(_wpfd_text('Your browser does not support HTML5 file uploads!'));
255        }
256
257        if (typeof (willUpload) === 'undefined') {
258            var willUpload = true;
259        }
260
261        uploader.on('createFolders', function (files) {
262            upload_type = 'folder';
263            var currentRootCat = currentContainer.find('input[name=id_category]').val()
264            // Prepare category tree
265            var paths = files.map(function(file) {
266                if (file.hasOwnProperty('catId')) {
267                    currentRootCat = file.catId;
268                }
269                var filePath = (file.hasOwnProperty('relativePath')) ? file.relativePath : file.webkitRelativePath;
270                var namePos = filePath.lastIndexOf(file.name);
271                return filePath.substr(0,namePos);
272            });
273            // get unique value (not empty value)
274            paths = paths.filter( function(item, i, ar) { return item && ar.indexOf(item) === i } );
275            if (paths.length > 0) {
276                var categoryType = currentContainer.find('input[name=category_type]').val();
277                // Send ajax to initial categories
278                $.ajax({
279                    url: wpfdparams.wpfduploadajax + '?action=wpfd&task=categories.createCategoriesDeep',
280                    data: {
281                        paths: paths.join('|'),
282                        category_id: currentRootCat,
283                        type: categoryType
284                    },
285                    method: 'POST',
286                    success: function (data) {
287                    }
288                });
289            }
290        })
291
292        uploader.on('filesAdded', function (files) {
293            files.forEach(function (file) {
294                var progressBlock = '<div class="wpfd_process_block" id="' + file.uniqueIdentifier + '">'
295                    + '<div class="wpfd_process_fileinfo">'
296                    + '<span class="wpfd_process_filename">' + file.fileName + '</span>'
297                    + '<span class="wpfd_process_cancel">Cancel</span>'
298                    + '</div>'
299                    + '<div class="wpfd_process_full" style="display: block;">'
300                    + '<div class="wpfd_process_run" data-w="0" style="width: 0%;"></div>'
301                    + '</div></div>';
302
303                //$('#preview', '.wpreview').before(progressBlock);
304                currentContainer.find('#preview', '.wpreview').before(progressBlock);
305                $(currentContainer).find('.wpfd_process_cancel').unbind('click').click(function () {
306                    fileID = $(this).parents('.wpfd_process_block').attr('id');
307                    fileObj = uploader.getFromUniqueIdentifier(fileID);
308                    uploader.removeFile(fileObj);
309                    $(this).parents('.wpfd_process_block').fadeOut('normal', function () {
310                        $(this).remove();
311                    });
312
313                    if (uploader.files.length === 0) {
314                        $(currentContainer).find('.wpfd_process_pause').fadeOut('normal', function () {
315                            $(this).remove();
316                        });
317                    }
318
319                    $.ajax({
320                        url: wpfdparams.wpfduploadajax + '?action=wpfd&task=files.upload',
321                        method: 'POST',
322                        dataType: 'json',
323                        data: {
324                            id_category: $('input[name=id_category]').val(),
325                            deleteChunks: fileID
326                        },
327                        success: function (res, stt) {
328                            if (res.response === true) {
329                            }
330                        }
331                    })
332                });
333            });
334
335            // Do not run uploader if no files added or upload same files again
336            if (files.length > 0) {
337                uploadPauseBtn = $(currentContainer).find('.wpreview').find('.wpfd_process_pause').length;
338                restableBlock = $(currentContainer).find('.wpfd_process_block');
339
340                if (!uploadPauseBtn) {
341                    restableBlock.before('<div class="wpfd_process_pause">Pause</div>');
342                    $(currentContainer).find('.wpfd_process_pause').unbind('click').click(function () {
343                        if (uploader.isUploading()) {
344                            uploader.pause();
345                            $(this).text('Start');
346                            $(this).addClass('paused');
347                            willUpload = false;
348                        } else {
349                            uploader.upload();
350                            $(this).text('Pause');
351                            $(this).removeClass('paused');
352                            willUpload = true;
353                        }
354                    });
355                }
356
357                uploader.opts.query = {
358                    id_category: currentContainer.find('input[name=id_category]').val()
359                };
360
361                if (willUpload) {
362                    setTimeout( function() {uploader.upload();}, 1000);
363                }
364            }
365        });
366
367        uploader.on('fileProgress', function (file) {
368            $(currentContainer).find('.wpfd_process_block#' + file.uniqueIdentifier)
369                .find('.wpfd_process_run').width(Math.floor(file.progress() * 100) + '%');
370        });
371
372        uploader.on('fileSuccess', function (file, res) {
373            var thisUploadBlock = currentContainer.find('.wpfd_process_block#' + file.uniqueIdentifier);
374            thisUploadBlock.find('.wpfd_process_cancel').addClass('uploadDone').text('OK').unbind('click');
375            thisUploadBlock.find('.wpfd_process_full').remove();
376
377            var response = JSON.parse(res);
378            if (response.response === false && typeof(response.datas) !== 'undefined') {
379                if (typeof(response.datas.code) !== 'undefined' && response.datas.code > 20) {
380                    alert(response.datas.message);
381                    return false;
382                }
383            }
384            if (typeof(response) === 'string') {
385                alert(response);
386                return false;
387            }
388
389            if (response.response !== true) {
390                alert(response.response);
391                return false;
392            }
393        });
394
395        uploader.on('fileError', function (file, msg) {
396            thisUploadBlock = currentContainer.find('.wpfd_process_block#' + file.uniqueIdentifier);
397            thisUploadBlock.find('.wpfd_process_cancel').addClass('uploadError').text('Error').unbind('click');
398            thisUploadBlock.find('.wpfd_process_full').remove();
399        });
400
401        uploader.on('complete', function () {
402            var currentRootCat = currentContainer.find('input[name=id_category]').val();
403            var sourcecat = currentContainer.parents('.wpfd-content.wpfd-content-multi').data('category');
404            var theme = currentContainer.parents('.wpfd-content.wpfd-content-multi[data-category=' + sourcecat + ']').find('.wpfd_root_category_theme').val();
405            var cloneThemeName = currentContainer.parents('.wpfd-content.wpfd-content-multi[data-category=' + sourcecat + ']').find('.wpfd_root_category_theme').val();
406            var wpfd_tree = $('.wpfd-content[data-category="'+sourcecat+'"] .wpfd-foldertree');
407            wpfd_tree.jaofiletree({
408                script: wpfdparams.wpfduploadajax + '?juwpfisadmin=false&action=wpfd&task=categories.getCats',
409                usecheckboxes: false,
410                root: sourcecat,
411                expanded: parseInt(wpfdparams.allow_category_tree_expanded) === 1 ? true : false
412            });
413
414            var categoryAjaxUrl = wpfdparams.wpfdajaxurl + "task=categories.display&view=categories&id=" + currentRootCat + "&top=" + sourcecat;
415            if (wpfdTableCategoriesLocalCache.exist(categoryAjaxUrl)) {
416                wpfdTableCategoriesLocalCache.remove(categoryAjaxUrl);
417            }
418
419            var fileCount  = $(currentContainer).find('.wpfd_process_cancel').length;
420            var categoryId = $(currentContainer).find('input[name=id_category]').val();
421
422            $.ajax({
423                url: wpfdparams.wpfduploadajax + '?action=wpfd&task=files.wpfdPendingUploadFiles',
424                method: 'POST',
425                dataType: 'json',
426                data: {
427                    uploadedFiles: fileCount,
428                    id_category: categoryId,
429                },
430                success: function (res) {
431                    currentContainer.find('.progress').delay(300).fadeIn(300).hide(300, function () {
432                        $(this).remove();
433                    });
434                    currentContainer.find('.uploaded').delay(300).fadeIn(300).hide(300, function () {
435                        $(this).remove();
436                    });
437                    $('#wpreview .file').delay(1200).show(1200, function () {
438                        $(this).removeClass('done placeholder');
439                    });
440
441                    $('.gritter-item-wrapper ').remove();
442                    $(currentContainer).find('#wpfd-upload-messages').append(wpfdparams.translates.msg_upload_file);
443                    $(currentContainer).find('#wpfd-upload-messages').delay(1200).fadeIn(1200, function () {
444                        $(currentContainer).find('#wpfd-upload-messages').empty();
445                        $(currentContainer).find('.wpfd_process_pause').remove();
446                        $(currentContainer).find('.wpfd_process_block').remove();
447                    });
448
449                    // Call list files
450                    if (currentContainer.parent('.wpfd-upload-form').length) {
451                        // Refresh uploaded files on caching
452                        var downloadlist_sourcecat   = currentContainer.parents('.wpfd-content.wpfd-content-multi').data('category');
453                        var current_category  = currentContainer.parents('.wpfd-content.wpfd-content-multi').find('#current_category_' + downloadlist_sourcecat).val();
454                        var ordering = $(".wpfd-content-multi[data-category=" + downloadlist_sourcecat + "]").find('#current_ordering_' + downloadlist_sourcecat).val();
455                        var orderingDirection = $(".wpfd-content-multi[data-category=" + downloadlist_sourcecat + "]").find('#current_ordering_direction_' + downloadlist_sourcecat).val();
456                        var page_limit = $(".wpfd-content-multi[data-category=" + downloadlist_sourcecat + "]").find('#page_limit_' + downloadlist_sourcecat).val();
457                        var params = $.param({
458                            task: 'files.display',
459                            view: 'files',
460                            id: current_category,
461                            rootcat: downloadlist_sourcecat,
462                            page: page,
463                            orderCol: ordering,
464                            orderDir: orderingDirection,
465                            page_limit: page_limit
466                        });
467                        var tableFilesAjaxUrl = wpfdparams.wpfdajaxurl + params;
468                        if (wpfdTableFilesLocalCache.exist(tableFilesAjaxUrl)) {
469                            wpfdTableFilesLocalCache.remove(tableFilesAjaxUrl);
470                        }
471
472                        upload_type = 'file';
473                        downloadlist_load(downloadlist_sourcecat, current_category, null, upload_type);
474                    }
475                }
476            });
477        });
478
479        uploader.assignBrowse($(currentContainer).find('#upload_button'));
480        uploader.assignBrowse($(currentContainer).find('#upload_folder_button'), true);
481        uploader.assignDrop($(currentContainer).find('.jsWpfdFrontUpload'));
482    }
483
484
485    function downloadlist_load(sourcecat, catid, page, upload_type) {
486        $(document).trigger('wpfd:category-loading');
487        var pathname = window.location.href.replace(window.location.hash, '');
488        var container = $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "]");
489        var downloadlist_empty_subcategories = $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] #wpfd_is_empty_subcategories");
490        var downloadlist_empty_files = $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] #wpfd_is_empty_f
490iles");
491        container.find('#current_category_' + sourcecat).val(catid);
492        container.next('.wpfd-pagination').remove();
493
494        $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").empty();
495        wpfd_remove_loading($(".wpfd-content-multi"));
496        $(".wpfd-content-multi[data-category=" + sourcecat + "] table").after($('#wpfd-loading-wrap').html());
497        $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-categories").empty();
498        let loading_message = '<div class="wpfd-loading-message-section" style="width: 100%; display: block; margin: 20px 10px; box-sizing: border-box;"><span style="font-size: 16px; color: #ffc107;">' + wpfdparams.translates.msg_loading + '</span></div>';
499        if (wpfdparams.allow_loading_message) {
500            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").prepend(loading_message);
501        }
502
503        if (downloadlist_empty_subcategories.length) {
504            downloadlist_empty_subcategories.val('1');
505        }
506
507        if (downloadlist_empty_files.length) {
508            downloadlist_empty_files.val('1');
509        }
510
511        // Get categories
512        var oldCategoryAjax = window.wpfdAjax[downloadlist_root_cat].category;
513        var tableCategoriesAjaxUrl = wpfdparams.wpfdajaxurl + "task=categories.display&view=categories&id=" + catid + "&top=" + sourcecat;
514        if (oldCategoryAjax !== null) {
515            oldCategoryAjax.abort();
516        }
517        window.wpfdAjax[downloadlist_root_cat].category = $.ajax({
518            url: tableCategoriesAjaxUrl,
519            dataType: "json",
520            cache: true,
521            beforeSend: function () {
522                if (container.find('.wpfd-form-search-file-category').length) {
523                    container.find('.wpfd-form-search-file-category').remove();
524                }
525
526                if (wpfdTableCategoriesLocalCache.exist(tableCategoriesAjaxUrl) && upload_type != 'folder') {
527                    var tableTriggerCategories = wpfdTableCategoriesLocalCache.get(tableCategoriesAjaxUrl);
528                    wpfdTableCategoriesLocalCacheTrigger(tableTriggerCategories, sourcecat, page, pathname, catid, container, downloadlist_empty_subcategories, downloadlist_empty_files);
529                    if ($(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-loading-message-section").length) {
530                        $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-loading-message-section").remove();
531                    }
532                    return false;
533                }
534
535                return true;
536            }
537        }).done(function (categories) {
538            if ($(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-loading-message-section").length) {
539                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-loading-message-section").remove();
540            }
541            // Set table categories cache
542            wpfdTableCategoriesLocalCache.set(tableCategoriesAjaxUrl, categories);
543
544            // Search file in category section
545            var $displayFileSearch = container.find('.wpfd_root_category_display_file_search');
546            if ($displayFileSearch.length) {
547                var $themeName = container.find('.wpfd_root_category_theme').val();
548
549                if (typeof (categories.category.correctConvertCategoryId) === 'undefined') {
550                    categories.category.correctConvertCategoryId = 0;
551                }
552
553                var $searchContent = '<form action="" id="adminForm-'+ categories.category.term_id +'" class="wpfd-adminForm wpfd-form-search-file-category" name="adminForm" method="post">' +
554                    '<div id="loader" style="display:none; text-align: center">' +
555                    '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/searchloader.svg" style="margin: 0 auto"/>' +
556                    '</div>' +
557                    '<div class="box-search-filter wpfd-category-search-section">' +
558                    '<div class="searchSection">' +
559                    '<div class="only-file input-group clearfix wpfd_search_input" id="Search_container">' +
560                    '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/search-24.svg" class="material-icons wpfd-icon-search wpfd-search-file-category-icon" />' +
561                    '<input type="text" class="pull-left required txtfilename" name="q" id="txtfilename" autocomplete="off" placeholder="'+ wpfdparams.translates.msg_search_file_category_placeholder +'" value="" />' +
562                    '</div>' +
563                    '<button id="btnsearchbelow" class="btnsearchbelow wpfd-btnsearchbelow" type="button">'+ wpfdparams.translates.msg_search_file_category_search +'</button>' +
564                    '</div>' +
565                    '<input type="hidden" id="filter_catid" class="chzn-select filter_catid" name="catid" value="'+ categories.category.correctConvertCategoryId +'" data-cattype="" data-slug="" />' +
566                    '<input type="hidden" name="theme" value="'+ $themeName +'">' +
567                    '<input type="hidden" name="limit" value="15">' +
568                    '<div id="wpfd-results" class="wpfd-results list-results"></div>' +
569                    '</div>' +
570                    '</form>';
571
572                container.prepend($searchContent);
573                wpfdTableSearchFileCategoryHandle();
574            }
575
576            if (page !== null && page !== undefined) {
577                var stateCatId = catid;
578
579                if (sourcecat === 'all_0' && parseInt(catid) === 0) {
580                    stateCatId = 'all_0';
581                }
582
583                window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + stateCatId + '-' + categories.category.slug + '-p' + page);
584            } else {
585                window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + catid + '-' + categories.category.slug);
586            }
587
588            container.find('#current_category_slug_' + sourcecat).val(categories.category.slug);
589            var tpldownloadlist_sourcecategories = container.parents().find("#wpfd-template-downloadlist-categories-" + sourcecat).html();
590            if (tpldownloadlist_sourcecategories) {
591                var template = Handlebars.compile(tpldownloadlist_sourcecategories);
592                var html = template(categories);
593                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-categories").replaceWith(html);
594            }
595            if (categories.category.breadcrumbs !== undefined) {
596                if (sourcecat.toString() === 'all_0' && catid.toString() !== 'all_0' && parseInt(catid) !== 0) {
597                    categories.category.breadcrumbs = allCategoriesDividerBreadcrumbs + categories.category.breadcrumbs;
598                }
599                $(".wpfd-content-multi[data-category=" + sourcecat + "] .breadcrumbs").html(categories.category.breadcrumbs);
600            }
601            if (downloadlist_tree.length) {
602                var currentTree = container.find('.wpfd-foldertree-downloadlist');
603                currentTree.find('li').removeClass('selected');
604                currentTree.find('i.md').removeClass('md-folder-open').addClass("md-folder");
605
606                currentTree.jaofiletree('open', catid, currentTree);
607
608                var el = currentTree.find('a[data-file="' + catid + '"]').parent();
609                el.find(' > i.md').removeClass("md-folder").addClass("md-folder-open");
610
611                if (!el.hasClass('selected')) {
612                    el.addClass('selected');
613                }
614
615                var ps = currentTree.find('.icon-open-close');
616
617                $.each(ps.get().reverse(), function (i, p) {
618                    if (typeof $(p).data() !== 'undefined' && $(p).data('id') == Number(hash_category_id)) {
619                        hash_category_id = $(p).data('parent_id');
620                        if(parseInt(wpfdparams.allow_category_tree_expanded) !== 1) {
621                            $(p).click();
622                        }
623                    }
624                });
625            }
626
627            var ordering = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_' + sourcecat).val();
628            var orderingDirection = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_direction_' + sourcecat).val();
629            var page_limit = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('#page_limit_' + sourcecat).val();
630            var themeName = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.wpfd_root_category_theme').val();
631            var show_files = 1;
632            var atts_shortcode = window["wpfdfrontend_" + themeName];
633            if (atts_shortcode !== undefined && atts_shortcode.shortcode_param.show_files !== undefined && sourcecat === 'all_0' && (parseInt(catid) === 0 || catid === 'all_0')) {
634                show_files = atts_shortcode.shortcode_param.show_files;
635            }
636
637            var params = $.param({
638                task: 'files.display',
639                view: 'files',
640                id: catid,
641                rootcat: sourcecat,
642                page: page,
643                orderCol: ordering,
644                orderDir: orderingDirection,
645                page_limit: page_limit,
646                show_files: show_files
647            });
648
649            if (downloadlist_empty_subcategories.length) {
650                downloadlist_empty_subcategories.val(categories.categories.length);
651                container.find('table.change_display').removeClass('change_display');
652                downloadlist_fire_empty_category_message(sourcecat);
653            }
654
655            //Get files
656            var oldCategoryAjax = window.wpfdAjax[downloadlist_root_cat].file;
657            var tableFilesAjaxUrl = wpfdparams.wpfdajaxurl + params;
658            if (oldCategoryAjax !== null) {
659                oldCategoryAjax.abort();
660            }
661            window.wpfdAjax[downloadlist_root_cat].file = $.ajax({
662                url: tableFilesAjaxUrl,
663                dataType: "json",
664                cache: true,
665                beforeSend: function () {
666                    if (wpfdTableFilesLocalCache.exist(tableFilesAjaxUrl) && (upload_type === null || upload_type === undefined)) {
667                        var tableFilesTrigger = wpfdTableFilesLocalCache.get(tableFilesAjaxUrl);
668                        wpfdTableFilesLocalCacheTrigger(tableFilesTrigger, sourcecat, downloadlist_empty_files, container, categories, catid, tableFilesAjaxUrl);
669                        if ($(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-loading-message-section").length) {
670                            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-loading-message-section").remove();
671                        }
672
673                        return false;
674                    }
675                    return true;
676                }
677            }).done(function (content) {
678                // Set files local cache
679                if (typeof (content.pagination) !== 'undefined' && content.pagination.length) {
680                    content.cache_pagination = content.pagination;
681                }
682                wpfdTableFilesLocalCache.set(tableFilesAjaxUrl, content);
683
684                if (typeof (content.categoryPassword) !== 'undefined' && content.categoryPassword.length) {
685                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .category-pw-form").remove();
686                    var category_pwf = '<div class="category-pw-form">' + content.categoryPassword + '</div>';
687                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .wpfd-categories").hide();
688                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .mediaTableWrapper").hide();
689                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").append(category_pwf);
690
691                    downloadlist_breadcrum(sourcecat, catid, categories.category);
692
693                    downloadlist_initClick();
694                } else {
695                    if (content.files.length) {
696                        container.find(".downloadlist-download-category").removeClass("display-download-category");
697                    } else {
698                        container.find(".downloadlist-download-category").addClass("display-download-category");
699                    }
700
701                    if (sourcecat.toString() === 'all_0') {
702                        $(".wpfd-content-multi[data-category=" + sourcecat + "]").parent().find('.wpfd-pagination').remove();
703                        $(".wpfd-content-multi[data-category=" + sourcecat + "]").parent().find('.wpfd-content + .wpfd-pagination').remove();
704                    }
705
706                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").after(content.pagination);
707                    delete content.pagination;
708
709                    var tpldownloadlist_source = container.parents().find("#wpfd-template-downloadlist-" + sourcecat).html();
710
711                    if (typeof (tpldownloadlist_source) === 'undefined' && sourcecat.toString() === 'all_0') {
712                        tpldownloadlist_source = container.parents('.wpfd-all-file-category').find("#wpfd-template-downloadlist-" + sourcecat).html();
713                    }
714
715                    var template_downloadlist = Handlebars.compile(tpldownloadlist_source);
716                    var html = template_downloadlist(content);
717                    //html = $('<textarea/>').html(html).val();
718                    $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").append(html);
719                    $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").trigger('change');
720                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .mediaTableMenu").find('input').trigger('change');
721
722                    if ($(".wpfd-content-multi[data-category=" + sourcecat + "] table .file-custom-field.file-url").length) {
723                        var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link';
724                        $(".wpfd-content-multi[data-category=" + sourcecat + "] table .file-custom-field.file-url").each(function () {
725                            var label = $(this).attr('data-field-label');
726                            var url = $(this).attr('data-field-val');
727                            var urlContents = '<div><span>
727' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>';
728                            $(this).empty().append(urlContents);
729                        });
730                    }
731
732                    if ($(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-upload-form").length) {
733                        $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-upload-form").remove();
734                    }
735
736                    if (typeof (content.filepasswords) !== 'undefined') {
737                        $.each(content.filepasswords, function( file_id, pw_form ) {
738                            var content_form = '<td class="full-width">' + pw_form + '</td>';
739                            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').empty();
740                            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form');
741                            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').append(content_form);
742                        });
743                    }
744
745                    if (content.uploadform !== undefined && content.uploadform.length) {
746                        var upload_form_html = '<div class="wpfd-upload-form" style="margin: 20px 10px">';
747                        upload_form_html += content.uploadform;
748                        upload_form_html += '</div>';
749                        $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").append(upload_form_html);
750
751                        if (typeof (Wpfd) === 'undefined') {
752                            Wpfd = {};
753                        }
754
755                        var containers = $(".wpfd-content-multi[data-category=" + sourcecat + "] div[class*=wpfdUploadForm]");
756                        if (containers.length > 0) {
757                            containers.each(function(i, el) {
758                                initUploader($(el));
759                            });
760                        }
761                    }
762
763                    for (var i = 0; i < categories.categories.length; i++) {
764                        downloadlist_cParents[categories.categories[i].term_id] = categories.categories[i];
765                    }
766
767                    downloadlist_breadcrum(sourcecat, catid, categories.category);
768
769                    downloadlist_initClick();
770                    if (typeof wpfdColorboxInit !== 'undefined') {
771                        wpfdColorboxInit();
772                    }
773                    wpfdTrackDownload();
774
775                    if ($(".wpfd-content-multi[data-category=" + sourcecat + "] .category-pw-form").length) {
776                        $(".wpfd-content-multi[data-category=" + sourcecat + "] .category-pw-form").remove();
777                    }
778
779                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .mediaTableWrapper").show();
780
781                    downloadlist_init_pagination($('.wpfd-content-downloadlist[data-category=' + sourcecat + '] + .wpfd-pagination'));
782                    wpfd_remove_loading($(".wpfd-content-multi"));
783                    $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdSelectedFiles").remove();
784                    $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .downloadlist-download-selected").remove();
785                    hideDownloadAllBtn(sourcecat, false);
786
787                    if (downloadlist_empty_files.length) {
788                        downloadlist_empty_files.val(content.files.length);
789                        container.find('table.change_display').removeClass('change_display');
790                        downloadlist_fire_empty_category_message(sourcecat);
791                    }
792                }
793
794                if ($(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .category-pw-form").length) {
795                    hideDownloadAllBtn(sourcecat, true);
796                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .downloadlist-download-category").attr('href', '#');
797                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide();
798                }
799
800                if (content.files.length) {
801                    container.find(".wpfd-container-downloadlist").removeClass("wpfd-downloadlist-hidden");
802                    container.find(".mediaTableWrapper .wpfd-downloadlist thead").show();
803                    container.find(".mediaTableWrapper .mediaTableMenu").show();
804                } else {
805                    container.find(".wpfd-container-downloadlist").addClass("wpfd-downloadlist-hidden");
806                    container.find(".mediaTableWrapper .wpfd-downloadlist thead").css({'display': 'none'});
807                    container.find(".mediaTableWrapper .mediaTableMenu").css({'display': 'none'});
808                }
809
810                wpfdTableDisplayDownloadedFiles();
811                wpfdTableDownloadFiles();
812                wpfdPreviewFileNewName();
813            });
814
815        });
816
817        $(document).trigger('wpfd:category-loaded');
818    }
819
820    function downloadlist_breadcrum(sourcecat, catid, category) {
821        var links = [];
822        var current_Cat = downloadlist_cParents[catid];
823        if (!current_Cat) {
824            $(".wpfd-content-downloadlist[data-category=" + sourcecat + "] .downloadlist-download-category").attr('href', category.linkdownload_cat);
825            return false;
826        }
827
828        links.unshift(current_Cat);
829
830        if (current_Cat.parent !== 0) {
831            while (downloadlist_cParents[current_Cat.parent]) {
832                current_Cat = downloadlist_cParents[current_Cat.parent];
833                if (links.includes(current_Cat)) {
834                    break;
835                }
836                links.unshift(current_Cat);
837            }
838        }
839
840        var html = '';
841
842        if (sourcecat.toString() === 'all_0' && catid.toString() !== 'all_0' && parseInt(catid) !== 0) {
843            html = allCategoriesDividerBreadcrumbs;
844        } else if ((sourcecat.toString() === 'all_0' && catid.toString() === 'all_0')
845            || (sourcecat.toString() === 'all_0' && parseInt(catid) === 0)) {
846            html = allCategoriesBreadcrumbs;
847        }
848
849        for (var i = 0; i < links.length; i++) {
850            if (parseInt(links[i].term_id) === 0) {
851                continue;
852            }
853
854            if (i < links.length - 1) {
855                if (links[i].parent.toString() === 'undefined') {
856                    continue;
857                }
858                html += '<li><a class="catlink" data-idcat="' + links[i].term_id + '" href="javascript:void(0)">' + links[i].name + '</a><span class="divider"> &gt; </span></li>';
859            } else {
860                html += '<li><span>' + links[i].name + '</span></li>';
861            }
862        }
863
864        $(".wpfd-content-downloadlist[data-category=" + sourcecat + "] .wpfd-breadcrumbs-downloadlist li").remove();
865        $(".wpfd-content-downloadlist[data-category=" + sourcecat + "] .wpfd-breadcrumbs-downloadlist").html(html);
866        $(".wpfd-content-downloadlist[data-category=" + sourcecat + "] .downloadlist-download-category").attr('href', category.linkdownload_cat);
867    }
868
869    if (downloadlist_tree.length) {
870        downloadlist_tree.each(function () {
871            var downloadlist_topCat = $(this).parents('.wpfd-content-downloadlist.wpfd-content-multi').data('category');
872            var is_private_category = $(this).parents('.wpfd-content-downloadlist.wpfd-content-multi').hasClass('wpfd-private-category-content');
873            var private_category = is_private_category ? 1 : 0;
874            $(this).jaofiletree({
875                script: wpfdparams.wpfdajaxurl + 'task=categories.getCats&private_category=' + private_category,
876                usecheckboxes: false,
877                root: downloadlist_topCat,
878                showroot: downloadlist_cParents[downloadlist_topCat].name,
879                expanded: parseInt(wpfdparams.allow_category_tree_expanded) === 1 ? true : false,
880                onclick: function (elem, file) {
881                    if (is_private_category) {
882                        return false;
883                    }
884
885                    var downloadlist_topCat = $(elem).parents('.wpfd-content-downloadlist.wpfd-content-multi').data('category');
886                    if (downloadlist_topCat !== file) {
887                        $('.directory', $(elem).parents('.wpfd-content-downloadlist.wpfd-content-multi')).each(function () {
888                            if (!$(this).hasClass('selected') && $(this).find('> ul > li').length === 0) {
889                                $(this).removeClass('expanded');
890                            }
891                        });
892
893                        if (parseInt(wpfdparams.allow_category_tree_expanded) !== 1) {
894                            $(elem).parents('.directory').each(function () {
895                                var $this = $(this);
896                                var category = $this.find(' > a');
897                                var parent = $this.find('.icon-open-close');
898                                if (parent.length > 0) {
899                                    if (typeof downloadlist_cParents[category.data('file')] === 'undefined') {
900                                        downloadlist_cParents[category.data('file')] = {
901                                            parent: parent.data('parent_id'),
902                                            term_id: category.data('file'),
903                                            name: category.text()
904                                        };
905                                    }
906                                }
907                            });
908                        }
909                    }
910
911                    downloadlist_load(downloadlist_topCat, file);
912                }
913            });
914
915            var ele = $(this);
916            setTimeout(function() {
917                ele.find("li.directory a").each(function () {
918                    var tempCatID = $(this).data('catid');
919                    var patentCatID = $(this).data('parent_id');
920                    if (tempCatID == 'all_0') {
921                        downloadlist_cParents[tempCatID] = {parent: 0, term_id: 0, name: $(this).text().trim()};
922                    } else {
923                        downloadlist_cParents[tempCatID] = {parent: patentCatID, term_id: tempCatID, name: $(this).text().trim()};
924                    }
925                });
926            }, 1000);
927        })
928    }
929
930    $('.wpfd-content-downloadlist + .wpfd-pagination').each(function (index, elm) {
931        var $this = $(elm);
932        downloadlist_init_pagination($this);
933    });
934
935    function downloadlist_init_pagination($this) {
936        var number = $this.find('a:not(.current)');
937        var wrap = $this.prev('.wpfd-content-downloadlist');
938        var sourcecat = wrap.data('category');
939        var current_category = wrap.find('#current_category_' + sourcecat).val();
940
941        number.unbind('click').bind('click', function () {
942            var page_number = $(this).attr('data-page');
943            var current_sourcecat = $(this).attr('data-sourcecat');
944            var wrap = $(".wpfd-content-multi[data-category=" + current_sourcecat + "]");
945            var current_category = wrap.find('#current_category_' + sourcecat).val();
946            if (typeof page_number !== 'undefined') {
947                var pathname = window.location.href.replace(window.location.hash, '');
948                var category = $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_' + current_sourcecat).val();
949                var category_slug = $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_slug_' + current_sourcecat).val();
950                var ordering = $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_ordering_' + current_sourcecat).val();
951                var orderingDirection = $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_ordering_direction_' + current_sourcecat).val();
952                var page_limit = $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#page_limit_' + current_sourcecat).val();
953                var stateCatId = category;
954
955                if (current_sourcecat === 'all_0' && parseInt(category) === 0) {
956                    stateCatId = 'all_0';
957                }
958
959                window.history.pushState('', document.title, pathname + '#' + current_sourcecat + '-' + stateCatId + '-' + category_slug + '-p' + page_number);
960
961                $(".wpfd-content-multi[data-category=" + current_sourcecat + "] table:not(.wpfd-results .wpfd-downloadlist) tbody tr:not(.topheader)").remove();
962                $(".wpfd-content-multi[data-category=" + current_sourcecat + "] table:not(.wpfd-results .wpfd-downloadlist)").after($('#wpfd-loading-wrap').html());
963
964                var themeName = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.wpfd_root_category_theme').val();
965                var show_files = 1;
966                var atts_shortcode = window["wpfdfrontend_" + themeName];
967                if (atts_shortcode !== undefined && atts_shortcode.shortcode_param.show_files !== undefined && sourcecat === 'all_0' && (parseInt(catid) === 0 || catid === 'all_0')) {
968                    show_files = atts_shortcode.shortcode_param.show_files;
969                }
970
971                var params = $.param({
972                    task: 'files.display',
973                    view: 'files',
974                    id: current_category,
975                    rootcat: current_sourcecat,
976                    page: page_number,
977                    orderCol: ordering,
978                    orderDir: orderingDirection,
979                    page_limit: page_limit,
980                    show_files: show_files
981                });
982
983                //Get files
984                $.ajax({
985                    url: wpfdparams.wpfdajaxurl + params,
986                    dataType: "json",
987                    beforeSend: function () {
988                        $('html, body').animate({scrollTop: wrap.offset().top}, 'fast');
989                    }
990                }).done(function (content) {
991                    delete content.category;
992                    wrap.next('.wpfd-pagination').remove();
993                    wrap.after(content.pagination);
994                    delete content.pagination;
995                    var tpldownloadlist_source = wrap.parents().find("#wpfd-template-downloadlist-" + current_sourcecat).html();
996                    var template_downloadlist = Handlebars.compile(tpldownloadlist_source);
997                    var html = template_downloadlist(content);
998                    $(".wpfd-content-multi[data-category=" + current_sourcecat + "] table:not(.wpfd-results .wpfd-downloadlist) tbody").append(html);
999                    $(".wpfd-content-multi[data-category=" + current_sourcecat + "] table:not(.wpfd-results .wpfd-downloadlist) tbody").trigger('change');
1000                    $(".wpfd-content-multi[data-category=" + current_sourcecat + "] .mediaTableMenu").find('input').trigger('change');
1001
1002                    if ($(".wpfd-content-multi[data-category=" + current_sourcecat + "] table .file-custom-field.file-url").length) {
1003                        var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link';
1004                        $(".wpfd-content-multi[data-category=" + current_sourcecat + "] table .file-custom-field.file-url").each(function () {
1005                            var label = $(this).attr('data-field-label');
1006                            var url = $(this).attr('data-field-val');
1007                            var urlContents = '<div><span>
1007' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>';
1008                            $(this).empty().append(urlContents);
1009                        });
1010                    }
1011
1012                    if (typeof (content.filepasswords) !== 'undefined') {
1013                        $.each(content.filepasswords, function( file_id, pw_form ) {
1014                            var content_form = '<td class="full-width">' + pw_form + '</td>';
1015                            $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('.file[data-id="' + file_id + '"]').empty();
1016                            $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form');
1017                            $(".wpfd-content-multi[data-category=" + current_sourcecat + "]").find('.file[data-id="' + file_id + '"]').append(content_form);
1018                        });
1019                    }
1020
1021                    if (typeof wpfdColorboxInit !== 'undefined') {
1022                        wpfdColorboxInit();
1023                    }
1024                    downloadlist_init_pagination(wrap.next('.wpfd-pagination'));
1025                    wpfd_remove_loading($(".wpfd-content-multi"));
1026                    wpfdTableDisplayDownloadedFiles();
1027                    wpfdTableDownloadFiles();
1028                    wpfdPreviewFileNewName();
1029                });
1030            }
1031
1032        });
1033    }
1034
1035    function optimize_Show_fields() {
1036        if($('.wpfd-content-downloadlist .wpfd-container-downloadlist').width() < 600) {
1037            $('.mediaTableMenu li').each(function () {
1038                if($(this).find('label').text() == 'Description') {
1039                    $(this).find('input').prop('checked',false);
1040                }
1041            });
1042            $('.wpfd-downloadlist .file_desc').hide();
1043        }
1044    }
1045
1046    function wpfd_Table_with_foldertree() {
1047        //parent-content
1048        $('.wpfd-content-downloadlist').each(function () {
1049            if($(this).children().has('.wpfd-foldertree').length > 0) {
1050                $(this).addClass('wpfdcontent_downloadlist_folder_tree');
1051            } else {
1052                if($(this).hasClass('wpfdcontent_downloadlist_folder_tree')) {
1053                    $(this).removeClass('wpfdcontent_downloadlist_folder_tree');
1054                }
1055            }
1056        });
1057    }
1058
1059    optimize_Show_fields();
1060
1061    wpfd_Table_with_foldertree();
1062
1063    function downloadlist_fire_empty_category_message(category_id) {
1064        if (!category_id) {
1065            return;
1066        }
1067        var root_category = '.wpfd-content-downloadlist.wpfd-content-multi[data-category=' + category_id + ']';
1068        var display_empty_category_message = $(root_category).find('#wpfd_display_empty_category_message').val();
1069        var empty_category_message_val = $(root_category).find('#wpfd_empty_category_message_val').val();
1070        var is_empty_subcategories = $(root_category).find('#wpfd_is_empty_subcategories').val();
1071        var is_empty_files = $(root_category).find('#wpfd_is_empty_files').val();
1072
1073        if (parseInt(display_empty_category_message) !== 1
1074            || parseInt(is_empty_subcategories) !== 0 || parseInt(is_empty_files) !== 0 ) {
1075            return;
1076        }
1077
1078        var code = '<tr class="wpfd-empty-category-message-section">';
1079        code += '<td class="wpfd-empty-category-message full-width">';
1080        code += empty_category_message_val;
1081        code += '</td>';
1082        code += '</tr>';
1083
1084        $(root_category).find('.wpfd-empty-category-message-section').remove();
1085        $(root_category).find('.wpfd-container-downloadlist table.wpfd-downloadlist').addClass('change_display');
1086        $(root_category).find('.wpfd-container-downloadlist table tbody').append(code);
1087    }
1088
1089    var destroy_upload = $('.wpfd-upload-form.destroy');
1090    if (destroy_upload.length) {
1091        destroy_upload.remove();
1092    }
1093
1094    function wpfdTableCategoriesLocalCacheTrigger(tableTriggerCategories, sourcecat, page, pathname, catid, container, downloadlist_empty_subcategories, downloadlist_empty_files) {
1095        var $displayFileSearch = container.find('.wpfd_root_category_display_file_search');
1096
1097        if (typeof (tableTriggerCategories.category.correctConvertCategoryId) === 'undefined') {
1098            tableTriggerCategories.category.correctConvertCategoryId = 0;
1099        }
1100
1101        if ($displayFileSearch.length) {
1102            var $themeName = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.wpfd_root_category_theme').val();
1103            var $searchContent = '<form action="" id="adminForm-'+ tableTriggerCategories.category.term_id +'" class="wpfd-adminForm wpfd-form-search-file-category" name="adminForm" method="post">' +
1104                '<div id="loader" style="display:none; text-align: center">' +
1105                '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/searchloader.svg" style="margin: 0 auto"/>' +
1106                '</div>' +
1107                '<div class="box-search-filter wpfd-category-search-section">' +
1108                '<div class="searchSection">' +
1109                '<div class="only-file input-group clearfix wpfd_search_input" id="Search_container">' +
1110                '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/search-24.svg" class="material-icons wpfd-icon-search wpfd-search-file-category-icon" />' +
1111                '<input type="text" class="pull-left required txtfilename" name="q" id="txtfilename" autocomplete="off" placeholder="'+ wpfdparams.translates.msg_search_file_category_placeholder +'" value="" />' +
1112                '</div>' +
1113                '<button id="btnsearchbelow" class="btnsearchbelow wpfd-btnsearchbelow" type="button">'+ wpfdparams.translates.msg_search_file_category_search +'</button>' +
1114                '</div>' +
1115                '<input type="hidden" id="filter_catid" class="chzn-select filter_catid" name="catid" value="'+ tableTriggerCategories.category.correctConvertCategoryId +'" data-cattype="" data-slug="" />' +
1116                '<input type="hidden" name="theme" value="'+ $themeName +'">' +
1117                '<input type="hidden" name="limit" value="15">' +
1118                '<div id="wpfd-results" class="wpfd-results list-results"></div>' +
1119                '</div>' +
1120                '</form>';
1121
1122            $(".wpfd-content-multi[data-category=" + sourcecat + "]").prepend($searchContent);
1123            wpfdTableSearchFileCategoryHandle();
1124        }
1125
1126        if (page !== null && page !== undefined) {
1127            var stateCatId = catid;
1128
1129            if (sourcecat === 'all_0' && parseInt(catid) === 0) {
1130                stateCatId = 'all_0';
1131            }
1132
1133            window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + stateCatId + '-' + tableTriggerCategories.category.slug + '-p' + page);
1134        } else {
1135            window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + catid + '-' + tableTriggerCategories.category.slug);
1136        }
1137
1138        container.find('#current_category_slug_' + sourcecat).val(tableTriggerCategories.category.slug);
1139        var tpldownloadlist_sourcecategories = container.parents().find("#wpfd-template-downloadlist-categories-" + sourcecat).html();
1140        if (tpldownloadlist_sourcecategories) {
1141            var template = Handlebars.compile(tpldownloadlist_sourcecategories);
1142            var html = template(tableTriggerCategories);
1143            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-categories").replaceWith(html);
1144        }
1145        if (tableTriggerCategories.category.breadcrumbs !== undefined) {
1146            $(".wpfd-content-multi[data-category=" + sourcecat + "] .breadcrumbs").html(tableTriggerCategories.category.breadcrumbs);
1147        }
1148        if (downloadlist_tree.length) {
1149            var currentTree = container.find('.wpfd-foldertree-downloadlist');
1150            currentTree.find('li').removeClass('selected');
1151            currentTree.find('i.md').removeClass('md-folder-open').addClass("md-folder");
1152
1153            currentTree.jaofiletree('open', catid, currentTree);
1154
1155            var el = currentTree.find('a[data-file="' + catid + '"]').parent();
1156            el.find(' > i.md').removeClass("md-folder").addClass("md-folder-open");
1157
1158            if (!el.hasClass('selected')) {
1159                el.addClass('selected');
1160            }
1161
1162            var ps = currentTree.find('.icon-open-close');
1163
1164            $.each(ps.get().reverse(), function (i, p) {
1165                if (typeof $(p).data() !== 'undefined' && $(p).data('id') == Number(hash_category_id)) {
1166                    hash_category_id = $(p).data('parent_id');
1167                    $(p).click();
1168                }
1169            });
1170        }
1171
1172        var ordering = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_' + sourcecat).val();
1173        var orderingDirection = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_direction_' + sourcecat).val();
1174        var page_limit = $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('#page_limit_' + sourcecat).val();
1175        var params = $.param({
1176            task: 'files.display',
1177            view: 'files',
1178            id: catid,
1179            rootcat: sourcecat,
1180            page: page,
1181            orderCol: ordering,
1182            orderDir: orderingDirection,
1183            page_limit: page_limit
1184        });
1185
1186        if (downloadlist_empty_subcategories.length) {
1187            downloadlist_empty_subcategories.val(tableTriggerCategories.categories.length);
1188            container.find('table.change_display').removeClass('change_display');
1189            downloadlist_fire_empty_category_message(sourcecat);
1190        }
1191
1192        //Get files
1193        var oldCategoryAjax = window.wpfdAjax[downloadlist_root_cat].file;
1194        var tableFilesAjaxUrl = wpfdparams.wpfdajaxurl + params;
1195        if (oldCategoryAjax !== null) {
1196            oldCategoryAjax.abort();
1197        }
1198        window.wpfdAjax[downloadlist_root_cat].file = $.ajax({
1199            url: tableFilesAjaxUrl,
1200            dataType: "json",
1201            cache: true,
1202            beforeSend: function () {
1203                if (wpfdTableFilesLocalCache.exist(tableFilesAjaxUrl)) {
1204                    var tableFilesTrigger = wpfdTableFilesLocalCache.get(tableFilesAjaxUrl);
1205                    wpfdTableFilesLocalCacheTrigger(tableFilesTrigger, sourcecat, downloadlist_empty_files, container, tableTriggerCategories, catid, tableFilesAjaxUrl);
1206
1207                    return false;
1208                }
1209
1210                return true;
1211            }
1212        }).done(function (content) {
1213            // Set table files cache
1214            wpfdTableFilesLocalCache.set(tableFilesAjaxUrl, content);
1215
1216            if (typeof (content.categoryPassword) !== 'undefined' && content.categoryPassword.length) {
1217                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .category-pw-form").remove();
1218                var category_pwf = '<div class="category-pw-form">' + content.categoryPassword + '</div>';
1219                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .wpfd-categories").hide();
1220                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .mediaTableWrapper").hide();
1221                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").append(category_pwf);
1222
1223                downloadlist_breadcrum(sourcecat, catid, tableTriggerCategories.category);
1224
1225                downloadlist_initClick();
1226            } else {
1227                if (content.files.length) {
1228                    container.find(".downloadlist-download-category").removeClass("display-download-category");
1229                } else {
1230                    container.find(".downloadlist-download-category").addClass("display-download-category");
1231                }
1232
1233                if (sourcecat.toString() === 'all_0') {
1234                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").parent().find('.wpfd-pagination').remove();
1235                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").parent().find('.wpfd-content + .wpfd-pagination').remove();
1236                }
1237
1238                $(".wpfd-content-multi[data-category=" + sourcecat + "]").after(content.pagination);
1239                delete content.pagination;
1240
1241                var tpldownloadlist_source = container.parents().find("#wpfd-template-downloadlist-" + sourcecat).html();
1242                var template_downloadlist = Handlebars.compile(tpldownloadlist_source);
1243                var html = template_downloadlist(content);
1244                //html = $('<textarea/>').html(html).val();
1245                $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").append(html);
1246                $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").trigger('change');
1247                $(".wpfd-content-multi[data-category=" + sourcecat + "] .mediaTableMenu").find('input').trigger('change');
1248
1249                if ($(".wpfd-content-multi[data-category=" + sourcecat + "] table .file-custom-field.file-url").length) {
1250                    var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link';
1251                    $(".wpfd-content-multi[data-category=" + sourcecat + "] table .file-custom-field.file-url").each(function () {
1252                        var label = $(this).attr('data-field-label');
1253                        var url = $(this).attr('data-field-val');
1254                        var urlContents = '<div><span>
1254' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>';
1255                        $(this).empty().append(urlContents);
1256                    });
1257                }
1258
1259                if ($(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-upload-form").length) {
1260                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-upload-form").remove();
1261                }
1262
1263                if (typeof (content.filepasswords) !== 'undefined') {
1264                    $.each(content.filepasswords, function( file_id, pw_form ) {
1265                        var content_form = '<td class="full-width">' + pw_form + '</td>';
1266                        $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').empty();
1267                        $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form');
1268                        $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').append(content_form);
1269                    });
1270                }
1271
1272                if (content.uploadform !== undefined && content.uploadform.length) {
1273                    var upload_form_html = '<div class="wpfd-upload-form" style="margin: 20px 10px">';
1274                    upload_form_html += content.uploadform;
1275                    upload_form_html += '</div>';
1276                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").append(upload_form_html);
1277
1278                    if (typeof (Wpfd) === 'undefined') {
1279                        Wpfd = {};
1280                    }
1281
1282                    var containers = $(".wpfd-content-multi[data-category=" + sourcecat + "] div[class*=wpfdUploadForm]");
1283                    if (containers.length > 0) {
1284                        containers.each(function(i, el) {
1285                            initUploader($(el));
1286                        });
1287                    }
1288                }
1289
1290                for (var i = 0; i < tableTriggerCategories.categories.length; i++) {
1291                    downloadlist_cParents[tableTriggerCategories.categories[i].term_id] = tableTriggerCategories.categories[i];
1292                }
1293
1294                downloadlist_breadcrum(sourcecat, catid, tableTriggerCategories.category);
1295
1296                downloadlist_initClick();
1297                if (typeof wpfdColorboxInit !== 'undefined') {
1298                    wpfdColorboxInit();
1299                }
1300                wpfdTrackDownload();
1301
1302                if ($(".wpfd-content-multi[data-category=" + sourcecat + "] .category-pw-form").length) {
1303                    $(".wpfd-content-multi[data-category=" + sourcecat + "] .category-pw-form").remove();
1304                }
1305
1306                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .mediaTableWrapper").show();
1307
1308                downloadlist_init_pagination($('.wpfd-content-downloadlist[data-category=' + sourcecat + '] + .wpfd-pagination'));
1309                wpfd_remove_loading($(".wpfd-content-multi"));
1310                $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdSelectedFiles").remove();
1311                $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .downloadlist-download-selected").remove();
1312                hideDownloadAllBtn(sourcecat, false);
1313
1314                if (downloadlist_empty_files.length) {
1315                    downloadlist_empty_files.val(content.files.length);
1316                    container.find('table.change_display').removeClass('change_display');
1317                    downloadlist_fire_empty_category_message(sourcecat);
1318                }
1319            }
1320
1321            if ($(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .category-pw-form").length) {
1322                hideDownloadAllBtn(sourcecat, true);
1323                $(".wpfd-content-multi[data-category=" + sourcecat + "] .downloadlist-download-category").attr('href', '#');
1324                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide();
1325            }
1326
1327            wpfdTableDisplayDownloadedFiles();
1328            wpfdTableDownloadFiles();
1329            wpfdPreviewFileNewName();
1330        });
1331    }
1332
1333    function wpfdTableFilesLocalCacheTrigger(tableFilesTrigger, sourcecat, downloadlist_empty_files, container, categories, catid, tableFilesAjaxUrl) {
1334        if (typeof (tableFilesTrigger.categoryPassword) !== 'undefined' && tableFilesTrigger.categoryPassword.length) {
1335            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .category-pw-form").remove();
1336            var category_pwf = '<div class="category-pw-form">' + tableFilesTrigger.categoryPassword + '</div>';
1337            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .wpfd-categories").hide();
1338            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .mediaTableWrapper").hide();
1339            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").append(category_pwf);
1340
1341            downloadlist_breadcrum(sourcecat, catid, categories.category);
1342
1343            downloadlist_initClick();
1344        } else {
1345            if (tableFilesTrigger.files.length) {
1346                container.find(".downloadlist-download-category").removeClass("display-download-category");
1347            } else {
1348                container.find(".downloadlist-download-category").addClass("display-download-category");
1349            }
1350            $(".wpfd-content-multi[data-category=" + sourcecat + "]").after(tableFilesTrigger.cache_pagination);
1351
1352            var tpldownloadlist_source = container.parents().find("#wpfd-template-downloadlist-" + sourcecat).html();
1353            var template_downloadlist = Handlebars.compile(tpldownloadlist_source);
1354            var html = template_downloadlist(tableFilesTrigger);
1355            $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").append(html);
1356            $(".wpfd-content-multi[data-category=" + sourcecat + "] table tbody").trigger('change');
1357            $(".wpfd-content-multi[data-category=" + sourcecat + "] .mediaTableMenu").find('input').trigger('change');
1358
1359            if ($(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-upload-form").length) {
1360                $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-upload-form").remove();
1361            }
1362
1363            if (typeof (tableFilesTrigger.filepasswords) !== 'undefined') {
1364                $.each(tableFilesTrigger.filepasswords, function( file_id, pw_form ) {
1365                    var content_form = '<td class="full-width">' + pw_form + '</td>';
1366                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').empty();
1367                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form');
1368                    $(".wpfd-content-multi[data-category=" + sourcecat + "]").find('.file[data-id="' + file_id + '"]').append(content_form);
1369                });
1370            }
1371
1372            if (tableFilesTrigger.uploadform !== undefined && tableFilesTrigger.uploadform.length) {
1373                var upload_form_html = '<div class="wpfd-upload-form" style="margin: 20px 10px">';
1374                upload_form_html += tableFilesTrigger.uploadform;
1375                upload_form_html += '</div>';
1376                $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist").append(upload_form_html);
1377
1378                if (typeof (Wpfd) === 'undefined') {
1379                    Wpfd = {};
1380                }
1381
1382                var containers = $(".wpfd-content-multi[data-category=" + sourcecat + "] div[class*=wpfdUploadForm]");
1383                if (containers.length > 0) {
1384                    containers.each(function(i, el) {
1385                        initUploader($(el));
1386                    });
1387                }
1388            }
1389
1390            for (var i = 0; i < categories.categories.length; i++) {
1391                downloadlist_cParents[categories.categories[i].term_id] = categories.categories[i];
1392            }
1393
1394            downloadlist_breadcrum(sourcecat, catid, categories.category);
1395
1396            downloadlist_initClick();
1397            if (typeof wpfdColorboxInit !== 'undefined') {
1398                wpfdColorboxInit();
1399            }
1400            wpfdTrackDownload();
1401
1402            if ($(".wpfd-content-multi[data-category=" + sourcecat + "] .category-pw-form").length) {
1403                $(".wpfd-content-multi[data-category=" + sourcecat + "] .category-pw-form").remove();
1404            }
1405
1406            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .mediaTableWrapper").show();
1407
1408            downloadlist_init_pagination($('.wpfd-content-downloadlist[data-category=' + sourcecat + '] + .wpfd-pagination'));
1409            wpfd_remove_loading($(".wpfd-content-multi"));
1410            $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdSelectedFiles").remove();
1411            $(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .downloadlist-download-selected").remove();
1412            hideDownloadAllBtn(sourcecat, false);
1413
1414            if (downloadlist_empty_files.length) {
1415                downloadlist_empty_files.val(tableFilesTrigger.files.length);
1416                container.find('table.change_display').removeClass('change_display');
1417                downloadlist_fire_empty_category_message(sourcecat);
1418            }
1419        }
1420
1421        if ($(".wpfd-content-downloadlist.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-downloadlist .category-pw-form").length) {
1422            hideDownloadAllBtn(sourcecat, true);
1423            $(".wpfd-content-multi[data-category=" + sourcecat + "] .downloadlist-download-category").attr('href', '#');
1424            $(".wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide();
1425        }
1426
1427        if (tableFilesTrigger.files.length) {
1428            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-container-downloadlist").removeClass("wpfd-downloadlist-hidden");
1429            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".mediaTableWrapper .wpfd-downloadlist thead").show();
1430            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".mediaTableWrapper .mediaTableMenu").show();
1431        } else {
1432            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".wpfd-container-downloadlist").addClass("wpfd-downloadlist-hidden");
1433            $(".wpfd-content-multi[data-category=" + sourcecat + "]").find(".mediaTableWrapper .mediaTableMenu").css({'display': 'none'});
1434        }
1435
1436        wpfdTableDisplayDownloadedFiles();
1437        wpfdTableDownloadFiles();
1438        wpfdPreviewFileNewName();
1439    }
1440
1441    // Search file category
1442    function wpfdTableCategoryAjaxSearch(element, ordering, direction, pushState = true) {
1443        var $ = jQuery;
1444        var sform = element;
1445        var $key = $(sform).find('input[name=q]').val();
1446        var $placeholder = $(sform).find('input[name=q]').attr('placeholder');
1447
1448        // Avoid conflict key search
1449        if ($key.toString() === $placeholder.toString()) {
1450            $key = '';
1451        }
1452
1453        // Get the form data
1454        var formData = {
1455            'q': $key,
1456            'catid': $(sform).find('[name=catid]').val(),
1457            'theme': $(sform).find('[name=theme]').val(),
1458            'limit': $(sform).find('[name=limit]').val(),
1459            'theme_column': $(sform).find('[name=theme_column]').val()
1460        };
1461
1462        formData = cleanObj(formData);
1463
1464        if (jQuery.isEmptyObject(formData) ||
1465            (typeof (formData.q) === 'undefined' &&
1466                typeof (formData.catid) !== 'undefined' &&
1467                parseInt(formData.catid) === 0) || typeof (formData.q) === 'undefined') {
1468            $(element).find(".txtfilename").focus();
1469            return false;
1470        }
1471
1472        if ((typeof ordering !== 'undefined') && ordering) formData.ordering = ordering;
1473        if ((typeof direction !== 'undefined') && direction) formData.dir = direction;
1474
1475        // Pagination
1476        if (pushState) {
1477            var filter_url = jQuery.param(formData);
1478            var currentUrl = window.location.search;
1479            var pushUrl;
1480            if (typeof URLSearchParams !== 'undefined') {
1481                var currentFilters = new URLSearchParams(currentUrl.substring(1));
1482                Object.keys(formData).forEach(function (key) {
1483                    if (currentFilters.has(key)) {
1484                        currentFilters.delete(key);
1485                    }
1486                });
1487                if (currentUrl.substring(1) === '?' && currentFilters.toString() !== '') {
1488                    pushUrl = currentFilters.toString() + '&' + filter_url;
1489
1490                } else {
1491                    pushUrl = '?' + filter_url;
1492                }
1493
1494                window.history.pushState(formData, "", pushUrl);
1495            }
1496        }
1497
1498        $.ajax({
1499            method: "POST",
1500            url: wpfdparams.wpfdajaxurl + "task=search.display",
1501            data: formData,
1502            beforeSend: function () {
1503                $(element).find(".wpfd-results").html('');
1504                $(element).find(".wpfd-results").prepend($(element).find("#loader").clone().show());
1505            },
1506            success: function (result) {
1507                $(element).find(".wpfd_search_file_suggestion").html('');
1508                $(element).find(".wpfd_search_file_suggestion").fadeOut(300);
1509
1510                $(element).find(".wpfd-results").html(result);
1511                $(element).find(".wpfd-results .wpfd-downloadlist").addClass('wpfd-downloadlist-search');
1512                if ($(element).find(".wpfd-results .wpfd-form-search-file-category").length) {
1513                    $(element).find(".wpfd-results .wpfd-form-search-file-category").remove();
1514                }
1515                wpfdTableInitSorting();
1516                if (typeof wpfdColorboxInit !== 'undefined') {
1517                    wpfdColorboxInit();
1518                }
1519            }
1520        });
1521    }
1522
1523    // Sort initial
1524    function wpfdTableInitSorting() {
1525        jQuery('.orderingCol').click(function (e) {
1526            e.preventDefault();
1527            var ordering = jQuery(this).data('ordering');
1528            var direction = jQuery(this).data('direction');
1529            wpfdTableCategoryAjaxSearch(ordering, direction);
1530        });
1531
1532        jQuery(".list-results #limit").change(function (e) {
1533            e.preventDefault();
1534            jQuery('input[name="limit"]').val(jQuery(this).val());
1535            var formID = '#' + jQuery(this).closest('form').attr('id');
1536            wpfdTableCategoryAjaxSearch(formID);
1537            return false;
1538        });
1539    }
1540
1541    function wpfdTableSearchFileCategoryHandle() {
1542        $(".wpfd-content .wpfd-adminForm").submit(function (e) {
1543            e.preventDefault();
1544            return false;
1545        });
1546
1547        $('.wpfd-content .txtfilename').on('keyup', function(e) {
1548            var $this = $(this);
1549            if (e.keyCode === 13 || e.which === 13 || e.key === 'Enter')
1550            {
1551                e.preventDefault();
1552
1553                if ($this.val() === '') {
1554                    return;
1555                }
1556
1557                var formID = '#' + $this.closest('form').attr('id');
1558                wpfdTableCategoryAjaxSearch(formID);
1559
1560                return;
1561            }
1562        });
1563
1564        // Ajax filters
1565        $(".wpfd-content .btnsearchbelow").on('click', function (e) {
1566            e.preventDefault();
1567            var formID = '#' + $(this).closest('form').attr('id');
1568            wpfdTableCategoryAjaxSearch(formID);
1569            return false;
1570        });
1571    }
1572    wpfdTableSearchFileCategoryHandle();
1573
1574    function wpfdTableDisplayDownloadedFiles() {
1575        var fileDownload = $('.wpfd-content.wpfd-content-downloadlist .file');
1576        var linkDownload = $('.wpfd-content.wpfd-content-downloadlist .wpfd_downloadlink');
1577        var user_login_id = wpfdparams.wpfd_user_login_id;
1578        if (linkDownload.length) {
1579            linkDownload.on('click', function () {
1580                var fileId = $(this).parents('.file').data('id');
1581                var isDownloadedFile = localStorage.getItem('wpfd_downloaded_file_' + user_login_id + '_' + fileId);
1582                if (isDownloadedFile === null) {
1583                    localStorage.setItem('wpfd_downloaded_file_' + user_login_id + '_' + fileId, 'yes');
1584                    $(this).parents('.file').addClass('is_downloaded');
1585                }
1586            });
1587        }
1588
1589        if (fileDownload.length) {
1590            fileDownload.each(function () {
1591                var id = $(this).data('id');
1592                var isFileDownload = localStorage.getItem('wpfd_downloaded_file_' + user_login_id + '_' + id);
1593                if (isFileDownload) {
1594                    $(this).addClass('is_downloaded');
1595                }
1596            });
1597        }
1598    }
1599    wpfdTableDisplayDownloadedFiles();
1600
1601    function wpfdTableDownloadFiles() {
1602        if (!wpfdparams.offRedirectLinkDownloadImageFile) {
1603            $('.file.png .wpfd_downloadlink, .file.jpg .wpfd_downloadlink, .file.jpeg .wpfd_downloadlink, .file.gif .wpfd_downloadlink').on('click', function (event) {
1604                event.preventDefault();
1605                var fileId = $(this).parents('.file').data('id');
1606                var categoryId = $(this).parents('.file').data('catid');
1607                var cloudType = $(this).parents('.wpfd-content-downloadlist').find('.wpfd_root_category_type').val();
1608
1609                if (!fileId || !categoryId) {
1610                    return false;
1611                }
1612
1613                if ($(this).find('.wpfd-add-to-cart').length) {
1614                    return false;
1615                }
1616
1617                window.location.href = wpfdparams.site_url + "?wpfd_action=wpfd_download_file&wpfd_file_id=" + fileId + "&wpfd_category_id=" + categoryId + "&cloudType=" + cloudType;
1618            });
1619        }
1620    }
1621    wpfdTableDownloadFiles();
1622
1623    function wpfdTableInitDefaultOption() {
1624        var $           = jQuery;
1625        var checkitem   = $('.wpfdTableMenu .media-item');
1626        var showList    = [];
1627        if (checkitem.length) {
1628            checkitem.each(function () {
1629                if ($(this).prop("checked") == true) {
1630                    showList.push($(this).val());
1631                }
1632            });
1633            if (showList.length > 0) {
1634                jQuery("#total-media-list").val(showList.join(","));
1635            } else {
1636                jQuery("#total-media-list").val("");
1637            }
1638            var desc = "";
1639            var category = "";
1640            var ver = "";
1641            var size = "";
1642            var hits = "";
1643            var dateadd = "";
1644            var download = "";
1645            for(var i = 0; i<showList.length;i++) {
1646                if(showList[i] == "Description" ) {
1647                    desc = "Description";
1648                }
1649                if(showList[i] == "Category" ) {
1650                    category = "Category";
1651                }
1652                if(showList[i] == "Version") {
1653                    ver = "Version";
1654                }
1655                if(showList[i] == "Size") {
1656                    size = "Size";
1657                }
1658                if(showList[i] == "Hits") {
1659                    hits = "Hits";
1660                }
1661                if(showList[i] == "Date added") {
1662                    dateadd = "Date added";
1663                }
1664                if(showList[i] == "Download") {
1665                    download = "Download";
1666                }
1667            }
1668            if(desc === "Description") {
1669                jQuery(".file_desc").removeClass('filehidden');
1670            } else {
1671                jQuery(".file_desc").addClass('filehidden');
1672            }
1673            if(category === "Category") {
1674                jQuery(".file_category").removeClass('filehidden');
1675            } else {
1676                jQuery(".file_category").addClass('filehidden');
1677            }
1678            if (ver === "Version") {
1679                jQuery(".file_version").removeClass('filehidden');
1680            } else {
1681                jQuery(".file_version").addClass('filehidden');
1682            }
1683            if (size === "Size") {
1684                jQuery(".file_size").removeClass('filehidden');
1685            } else {
1686                jQuery(".file_size").addClass('filehidden');
1687            }
1688            if (hits === "Hits") {
1689                jQuery(".file_hits").removeClass('filehidden');
1690            } else {
1691                jQuery(".file_hits").addClass('filehidden');
1692            }
1693            if (dateadd === "Date added") {
1694                jQuery(".file_created").removeClass('filehidden');
1695            } else {
1696                jQuery(".file_created").addClass('filehidden');
1697            }
1698            if (download === "Download") {
1699                jQuery(".file_download_tbl").removeClass('filehidden');
1700            } else {
1701                jQuery(".file_download_tbl").addClass('filehidden');
1702            }
1703
1704            var wpfdTable = $('.wpfd-results table.wpfd-search-result');
1705            wpfdTable.each(function() {
1706                var visibleRow = $(this).find('tbody tr');
1707                visibleRow.each(function() {
1708                    var visibleColumn = $(this).find('td:not(.filehidden)');
1709                    visibleColumn.each(function() {
1710                        if ($(this).is(visibleColumn.last())) {
1711                            $(this).attr('colspan', 2);
1712                        } else {
1713                            $(this).attr('colspan', 1);
1714                        }
1715                    })
1716                })
1717            })
1718        }
1719
1720    }
1721    function wpfdTableInitUploadDefaultOption(container) {
1722        var $           = jQuery;
1723        var checkitem   = $(".file-upload-content[data-container='" + container + "'] .wpfdTableMenu .media-item");
1724        var showList    = [];
1725        checkitem.each(function () {
1726            if ($(this).prop("checked") == true) {
1727                showList.push($(this).val());
1728            }
1729        });
1730        if (showList.length > 0) {
1731            jQuery(".file-upload-content[data-container='" + container + "'] #total-media-list").val(showList.join(","));
1732        } else {
1733            jQuery(".file-upload-content[data-container='" + container + "'] #total-media-list").val("");
1734        }
1735        var desc        = "";
1736        var category    = "";
1737        var ver         = "";
1738        var size        = "";
1739        var hits        = "";
1740        var dateadd     = "";
1741        var download    = "";
1742        for(var i = 0; i<showList.length;i++) {
1743            if(showList[i] == "Description" ) {
1744                desc = "Description";
1745            }
1746            if(showList[i] == "Category") {
1747                category = "Category";
1748            }
1749            if(showList[i] == "Version") {
1750                ver = "Version";
1751            }
1752            if(showList[i] == "Size") {
1753                size = "Size";
1754            }
1755            if(showList[i] == "Hits") {
1756                hits = "Hits";
1757            }
1758            if(showList[i] == "Date added") {
1759                dateadd = "Date added";
1760            }
1761            if(showList[i] == "Download") {
1762                download = "Download";
1763            }
1764        }
1765        if(desc === "Description") {
1766            jQuery(".file-upload-content[data-container='" + container + "'] .file_desc").removeClass('filehidden');
1767        } else {
1768            jQuery(".file-upload-content[data-container='" + container + "'] .file_desc").addClass('filehidden');
1769        }
1770        if(category === "Category") {
1771            jQuery(".file-upload-content[data-container='" + container + "'] .file_category").removeClass('filehidden');
1772        } else {
1773            jQuery(".file-upload-content[data-container='" + container + "'] .file_category").addClass('filehidden');
1774        }
1775        if (ver === "Version") {
1776            jQuery(".file-upload-content[data-container='" + container + "'] .file_version").removeClass('filehidden');
1777        } else {
1778            jQuery(".file-upload-content[data-container='" + container + "'] .file_version").addClass('filehidden');
1779        }
1780        if (size === "Size") {
1781            jQuery(".file-upload-content[data-container='" + container + "'] .file_size").removeClass('filehidden');
1782        } else {
1783            jQuery(".file-upload-content[data-container='" + container + "'] .file_size").addClass('filehidden');
1784        }
1785        if (hits === "Hits") {
1786            jQuery(".file-upload-content[data-container='" + container + "'] .file_hits").removeClass('filehidden');
1787        } else {
1788            jQuery(".file-upload-content[data-container='" + container + "'] .file_hits").addClass('filehidden');
1789        }
1790        if (dateadd === "Date added") {
1791            jQuery(".file-upload-content[data-container='" + container + "'] .file_created").removeClass('filehidden');
1792        } else {
1793            jQuery(".file-upload-content[data-container='" + container + "'] .file_created").addClass('filehidden');
1794        }
1795        if (download === "Download") {
1796            jQuery(".file-upload-content[data-container='" + container + "'] .file_download_tbl").removeClass('filehidden');
1797        } else {
1798            jQuery(".file-upload-content[data-container='" + container + "'] .file_download_tbl").addClass('filehidden');
1799        }
1800    }
1801    function wpfdTableShowViewOption() {
1802        var $         = jQuery;
1803        var checkitem = $('.wpfdTableMenu .media-item');
1804        $(document).on("click", ".wpfdTableMenu", function() {
1805            $(this).addClass('showlist');
1806            $(this).removeClass('mediaTableMenuClosed');
1807            $(document).on("click", checkitem, function() {
1808                if (!$(this).parents('.file-upload-content').length) {
1809                    wpfdTableInitDefaultOption();
1810                    if($(".list-results .file_desc").hasClass("filehidden") && $(".list-results .file_created").hasClass("filehidden") ) {
1811                        $(".list-results .file_download_tbl").addClass("file_download_inline");
1812                    } else {
1813                        $(".list-results .file_download_tbl").removeClass("file_download_inline");
1814                    }
1815                    var checkall = $(".list-results .table thead th");
1816                    if(!checkall.hasClass("filehidden")) {
1817                        $(".list-results .file_title").addClass("adv_file_tt");
1818                    } else {
1819                        $(".list-results .file_title").removeClass("adv_file_tt");
1820                    }
1821                } else {
1822                    var container = $(this).parents('.file-upload-content').data('container');
1823                    wpfdTableInitUploadDefaultOption(container);
1824                    if($(".file-upload-content[data-container='" + container + "'] .list-results .file_desc").hasClass("filehidden") && $(".file-upload-content[data-container='" + container + "'] .list-results .file_created").hasClass("filehidden") ) {
1825                        $(".file-upload-content[data-container='" + container + "'] .list-results .file_download_tbl").addClass("file_download_inline");
1826                    } else {
1827                        $(".file-upload-content[data-container='" + container + "'] .list-results .file_download_tbl").removeClass("file_download_inline");
1828                    }
1829                    var checkall = $(".file-upload-content[data-container='" + container + "'] .list-results .table thead th");
1830                    if(!checkall.hasClass("filehidden")) {
1831                        $(".file-upload-content[data-container='" + container + "'] .list-results .file_title").addClass("adv_file_tt");
1832                    } else {
1833                        $(".file-upload-content[data-container='" + container + "'] .list-results .file_title").removeClass("adv_file_tt");
1834                    }
1835                }
1836            });
1837
1838            $(document).mouseup(e => {
1839                if (!$(".wpfdTableMenu").is(e.target)
1840                    && $(".wpfdTableMenu").has(e.target).length === 0)
1841                {
1842                    $(".wpfdTableMenu").removeClass('showlist');
1843                    $(".wpfdTableMenu").show();
1844                }
1845            });
1846
1847            // Close media option when clicking outside
1848            $(document).mouseup(function(e)
1849            {
1850                var container = $(".wpfd-content.wpfd-content-downloadlist .mediaTableMenu");
1851
1852                // if the target of the click isn't the container nor a descendant of the container
1853                if (!container.is(e.target) && container.has(e.target).length === 0)
1854                {
1855                    if (!container.hasClass('wpfdTableMenu')) {
1856                        container.hide();
1857                    }
1858                    container.addClass('mediaTableMenuClosed');
1859                }
1860            });
1861        });
1862    }
1863    wpfdTableInitDefaultOption();
1864    wpfdTableShowViewOption();
1865    if (jQuery('.wpfd-results-tooltip').length) {
1866        jQuery('.wpfd-results-tooltip').qtip({
1867            content: {
1868                attr: 'title',
1869            },
1870            position: {
1871                my: 'bottom left',
1872                at: 'top left',
1873            },
1874            style: {
1875                tip: {
1876                    corner: true,
1877                },
1878                classes: 'wpfd-qtip qtip-rounded wpfd-qtip-dashboard',
1879            },
1880            show: 'mouseover',
1881            hide: {
1882                fixed: true,
1883                delay: 10,
1884            }
1885        });
1886    }
1887
1888    function wpfdPreviewFileNewName()
1889    {
1890        $('.wpfd_previewlink').click(function (e) {
1891            var newWindow = $(this).attr('target');
1892            var previewLink = $(this).attr('href');
1893            var fileTitle = $(this).parents('.file').find('.wpfd_downloadlink').attr('title');
1894            var fileName = fileTitle;
1895            fileName = fileName ? fileName : 'WPFD Preview File';
1896
1897            if (newWindow === '_blank' && (previewLink.indexOf('previews') !== -1) && previewLink.indexOf('docs.google.com') === -1) {
1898                e.preventDefault();
1899                var win = window.open(previewLink, '_blank');
1900                win.onload = function () {
1901                    setTimeout(function () {
1902                        win.document.title = fileName;
1903                    }, 100);
1904
1905                    setTimeout(function () {
1906                        $(win.document.head).append('<title>'+ fileName +'</title>');
1907                    }, 3000);
1908                };
1909
1910                setTimeout(function () {
1911                    if (win.document.title !== fileName) {
1912                        win.document.title = fileName;
1913                    }
1914                }, 1000);
1915
1916                setTimeout(function () {
1917                    if (win.document.title !== fileName) {
1918                        win.document.title = fileName;
1919                    }
1920                }, 3000);
1921            }
1922        });
1923    }
1924    wpfdPreviewFileNewName();
1925});
1926
1927// Table categories local cache
1928var wpfdTableCategoriesLocalCache = {
1929    data: {},
1930    remove: function (url) {
1931        delete wpfdTableCategoriesLocalCache.data[url];
1932    },
1933    exist: function (url) {
1934        return wpfdTableCategoriesLocalCache.data.hasOwnProperty(url) && wpfdTableCategoriesLocalCache.data[url] !== null;
1935    },
1936    get: function (url) {
1937        return wpfdTableCategoriesLocalCache.data[url];
1938    },
1939    set: function (url, cachedData) {
1940        wpfdTableCategoriesLocalCache.remove(url);
1941        wpfdTableCategoriesLocalCache.data[url] = cachedData;
1942    }
1943};
1944
1945// Table files local cache
1946var wpfdTableFilesLocalCache = {
1947    data: {},
1948    remove: function (url) {
1949        delete wpfdTableFilesLocalCache.data[url];
1950    },
1951    exist: function (url) {
1952        return wpfdTableFilesLocalCache.data.hasOwnProperty(url) && wpfdTableFilesLocalCache.data[url] !== null;
1953    },
1954    get: function (url) {
1955        return wpfdTableFilesLocalCache.data[url];
1956    },
1957    set: function(url, cachedData) {
1958        wpfdTableFilesLocalCache.remove(url);
1959        wpfdTableFilesLocalCache.data[url] = cachedData;
1960    }
1961};

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.