| @@ -10,16 +10,15 @@ | ||
| 10 | 10 | var heartbeat_agents = []; |
| 11 | 11 | |
| 12 | 12 | var last_ui_update_agent_uid = null; |
| 13 | 13 | |
| 14 | + var block_ui = wp_optimize.block_ui; | |
| 15 | + | |
| 14 | 16 | /** |
| 15 | 17 | * Variables for smushing. |
| 16 | 18 | */ |
| 17 | - var smush_nav_tab = $('#wp-optimize-images-nav-tab-smush'), | |
| 18 | - smush_images_grid = $('#wpo_smush_images_grid'), | |
| 19 | + var smush_images_grid = $('#wpo_smush_images_grid'), | |
| 19 | 20 | smush_images_optimization_message = $('#smush_info_images'), |
| 20 | - smush_images_pending_tasks_container = $('#wpo_smush_images_pending_tasks_container'), | |
| 21 | - smush_images_pending_tasks_btn = $('#wpo_smush_images_pending_tasks_button'), | |
| 22 | 21 | smush_images_refresh_btn = $('#wpo_smush_images_refresh'), |
| 23 | 22 | smush_images_select_all_btn = $('#wpo_smush_images_select_all'), |
| 24 | 23 | smush_images_select_none_btn = $('#wpo_smush_images_select_none'), |
| 25 | 24 | smush_images_stats_clear_btn = $('#wpo_smush_clear_stats_btn'), |
| @@ -24,11 +23,8 @@ | ||
| 24 | 23 | smush_images_select_none_btn = $('#wpo_smush_images_select_none'), |
| 25 | 24 | smush_images_stats_clear_btn = $('#wpo_smush_clear_stats_btn'), |
| 26 | 25 | smush_selected_images_btn = $('#wpo_smush_images_btn'), |
| 27 | 26 | smush_mark_as_compressed_btn = $('#wpo_smush_mark_as_compressed'), |
| 28 | - smush_single_image_btn = $('.wpo_smush_single_image .button'), | |
| 29 | - smush_single_restore_btn = $('.wpo_restore_single_image .button'), | |
| 30 | - convert_to_webp_btn = $('.wpo_smush.column-wpo_smush .convert-to-webp'); | |
| 31 | 27 | smush_mark_all_as_uncompressed_btn = $('#wpo_smush_mark_all_as_uncompressed_btn'), |
| 32 | 28 | restore_all_compressed_images_btn = $('#wpo_smush_restore_all_compressed_images_btn'), |
| 33 | 29 | smush_view_logs_btn = $('.wpo_smush_get_logs'), |
| 34 | 30 | smush_delete_backup_images_btn = $('#wpo_smush_delete_backup_btn'), |
| @@ -46,8 +42,22 @@ | ||
| 46 | 42 | smush_affected_images = {}, |
| 47 | 43 | pending_tasks_cancel_btn = $('#wpo_smush_images_pending_tasks_cancel_button'), |
| 48 | 44 | uncompressed_images_sites_select = $('#wpo_uncompressed_images_sites_select'); |
| 49 | 45 | |
| 46 | + /** | |
| 47 | + * These options used for block UI with custom content. | |
| 48 | + */ | |
| 49 | + var block_ui_custom_options = { | |
| 50 | + baseZ: 160001, | |
| 51 | + css: { | |
| 52 | + top: '50%', | |
| 53 | + transform: 'translate(0, -50%)', | |
| 54 | + width: '400px', | |
| 55 | + padding: '20px', | |
| 56 | + cursor: 'pointer' | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 50 | 60 | $('#doaction, #doaction2').on('click', function(e) { |
| 51 | 61 | e.stopImmediatePropagation(); |
| 52 | 62 | var action = $(this).prev('select').val(); |
| 53 | 63 | if ('wp_optimize_bulk_compression' !== action && 'wp_optimize_bulk_restore' !== action ) return; |
| @@ -64,10 +74,9 @@ | ||
| 64 | 74 | * |
| 65 | 75 | * @param {Object} $selected_images |
| 66 | 76 | */ |
| 67 | 77 | function bulk_compression($selected_images) { |
| 68 | - $('#smush-information-modal .smush-information').text(wposmush.server_check); | |
| 69 | - update_view_modal_message($('#smush-information-modal')); | |
| 78 | + block_ui(wposmush.server_check); | |
| 70 | 79 | |
| 71 | 80 | data = { 'server': wposmush.smush_settings.compression_server, skip_notice: true }; |
| 72 | 81 | smush_manager_send_command('check_server_status', data, function(resp) { |
| 73 | 82 | if (resp.online) { |
| @@ -91,24 +100,16 @@ | ||
| 91 | 100 | } |
| 92 | 101 | smush_from_media_library = true; |
| 93 | 102 | smush_completed = false; |
| 94 | 103 | if (smush_timer_locked) return; |
| 95 | - update_view_modal_message($('#wpo_smush_images_information_container')); | |
| 96 | - | |
| 97 | - $('#wpo_smush_images_information_server').html(wposmush.smush_settings.compression_server); | |
| 98 | - | |
| 104 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#wpo_smush_images_information_container')}), false, true); | |
| 99 | 105 | clear_smush_stats(); |
| 100 | 106 | |
| 101 | 107 | smush_timer_handle = window.setInterval(smush_timer, 1000); |
| 102 | 108 | smush_manager_send_command('process_bulk_smush', data); |
| 103 | 109 | } else { |
| 104 | - if (resp.error) { | |
| 105 | - error_message = resp.error + '<br>' + wposmush.server_error | |
| 106 | - $('#smush-information-modal .smush-information').html(error_message); | |
| 107 | - } else { | |
| 108 | - $('#smush-information-modal .smush-information').text(wposmush.server_error); | |
| 109 | - } | |
| 110 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 110 | + error_message = resp.error ? resp.error + '<br>' + wposmush.server_error : wposmush.server_error; | |
| 111 | + block_ui(error_message); | |
| 111 | 112 | } |
| 112 | 113 | }); |
| 113 | 114 | } |
| 114 | 115 | |
| @@ -166,9 +167,9 @@ | ||
| 166 | 167 | smush_manager_send_command('reset_webp_serving_method', { skip_notice: true }, function(resp) { |
| 167 | 168 | if (!resp.success) { |
| 168 | 169 | $('#enable_webp_conversion').prop("checked", false); |
| 169 | 170 | $('#smush-information-modal .smush-information').text(resp.error_message); |
| 170 | - update_view_modal_message($('#smush-information-modal')) | |
| 171 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#smush-information-modal')}), false, true); | |
| 171 | 172 | } else { |
| 172 | 173 | $('#wpo_reset_webp_serving_method_done').show().delay(3000).fadeOut(); |
| 173 | 174 | } |
| 174 | 175 | }); |
| @@ -258,15 +259,13 @@ | ||
| 258 | 259 | */ |
| 259 | 260 | smush_selected_images_btn.off().on('click', function() { |
| 260 | 261 | |
| 261 | 262 | if (0 == $('#wpo_smush_images_grid input[type="checkbox"]:checked').length) { |
| 262 | - $('#smush-information-modal .smush-information').text(wposmush.please_select_images) | |
| 263 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 263 | + block_ui(wposmush.please_select_images); | |
| 264 | 264 | return; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $('#smush-information-modal .smush-information').text(wposmush.server_check); | |
| 268 | - update_view_modal_message($('#smush-information-modal')); | |
| 267 | + block_ui(wposmush.server_check); | |
| 269 | 268 | |
| 270 | 269 | data = { 'server': $("input[name='compression_server']:checked").val(), skip_notice: true }; |
| 271 | 270 | smush_manager_send_command('check_server_status', data, function(resp) { |
| 272 | 271 | if (resp.online) { |
| @@ -271,15 +270,10 @@ | ||
| 271 | 270 | smush_manager_send_command('check_server_status', data, function(resp) { |
| 272 | 271 | if (resp.online) { |
| 273 | 272 | bulk_smush_selected_images(); |
| 274 | 273 | } else { |
| 275 | - if (resp.error) { | |
| 276 | - error_message = resp.error + '<br>' + wposmush.server_error | |
| 277 | - $('#smush-information-modal .smush-information').html(error_message); | |
| 278 | - } else { | |
| 279 | - $('#smush-information-modal .smush-information').text(wposmush.server_error); | |
| 280 | - } | |
| 281 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 274 | + error_message = resp.error ? resp.error + '<br>' + wposmush.server_error : wposmush.server_error; | |
| 275 | + block_ui(error_message); | |
| 282 | 276 | } |
| 283 | 277 | }); |
| 284 | 278 | }); |
| 285 | 279 | |
| @@ -286,13 +280,8 @@ | ||
| 286 | 280 | /** |
| 287 | 281 | * Mark as compressed |
| 288 | 282 | */ |
| 289 | 283 | smush_mark_as_compressed_btn.off().on('click', function() { |
| 290 | - if (0 == $('#wpo_smush_images_grid input[type="checkbox"]:checked').length) { | |
| 291 | - $('#smush-information-modal .smush-information').text(wposmush.please_select_compressed_images) | |
| 292 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 293 | - return; | |
| 294 | - } | |
| 295 | 284 | |
| 296 | 285 | var selected_images = [], |
| 297 | 286 | image; |
| 298 | 287 | |
| @@ -303,15 +292,15 @@ | ||
| 303 | 292 | }; |
| 304 | 293 | selected_images.push(image); |
| 305 | 294 | }); |
| 306 | 295 | |
| 307 | - update_view_modal_message(wposmush.please_updating_images_info); | |
| 296 | + block_ui(wposmush.please_updating_images_info); | |
| 308 | 297 | |
| 309 | 298 | smush_manager_send_command('mark_as_compressed', {selected_images: selected_images}, function(response) { |
| 310 | 299 | $('#smush-information-modal .smush-information').text(response.summary); |
| 311 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 300 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#smush-information-modal')})); | |
| 312 | 301 | // refresh images list. |
| 313 | - get_info_from_smush_manager(); | |
| 302 | + get_info_from_smush_manager(false); | |
| 314 | 303 | }); |
| 315 | 304 | }); |
| 316 | 305 | |
| 317 | 306 | /** |
| @@ -321,10 +310,9 @@ | ||
| 321 | 310 | if (!confirm(wposmush.mark_all_images_uncompressed)) return; |
| 322 | 311 | |
| 323 | 312 | var restore_backup = confirm(wposmush.restore_images_from_backup); |
| 324 | 313 | |
| 325 | - update_view_modal_message($('#smush-information-modal-cancel-btn')); | |
| 326 | - $('#smush-information-modal-cancel-btn .smush-information').text(wposmush.please_wait); | |
| 314 | + block_ui(wposmush.please_wait); | |
| 327 | 315 | |
| 328 | 316 | smush_mark_all_as_uncompressed = true; |
| 329 | 317 | run_mark_all_as_uncompressed(restore_backup); |
| 330 | 318 | }); |
| @@ -334,10 +322,9 @@ | ||
| 334 | 322 | */ |
| 335 | 323 | restore_all_compressed_images_btn.on('click', function() { |
| 336 | 324 | if (!confirm(wposmush.restore_all_compressed_images)) return; |
| 337 | 325 | |
| 338 | - update_view_modal_message($('#smush-information-modal-cancel-btn')); | |
| 339 | - $('#smush-information-modal-cancel-btn .smush-information').text(wposmush.please_wait); | |
| 326 | + block_ui(wposmush.please_wait); | |
| 340 | 327 | |
| 341 | 328 | smush_mark_all_as_uncompressed = true; |
| 342 | 329 | run_mark_all_as_uncompressed(true, true); |
| 343 | 330 | }); |
| @@ -375,10 +362,9 @@ | ||
| 375 | 362 | if (!smush_mark_all_as_uncompressed) return; |
| 376 | 363 | |
| 377 | 364 | // if we get an error then show it |
| 378 | 365 | if (resp.hasOwnProperty('error')) { |
| 379 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 380 | - $('#smush-information-modal .smush-information').text(resp.error); | |
| 366 | + block_ui(resp.error); | |
| 381 | 367 | get_info_from_smush_manager(); |
| 382 | 368 | return; |
| 383 | 369 | } |
| 384 | 370 | |
| @@ -383,9 +369,9 @@ | ||
| 383 | 369 | } |
| 384 | 370 | |
| 385 | 371 | // if completed then refresh uncompressed images list and show final message. |
| 386 | 372 | if (resp.completed) { |
| 387 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 373 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#smush-information-modal')})); | |
| 388 | 374 | $('#smush-information-modal .smush-information').text(resp.message); |
| 389 | 375 | get_info_from_smush_manager(); |
| 390 | 376 | } else { |
| 391 | 377 | info.text(resp.message); |
| @@ -475,35 +461,8 @@ | ||
| 475 | 461 | }); |
| 476 | 462 | }); |
| 477 | 463 | |
| 478 | 464 | /** |
| 479 | - * Binds pending tasks button | |
| 480 | - */ | |
| 481 | - smush_images_pending_tasks_btn.off().on('click', function(e) { | |
| 482 | - $('#smush-information-modal .smush-information').text(wposmush.server_check); | |
| 483 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 484 | - data = { 'server': $("input[name='compression_server']:checked").val(), skip_notice: true }; | |
| 485 | - smush_manager_send_command('check_server_status', data, function(resp) { | |
| 486 | - if (resp.online) { | |
| 487 | - update_view_bulk_smush_start(); | |
| 488 | - smush_manager_send_command('process_pending_images', {}, function(resp) { | |
| 489 | - handle_response_from_smush_manager(resp, update_view_bulk_smush_progress); | |
| 490 | - }); | |
| 491 | - } else { | |
| 492 | - if (resp.error) { | |
| 493 | - error_message = resp.error + '<br>' + wposmush.server_error | |
| 494 | - $('#smush-information-modal .smush-information').html(error_message); | |
| 495 | - } else { | |
| 496 | - $('#smush-information-modal .smush-information').text(wposmush.server_error); | |
| 497 | - } | |
| 498 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 499 | - } | |
| 500 | - }); | |
| 501 | - | |
| 502 | - }); | |
| 503 | - | |
| 504 | - | |
| 505 | - /** | |
| 506 | 465 | * Binds smush cancel button |
| 507 | 466 | */ |
| 508 | 467 | $('body').on('click', '#wpo_smush_images_pending_tasks_cancel_button', function(e) { |
| 509 | 468 | |
| @@ -510,9 +469,9 @@ | ||
| 510 | 469 | if (wposmush.cancel === pending_tasks_cancel_btn.val()) { |
| 511 | 470 | pending_tasks_cancel_btn.val(wposmush.cancelling); |
| 512 | 471 | pending_tasks_cancel_btn.prop('disabled', true); |
| 513 | 472 | } |
| 514 | - smush_manager_send_command('clear_pending_images', {}, function(resp) { | |
| 473 | + smush_manager_send_command('clear_pending_images', { restore_images: smush_image_list }, function(resp) { | |
| 515 | 474 | $.unblockUI(); |
| 516 | 475 | if (resp.status) { |
| 517 | 476 | get_info_from_smush_manager(); |
| 518 | 477 | reset_view_bulk_smush(); |
| @@ -548,9 +507,9 @@ | ||
| 548 | 507 | '</div>', |
| 549 | 508 | ' ', |
| 550 | 509 | '<a href="#" class="button wpo-smush-popup-cancel-btn">',wposmush.close,'</a>' |
| 551 | 510 | ].join(''); |
| 552 | - update_view_modal_message(html, $.unblockUI); | |
| 511 | + block_ui('', $.extend(block_ui_custom_options, {message: html})); | |
| 553 | 512 | } |
| 554 | 513 | }); |
| 555 | 514 | |
| 556 | 515 | }); |
| @@ -589,20 +548,15 @@ | ||
| 589 | 548 | 'preserve_exif': $('#smush_exif_' + image.attachment_id).is(":checked") |
| 590 | 549 | } |
| 591 | 550 | |
| 592 | 551 | data = { 'server': $("input[name='compression_server_" + $(this).attr('id').substring(15) + "']:checked").val() }; |
| 593 | - update_view_modal_message(wposmush.server_check); | |
| 552 | + block_ui(wposmush.server_check); | |
| 594 | 553 | smush_manager_send_command('check_server_status', data, function(resp) { |
| 595 | 554 | if (resp.online) { |
| 596 | 555 | smush_selected_image(image, smush_options); |
| 597 | 556 | } else { |
| 598 | - if (resp.error) { | |
| 599 | - error_message = resp.error + '<br>' + wposmush.server_error | |
| 600 | - | |
| 601 | - update_view_modal_message(error_message, $.unblockUI); | |
| 602 | - } else { | |
| 603 | - update_view_modal_message(wposmush.server_error, $.unblockUI); | |
| 604 | - } | |
| 557 | + error_message = resp.error ? resp.error + '<br>' + wposmush.server_error : wposmush.server_error; | |
| 558 | + block_ui(error_message); | |
| 605 | 559 | } |
| 606 | 560 | }); |
| 607 | 561 | }); |
| 608 | 562 | |
| @@ -656,16 +610,15 @@ | ||
| 656 | 610 | } |
| 657 | 611 | |
| 658 | 612 | e.preventDefault(); |
| 659 | 613 | |
| 660 | - update_view_modal_message(wposmush.please_updating_images_info); | |
| 661 | - | |
| 614 | + block_ui(wposmush.please_updating_images_info); | |
| 615 | + | |
| 662 | 616 | smush_manager_send_command('mark_as_compressed', data, function(response) { |
| 663 | - // if we are on the Media Library list view page append popup element | |
| 664 | - if (0 == $('#smush-information-modal').length) append_smush_information_modal(); | |
| 665 | - | |
| 617 | + | |
| 666 | 618 | $('#smush-information-modal .smush-information').text(response.summary); |
| 667 | - update_view_modal_message($('#smush-information-modal'), $.unblockUI); | |
| 619 | + | |
| 620 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#smush-information-modal')})); | |
| 668 | 621 | |
| 669 | 622 | if (response.status) { |
| 670 | 623 | if (wrapper.length) { |
| 671 | 624 | if (mark) { |
| @@ -769,9 +722,9 @@ | ||
| 769 | 722 | $('#enable_webp_conversion').prop("checked", false); |
| 770 | 723 | if ('update_failed_no_working_webp_converter' === resp.error_code) { |
| 771 | 724 | var html_msg = '<p>' |
| 772 | 725 | + wposmush.webp_conversion_tool_error |
| 773 | - + ' <a href="https://getwpo.com/faqs/#How-can-I-get-WebP-conversion-tools-to-work-" target="_blank">' | |
| 726 | + + ' <a href="https://teamupdraft.com/documentation/wp-optimize/topics/image-compression/troubleshooting/the-webp-conversion-tool-is-not-working/" target="_blank">' | |
| 774 | 727 | + wposmush.webp_conversion_tool_how_to |
| 775 | 728 | + '</a></p>'; |
| 776 | 729 | $('#smush-information-modal .smush-information').html(html_msg); |
| 777 | 730 | } else { |
| @@ -776,15 +729,15 @@ | ||
| 776 | 729 | $('#smush-information-modal .smush-information').html(html_msg); |
| 777 | 730 | } else { |
| 778 | 731 | $('#smush-information-modal .smush-information').text(resp.error_message); |
| 779 | 732 | } |
| 780 | - update_view_modal_message($('#smush-information-modal')); | |
| 733 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#smush-information-modal')}), false, true); | |
| 781 | 734 | } |
| 782 | 735 | $('#enable_webp_conversion').prop("disabled", false); |
| 783 | 736 | }); |
| 784 | 737 | }); |
| 785 | 738 | |
| 786 | - convert_to_webp_btn.on('click', function(e){ | |
| 739 | + $('body').on('click', '.wpo_smush.column-wpo_smush .convert-to-webp', function(e){ | |
| 787 | 740 | e.preventDefault(); |
| 788 | 741 | var $link = $(this); |
| 789 | 742 | data = { |
| 790 | 743 | 'attachment_id': $(this).data('attachment-id'), |
| @@ -789,22 +742,17 @@ | ||
| 789 | 742 | data = { |
| 790 | 743 | 'attachment_id': $(this).data('attachment-id'), |
| 791 | 744 | skip_notice: true |
| 792 | 745 | }; |
| 793 | - update_view_modal_message(wposmush.converting_to_webp); | |
| 746 | + block_ui(wposmush.converting_to_webp, {}, 0, true); | |
| 794 | 747 | smush_manager_send_command('convert_to_webp_format', data, function(response) { |
| 795 | - if (response.error) { | |
| 796 | - update_view_modal_message(response.error, $.unblockUI); | |
| 797 | - setTimeout(function() { | |
| 798 | - $.unblockUI(); | |
| 799 | - }, 2000); | |
| 800 | - } else { | |
| 801 | - update_view_modal_message(response.success, $.unblockUI); | |
| 802 | - setTimeout(function() { | |
| 803 | - $.unblockUI(); | |
| 804 | - }, 2000); | |
| 748 | + if (response.success) { | |
| 749 | + block_ui(response.success, {}, 2000); | |
| 805 | 750 | $link.next().remove(); |
| 751 | + if ($link.prev().is('.wpo-action-separator')) $link.prev().remove(); | |
| 806 | 752 | $link.remove(); |
| 753 | + } else { | |
| 754 | + block_ui(response.error || response.error_message || wposmush.server_error , {}, 2000); | |
| 807 | 755 | } |
| 808 | 756 | }); |
| 809 | 757 | }); |
| 810 | 758 | |
| @@ -820,9 +768,8 @@ | ||
| 820 | 768 | var use_cache = (typeof use_cache === 'undefined') ? true : use_cache; |
| 821 | 769 | var data = { 'use_cache': use_cache }; |
| 822 | 770 | |
| 823 | 771 | smush_images_optimization_message.html('...'); |
| 824 | - smush_images_pending_tasks_container.hide(); | |
| 825 | 772 | |
| 826 | 773 | disable_image_optimization_controls(true); |
| 827 | 774 | |
| 828 | 775 | heartbeat_agents.push(heartbeat.add_agent({ |
| @@ -979,9 +926,9 @@ | ||
| 979 | 926 | |
| 980 | 927 | /** |
| 981 | 928 | * Update images optimization tab view with data returned from images optimization. |
| 982 | 929 | * |
| 983 | - * @param {Object} data - meta data returned from task manager | |
| 930 | + * @param {Object} data - metadata returned from task manager | |
| 984 | 931 | * |
| 985 | 932 | * @return void |
| 986 | 933 | */ |
| 987 | 934 | function update_view_show_uncompressed_images(data) { |
| @@ -996,12 +943,8 @@ | ||
| 996 | 943 | if (0 == unsmushed_images.length && 0 == pending_tasks) { |
| 997 | 944 | smush_images_grid.text(wposmush.all_images_compressed).wrapInner("<div class='wpo-fieldgroup'> </div>"); |
| 998 | 945 | } |
| 999 | 946 | |
| 1000 | - if (0 != pending_tasks) { | |
| 1001 | - smush_images_pending_tasks_container.show().find('.red').text(data.pending); | |
| 1002 | - } | |
| 1003 | - | |
| 1004 | 947 | if (1 === data.is_multisite) { |
| 1005 | 948 | blog_id = uncompressed_images_sites_select.find(":selected").val(); |
| 1006 | 949 | add_unsmushed_images_to_grid(blog_id, data); |
| 1007 | 950 | } else { |
| @@ -1043,12 +986,10 @@ | ||
| 1043 | 986 | * @return void |
| 1044 | 987 | */ |
| 1045 | 988 | function update_view_bulk_smush_start() { |
| 1046 | 989 | if (smush_timer_locked) return; |
| 1047 | - update_view_modal_message($('#wpo_smush_images_information_container')); | |
| 1048 | 990 | |
| 1049 | - service = $('.compression_server input[type="radio"]:checked + label small').text(); | |
| 1050 | - $('#wpo_smush_images_information_server').html(service); | |
| 991 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#wpo_smush_images_information_container')}), false, true); | |
| 1051 | 992 | |
| 1052 | 993 | clear_smush_stats(); |
| 1053 | 994 | |
| 1054 | 995 | smush_timer_handle = window.setInterval(smush_timer, 1000); |
| @@ -1123,8 +1064,11 @@ | ||
| 1123 | 1064 | }; |
| 1124 | 1065 | |
| 1125 | 1066 | (function(single_callback) { |
| 1126 | 1067 | heartbeat_agents.push(heartbeat.add_agent({ |
| 1068 | + // We have to use a non-unique agent in the complete action because the info update subactions | |
| 1069 | + // have the same names, and the agent may not be added. This ensures that the "smush_complete" action will run. | |
| 1070 | + _unique: false, | |
| 1127 | 1071 | _wait: false, |
| 1128 | 1072 | _keep: false, |
| 1129 | 1073 | command: 'updraft_smush_ajax', |
| 1130 | 1074 | command_data: {data: data, subaction: 'get_ui_update'}, |
| @@ -1130,8 +1074,12 @@ | ||
| 1130 | 1074 | command_data: {data: data, subaction: 'get_ui_update'}, |
| 1131 | 1075 | callback: function(resp) { |
| 1132 | 1076 | |
| 1133 | 1077 | summary = resp.session_stats; |
| 1078 | + // Prevent pops with undefined headers | |
| 1079 | + if (!resp.session_stats) { | |
| 1080 | + return; | |
| 1081 | + } | |
| 1134 | 1082 | |
| 1135 | 1083 | if (0 != resp.completed_task_count) { |
| 1136 | 1084 | summary += '<hr>' + resp.summary; |
| 1137 | 1085 | } |
| @@ -1158,9 +1106,9 @@ | ||
| 1158 | 1106 | if (smush_completed) return; |
| 1159 | 1107 | |
| 1160 | 1108 | $('#summary-message').html(summary); |
| 1161 | 1109 | reset_view_bulk_smush(); |
| 1162 | - update_view_modal_message($('#smush-complete-summary')); | |
| 1110 | + block_ui('', $.extend(block_ui_custom_options, {message: $('#smush-complete-summary')})); | |
| 1163 | 1111 | smush_completed = true; |
| 1164 | 1112 | |
| 1165 | 1113 | heartbeat.cancel_agents(heartbeat_agents); |
| 1166 | 1114 | } |
| @@ -1243,9 +1191,8 @@ | ||
| 1243 | 1191 | smush_selected_images_btn, |
| 1244 | 1192 | smush_images_select_all_btn, |
| 1245 | 1193 | smush_images_select_none_btn, |
| 1246 | 1194 | smush_images_refresh_btn, |
| 1247 | - smush_images_pending_tasks_btn, | |
| 1248 | 1195 | smush_mark_as_compressed_btn, |
| 1249 | 1196 | ], function(i, el) { |
| 1250 | 1197 | el.prop('disabled', disable); |
| 1251 | 1198 | }); |
| @@ -1273,12 +1220,13 @@ | ||
| 1273 | 1220 | if (0 == selected_image.length) return; |
| 1274 | 1221 | |
| 1275 | 1222 | data = { |
| 1276 | 1223 | selected_image: selected_image, |
| 1277 | - smush_options: smush_options | |
| 1224 | + smush_options: smush_options, | |
| 1225 | + skip_notice: true | |
| 1278 | 1226 | } |
| 1279 | 1227 | |
| 1280 | - update_view_modal_message(wposmush.compress_single_image_dialog); | |
| 1228 | + block_ui(wposmush.compress_single_image_dialog, {}, false, true); | |
| 1281 | 1229 | smush_manager_send_command('compress_single_image', data, function(resp) { |
| 1282 | 1230 | handle_response_from_smush_manager(resp, update_view_single_image_complete); |
| 1283 | 1231 | }); |
| 1284 | 1232 | } |
| @@ -1296,10 +1244,10 @@ | ||
| 1296 | 1244 | |
| 1297 | 1245 | // if no selected images then exit. |
| 1298 | 1246 | if (0 == selected_image.length) return; |
| 1299 | 1247 | |
| 1300 | - update_view_modal_message(wposmush.please_wait, $.unblockUI); | |
| 1301 | - var data = { 'blog_id': blog_id, 'selected_image': selected_image }; | |
| 1248 | + block_ui(wposmush.please_wait); | |
| 1249 | + var data = { 'blog_id': blog_id, 'selected_image': selected_image, skip_notice: true }; | |
| 1302 | 1250 | |
| 1303 | 1251 | smush_manager_send_command.apply({unique: false}, ['restore_single_image', data, function(resp) { |
| 1304 | 1252 | var done = function(resp_summary_alt) { |
| 1305 | 1253 | if ('undefined' != typeof(resp_summary_alt)) { |
| @@ -1326,13 +1274,10 @@ | ||
| 1326 | 1274 | */ |
| 1327 | 1275 | function update_view_single_image_complete(resp) { |
| 1328 | 1276 | |
| 1329 | 1277 | if (resp.hasOwnProperty('success') && resp.success) { |
| 1330 | - // if we are on the Media Library list view page | |
| 1331 | - if (0 === $('#smush-information-modal').length) append_smush_information_modal(); | |
| 1332 | - | |
| 1333 | 1278 | $(".smush-information").text(resp.summary); |
| 1334 | - update_view_modal_message($("#smush-information-modal"), $.unblockUI); | |
| 1279 | + block_ui('', $.extend(block_ui_custom_options, {message: $("#smush-information-modal")})); | |
| 1335 | 1280 | |
| 1336 | 1281 | $('.wpo-toggle-advanced-options.wpo_smush_single_image').removeClass('opened'); |
| 1337 | 1282 | |
| 1338 | 1283 | update_view_singe_image_compress(resp.operation, resp.summary, resp.restore_possible, resp); |
| @@ -1364,26 +1309,15 @@ | ||
| 1364 | 1309 | operation: resp.operation |
| 1365 | 1310 | } |
| 1366 | 1311 | } |
| 1367 | 1312 | } else { |
| 1368 | - $(".smush-information").text(resp.error_message); | |
| 1369 | - update_view_modal_message($("#smush-information-modal"), $.unblockUI); | |
| 1313 | + // Update the error message to be user-friendly | |
| 1314 | + if (/exceeded_max_filesize/.test(resp.error_message)) resp.error_message = wposmush.exceeded_max_filesize | |
| 1315 | + block_ui(resp.error_message, {}, 4000); | |
| 1370 | 1316 | } |
| 1371 | 1317 | } |
| 1372 | 1318 | |
| 1373 | 1319 | /** |
| 1374 | - * Append smush information modal element to body | |
| 1375 | - */ | |
| 1376 | - function append_smush_information_modal() { | |
| 1377 | - $('body').append([ | |
| 1378 | - '<div id="smush-information-modal" class="wp-core-ui" style="display:none;">', | |
| 1379 | - '<div class="smush-information"></div>', | |
| 1380 | - '<input type="button" class="wpo_primary_small button-primary information-modal-close" value="',wposmush.close,'" />', | |
| 1381 | - '</div>' | |
| 1382 | - ].join('')); | |
| 1383 | - } | |
| 1384 | - | |
| 1385 | - /** | |
| 1386 | 1320 | * Update information for the WP-Optimize column in the Media Library. |
| 1387 | 1321 | * |
| 1388 | 1322 | * @param {number} blog_id |
| 1389 | 1323 | * @param {number} image_id |
| @@ -1453,32 +1387,8 @@ | ||
| 1453 | 1387 | } |
| 1454 | 1388 | }); |
| 1455 | 1389 | |
| 1456 | 1390 | /** |
| 1457 | - * Display a modal message | |
| 1458 | - * | |
| 1459 | - * @param {string} message The message or element to display | |
| 1460 | - * @param {Function} callback Called when the overlay is clicked | |
| 1461 | - * | |
| 1462 | - * @return void | |
| 1463 | - */ | |
| 1464 | - function update_view_modal_message(message, callback) { | |
| 1465 | - | |
| 1466 | - $.blockUI({ | |
| 1467 | - message: message, | |
| 1468 | - onOverlayClick: callback, | |
| 1469 | - baseZ: 160001, | |
| 1470 | - css: { | |
| 1471 | - top: '50%', | |
| 1472 | - transform: 'translate(0, -50%)', | |
| 1473 | - width: '400px', | |
| 1474 | - padding: '20px', | |
| 1475 | - cursor: 'pointer' | |
| 1476 | - } | |
| 1477 | - }); | |
| 1478 | - } | |
| 1479 | - | |
| 1480 | - /** | |
| 1481 | 1391 | * Check returned response from the smush manager and call update view callback. |
| 1482 | 1392 | * |
| 1483 | 1393 | * @param {Object} resp - response from smush manager. |
| 1484 | 1394 | * @param {Function} update_view_callback - callback function to update view. |
| @@ -1533,19 +1443,27 @@ | ||
| 1533 | 1443 | * @param {string} action The action to send |
| 1534 | 1444 | * @param {[type]} data Data to send |
| 1535 | 1445 | * @param {Function} callback Will be called with the results |
| 1536 | 1446 | * @param {boolean} json_parse JSON parse the results |
| 1447 | + * @param {boolean} wait Wait for the response | |
| 1537 | 1448 | * |
| 1538 | 1449 | * @return {JSON} |
| 1539 | 1450 | */ |
| 1540 | - function smush_manager_send_command(action, data, callback, json_parse) { | |
| 1451 | + function smush_manager_send_command(action, data, callback, json_parse, wait) { | |
| 1541 | 1452 | |
| 1542 | 1453 | json_parse = ('undefined' === typeof json_parse) ? true : json_parse; |
| 1543 | - data = $.isEmptyObject(data) ? {'use_cache' : false} : data; | |
| 1454 | + var _wait = ('undefined' === typeof wait) ? false : wait; | |
| 1544 | 1455 | |
| 1456 | + var skip_notice = data.hasOwnProperty('skip_notice'); | |
| 1457 | + var data_has_only_skip_notice = skip_notice && 1 === Object.keys(data).length; | |
| 1458 | + var is_data_empty = $.isEmptyObject(data); | |
| 1459 | + | |
| 1460 | + data = is_data_empty ? {'use_cache' : false} : data; | |
| 1461 | + if (data_has_only_skip_notice) data.use_cache = false; | |
| 1462 | + | |
| 1545 | 1463 | (function(single_callback, _keep, _unique) { |
| 1546 | 1464 | heartbeat_agents.push(heartbeat.add_agent({ |
| 1547 | - _wait: false, | |
| 1465 | + _wait: _wait, | |
| 1548 | 1466 | _keep: _keep, |
| 1549 | 1467 | _unique: _unique, |
| 1550 | 1468 | command: 'updraft_smush_ajax', |
| 1551 | 1469 | command_data: {data: data, subaction: action}, |