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