1/** 2 * WP File Download 3 * 4 * @package WP File Download 5 * @author Joomunited 6 * @version 1.0 7 */ 8 9jQuery(document).ready(function ($) { 10 // var sourcefiles = $("#wpfd-template-files").html(); 11 // var sourcecategories = $("#wpfd-template-categories").html(); 12 var default_hash = window.location.hash; 13 var tree = $('.wpfd-foldertree-default'); 14 var tree_source_cat = $('.wpfd-content-default').data('category'); 15 var allCategoriesBreadcrumbs = '<li><a class="catlink" data-idcat="all_0" href="javascript:void(0);">' + wpfdparams.translates.wpfd_all_categories + '</a></li>'; 16 var allCategoriesDividerBreadcrumbs = '<li><a class="catlink" data-idcat="all_0" href="javascript:void(0);">' + wpfdparams.translates.wpfd_all_categories + '</a><span class="divider"> > </span></li>'; 17 var cParents = {}; 18 if (window.wpfdAjax === undefined) { 19 window.wpfdAjax = {}; 20 } 21 window.wpfdAjax[tree_source_cat] = {category: null, file: null}; 22 23 $(".wpfd-content-default").each(function () { 24 var topCat = $(this).data('category'); 25 if (topCat == 'all_0') { 26 cParents[topCat] = {parent: 0, term_id: 0, name: $(this).find("h2").text().trim()}; 27 } else { 28 cParents[topCat] = {parent: 0, term_id: topCat, name: $(this).find("h2").text().trim()}; 29 } 30 31 $(this).find(".wpfdcategory.catlink").each(function () { 32 var tempidCat = $(this).data('idcat'); 33 cParents[tempidCat] = {parent: topCat, term_id: tempidCat, name: $(this).text().trim()}; 34 }); 35 initInputSelected(topCat); 36 initDownloadSelected(topCat); 37 }); 38 39 Handlebars.registerHelper('bytesToSize', function (bytes) { 40 if (typeof bytes === "undefined") { 41 return 'n/a'; 42 } 43 44 return bytes.toString().toLowerCase() === 'n/a' ? bytes : bytesToSize(parseInt(bytes)); 45 }); 46 47 Handlebars.registerHelper("xif", function(param, second, options) { 48 if (param === second) { 49 return options.fn(this); 50 } else { 51 return options.inverse(this); 52 } 53 }); 54 55 Handlebars.registerHelper('UrlCustomFields', function (url) { 56 if (typeof url === "undefined") { 57 return ''; 58 } 59 60 return bytes.toString().toLowerCase() === 'n/a' ? bytes : bytesToSize(parseInt(bytes)); 61 }); 62 63 Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) { 64 return (arg1 === arg2) ? options.fn(this) : options.inverse(this); 65 }); 66 67 function default_initClick() { 68 $(document).off('click', '.wpfd-content-default .catlink').on('click', '.wpfd-content-default .catlink', function(e) { 69 var ctheme = $(this).parents('.wpfd-content').find('.wpfd_root_category_theme').val(); 70 var c_root_cat = $(this).parents('.wpfd-content').find('.wpfd_root_category_id').val(); 71 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + c_root_cat + "]"; 72 var current_category = $(rootCat).find('#current_category_' + c_root_cat).val(); 73 $(".wpfd-content[data-category=" + $(this).parents('.wpfd-content-'+ctheme).data('category') + "] .wpfd-container-"+ctheme).find('.wpfd-categories .wpfdcategory.catlink').each(function () { 74 var tempidCat = $(this).data('idcat'); 75 var catName = ''; 76 if ($(this).attr('title') !== undefined) { 77 catName = $(this).attr('title').trim(); 78 } else if ($(this).data('title') !== undefined) { 79 catName = $(this).data('title').trim(); 80 } 81 cParents[tempidCat] = {parent: current_category, term_id: tempidCat, name: catName}; 82 }); 83 default_load(c_root_cat, $(this).data('idcat')); 84 return false; 85 }) 86 } 87 88 function initInputSelected(sc) { 89 $(document).on('change', ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "] input.cbox_file_download", function () { 90 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "]"; 91 var selectedFiles = $(rootCat + " input.cbox_file_download:checked"); 92 var filesId = []; 93 if (selectedFiles.length) { 94 selectedFiles.each(function (index, file) { 95 filesId.push($(file).data('id')); 96 }); 97 } 98 if (filesId.length > 0) { 99 $(rootCat + " .wpfdSelectedFiles").remove(); 100 $('<input type="hidden" class="wpfdSelectedFiles" value="' + filesId.join(',') + '" />') 101 .insertAfter($(rootCat).find(" #current_category_slug_" + sc)); 102 hideDownloadAllBtn(sc, true); 103 $(rootCat + " .default-download-selected").remove(); 104 var downloadSelectedBtn = $('<a href="javascript:void(0);" class="default-download-selected" style="display: block;">
104' + wpfdparams.translates.download_selected + '<i class="zmdi zmdi-check-all wpfd-download-category"></i></a>'); 105 if ($(rootCat).find("ul.breadcrumbs").length) { 106 downloadSelectedBtn.insertBefore($(rootCat).find("ul.breadcrumbs")); 107 } else { 108 downloadSelectedBtn.insertBefore($(rootCat).find("div.wpfd-container")); 109 } 110 } else { 111 $(rootCat + " .wpfdSelectedFiles").remove(); 112 $(rootCat + " .default-download-selected").remove(); 113 hideDownloadAllBtn(sc, false); 114 } 115 }); 116 } 117 118 function hideDownloadAllBtn(sc, hide) { 119 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "]"; 120 var downloadCatButton = $(rootCat + " .default-download-category"); 121 if (downloadCatButton.length === 0 || downloadCatButton.hasClass('display-download-category')) { 122 return; 123 } 124 if (hide) { 125 $(rootCat + " .default-download-category").hide(); 126 } else { 127 $(rootCat + " .default-download-category").show(); 128 } 129 } 130 131 function initDownloadSelected(sc) { 132 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "]"; 133 $(document).on('click', rootCat + ' .default-download-selected', function () { 134 if ($(rootCat).find('.wpfdSelectedFiles').length > 0) { 135 var current_category = $(rootCat).find('#current_category_' + sc).val(); 136 var category_name = $(rootCat).find('#current_category_slug_' + sc).val(); 137 var selectedFilesId = $(rootCat).find('.wpfdSelectedFiles').val(); 138 $.ajax({ 139 url: wpfdparams.wpfdajaxurl + "?action=wpfd&task=files.zipSeletedFiles&filesId=" + selectedFilesId + "&wpfd_category_id=" + current_category, 140 dataType: "json", 141 }).done(function (results) { 142 if (results.success) { 143 var hash = results.data.hash; 144 window.location.href = wpfdparams.wpfdajaxurl + "?action=wpfd&task=files.downloadZipedFile&hash=" + hash + "&wpfd_category_id=" + current_category + "&wpfd_category_name=" + category_name; 145 } else { 146 alert(results.data.message); 147 } 148 }) 149 } 150 }); 151 } 152 153 default_initClick(); 154 155 if (typeof wpfdColorboxInit !== 'undefined') { 156 wpfdColorboxInit(); 157 } 158 159 function wpfd_default_menu_category_link_handlers() { 160 if ($('.wpfd_menu_category_links .elementor-icon-list-item').length) { 161 $('.wpfd_menu_category_links .elementor-icon-list-item').unbind('click').on('click', function (e) { 162 var hashSubUrl = $(this).find('a').attr('href'); 163 var hashGoId = ''; 164 165 if (hashSubUrl.indexOf('/') !== -1) { 166 var hashParams = hashSubUrl.split('/'); 167 hashGoId = hashParams[hashParams.length - 1]; 168 hashGoId = hashGoId.replace('#', ''); 169 170 if (hashGoId !== '') { 171 var hashGoIda = hashGoId.split('-'); 172 var hashGoIda_sourcecat = hashGoIda[0]; 173 var hashGoIda_category_id = hashGoIda[1]; 174 175 setTimeout(function () { 176 default_load(hashGoIda_sourcecat, hashGoIda_category_id, null); 177 if ($('#e-n-menu-content-1872').length) { 178 $('#e-n-menu-content-1872').hide(); 179 } 180 }, 100); 181 } 182 } 183 }); 184 } 185 } 186 187 wpfd_default_menu_category_link_handlers(); 188 189 default_hash = default_hash.replace('#', ''); 190 if (default_hash !== '' && default_hash.indexOf('-wpfd-') !== -1) { 191 var hasha = default_hash.split('-'); 192 var re = new RegExp("^(p[0-9]+)$"); 193 var page = null; 194 var stringpage = hasha.pop(); 195 196 if (re.test(stringpage)) { 197 page = stringpage.replace('p', ''); 198 } 199 200 var hash_category_id = hasha[1]; 201 var hash_sourcecat = hasha[0]; 202 203 if (hash_sourcecat.toString() === 'all_0' && parseInt(hash_category_id) === 0) { 204 hash_category_id = 'all_0'; 205 } 206 207 if (parseInt(hash_category_id) > 0 || hash_category_id === 'all_0') { 208 if (hash_sourcecat.toString() !== 'all_0' && hash_category_id == 'all_0') { 209 hash_category_id = 0; 210 } 211 setTimeout(function () { 212 default_load(hash_sourcecat, hash_category_id, page); 213 }, 100); 214 } 215 } 216 217 _wpfd_text = function (text) { 218 if (typeof (l10n) !== 'undefined') { 219 return l10n[text]; 220 } 221 return text; 222 }; 223 224 function toMB(mb) { 225 return mb * 1024 * 1024; 226 } 227 var allowedExt = wpfdparams.allowed; 228 allowedExt = allowedExt.split(','); 229 allowedExt.sort(); 230 231 function initUploader(currentContainer) { 232 var upload_type = 'file'; 233 // Init the uploader 234 var uploader = new Resumable({ 235 target: wpfdparams.wpfduploadajax + '?action=wpfd&task=files.upload&upload_from=front', 236 query: { 237 id_category: $(currentContainer).find('input[name=id_category]').val(), 238 }, 239 fileParameterName: 'file_upload', 240 simultaneousUploads: 2, 241 maxFileSize: toMB(wpfdparams.maxFileSize), 242 maxFileSizeErrorCallback: function (file) { 243 alert(file.name + ' ' + _wpfd_text('is too large, please upload file(s) less than ') + wpfdparams.maxFileSize + 'Mb!'); 244 }, 245 chunkSize: wpfdparams.serverUploadLimit - 50 * 1024, // Reduce 50KB to avoid error 246 forceChunkSize: true, 247 fileType: allowedExt, 248 fileTypeErrorCallback: function (file) { 249 alert(file.name + ' cannot upload!<br/><br/>' + _wpfd_text('This type of file is not allowed to be uploaded. You can add new file types in the plugin configuration')); 250 }, 251 generateUniqueIdentifier: function (file, event) { 252 var relativePath = file.webkitRelativePath || file.fileName || file.name; 253 var size = file.size; 254 var prefix = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); 255 return (prefix + size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, '')); 256 } 257 }); 258 259 if (!uploader.support) { 260 alert(_wpfd_text('Your browser does not support HTML5 file uploads!')); 261 } 262 263 if (typeof (willUpload) === 'undefined') { 264 var willUpload = true; 265 } 266 267 uploader.on('createFolders', function (files) { 268 upload_type = 'folder'; 269 var currentRootCat = currentContainer.find('input[name=id_category]').val() 270 // Prepare category tree 271 var paths = files.map(function(file) { 272 if (file.hasOwnProperty('catId')) { 273 currentRootCat = file.catId; 274 } 275 var filePath = (file.hasOwnProperty('relativePath')) ? file.relativePath : file.webkitRelativePath; 276 var namePos = filePath.lastIndexOf(file.name); 277 return filePath.substr(0,namePos); 278 }); 279 // get unique value (not empty value) 280 paths = paths.filter( function(item, i, ar) { return item && ar.indexOf(item) === i } ); 281 if (paths.length > 0) { 282 var categoryType = currentContainer.find('input[name=category_type]').val(); 283 // Send ajax to initial categories 284 $.ajax({ 285 url: wpfdparams.wpfduploadajax + '?action=wpfd&task=categories.createCategoriesDeep', 286 data: { 287 paths: paths.join('|'), 288 category_id: currentRootCat, 289 type: categoryType 290 }, 291 method: 'POST', 292 success: function (data) { 293 } 294 }); 295 } 296 }) 297 298 uploader.on('filesAdded', function (files) {
299 files.forEach(function (file) { 300 var progressBlock = '<div class="wpfd_process_block" id="' + file.uniqueIdentifier + '">' 301 + '<div class="wpfd_process_fileinfo">' 302 + '<span class="wpfd_process_filename">' + file.fileName + '</span>' 303 + '<span class="wpfd_process_cancel">Cancel</span>' 304 + '</div>' 305 + '<div class="wpfd_process_full" style="display: block;">' 306 + '<div class="wpfd_process_run" data-w="0" style="width: 0%;"></div>' 307 + '</div></div>'; 308 309 //$('#preview', '.wpreview').before(progressBlock); 310 currentContainer.find('#preview', '.wpreview').before(progressBlock); 311 $(currentContainer).find('.wpfd_process_cancel').unbind('click').click(function () { 312 fileID = $(this).parents('.wpfd_process_block').attr('id'); 313 fileObj = uploader.getFromUniqueIdentifier(fileID); 314 uploader.removeFile(fileObj); 315 $(this).parents('.wpfd_process_block').fadeOut('normal', function () { 316 $(this).remove(); 317 }); 318 319 if (uploader.files.length === 0) { 320 $(currentContainer).find('.wpfd_process_pause').fadeOut('normal', function () { 321 $(this).remove(); 322 }); 323 } 324 325 $.ajax({ 326 url: wpfdparams.wpfduploadajax + '?action=wpfd&task=files.upload', 327 method: 'POST', 328 dataType: 'json', 329 data: { 330 id_category: currentContainer.find('input[name=id_category]').val(), 331 deleteChunks: fileID 332 }, 333 success: function (res, stt) { 334 if (res.response === true) { 335 } 336 } 337 }) 338 }); 339 }); 340 341 // Do not run uploader if no files added or upload same files again 342 if (files.length > 0) { 343 uploadPauseBtn = $(currentContainer).find('.wpreview').find('.wpfd_process_pause').length; 344 restableBlock = $(currentContainer).find('.wpfd_process_block'); 345 346 if (!uploadPauseBtn) { 347 restableBlock.before('<div class="wpfd_process_pause">Pause</div>'); 348 $(currentContainer).find('.wpfd_process_pause').unbind('click').click(function () { 349 if (uploader.isUploading()) { 350 uploader.pause(); 351 $(this).text('Start'); 352 $(this).addClass('paused'); 353 willUpload = false; 354 } else { 355 uploader.upload(); 356 $(this).text('Pause'); 357 $(this).removeClass('paused'); 358 willUpload = true; 359 } 360 }); 361 } 362 363 uploader.opts.query = { 364 id_category: currentContainer.find('input[name=id_category]').val() 365 }; 366 367 if (willUpload) { 368 setTimeout( function() {uploader.upload();}, 1000); 369 } 370 } 371 }); 372 373 uploader.on('fileProgress', function (file) { 374 $(currentContainer).find('.wpfd_process_block#' + file.uniqueIdentifier) 375 .find('.wpfd_process_run').width(Math.floor(file.progress() * 100) + '%'); 376 }); 377 378 uploader.on('fileSuccess', function (file, res) { 379 var thisUploadBlock = currentContainer.find('.wpfd_process_block#' + file.uniqueIdentifier); 380 thisUploadBlock.find('.wpfd_process_cancel').addClass('uploadDone').text('OK').unbind('click'); 381 thisUploadBlock.find('.wpfd_process_full').remove(); 382 383 var response = JSON.parse(res); 384 if (response.response === false && typeof(response.datas) !== 'undefined') { 385 if (typeof(response.datas.code) !== 'undefined' && response.datas.code > 20) { 386 alert('<div>' + response.datas.message + '</div>'); 387 return false;
388 } 389 } 390 if (typeof(response) === 'string') { 391 alert('<div>' + response + '</div>'); 392 return false; 393 } 394 395 if (response.response !== true) { 396 alert(response.response); 397 return false; 398 } 399 }); 400 401 uploader.on('fileError', function (file, msg) { 402 thisUploadBlock = currentContainer.find('.wpfd_process_block#' + file.uniqueIdentifier); 403 thisUploadBlock.find('.wpfd_process_cancel').addClass('uploadError').text('Error').unbind('click'); 404 thisUploadBlock.find('.wpfd_process_full').remove(); 405 }); 406 407 uploader.on('complete', function () { 408 //load sub categories 409 var currentRootCat = currentContainer.find('input[name=id_category]').val(); 410 var sourcecat = currentContainer.parents('.wpfd-content.wpfd-content-multi').data('category'); 411 var theme = currentContainer.parents('.wpfd-content.wpfd-content-multi[data-category=' + sourcecat + ']').find('.wpfd_root_category_theme').val(); 412 var wpfd_tree = $('.wpfd-content[data-category="'+sourcecat+'"] .wpfd-foldertree'); 413 wpfd_tree.jaofiletree({ 414 script: wpfdparams.wpfduploadajax + '?juwpfisadmin=false&action=wpfd&task=categories.getCats', 415 usecheckboxes: false, 416 root: sourcecat, 417 expanded: parseInt(wpfdparams.allow_category_tree_expanded) === 1 ? true : false 418 }); 419 420 var categoryAjaxUrl = wpfdparams.wpfdajaxurl + "task=categories.display&view=categories&id=" + currentRootCat + "&top=" + sourcecat; 421 if (wpfdDefaultCategoriesLocalCache.exist(categoryAjaxUrl)) { 422 wpfdDefaultCategoriesLocalCache.remove(categoryAjaxUrl); 423 } 424 425 var fileCount = $(currentContainer).find('.wpfd_process_cancel').length; 426 var categoryId = $(currentContainer).find('input[name=id_category]').val(); 427 var ajax_url = typeof (wpfdparams.wpfduploadajax) !== 'undefined' ? wpfdparams.wpfduploadajax : wpfd_var.wpfduploadajax; 428 $.ajax({ 429 url: ajax_url + '?action=wpfd&task=files.wpfdPendingUploadFiles', 430 method: 'POST', 431 dataType: 'json', 432 data: { 433 uploadedFiles: fileCount, 434 id_category: categoryId, 435 }, 436 success: function (res) { 437 currentContainer.find('.progress').delay(300).fadeIn(300).hide(300, function () { 438 $(this).remove(); 439 }); 440 currentContainer.find('.uploaded').delay(300).fadeIn(300).hide(300, function () { 441 $(this).remove(); 442 }); 443 $('#wpreview .file').delay(1200).show(1200, function () { 444 $(this).removeClass('done placeholder'); 445 }); 446 447 $('.gritter-item-wrapper ').remove(); 448 $(currentContainer).find('#wpfd-upload-messages').append(wpfdparams.translates.msg_upload_file); 449 $(currentContainer).find('#wpfd-upload-messages').delay(1200).fadeIn(1200, function () { 450 $(currentContainer).find('#wpfd-upload-messages').empty(); 451 $(currentContainer).find('.wpfd_process_pause').remove(); 452 $(currentContainer).find('.wpfd_process_block').remove(); 453 }); 454 455 // Call list files 456 if (currentContainer.parent('.wpfd-upload-form').length) { 457 var sourcecat = currentContainer.parents('.wpfd-content.wpfd-content-multi').data('category'); 458 var current_category = currentContainer.parents('.wpfd-content.wpfd-content-multi').find('#current_category_' + sourcecat).val(); 459 460 // Refresh uploaded files on caching 461 var ordering = currentContainer.parents('.wpfd-content.wpfd-content-multi').find('#current_ordering_' + sourcecat).val(); 462 var orderingDirection = currentContainer.parents('.wpfd-content.wpfd-content-multi').find('#current_ordering_direction_' + sourcecat).val(); 463 var page_limit = currentContainer.parents('.wpfd-content.wpfd-content-multi').find('#page_limit_' + sourcecat).val(); 464 var params = $.param({ 465 task: 'files.display', 466 view: 'files', 467 id: current_category, 468 rootcat: sourcecat, 469 page: page, 470 orderCol: ordering, 471 orderDir: orderingDirection, 472 page_limit: page_limit 473 }); 474 var fileAjaxUrl = wpfdparams.wpfdajaxurl + params; 475 if (wpfdDefaultFilesLocalCache.exist(fileAjaxUrl)) { 476 wpfdDefaultFilesLocalCache.remove(fileAjaxUrl); 477 } 478 479 upload_type = 'file'; 480 default_load(sourcecat, current_category, null,upload_type); 481 return false;
482 } 483 } 484 }); 485 }); 486 487 uploader.assignBrowse($(currentContainer).find('#upload_button')); 488 uploader.assignBrowse($(currentContainer).find('#upload_folder_button'), true); 489 uploader.assignDrop($(currentContainer).find('.jsWpfdFrontUpload')); 490 } 491 492 function default_load(sourcecat, catid, page, upload_type) { 493 $(document).trigger('wpfd:category-loading'); 494 var pathname = window.location.href.replace(window.location.hash, ''); 495 var container = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]"); 496 var containerDefault = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default"); 497 var empty_subcategories = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] #wpfd_is_empty_subcategories"); 498 var empty_files = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] #wpfd_is_empty_files"); 499 container.find('#current_category_' + sourcecat).val(catid); 500 container.next('.wpfd-pagination').remove(); 501 502 containerDefault.empty(); 503 containerDefault.html($('#wpfd-loading-wrap').html()); 504 505 if (empty_subcategories.length) { 506 empty_subcategories.val('1'); 507 } 508 509 if (empty_files.length) { 510 empty_files.val('1'); 511 } 512 513 // Get categories 514 var oldCategoryAjax = window.wpfdAjax[tree_source_cat].category; 515 if (oldCategoryAjax !== null) { 516 oldCategoryAjax.abort(); 517 } 518 var categoryAjaxUrl = wpfdparams.wpfdajaxurl + "task=categories.display&view=categories&id=" + catid + "&top=" + sourcecat; 519 window.wpfdAjax[tree_source_cat].category = $.ajax({ 520 url: categoryAjaxUrl, 521 dataType: "json", 522 cache: true, 523 beforeSend: function () { 524 if (container.find('.wpfd-form-search-file-category').length) { 525 container.find('.wpfd-form-search-file-category').remove(); 526 } 527 528 if (wpfdDefaultCategoriesLocalCache.exist(categoryAjaxUrl) && upload_type != 'folder') { 529 var triggerCategories = wpfdDefaultCategoriesLocalCache.get(categoryAjaxUrl); 530 wpfdDefaultCategoriesLocalCacheTrigger(triggerCategories, sourcecat, page, pathname, catid, container, empty_subcategories); 531 return false; 532 } 533 return true; 534 } 535 }).done(function (categories) { 536 wpfdDefaultCategoriesLocalCache.set(categoryAjaxUrl, categories); 537 538 // Search file in category section 539 var $displayFileSearch = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('.wpfd_root_category_display_file_search'); 540 if ($displayFileSearch.length) { 541 var $themeName = container.find('.wpfd_root_category_theme').val(); 542 543 if (typeof (categories.category.correctConvertCategoryId) === 'undefined') { 544 categories.category.correctConvertCategoryId = 0; 545 } 546 547 var $searchContent = '<form action="" id="adminForm-'+ categories.category.term_id +'" class="wpfd-adminForm wpfd-form-search-file-category" name="adminForm" method="post">' + 548 '<div id="loader" style="display:none; text-align: center">' + 549 '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/searchloader.svg" style="margin: 0 auto"/>' + 550 '</div>' + 551 '<div class="box-search-filter wpfd-category-search-section">' + 552 '<div class="searchSection">' + 553 '<div class="only-file input-group clearfix wpfd_search_input" id="Search_container">' + 554 '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/search-24.svg" class="material-icons wpfd-icon-search wpfd-search-file-category-icon" />' + 555 '<input type="text" class="pull-left required txtfilename" name="q" id="txtfilename" autocomplete="off" placeholder="'+ wpfdparams.translates.msg_search_file_category_placeholder +'" value="" />' + 556 '</div>' + 557 '<button id="btnsearchbelow" class="btnsearchbelow wpfd-btnsearchbelow" type="button">'+ wpfdparams.translates.msg_search_file_category_search +'</button>' + 558 '</div>' + 559 '<input type="hidden" id="filter_catid" class="chzn-select filter_catid" name="catid" value="'+ categories.category.correctConvertCategoryId +'" data-cattype="" data-slug="" />' + 560 '<input type="hidden" name="theme" value="'+ $themeName +'">' + 561 '<input type="hidden" name="limit" value="15">' + 562 '<div id="wpfd-results" class="wpfd-results list-results"></div>' + 563 '</div>' + 564 '</form>'; 565 566 container.prepend($searchContent); 567 wpfdDefaultSearchFileCategoryHandle(); 568 } 569 570 if (page !== null && page !== undefined) { 571 window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + catid + '-wpfd-' + categories.category.slug + '-p' + page); 572 } else { 573 window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + catid + '-wpfd-' + categories.category.slug); 574 } 575 576 container.find('#current_category_slug_' + sourcecat).val(categories.category.slug); 577 var sourcecategories = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-template-categories").html(); 578 if (sourcecategories) { 579 var template = Handlebars.compile(sourcecategories); 580 var html = template(categories); 581 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").prepend(html); 582 } 583 584 if (categories.category.breadcrumbs !== undefined) { 585 if (sourcecat.toString() === 'all_0' && catid.toString() !== 'all_0' && parseInt(catid) !== 0) { 586 categories.category.breadcrumbs = allCategoriesBreadcrumbs + categories.category.breadcrumbs; 587 } 588 $(".wpfd-content-multi[data-category=" + sourcecat + "] .breadcrumbs").html(categories.category.breadcrumbs); 589 } 590 for (var i = 0; i < categories.categories.length; i++) { 591 cParents[categories.categories[i].term_id] = categories.categories[i]; 592 } 593 594 default_breadcrum(sourcecat, catid, categories.category); 595 default_initClick(); 596 597 if (tree.length) { 598 var currentTree = container.find('.wpfd-foldertree-default'); 599 currentTree.find('li').removeClass('selected'); 600 currentTree.find('i.md').removeClass('md-folder-open').addClass("md-folder"); 601 602 currentTree.jaofiletree('open', catid, currentTree); 603 604 var el = currentTree.find('a[data-file="' + catid + '"]').parent(); 605 el.find(' > i.md').removeClass("md-folder").addClass("md-folder-open"); 606 607 if (!el.hasClass('selected')) { 608 el.addClass('selected'); 609 } 610 var ps = currentTree.find('.icon-open-close'); 611 612 $.each(ps.get().reverse(), function (i, p) { 613 if (typeof $(p).data() !== 'undefined' && $(p).data('id') == Number(hash_category_id)) { 614 hash_category_id = $(p).data('parent_id'); 615 if(parseInt(wpfdparams.allow_category_tree_expanded) !== 1) { 616 $(p).click(); 617 } 618 } 619 }); 620 } 621 622 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default >
622 .wpfd-password-form").length) { 623 hideDownloadAllBtn(sourcecat, true); 624 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").attr('href', '#'); 625 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide(); 626 } 627 628 if (empty_subcategories.length) { 629 empty_subcategories.val(categories.categories.length); 630 fire_empty_category_message(sourcecat); 631 } 632 }); 633 var ordering = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_' + sourcecat).val(); 634 var orderingDirection = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_direction_' + sourcecat).val(); 635 var page_limit = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('#page_limit_' + sourcecat).val(); 636 var themeName = $(".wpfd-content-default[data-category=" + sourcecat + "]").find('.wpfd_root_category_theme').val(); 637 var show_files = 1; 638 var atts_shortcode = window["wpfdfrontend_" + themeName]; 639 if (atts_shortcode !== undefined && atts_shortcode.shortcode_param.show_files !== undefined && sourcecat === 'all_0' && (parseInt(catid) === 0 || catid === 'all_0')) { 640 show_files = atts_shortcode.shortcode_param.show_files; 641 } 642 643 var params = $.param({ 644 task: 'files.display', 645 view: 'files', 646 id: catid, 647 rootcat: sourcecat, 648 page: page, 649 orderCol: ordering, 650 orderDir: orderingDirection, 651 page_limit: page_limit, 652 show_files: show_files 653 }); 654 655 //Get files 656 var oldFileAjax = window.wpfdAjax[tree_source_cat].file; 657 var fileAjaxUrl = wpfdparams.wpfdajaxurl + params; 658 if (oldFileAjax !== null) { 659 oldFileAjax.abort(); 660 } 661 window.wpfdAjax[tree_source_cat].file = $.ajax({ 662 url: fileAjaxUrl, 663 dataType: "json", 664 cache: true, 665 beforeSend: function () { 666 if (wpfdDefaultFilesLocalCache.exist(fileAjaxUrl) && (upload_type === null || upload_type === undefined)) { 667 var triggerFiles = wpfdDefaultFilesLocalCache.get(fileAjaxUrl); 668 wpfdDefaultFilesLocalCacheTrigger(triggerFiles, sourcecat, empty_files, fileAjaxUrl); 669 return false; 670 } 671 return true; 672 } 673 }).done(function (content) { 674 // Set files local cache 675 if (typeof (content.pagination) !== 'undefined' && content.pagination.length) { 676 content.cache_pagination = content.pagination; 677 } 678 wpfdDefaultFilesLocalCache.set(fileAjaxUrl, content); 679 680 if (typeof (content.categoryPassword) !== 'undefined' && content.categoryPassword.length) { 681 hideDownloadAllBtn(sourcecat, true); 682 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").attr('href', '#'); 683 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide(); 684 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").empty(); 685 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").append(content.categoryPassword); 686 } else { 687 if (content.files.length) { 688 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").removeClass("display-download-category"); 689 } else { 690 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").addClass("display-download-category"); 691 } 692 693 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").after(content.pagination); 694 delete content.pagination; 695 var sourcefiles = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-template-files").html(); 696 if (sourcefiles) { 697 var template = Handlebars.compile(sourcefiles); 698 var html = template(content); 699 html = $('<textarea/>').html(html).val(); 700 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").append(html); 701 702 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default .file .file-custom-field.file-url").length) { 703 var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link'; 704 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default .file .file-custom-field.file-url").each(function () { 705 var label = $(this).attr('data-field-label'); 706 var url = $(this).attr('data-field-val'); 707 var urlContents = '<div><span>
707' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>'; 708 $(this).empty().append(urlContents); 709 }); 710 } 711 } 712 713 if (typeof (content.filepasswords) !== 'undefined') { 714 $.each(content.filepasswords, function( file_id, pw_form ) { 715 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').empty(); 716 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form'); 717 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').append(pw_form); 718 }); 719 } 720 721 if (content.uploadform !== undefined && content.uploadform.length) { 722 var upload_form_html = '<div class="wpfd-upload-form" style="margin: 20px 10px">'; 723 upload_form_html += content.uploadform; 724 upload_form_html += '</div>'; 725 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").append(upload_form_html); 726 727 if (typeof (Wpfd) === 'undefined') { 728 Wpfd = {}; 729 } 730 731 var containers = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] div[class*=wpfdUploadForm]"); 732 if (containers.length > 0) { 733 containers.each(function(i, el) { 734 initUploader($(el)); 735 }); 736 } 737 } 738 739 if (typeof wpfdColorboxInit !== 'undefined') { 740 wpfdColorboxInit(); 741 } 742 743 wpfdTrackDownload(); 744 745 default_init_pagination($('.wpfd-content-default[data-category=' + sourcecat + '] + .wpfd-pagination')); 746 wpfd_remove_loading($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default")); 747 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdSelectedFiles").remove(); 748 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-selected").remove(); 749 hideDownloadAllBtn(sourcecat, false); 750 } 751 if (empty_files.length) { 752 empty_files.val(content.files.length); 753 fire_empty_category_message(sourcecat); 754 } 755 756 wpfdDefaultDisplayDownloadedFiles(); 757 wpfdDefaultDownloadFiles(); 758 wpfdPreviewFileNewName(); 759 }); 760 $(document).trigger('wpfd:category-loaded'); 761 } 762 763 function default_breadcrum(sourcecat, catid, category) { 764 var links = []; 765 var current_Cat = cParents[catid]; 766 var defaultdownloadcategory = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category"); 767 if (!current_Cat) { 768 defaultdownloadcategory.attr('href', category.linkdownload_cat); 769 return false; 770 } 771 links.unshift(current_Cat); 772 if (current_Cat.parent !== 0) { 773 while (cParents[current_Cat.parent]) { 774 current_Cat = cParents[current_Cat.parent]; 775 if (links.includes(current_Cat)) { 776 break; 777 } 778 links.unshift(current_Cat); 779 } 780 } 781 782 var html = ''; 783 if (sourcecat.toString() === 'all_0' && catid.toString() !== 'all_0' && parseInt(catid) !== 0) { 784 html = allCategoriesDividerBreadcrumbs; 785 } 786 for (var i = 0; i < links.length; i++) { 787 if (links[i].parent.toString() === 'undefined') { 788 continue; 789 } 790 if (i < links.length - 1) { 791 if (links[i].term_id != "all_0" && parseInt(links[i].term_id) != 0) { 792 html += '<li><a class="catlink" data-idcat="' + links[i].term_id + '" href="javascript:void(0)">'; 793 html += links[i].name + '</a><span class="divider"> > </span></li>'; 794 } 795 } else { 796 if (links[i].term_id != "all_0" && parseInt(links[i].term_id) != 0) { 797 html += '<li><span>' + links[i].name + '</span></li>'; 798 } else { 799 html += '<li><span>' + wpfdparams.translates.wpfd_all_categories + '</span></li>'; 800 } 801 } 802 } 803 804 if (html == '' && (catid.toString() == 'all_0' || parseInt(catid) == 0)
804) { 805 html += '<li><span>' + wpfdparams.translates.wpfd_all_categories + '</span></li>'; 806 } 807 808 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-breadcrumbs-default").html(html); 809 defaultdownloadcategory.attr('href', category.linkdownload_cat); 810 } 811 812 if (tree.length) { 813 tree.each(function () { 814 var topCat = $(this).parents('.wpfd-content-default.wpfd-content-multi').data('category'); 815 $(this).jaofiletree({ 816 script: wpfdparams.wpfdajaxurl + 'task=categories.getCats', 817 usecheckboxes: false, 818 root: topCat, 819 showroot: cParents[topCat].name, 820 expanded: parseInt(wpfdparams.allow_category_tree_expanded) === 1 ? true : false, 821 onclick: function (elem, file) { 822 var topCat = $(elem).parents('.wpfd-content-default.wpfd-content-multi').data('category'); 823 if (topCat !== file) { 824 $('.directory', $(elem).parents('.wpfd-content-default.wpfd-content-multi')).each(function() { 825 if (!$(this).hasClass('selected') && $(this).find('> ul > li').length === 0) { 826 $(this).removeClass('expanded'); 827 } 828 }); 829 830 if(parseInt(wpfdparams.allow_category_tree_expanded) !== 1) { 831 $(elem).parents('.directory').each(function () { 832 var $this = $(this); 833 var category = $this.find(' > a'); 834 var parent = $this.find('.icon-open-close'); 835 if (parent.length > 0) { 836 if (typeof cParents[category.data('file')] === 'undefined') { 837 cParents[category.data('file')] = { 838 parent: parent.data('parent_id'), 839 term_id: category.data('file'), 840 name: category.text() 841 }; 842 } 843 } 844 }); 845 } 846 } 847 848 default_load(topCat, file); 849 } 850 }); 851 852 if(parseInt(wpfdparams.allow_category_tree_expanded) === 1) { 853 var ele = $(this); 854 setTimeout(function() { 855 ele.find("li.directory a").each(function () { 856 var tempCatID = $(this).data('catid'); 857 var patentCatID = $(this).data('parent_id'); 858 if (tempCatID == 'all_0') { 859 cParents[tempCatID] = {parent: 0, term_id: 0, name: $(this).text().trim()}; 860 } else { 861 cParents[tempCatID] = {parent: patentCatID, term_id: tempCatID, name: $(this).text().trim()}; 862 } 863 }); 864 }, 1000); 865 } 866 }) 867 } 868 869 $('.wpfd-content-default + .wpfd-pagination').each(function (index, elm) { 870 var $this = $(elm); 871 default_init_pagination($this); 872 }); 873 874 function default_init_pagination($this) { 875 var number = $this.find('a:not(.current)'); 876 var wrap = $this.prev('.wpfd-content-default'); 877 var sourcecat = wrap.data('category'); 878 var current_category = wrap.find('#current_category_' + sourcecat).val(); 879 880 number.unbind('click').bind('click', function () { 881 var page_number = $(this).attr('data-page'); 882 var current_sourcecat = $(this).attr('data-sourcecat'); 883 var wrap = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]"); 884 var current_category = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_' + current_sourcecat).val(); 885 if (typeof page_number !== 'undefined') { 886 var pathname = window.location.href.replace(window.location.hash, ''); 887 var category = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_' + current_sourcecat).val(); 888 var category_slug = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_slug_' + current_sourcecat).val(); 889 var ordering = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_ordering_' + current_sourcecat).val(); 890 var orderingDirection = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_ordering_direction_' + current_sourcecat).val(); 891 var page_limit = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#page_limit_' + current_sourcecat).val(); 892 893 window.history.pushState('', document.title, pathname + '#' + current_sourcecat + '-' + category + '-wpfd-' + category_slug + '-p' + page_number); 894 895 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default:not(.wpfd-results .wpfd-container-default) .wpfd_list").remove(); 896 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default:not(.wpfd-results .wpfd-container-default)").append($('#wpfd-loading-wrap').html()); 897 var show_files = 1; 898 var themeName = $(".wpfd-content-default[data-category=" + sourcecat + "]").find('.wpfd_root_category_theme').val(); 899 var atts_shortcode = window["wpfdfrontend_" + themeName]; 900 if (atts_shortcode !== undefined && atts_shortcode.shortcode_param.show_files !== undefined && sourcecat === 'all_0' && (parseInt(catid) === 0 || catid === 'all_0')) { 901 show_files = atts_shortcode.shortcode_param.show_files; 902 } 903 904 var params = $.param({ 905 task: 'files.display', 906 view: 'files', 907 id: current_category, 908 rootcat: current_sourcecat, 909 page: page_number, 910 orderCol: ordering, 911 orderDir: orderingDirection, 912 page_limit: page_limit, 913 show_files: show_files 914 }); 915 916 //Get files 917 $.ajax({ 918 url: wpfdparams.wpfdajaxurl + params, 919 dataType: "json", 920 beforeSend: function () { 921 $('html, body').animate({scrollTop: $(".wpfd-content[data-category=" + current_sourcecat + "]").offset().top}, 'fast'); 922 } 923 }).done(function (content) { 924 delete content.category; 925 wrap.next('.wpfd-pagination').remove(); 926 wrap.after(content.pagination); 927 delete content.pagination; 928 var sourcefiles = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-template-files:not(.wpfd-results .wpfd-template-files)").html(); 929 var template = Handlebars.compile(sourcefiles); 930 var html = template(content); 931 932 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default:not(.wpfd-results .wpfd-container-default) .wpfd-upload-form").length) { 933 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default:not(.wpfd-results .wpfd-container-default) .wpfd-upload-form").before(html); 934 } else { 935 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default:not(.wpfd-results .wpfd-container-default)").append(html); 936 } 937 938 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default .file .file-custom-field.file-url").length) { 939 var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link'; 940 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default .file .file-custom-field.file-url").each(function () { 941 var label = $(this).attr('data-field-label'); 942 var url = $(this).attr('data-field-val'); 943 var urlContents = '<div><span>
943' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>'; 944 $(this).empty().append(urlContents); 945 }); 946 } 947 948 // File password security 949 if (typeof (content.filepasswords) !== 'undefined') { 950 $.each(content.filepasswords, function( file_id, pw_form ) { 951 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').empty(); 952 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form'); 953 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').append(pw_form); 954 }); 955 } 956 957 if (typeof wpfdColorboxInit !== 'undefined') { 958 wpfdColorboxInit(); 959 } 960 default_init_pagination(wrap.next('.wpfd-pagination')); 961 wpfd_remove_loading($(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default:not(.wpfd-results .wpfd-container-default)")); 962 wpfdDefaultDisplayDownloadedFiles(); 963 wpfdDefaultDownloadFiles(); 964 wpfdPreviewFileNewName(); 965 }); 966 } 967 }); 968 } 969 970 function wpfd_container_with_foldertree() { 971 $('.wpfd-content-default .wpfd-container').each(function () { 972 if($(this).children('.with_foldertree').length > 0) { 973 $(this).addClass('wpfd_dfcontainer_foldertree'); 974 } else { 975 if($(this).hasClass('wpfd_dfcontainer_foldertree')) { 976 $(this).removeClass('wpfd_dfcontainer_foldertree'); 977 } 978 } 979 }); 980 981 //parent-content 982 $('.wpfd-content-default').each(function () { 983 if($(this).children().has('.wpfd-foldertree').length > 0) { 984 $(this).addClass('wpfd_contentdefault_foldertree'); 985 } else { 986 if($(this).hasClass('wpfd_contentdefault_foldertree')) { 987 $(this).removeClass('wpfd_contentdefault_foldertree'); 988 } 989 } 990 }); 991 } 992 993 wpfd_container_with_foldertree(); 994 995 function fire_empty_category_message(category_id) { 996 if (!category_id) { 997 return; 998 } 999 var root_category = '.wpfd-content-default.wpfd-content-multi[data-category=' + category_id + ']'; 1000 var display_empty_category_message = $(root_category).find('#wpfd_display_empty_category_message').val(); 1001 var empty_category_message_val = $(root_category).find('#wpfd_empty_category_message_val').val(); 1002 var is_empty_subcategories = $(root_category).find('#wpfd_is_empty_subcategories').val(); 1003 var is_empty_files = $(root_category).find('#wpfd_is_empty_files').val(); 1004 1005 if (parseInt(display_empty_category_message) !== 1 1006 || parseInt(is_empty_subcategories) !== 0 || parseInt(is_empty_files) !== 0 ) { 1007 return; 1008 } 1009 1010 var code = '<div class="wpfd-empty-category-message-section">'; 1011 code += '<p class="wpfd-empty-category-message">'; 1012 code += empty_category_message_val; 1013 code += '</p>'; 1014 code += '</div>'; 1015 1016 $(root_category).find('.wpfd-empty-category-message-section').remove(); 1017 $(root_category).find('.wpfd-container-default').append(code); 1018 } 1019 1020 var destroy_upload = $('.wpfd-upload-form.destroy'); 1021 if (destroy_upload.length) { 1022 destroy_upload.remove(); 1023 } 1024 1025 // Local categories cache trigger 1026 function wpfdDefaultCategoriesLocalCacheTrigger(triggerCategories, sourcecat, page, pathname, catid, container, empty_subcategories) { 1027 1028 // Check if file search display is enabled 1029 var $displayFileSearch = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('.wpfd_root_category_display_file_search'); 1030 if ($displayFileSearch.length) { 1031 var $themeName = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('.wpfd_root_category_theme').val(); 1032 1033 if (typeof (triggerCategories.category.correctConvertCategoryId) === 'undefined') { 1034 triggerCategories.category.correctConvertCategoryId = 0; 1035 } 1036 1037 var $searchContent = '<form action="" id="adminForm-'+ triggerCategories.category.term_id +'" class="wpfd-adminForm wpfd-form-search-file-category" name="adminForm" method="post">' + 1038 '<div id="loader" style="display:none; text-align: center">' + 1039 '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/searchloader.svg" style="margin: 0 auto"/>' + 1040 '</div>' + 1041 '<div class="box-search-filter wpfd-category-search-section">' + 1042 '<div class="searchSection">' + 1043 '<div class="only-file input-group clearfix wpfd_search_input" id="Search_container">' + 1044 '<img src="'+ wpfdparams.wpfd_plugin_url +'/app/site/assets/images/search-24.svg" class="material-icons wpfd-icon-search wpfd-search-file-category-icon" />' + 1045 '<input type="text" class="pull-left required txtfilename" name="q" id="txtfilename" autocomplete="off" placeholder="'+ wpfdparams.translates.msg_search_file_category_placeholder +'" value="" />' + 1046 '</div>' + 1047 '<button id="btnsearchbelow" class="btnsearchbelow wpfd-btnsearchbelow" type="button">'+ wpfdparams.translates.msg_search_file_category_search +'</button>' + 1048 '</div>' + 1049 '<input type="hidden" id="filter_catid" class="chzn-select filter_catid" name="catid" value="'+ triggerCategories.category.correctConvertCategoryId +'" data-cattype="" data-slug="" />' + 1050 '<input type="hidden" name="theme" value="'+ $themeName +'">' + 1051 '<input type="hidden" name="limit" value="15">' + 1052 '<div id="wpfd-results" class="wpfd-results list-results"></div>' + 1053 '</div>' + 1054 '</form>'; 1055 1056 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").prepend($searchContent); 1057 wpfdDefaultSearchFileCategoryHandle(); 1058 } 1059 1060 // Update browser history 1061 var historyState = ''; 1062 if (page !== null && page !== undefined) { 1063 historyState = `#${sourcecat}-${catid}-wpfd-${triggerCategories.category.slug}-p${page}`; 1064 } else { 1065 historyState = `#${sourcecat}-${catid}-wpfd-${triggerCategories.category.slug}`; 1066 } 1067 window.history.pushState('', document.title, pathname + historyState); 1068 1069 // Update container and categories 1070 container.find('#current_category_slug_' + sourcecat).val(triggerCategories.category.slug); 1071 var sourcecategories = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-template-categories").html(); 1072 if (sourcecategories) { 1073 var template = Handlebars.compile(sourcecategories); 1074 var html = template(triggerCategories); 1075 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").prepend(html); 1076 } 1077 1078 // Update breadcrumbs and initialize click events 1079 if (triggerCategories.category.breadcrumbs !== undefined) { 1080 $(".wpfd-content-multi[data-category=" + sourcecat + "] .breadcrumbs").html(triggerCategories.category.breadcrumbs); 1081 } 1082 for (var i = 0; i < triggerCategories.categories.length; i++) { 1083 cParents[triggerCategories.categories[i].term_id] = triggerCategories.categories[i]; 1084 } 1085 1086 default_breadcrum(sourcecat, catid, triggerCategories.category); 1087 default_initClick(); 1088 1089 // Expand tree if present 1090 if (tree.length) { 1091 var currentTree = container.find('.wpfd-foldertree-default'); 1092 currentTree.find('li').removeClass('selected'); 1093 currentTree.find('i.md').removeClass('md-folder-open').addClass("md-folder"); 1094 1095 currentTree.jaofiletree('open', catid, currentTree); 1096 1097 var el = currentTree.find('a[data-file="' + catid + '"]').parent(); 1098 el.find(' > i.md').removeClass("md-folder").addClass("md-folder-open"); 1099 1100 if (!el.hasClass('selected')) { 1101 el.addClass('selected'); 1102 } 1103 var ps = currentTree.find('.icon-open-close'); 1104 1105 $.each(ps.get().reverse(), function (i, p) { 1106 if (typeof $(p).data() !== 'undefined' && $(p).data('id') == Number(hash_category_id)) { 1107 hash_category_id = $(p).data('parent_id'); 1108 $(p).click(); 1109 } 1110 }); 1111 1112 } 1113 1114 // Hide download button and empty subcategories message if needed 1115 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default >
1115 .wpfd-password-form").length) { 1116 hideDownloadAllBtn(sourcecat, true); 1117 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").attr('href', '#'); 1118 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide(); 1119 } 1120 1121 if (empty_subcategories.length) { 1122 empty_subcategories.val(triggerCategories.categories.length); 1123 fire_empty_category_message(sourcecat); 1124 } 1125 } 1126 1127 // Local files cache trigger 1128 function wpfdDefaultFilesLocalCacheTrigger(triggerFiles, sourcecat, empty_files, fileAjaxUrl) { 1129 var sourceCatSelector = ".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]"; 1130 1131 if (typeof (triggerFiles.categoryPassword) !== 'undefined' && triggerFiles.categoryPassword.length) { 1132 hideDownloadAllBtn(sourcecat, true); 1133 $(sourceCatSelector + " .default-download-category").attr('href', '#'); 1134 $(sourceCatSelector + " .wpfdcategory").hide(); 1135 $(sourceCatSelector + " .wpfd-container-default").empty().append(triggerFiles.categoryPassword); 1136 } else { 1137 if (triggerFiles.files.length) { 1138 $(sourceCatSelector + " .default-download-category").removeClass("display-download-category"); 1139 } else { 1140 $(sourceCatSelector + " .default-download-category").addClass("display-download-category"); 1141 } 1142 1143 $(sourceCatSelector).after(triggerFiles.cache_pagination); 1144 1145 var sourcefiles = $(sourceCatSelector + " .wpfd-template-files").html(); 1146 var template = Handlebars.compile(sourcefiles); 1147 var html = template(triggerFiles); 1148 html = $('<textarea/>').html(html).val(); 1149 $(sourceCatSelector + " .wpfd-container-default").append(html); 1150 1151 if ($(sourceCatSelector + " .wpfd-container-default .file .file-custom-field.file-url").length) { 1152 var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link'; 1153 $(sourceCatSelector + " .wpfd-container-default .file .file-custom-field.file-url").each(function () { 1154 var label = $(this).attr('data-field-label'); 1155 var url = $(this).attr('data-field-val'); 1156 var urlContents = '<div><span>
1156' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>'; 1157 $(this).empty().append(urlContents); 1158 }); 1159 } 1160 1161 if (typeof (triggerFiles.filepasswords) !== 'undefined') { 1162 $.each(triggerFiles.filepasswords, function( file_id, pw_form ) { 1163 var fileSelector = $(sourceCatSelector + " .wpfd-container-default").find('.file[data-id="' + file_id + '"]') 1164 $(fileSelector).empty().addClass('wpfd-password-protection-form').append(pw_form); 1165 }); 1166 } 1167 1168 if (triggerFiles.uploadform !== undefined && triggerFiles.uploadform.length) { 1169 var upload_form_html = '<div class="wpfd-upload-form" style="margin: 20px 10px">'; 1170 upload_form_html += triggerFiles.uploadform; 1171 upload_form_html += '</div>'; 1172 $(sourceCatSelector + " .wpfd-container-default").append(upload_form_html); 1173 1174 if (typeof (Wpfd) === 'undefined') { 1175 Wpfd = {}; 1176 } 1177 1178 var containers = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] div[class*=wpfdUploadForm]"); 1179 if (containers.length > 0) { 1180 containers.each(function(i, el) { 1181 initUploader($(el)); 1182 }); 1183 } 1184 } 1185 1186 if (typeof wpfdColorboxInit !== 'undefined') { 1187 wpfdColorboxInit(); 1188 } 1189 1190 wpfdTrackDownload(); 1191 1192 default_init_pagination($('.wpfd-content-default[data-category=' + sourcecat + '] + .wpfd-pagination')); 1193 wpfd_remove_loading($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default")); 1194 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdSelectedFiles").remove(); 1195 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-selected").remove(); 1196 hideDownloadAllBtn(sourcecat, false); 1197 } 1198 if (empty_files.length) { 1199 empty_files.val(triggerFiles.files.length); 1200 fire_empty_category_message(sourcecat); 1201 } 1202 1203 wpfdDefaultDisplayDownloadedFiles(); 1204 wpfdDefaultDownloadFiles(); 1205 wpfdPreviewFileNewName(); 1206 } 1207 1208 // Search file category 1209 function wpfdDefaultCategoryAjaxSearch(element, ordering, direction, pushState = true) { 1210 var $ = jQuery; 1211 var sform = element; 1212 var $key = $(sform).find('input[name=q]').val(); 1213 var $placeholder = $(sform).find('input[name=q]').attr('placeholder'); 1214 1215 // Avoid conflict key search 1216 if ($key.toString() === $placeholder.toString()) { 1217 $key = ''; 1218 } 1219 1220 // Get the form data 1221 var formData = { 1222 'q': $key, 1223 'catid': $(sform).find('[name=catid]').val(), 1224 'theme': $(sform).find('[name=theme]').val(), 1225 'limit': $(sform).find('[name=limit]').val() 1226 }; 1227 1228 formData = cleanObj(formData); 1229 1230 if (jQuery.isEmptyObject(formData) || 1231 (typeof (formData.q) === 'undefined' && 1232 typeof (formData.catid) !== 'undefined' && 1233 parseInt(formData.catid) === 0) || typeof (formData.q) === 'undefined') { 1234 $(element).find(".txtfilename").focus(); 1235 return false; 1236 } 1237 1238 if ((typeof ordering !== 'undefined') && ordering) formData.ordering = ordering; 1239 if ((typeof direction !== 'undefined') && direction) formData.dir = direction; 1240 1241 // Pagination 1242 if (pushState) { 1243 var filter_url = jQuery.param(formData); 1244 var currentUrl = window.location.search; 1245 var pushUrl; 1246 if (typeof URLSearchParams !== 'undefined') { 1247 var currentFilters = new URLSearchParams(currentUrl.substring(1)); 1248 Object.keys(formData).forEach(function (key) { 1249 if (currentFilters.has(key)) { 1250 currentFilters.delete(key); 1251 } 1252 }); 1253 if (currentUrl.substring(1) === '?' && currentFilters.toString() !== '') { 1254 pushUrl = currentFilters.toString() + '&' + filter_url; 1255 1256 } else { 1257 pushUrl = '?' + filter_url; 1258 } 1259 1260 window.history.pushState(formData, "", pushUrl); 1261 } 1262 } 1263 1264 $.ajax({ 1265 method: "POST", 1266 url: wpfdparams.wpfdajaxurl + "task=search.display", 1267 data: formData, 1268 beforeSend: function () { 1269 $(element).find(".wpfd-results").html(''); 1270 $(element).find(".wpfd-results").prepend($(element).find("#loader").clone().show()); 1271 }, 1272 success: function (result) { 1273 $(element).find(".wpfd_search_file_suggestion").html(''); 1274 $(element).find(".wpfd_search_file_suggestion").fadeOut(300); 1275 1276 $(element).find(".wpfd-results").html(result); 1277 $(element).find(".wpfd-results .wpfd-container-default").addClass('wpfd-container-default-search'); 1278 if ($(element).find(".wpfd-results .wpfd-form-search-file-category").length) { 1279 $(element).find(".wpfd-results .wpfd-form-search-file-category").remove(); 1280 } 1281 wpfdDefaultInitSorting(); 1282 if (typeof wpfdColorboxInit !== 'undefined') { 1283 wpfdColorboxInit(); 1284 } 1285 } 1286 }); 1287 } 1288 1289 // Sort initial 1290 function wpfdDefaultInitSorting() { 1291 jQuery('.orderingCol').click(function (e) { 1292 e.preventDefault(); 1293 var ordering = jQuery(this).data('ordering'); 1294 var direction = jQuery(this).data('direction'); 1295 wpfdDefaultCategoryAjaxSearch(ordering, direction); 1296 }); 1297 1298 jQuery(".list-results #limit").change(function (e) { 1299 e.preventDefault(); 1300 jQuery('input[name="limit"]').val(jQuery(this).val()); 1301 var formID = '#' + jQuery(this).closest('form').attr('id'); 1302 wpfdDefaultCategoryAjaxSearch(formID); 1303 return false;
1304 }); 1305 } 1306 1307 function wpfdDefaultSearchFileCategoryHandle() { 1308 $(".wpfd-content .wpfd-adminForm").submit(function (e) { 1309 e.preventDefault(); 1310 return false; 1311 }); 1312 1313 $('.wpfd-content .txtfilename').on('keyup', function(e) { 1314 var $this = $(this); 1315 if (e.keyCode === 13 || e.which === 13 || e.key === 'Enter') 1316 { 1317 e.preventDefault(); 1318 1319 if ($this.val() === '') { 1320 return; 1321 } 1322 1323 var formID = '#' + $this.closest('form').attr('id'); 1324 wpfdDefaultCategoryAjaxSearch(formID); 1325 1326 return; 1327 } 1328 }); 1329 1330 // Ajax filters 1331 $(".wpfd-content .btnsearchbelow").on('click', function (e) { 1332 e.preventDefault(); 1333 var formID = '#' + $(this).closest('form').attr('id'); 1334 wpfdDefaultCategoryAjaxSearch(formID); 1335 return false; 1336 }); 1337 } 1338 wpfdDefaultSearchFileCategoryHandle(); 1339 1340 function wpfdDefaultDisplayDownloadedFiles() { 1341 var fileDownload = $('.wpfd-content.wpfd-content-default .file'); 1342 var linkDownload = $('.wpfd-content.wpfd-content-default .wpfd_downloadlink'); 1343 var user_login_id = wpfdparams.wpfd_user_login_id; 1344 if (linkDownload.length) { 1345 linkDownload.on('click', function () { 1346 var fileId = $(this).parents('.file').data('id'); 1347 var isDownloadedFile = localStorage.getItem('wpfd_downloaded_file_' + user_login_id + '_' + fileId); 1348 if (isDownloadedFile === null) { 1349 localStorage.setItem('wpfd_downloaded_file_' + user_login_id + '_' + fileId, 'yes'); 1350 $(this).parents('.file').addClass('is_downloaded'); 1351 } 1352 }); 1353 } 1354 1355 if (fileDownload.length) { 1356 fileDownload.each(function () { 1357 var id = $(this).data('id'); 1358 var isFileDownload = localStorage.getItem('wpfd_downloaded_file_' + user_login_id + '_' + id); 1359 if (isFileDownload) { 1360 $(this).addClass('is_downloaded'); 1361 } 1362 }); 1363 } 1364 } 1365 wpfdDefaultDisplayDownloadedFiles(); 1366 1367 function wpfdDefaultDownloadFiles() { 1368 if (!wpfdparams.offRedirectLinkDownloadImageFile) { 1369 $('.file.png .wpfd_downloadlink, .file.jpg .wpfd_downloadlink, .file.jpeg .wpfd_downloadlink, .file.gif .wpfd_downloadlink').on('click', function (event) { 1370 event.preventDefault(); 1371 var fileId = $(this).parents('.file').data('id'); 1372 var categoryId = $(this).parents('.file').data('catid'); 1373 var cloudType = $(this).parents('.wpfd-content-default').find('.wpfd_root_category_type').val(); 1374 1375 if (!fileId || !categoryId) { 1376 return false; 1377 } 1378 1379 if ($(this).find('.wpfd-add-to-cart').length) { 1380 return false; 1381 } 1382 1383 window.location.href = wpfdparams.site_url + "?wpfd_action=wpfd_download_file&wpfd_file_id=" + fileId + "&wpfd_category_id=" + categoryId + "&cloudType=" + cloudType; 1384 }); 1385 } 1386 } 1387 wpfdDefaultDownloadFiles(); 1388 1389 function wpfdPreviewFileNewName() 1390 { 1391 $('.wpfd_previewlink').click(function (e) { 1392 var newWindow = $(this).attr('target'); 1393 var previewLink = $(this).attr('href'); 1394 var fileTitle = $(this).parents('.file').find('.wpfd_downloadlink').attr('title'); 1395 var fileName = fileTitle; 1396 fileName = fileName ? fileName : 'WPFD Preview File'; 1397 1398 if (newWindow === '_blank' && (previewLink.indexOf('previews') !== -1) && previewLink.indexOf('docs.google.com') === -1) { 1399 e.preventDefault(); 1400 var win = window.open(previewLink, '_blank'); 1401 win.onload = function () { 1402 setTimeout(function () { 1403 win.document.title = fileName; 1404 }, 100); 1405 1406 setTimeout(function () { 1407 $(win.document.head).append('<title>'+ fileName +'</title>'); 1408 }, 3000); 1409 }; 1410 1411 setTimeout(function () { 1412 if (win.document.title !== fileName) { 1413 win.document.title = fileName; 1414 } 1415 }, 1000); 1416 1417 setTimeout(function () { 1418 if (win.document.title !== fileName) { 1419 win.document.title = fileName; 1420 } 1421 }, 3000); 1422 } 1423 }); 1424 } 1425 wpfdPreviewFileNewName(); 1426}); 1427 1428// Default categories local cache 1429var wpfdDefaultCategoriesLocalCache = { 1430 data: {}, 1431 remove: function (url) { 1432 delete wpfdDefaultCategoriesLocalCache.data[url]; 1433 }, 1434 exist: function (url) { 1435 return wpfdDefaultCategoriesLocalCache.data.hasOwnProperty(url) && wpfdDefaultCategoriesLocalCache.data[url] !== null; 1436 }, 1437 get: function (url) { 1438 return wpfdDefaultCategoriesLocalCache.data[url]; 1439 }, 1440 set: function (url, cachedData) { 1441 wpfdDefaultCategoriesLocalCache.remove(url);
1442 wpfdDefaultCategoriesLocalCache.data[url] = cachedData; 1443 } 1444}; 1445 1446// Default files local cache 1447var wpfdDefaultFilesLocalCache = { 1448 data: {}, 1449 remove: function (url) { 1450 delete wpfdDefaultFilesLocalCache.data[url]; 1451 }, 1452 exist: function (url) { 1453 return wpfdDefaultFilesLocalCache.data.hasOwnProperty(url) && wpfdDefaultFilesLocalCache.data[url] !== null; 1454 }, 1455 get: function (url) { 1456 return wpfdDefaultFilesLocalCache.data[url]; 1457 }, 1458 set: function(url, cachedData) { 1459 wpfdDefaultFilesLocalCache.remove(url); 1460 wpfdDefaultFilesLocalCache.data[url] = cachedData; 1461 } 1462};
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.