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 cParents = {}; 16 if (window.wpfdAjax === undefined) { 17 window.wpfdAjax = {}; 18 } 19 window.wpfdAjax[tree_source_cat] = {category: null, file: null}; 20 21 $(".wpfd-content-default").each(function () { 22 var topCat = $(this).data('category'); 23 cParents[topCat] = {parent: 0, term_id: topCat, name: $(this).find("h2").text()}; 24 $(this).find(".wpfdcategory.catlink").each(function () { 25 var tempidCat = $(this).data('idcat'); 26 if (tempidCat == 'all_0') { 27 cParents[tempidCat] = {parent: 0, term_id: 0, name: $(this).text()}; 28 } else { 29 cParents[tempidCat] = {parent: topCat, term_id: tempidCat, name: $(this).text()}; 30 } 31 }); 32 initInputSelected(topCat); 33 initDownloadSelected(topCat); 34 }); 35 36 Handlebars.registerHelper('bytesToSize', function (bytes) { 37 if (typeof bytes === "undefined") { 38 return 'n/a'; 39 } 40 41 return bytes.toString().toLowerCase() === 'n/a' ? bytes : bytesToSize(parseInt(bytes)); 42 }); 43 44 Handlebars.registerHelper("xif", function(param, second, options) { 45 if (param === second) { 46 return options.fn(this); 47 } else { 48 return options.inverse(this); 49 } 50 }); 51 52 function default_initClick() { 53 $('.wpfd-content-default .catlink').unbind('click').click(function () { 54 default_load($(this).parents('.wpfd-content-default.wpfd-content-multi').data('category'), $(this).data('idcat')); 55 return false; 56 }); 57 } 58 59 function initInputSelected(sc) { 60 $(document).on('change', ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "] input.cbox_file_download", function () { 61 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "]"; 62 var selectedFiles = $(rootCat + " input.cbox_file_download:checked"); 63 var filesId = []; 64 if (selectedFiles.length) { 65 selectedFiles.each(function (index, file) { 66 filesId.push($(file).data('id')); 67 }); 68 } 69 if (filesId.length > 0) { 70 $(rootCat + " .wpfdSelectedFiles").remove(); 71 $('<input type="hidden" class="wpfdSelectedFiles" value="' + filesId.join(',') + '" />') 72 .insertAfter($(rootCat).find(" #current_category_slug_" + sc)); 73 hideDownloadAllBtn(sc, true); 74 $(rootCat + " .default-download-selected").remove(); 75 var downloadSelectedBtn = $('<a href="javascript:void(0);" class="default-download-selected" style="display: block;">' + wpfdparams.translates.download_selected + '<i class="zmdi zmdi-check-all wpfd-download-category"></i></a>'); 76 downloadSelectedBtn.insertAfter($(rootCat).find(" #current_category_slug_" + sc)); 77 } else { 78 $(rootCat + " .wpfdSelectedFiles").remove(); 79 $(rootCat + " .default-download-selected").remove(); 80 hideDownloadAllBtn(sc, false); 81 } 82 }); 83 } 84 85 function hideDownloadAllBtn(sc, hide) { 86 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "]"; 87 var downloadCatButton = $(rootCat + " .default-download-category"); 88 if (downloadCatButton.length === 0 || downloadCatButton.hasClass('display-download-category')) { 89 return; 90 } 91 if (hide) { 92 $(rootCat + " .default-download-category").hide(); 93 } else { 94 $(rootCat + " .default-download-category").show(); 95 } 96 } 97 98 function initDownloadSelected(sc) { 99 var rootCat = ".wpfd-content-default.wpfd-content-multi[data-category=" + sc + "]"; 100 $(document).on('click', rootCat + ' .default-download-selected', function () { 101 if ($(rootCat).find('.wpfdSelectedFiles').length > 0) { 102 var current_category = $(rootCat).find('#current_category_' + sc).val(); 103 var category_name = $(rootCat).find('#current_category_slug_' + sc).val(); 104 var selectedFilesId = $(rootCat).find('.wpfdSelectedFiles').val(); 105 $.ajax({ 106 url: wpfdparams.wpfdajaxurl + "?action=wpfd&task=files.zipSeletedFiles&filesId=" + selectedFilesId + "&wpfd_category_id=" + current_category, 107 dataType: "json", 108 }).done(function (results) { 109 if (results.success) { 110 var hash = results.data.hash; 111 window.location.href = wpfdparams.wpfdajaxurl + "?action=wpfd&task=files.downloadZipedFile&hash=" + hash + "&wpfd_category_id=" + current_category + "&wpfd_category_name=" + category_name; 112 } else { 113 alert(results.data.message); 114 } 115 }) 116 } 117 }); 118 } 119 default_initClick(); 120 121 default_hash = default_hash.replace('#', ''); 122 if (default_hash !== '' && default_hash.indexOf('-wpfd-') !== -1) { 123 var hasha = default_hash.split('-'); 124 var re = new RegExp("^(p[0-9]+)$"); 125 var page = null; 126 var stringpage = hasha.pop(); 127 128 if (re.test(stringpage)) { 129 page = stringpage.replace('p', ''); 130 } 131 132 var hash_category_id = hasha[1]; 133 var hash_sourcecat = hasha[0]; 134 135 if (parseInt(hash_category_id) > 0 || hash_category_id === 'all_0') { 136 if (hash_category_id == 'all_0') { 137 hash_category_id = 0; 138 } 139 setTimeout(function () { 140 default_load(hash_sourcecat, hash_category_id, page); 141 }, 100); 142 } 143 } 144 145 function default_load(sourcecat, catid, page) { 146 $(document).trigger('wpfd:category-loading'); 147 var pathname = window.location.href.replace(window.location.hash, ''); 148 var container = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]"); 149 var containerDefault = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default"); 150 var empty_subcategories = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] #wpfd_is_empty_subcategories"); 151 var empty_files = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] #wpfd_is_empty_f
151iles"); 152 container.find('#current_category_' + sourcecat).val(catid); 153 container.next('.wpfd-pagination').remove(); 154 155 containerDefault.empty(); 156 containerDefault.html($('#wpfd-loading-wrap').html()); 157 158 if (empty_subcategories.length) { 159 empty_subcategories.val('1'); 160 } 161 if (empty_files.length) { 162 empty_files.val('1'); 163 } 164 165 //Get categories 166 var oldCategoryAjax = window.wpfdAjax[tree_source_cat].category; 167 if (oldCategoryAjax !== null) { 168 oldCategoryAjax.abort(); 169 } 170 window.wpfdAjax[tree_source_cat].category = $.ajax({ 171 url: wpfdparams.wpfdajaxurl + "?action=wpfd&task=categories.display&view=categories&id=" + catid + "&top=" + sourcecat, 172 dataType: "json" 173 }).done(function (categories) { 174 if (page !== null && page !== undefined) { 175 window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + catid + '-wpfd-' + categories.category.slug + '-p' + page); 176 } else { 177 window.history.pushState('', document.title, pathname + '#' + sourcecat + '-' + catid + '-wpfd-' + categories.category.slug); 178 } 179 180 container.find('#current_category_slug_' + sourcecat).val(categories.category.slug); 181 var sourcecategories = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-template-categories").html(); 182 if (sourcecategories) { 183 var template = Handlebars.compile(sourcecategories); 184 var html = template(categories); 185 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").prepend(html); 186 } 187 if (categories.category.breadcrumbs !== undefined) { 188 $(".wpfd-content-multi[data-category=" + sourcecat + "] .breadcrumbs").html(categories.category.breadcrumbs); 189 } 190 for (var i = 0; i < categories.categories.length; i++) { 191 cParents[categories.categories[i].term_id] = categories.categories[i]; 192 } 193 194 default_breadcrum(sourcecat, catid, categories.category); 195 default_initClick(); 196 197 if (tree.length) { 198 var currentTree = container.find('.wpfd-foldertree-default'); 199 currentTree.find('li').removeClass('selected'); 200 currentTree.find('i.md').removeClass('md-folder-open').addClass("md-folder"); 201 202 currentTree.jaofiletree('open', catid, currentTree); 203 204 var el = currentTree.find('a[data-file="' + catid + '"]').parent(); 205 el.find(' > i.md').removeClass("md-folder").addClass("md-folder-open"); 206 207 if (!el.hasClass('selected')) { 208 el.addClass('selected'); 209 } 210 var ps = currentTree.find('.icon-open-close'); 211 212 $.each(ps.get().reverse(), function (i, p) { 213 if (typeof $(p).data() !== 'undefined' && $(p).data('id') == Number(hash_category_id)) { 214 hash_category_id = $(p).data('parent_id'); 215 $(p).click(); 216 } 217 }); 218 219 } 220 221 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default > .wpfd-password-form").length) { 222 hideDownloadAllBtn(sourcecat, true); 223 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").attr('href', '#'); 224 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide(); 225 } 226 227 if (empty_subcategories.length) { 228 empty_subcategories.val(categories.categories.length); 229 fire_empty_category_message(sourcecat); 230 } 231 }); 232 var ordering = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_' + sourcecat).val(); 233 var orderingDirection = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('#current_ordering_direction_' + sourcecat).val(); 234 235 var page_limit = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").find('#page_limit_' + sourcecat).val(); 236 var params = $.param({ 237 task: 'files.display', 238 view: 'files', 239 id: catid, 240 rootcat: sourcecat, 241 page: page, 242 orderCol: ordering, 243 orderDir: orderingDirection, 244 page_limit: page_limit 245 }); 246 //Get files 247 var oldFileAjax = window.wpfdAjax[tree_source_cat].file; 248 if (oldFileAjax !== null) { 249 oldFileAjax.abort(); 250 } 251 window.wpfdAjax[tree_source_cat].file = $.ajax({ 252 url: wpfdparams.wpfdajaxurl + params, 253 dataType: "json" 254 }).done(function (content) { 255 if (typeof (content.categoryPassword) !== 'undefined' && content.categoryPassword.length) { 256 hideDownloadAllBtn(sourcecat, true); 257 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").attr('href', '#'); 258 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdcategory").hide(); 259 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").empty(); 260 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").append(content.categoryPassword); 261 } else { 262 if (content.files.length) { 263 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").removeClass("display-download-category"); 264 } else { 265 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category").addClass("display-download-category"); 266 } 267 268 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "]").after(content.pagination); 269 delete content.pagination; 270 var sourcefiles = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-template-files").html() 271 var template = Handlebars.compile(sourcefiles); 272 var html = template(content); 273 html = $('<textarea/>').html(html).val(); 274 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").append(html); 275 276 if (typeof (content.filepasswords) !== 'undefined') { 277 $.each(content.filepasswords, function( file_id, pw_form ) { 278 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').empty(); 279 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').addClass('wpfd-password-protection-form'); 280 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").find('.file[data-id="' + file_id + '"]').append(pw_form); 281 }); 282 } 283 284 if (content.uploadform !== undefined && content.uploadform.length) { 285 var upload_form_html = '<div class="wpfd-upload-form" style="margin: 20px 10px">'; 286 upload_form_html += content.uploadform; 287 upload_form_html += '</div>'; 288 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default").append(upload_form_html); 289 290 if (typeof (Wpfd) === 'undefined') { 291 Wpfd = {}; 292 } 293 294 _wpfd_text = function (text) { 295 if (typeof (l10n) !== 'undefined') { 296 return l10n[text]; 297 } 298 return text; 299 }; 300 301 function toMB(mb) { 302 return mb * 1024 * 1024; 303 } 304 305 var allowedExt = wpfdparams.allowed; 306 allowedExt = allowedExt.split(','); 307 allowedExt.sort(); 308 309 var initUploader = function (currentContainer) { 310 // Init the uploader 311 var uploader = new Resumable({ 312 target: wpfdparams.wpfduploadajax + '?action=wpfd&task=files.upload&upload_from=front', 313 query: { 314 id_category: $(currentContainer).find('input[name=id_category]').val(), 315 }, 316 fileParameterName: 'file_upload', 317 simultaneousUploads: 2, 318 maxFileSize: toMB(wpfdparams.maxFileSize), 319 maxFileSizeErrorCallback: function (file) { 320 bootbox.alert(file.name + ' ' + _wpfd_text('is too large') + '!'); 321 }, 322 chunkSize: wpfdparams.serverUploadLimit - 50 * 1024, // Reduce 50KB to avoid error 323 forceChunkSize: true, 324 fileType: allowedExt, 325 fileTypeErrorCallback: function (file) { 326 bootbox.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')); 327 }, 328 generateUniqueIdentifier: function (file, event) { 329 var relativePath = file.webkitRelativePath || file.fileName || file.name; 330 var size = file.size; 331 var prefix = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); 332 return (prefix + size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, '')); 333 } 334 }); 335 336 if (!uploader.support) { 337 bootbox.alert(_wpfd_text('Your browser does not support HTML5 file uploads!')); 338 } 339 340 if (typeof (willUpload) === 'undefined') { 341 var willUpload = true; 342 } 343 344 uploader.on('filesAdded', function (files) {
345 files.forEach(function (file) { 346 var progressBlock = '<div class="wpfd_process_block" id="' + file.uniqueIdentifier + '">' 347 + '<div class="wpfd_process_fileinfo">' 348 + '<span class="wpfd_process_filename">' + file.fileName + '</span>' 349 + '<span class="wpfd_process_cancel">Cancel</span>' 350 + '</div>' 351 + '<div class="wpfd_process_full" style="display: block;">' 352 + '<div class="wpfd_process_run" data-w="0" style="width: 0%;"></div>' 353 + '</div></div>'; 354 355 //$('#preview', '.wpreview').before(progressBlock); 356 currentContainer.find('#preview', '.wpreview').before(progressBlock); 357 $(currentContainer).find('.wpfd_process_cancel').unbind('click').click(function () { 358 fileID = $(this).parents('.wpfd_process_block').attr('id'); 359 fileObj = uploader.getFromUniqueIdentifier(fileID); 360 uploader.removeFile(fileObj); 361 $(this).parents('.wpfd_process_block').fadeOut('normal', function () { 362 $(this).remove(); 363 }); 364 365 if (uploader.files.length === 0) { 366 $(currentContainer).find('.wpfd_process_pause').fadeOut('normal', function () { 367 $(this).remove(); 368 }); 369 } 370 371 $.ajax({ 372 url: wpfd_var.wpfduploadajax + '?action=wpfd&task=files.upload', 373 method: 'POST', 374 dataType: 'json', 375 data: { 376 id_category: $('input[name=id_category]').val(), 377 deleteChunks: fileID 378 }, 379 success: function (res, stt) { 380 if (res.response === true) { 381 } 382 } 383 }) 384 }); 385 }); 386 387 // Do not run uploader if no files added or upload same files again 388 if (files.length > 0) { 389 uploadPauseBtn = $(currentContainer).find('.wpreview').find('.wpfd_process_pause').length; 390 restableBlock = $(currentContainer).find('.wpfd_process_block'); 391 392 if (!uploadPauseBtn) { 393 restableBlock.before('<div class="wpfd_process_pause">Pause</div>'); 394 $(currentContainer).find('.wpfd_process_pause').unbind('click').click(function () { 395 if (uploader.isUploading()) { 396 uploader.pause(); 397 $(this).text('Start'); 398 $(this).addClass('paused'); 399 willUpload = false; 400 } else { 401 uploader.upload(); 402 $(this).text('Pause'); 403 $(this).removeClass('paused'); 404 willUpload = true; 405 } 406 }); 407 } 408 409 uploader.opts.query = { 410 id_category: currentContainer.find('input[name=id_category]').val() 411 }; 412 413 if (willUpload) uploader.upload(); 414 } 415 }); 416 417 uploader.on('fileProgress', function (file) { 418 $(currentContainer).find('.wpfd_process_block#' + file.uniqueIdentifier) 419 .find('.wpfd_process_run').width(Math.floor(file.progress() * 100) + '%'); 420 }); 421 422 uploader.on('fileSuccess', function (file, res) { 423 var thisUploadBlock = currentContainer.find('.wpfd_process_block#' + file.uniqueIdentifier); 424 thisUploadBlock.find('.wpfd_process_cancel').addClass('uploadDone').text('OK').unbind('click'); 425 thisUploadBlock.find('.wpfd_process_full').remove(); 426 427 var response = JSON.parse(res); 428 if (response.response === false && typeof(response.datas) !== 'undefined') { 429 if (typeof(response.datas.code) !== 'undefined' && response.datas.code > 20) { 430 bootbox.alert('<div>' + response.datas.message + '</div>'); 431 return false;
432 } 433 } 434 if (typeof(response) === 'string') { 435 bootbox.alert('<div>' + response + '</div>'); 436 return false; 437 } 438 439 if (response.response !== true) { 440 bootbox.alert(response.response); 441 return false; 442 } 443 }); 444 445 uploader.on('fileError', function (file, msg) { 446 thisUploadBlock = currentContainer.find('.wpfd_process_block#' + file.uniqueIdentifier); 447 thisUploadBlock.find('.wpfd_process_cancel').addClass('uploadError').text('Error').unbind('click'); 448 thisUploadBlock.find('.wpfd_process_full').remove(); 449 }); 450 451 uploader.on('complete', function () { 452 var fileCount = $(currentContainer).find('.wpfd_process_cancel').length; 453 var categoryId = $(currentContainer).find('input[name=id_category]').val(); 454 var ajax_url = typeof (wpfd_var.wpfduploadajax) !== 'undefined' ? wpfd_var.wpfduploadajax : wpfdparams.wpfduploadajax; 455 $.ajax({ 456 url: ajax_url + '?action=wpfd&task=files.wpfdPendingUploadFiles', 457 method: 'POST', 458 dataType: 'json', 459 data: { 460 uploadedFiles: fileCount, 461 id_category: categoryId, 462 }, 463 success: function (res) { 464 currentContainer.find('.progress').delay(300).fadeIn(300).hide(300, function () { 465 $(this).remove(); 466 }); 467 currentContainer.find('.uploaded').delay(300).fadeIn(300).hide(300, function () { 468 $(this).remove(); 469 }); 470 $('#wpreview .file').delay(1200).show(1200, function () { 471 $(this).removeClass('done placeholder'); 472 }); 473 474 $('.gritter-item-wrapper ').remove(); 475 $(currentContainer).find('#wpfd-upload-messages').append('File(s) uploaded with success!'); 476 $(currentContainer).find('#wpfd-upload-messages').delay(1200).fadeIn(1200, function () { 477 $(currentContainer).find('#wpfd-upload-messages').empty(); 478 $(currentContainer).find('.wpfd_process_pause').remove(); 479 $(currentContainer).find('.wpfd_process_block').remove(); 480 }); 481 482 // Call list files 483 if (currentContainer.parent('.wpfd-upload-form').length) { 484 var sourcecat = currentContainer.parents('.wpfd-content.wpfd-content-multi').data('category'); 485 var current_category = currentContainer.parents('.wpfd-content.wpfd-content-multi').find('#current_category_' + sourcecat).val(); 486 487 default_load(sourcecat, current_category); 488 return false; 489 } 490 } 491 }); 492 }); 493 494 uploader.assignBrowse($(currentContainer).find('#upload_button')); 495 uploader.assignDrop($(currentContainer).find('.jsWpfdFrontUpload')); 496 } 497 498 var containers = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] div[class*=wpfdUploadForm]"); 499 if (containers.length > 0) { 500 containers.each(function(i, el) { 501 initUploader($(el)); 502 }); 503 } 504 } 505 506 if (typeof wpfdColorboxInit !== 'undefined') { 507 wpfdColorboxInit(); 508 } 509 510 wpfdTrackDownload(); 511 512 default_init_pagination($('.wpfd-content-default[data-category=' + sourcecat + '] + .wpfd-pagination')); 513 wpfd_remove_loading($(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-container-default")); 514 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfdSelectedFiles").remove(); 515 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-selected").remove(); 516 hideDownloadAllBtn(sourcecat, false); 517 } 518 if (empty_files.length) { 519 empty_files.val(content.files.length); 520 fire_empty_category_message(sourcecat); 521 } 522 }); 523 $(document).trigger('wpfd:category-loaded'); 524 } 525 526 function default_breadcrum(sourcecat, catid, category) { 527 var links = []; 528 var current_Cat = cParents[catid]; 529 var defaultdownloadcategory = $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .default-download-category"); 530 if (!current_Cat) { 531 defaultdownloadcategory.attr('href', category.linkdownload_cat); 532 return false;
533 } 534 links.unshift(current_Cat); 535 if (current_Cat.parent !== 0) { 536 while (cParents[current_Cat.parent]) { 537 current_Cat = cParents[current_Cat.parent]; 538 links.unshift(current_Cat); 539 } 540 } 541 542 var html = ''; 543 for (var i = 0; i < links.length; i++) { 544 if (i < links.length - 1) { 545 html += '<li><a class="catlink" data-idcat="' + links[i].term_id + '" href="javascript:void(0)">'; 546 html += links[i].name + '</a><span class="divider"> > </span></li>'; 547 } else { 548 html += '<li><span>' + links[i].name + '</span></li>'; 549 } 550 } 551 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-breadcrumbs-default li").remove(); 552 $(".wpfd-content-default.wpfd-content-multi[data-category=" + sourcecat + "] .wpfd-breadcrumbs-default").append(html); 553 defaultdownloadcategory.attr('href', category.linkdownload_cat); 554 } 555 556 if (tree.length) { 557 tree.each(function () { 558 var topCat = $(this).parents('.wpfd-content-default.wpfd-content-multi').data('category'); 559 $(this).jaofiletree({ 560 script: wpfdparams.wpfdajaxurl + 'task=categories.getCats', 561 usecheckboxes: false, 562 root: topCat, 563 showroot: cParents[topCat].name, 564 onclick: function (elem, file) { 565 566 var topCat = $(elem).parents('.wpfd-content-default.wpfd-content-multi').data('category'); 567 if (topCat !== file) { 568 $('.directory', $(elem).parents('.wpfd-content-default.wpfd-content-multi')).each(function() { 569 if (!$(this).hasClass('selected') && $(this).find('> ul > li').length === 0) { 570 $(this).removeClass('expanded'); 571 } 572 }); 573 574 $(elem).parents('.directory').each(function () { 575 var $this = $(this); 576 var category = $this.find(' > a'); 577 var parent = $this.find('.icon-open-close'); 578 if (parent.length > 0) { 579 if (typeof cParents[category.data('file')] === 'undefined') { 580 cParents[category.data('file')] = { 581 parent: parent.data('parent_id'), 582 term_id: category.data('file'), 583 name: category.text() 584 }; 585 } 586 } 587 }); 588 589 } 590 591 default_load(topCat, file); 592 } 593 }); 594 }) 595 596 } 597 598 $('.wpfd-content-default + .wpfd-pagination').each(function (index, elm) { 599 var $this = $(elm); 600 default_init_pagination($this); 601 }); 602 603 function default_init_pagination($this) { 604 605 var number = $this.find('a:not(.current)'); 606 607 var wrap = $this.prev('.wpfd-content-default'); 608 609 var sourcecat = wrap.data('category'); 610 var current_category = wrap.find('#current_category_' + sourcecat).val(); 611 612 number.unbind('click').bind('click', function () { 613 var page_number = $(this).attr('data-page'); 614 var current_sourcecat = $(this).attr('data-sourcecat'); 615 var wrap = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]"); 616 var current_category = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_' + current_sourcecat).val(); 617 if (typeof page_number !== 'undefined') { 618 var pathname = window.location.href.replace(window.location.hash, ''); 619 var category = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_' + current_sourcecat).val(); 620 var category_slug = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_category_slug_' + current_sourcecat).val(); 621 var ordering = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_ordering_' + current_sourcecat).val(); 622 var orderingDirection = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#current_ordering_direction_' + current_sourcecat).val(); 623 624 var page_limit = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "]").find('#page_limit_' + current_sourcecat).val(); 625 626 window.history.pushState('', document.title, pathname + '#' + current_sourcecat + '-' + category + '-wpfd-' + category_slug + '-p' + page_number); 627 628 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default .wpfd_list").remove(); 629 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default").append($('#wpfd-loading-wrap').html()); 630 631 var params = $.param({ 632 task: 'files.display', 633 view: 'files', 634 id: current_category, 635 rootcat: current_sourcecat, 636 page: page_number, 637 orderCol: ordering, 638 orderDir: orderingDirection, 639 page_limit: page_limit 640 }); 641 642 //Get files 643 $.ajax({ 644 url: wpfdparams.wpfdajaxurl + params, 645 dataType: "json", 646 beforeSend: function () { 647 $('html, body').animate({scrollTop: $(".wpfd-content[data-category=" + current_sourcecat + "]").offset().top}, 'fast'); 648 } 649 }).done(function (content) { 650 delete content.category; 651 wrap.next('.wpfd-pagination').remove(); 652 wrap.after(content.pagination); 653 delete content.pagination; 654 var sourcefiles = $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-template-files").html() 655 var template = Handlebars.compile(sourcefiles); 656 var html = template(content); 657 658 if ($(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default .wpfd-upload-form").length) { 659 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default .wpfd-upload-form").before(html); 660 } else { 661 $(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default").append(html); 662 } 663 664 if (typeof wpfdColorboxInit !== 'undefined') { 665 wpfdColorboxInit(); 666 } 667 default_init_pagination(wrap.next('.wpfd-pagination')); 668 wpfd_remove_loading($(".wpfd-content-default.wpfd-content-multi[data-category=" + current_sourcecat + "] .wpfd-container-default")); 669 }); 670 } 671 }); 672 } 673 674 function wpfd_container_with_foldertree() { 675 $('.wpfd-content-default .wpfd-container').each(function () { 676 if($(this).children('.with_foldertree').length > 0) { 677 $(this).addClass('wpfd_dfcontainer_foldertree'); 678 } else { 679 if($(this).hasClass('wpfd_dfcontainer_foldertree')) { 680 $(this).removeClass('wpfd_dfcontainer_foldertree'); 681 } 682 } 683 }); 684 685 //parent-content 686 $('.wpfd-content-default').each(function () {
687 if($(this).children().has('.wpfd-foldertree').length > 0) { 688 $(this).addClass('wpfd_contentdefault_foldertree'); 689 } else { 690 if($(this).hasClass('wpfd_contentdefault_foldertree')) { 691 $(this).removeClass('wpfd_contentdefault_foldertree'); 692 } 693 } 694 }); 695 } 696 697 wpfd_container_with_foldertree(); 698 699 function fire_empty_category_message(category_id) { 700 if (!category_id) { 701 return; 702 } 703 var root_category = '.wpfd-content-default.wpfd-content-multi[data-category=' + category_id + ']'; 704 var display_empty_category_message = $(root_category).find('#wpfd_display_empty_category_message').val(); 705 var empty_category_message_val = $(root_category).find('#wpfd_empty_category_message_val').val(); 706 var is_empty_subcategories = $(root_category).find('#wpfd_is_empty_subcategories').val(); 707 var is_empty_files = $(root_category).find('#wpfd_is_empty_files').val(); 708 709 if (parseInt(display_empty_category_message) !== 1 710 || parseInt(is_empty_subcategories) !== 0 || parseInt(is_empty_files) !== 0 ) { 711 return; 712 } 713 714 var code = '<div class="wpfd-empty-category-message-section">'; 715 code += '<p class="wpfd-empty-category-message">'; 716 code += empty_category_message_val; 717 code += '</p>'; 718 code += '</div>'; 719 720 $(root_category).find('.wpfd-empty-category-message-section').remove(); 721 $(root_category).find('.wpfd-container-default').append(code); 722 } 723 724 var destroy_upload = $('.wpfd-upload-form.destroy'); 725 if (destroy_upload.length) { 726 destroy_upload.remove(); 727 } 728});
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.