From 770a758f4523051f82e250b64e98ae25c207bc83 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Brito Date: Tue, 17 Dec 2024 14:15:00 +0000 Subject: [PATCH 1/6] Update actions/cache to version 4 --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 71a613d..d20a780 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -42,7 +42,7 @@ jobs: if: "!! env.GIT_DIFF" - name: Cache Composer vendor directory - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} From 6c7e409b3a59029193278177832853295929242c Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Wed, 18 Dec 2024 14:27:55 +0530 Subject: [PATCH 2/6] Add ImageManager --- includes/Performance.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/Performance.php b/includes/Performance.php index 0efecdb..08c331e 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -6,6 +6,7 @@ use NewfoldLabs\WP\ModuleLoader\Container; use NewfoldLabs\WP\Module\Performance\Permissions; use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller; +use NewfoldLabs\WP\Module\Performance\Images\ImageManager; use Automattic\Jetpack\Current_Plan; From afab43f084b5ad2c53c12f5ff2127fe82f1055d1 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 23 Dec 2024 21:18:30 +0530 Subject: [PATCH 3/6] Remove duplicate import and move Constants before ImageManager --- includes/Performance.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/Performance.php b/includes/Performance.php index f7e73b5..6a1c260 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -10,7 +10,6 @@ use Automattic\Jetpack\Current_Plan; use NewfoldLabs\WP\Module\Performance\Data\Constants; -use NewfoldLabs\WP\Module\Performance\Images\ImageManager; /** * Performance Class @@ -76,8 +75,8 @@ public function __construct( Container $container ) { $cacheManager = new CacheManager( $container ); $cachePurger = new CachePurgingService( $cacheManager->getInstances() ); - new ImageManager(); new Constants( $container ); + new ImageManager(); add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 ); new LinkPrefetch( $container ); From 2a0b620fc167a0cc4a3baeaebad2a146662a1062 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 23 Dec 2024 21:30:51 +0530 Subject: [PATCH 4/6] Move Bulk Optimization above and also localize strings --- includes/Images/ImageSettings.php | 2 +- scripts/bulk-optimizer.js | 50 +++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/includes/Images/ImageSettings.php b/includes/Images/ImageSettings.php index a084ae4..58f39dd 100644 --- a/includes/Images/ImageSettings.php +++ b/includes/Images/ImageSettings.php @@ -18,6 +18,7 @@ class ImageSettings { */ private const DEFAULT_SETTINGS = array( 'enabled' => true, + 'bulk_optimization' => true, 'auto_optimized_uploaded_images' => array( 'enabled' => true, 'auto_delete_original_image' => true, @@ -25,7 +26,6 @@ class ImageSettings { 'lazy_loading' => array( 'enabled' => true, ), - 'bulk_optimization' => false, // Default value for bulk optimization ); /** diff --git a/scripts/bulk-optimizer.js b/scripts/bulk-optimizer.js index 8b82b52..0c735d7 100644 --- a/scripts/bulk-optimizer.js +++ b/scripts/bulk-optimizer.js @@ -1,4 +1,6 @@ document.addEventListener( 'DOMContentLoaded', () => { + const { __ } = wp.i18n; + const bulkOptimizeButtonId = 'nfd-bulk-optimize-btn'; let cancelRequested = false; @@ -56,11 +58,17 @@ document.addEventListener( 'DOMContentLoaded', () => { const modalTitle = document.createElement( 'h2' ); modalTitle.id = 'nfd-modal-title'; - modalTitle.textContent = 'Optimizing Images...'; + modalTitle.textContent = __( + 'Optimizing Images…', + 'wp-module-performance' + ); const currentFileName = document.createElement( 'p' ); currentFileName.id = 'nfd-current-file'; - currentFileName.textContent = 'Preparing files...'; + currentFileName.textContent = __( + 'Preparing files…', + 'wp-module-performance' + ); const progressContainer = document.createElement( 'div' ); progressContainer.style.cssText = ` @@ -83,7 +91,7 @@ document.addEventListener( 'DOMContentLoaded', () => { `; const cancelButton = document.createElement( 'button' ); - cancelButton.textContent = 'Cancel'; + cancelButton.textContent = __( 'Cancel', 'wp-module-performance' ); cancelButton.className = 'button button-secondary'; cancelButton.style.marginTop = '1rem'; cancelButton.addEventListener( 'click', () => { @@ -127,13 +135,14 @@ document.addEventListener( 'DOMContentLoaded', () => { /** * Extracts the file name from the attachment element. - * - * @param attachment */ const getFileName = ( attachment ) => { const mediaContent = attachment.closest( '.media-frame-content' ); const fileNameElement = mediaContent?.querySelector( '.filename' ); - return fileNameElement?.textContent || 'Unknown File'; + return ( + fileNameElement?.textContent || + __( 'Unknown File', 'wp-module-performance' ) + ); }; /** @@ -162,12 +171,17 @@ document.addEventListener( 'DOMContentLoaded', () => { try { for ( let i = 0; i < selectedItems.length; i++ ) { if ( cancelRequested ) { - modalTitle.textContent = 'Optimization Canceled'; + modalTitle.textContent = __( + 'Optimization Canceled', + 'wp-module-performance' + ); break; } const { id: mediaId, name: fileName } = selectedItems[ i ]; - currentFileName.textContent = `Optimizing: ${ fileName }`; + currentFileName.textContent = + __( 'Optimizing:', 'wp-module-performance' ) + + ` ${ fileName }`; try { await wp.apiFetch( { @@ -180,18 +194,27 @@ document.addEventListener( 'DOMContentLoaded', () => { progressBar.style.width = `${ progress }%`; } catch ( error ) { console.error( - `Error optimizing media ID: ${ mediaId }`, + __( + 'Error optimizing media ID:', + 'wp-module-performance' + ) + ` ${ mediaId }`, error ); } } if ( ! cancelRequested ) { - modalTitle.textContent = 'Optimization Complete!'; + modalTitle.textContent = __( + 'Optimization Complete!', + 'wp-module-performance' + ); setTimeout( closeModal, 2000 ); } } catch ( error ) { - modalTitle.textContent = 'An error occurred.'; + modalTitle.textContent = __( + 'An error occurred.', + 'wp-module-performance' + ); setTimeout( closeModal, 3000 ); } }; @@ -201,7 +224,10 @@ document.addEventListener( 'DOMContentLoaded', () => { bulkOptimizeButton.id = bulkOptimizeButtonId; bulkOptimizeButton.className = 'button media-button button-large button-primary'; - bulkOptimizeButton.textContent = 'Optimize'; + bulkOptimizeButton.textContent = __( + 'Optimize', + 'wp-module-performance' + ); bulkOptimizeButton.disabled = true; bulkOptimizeButton.addEventListener( 'click', handleBulkOptimize ); return bulkOptimizeButton; From 4284deee22f40bfd552f3f00dd10b5eb35929a1e Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 23 Dec 2024 21:56:58 +0530 Subject: [PATCH 5/6] Add a new results screen --- build/bulk-optimizer.min.asset.php | 2 +- build/bulk-optimizer.min.js | 3 +- scripts/bulk-optimizer.js | 141 ++++++++++++++++------------- 3 files changed, 82 insertions(+), 64 deletions(-) diff --git a/build/bulk-optimizer.min.asset.php b/build/bulk-optimizer.min.asset.php index fdb8c51..00b2586 100644 --- a/build/bulk-optimizer.min.asset.php +++ b/build/bulk-optimizer.min.asset.php @@ -1 +1 @@ - array(), 'version' => 'd69f4bfea2649c9caaee'); + array(), 'version' => '4dcdd6f17b25bd3e30f6'); diff --git a/build/bulk-optimizer.min.js b/build/bulk-optimizer.min.js index f576e24..dff66eb 100644 --- a/build/bulk-optimizer.min.js +++ b/build/bulk-optimizer.min.js @@ -1 +1,2 @@ -document.addEventListener("DOMContentLoaded",(()=>{const e="nfd-bulk-optimize-btn";let t=!1;const n=["button","media-button","select-mode-toggle-button"],o=["button","media-button","button-primary","button-large","delete-selected-button"],r=()=>{const e=document.getElementById("nfd-bulk-modal");e&&e.remove(),window.location.reload()},i=e=>{const t=e.closest(".media-frame-content"),n=t?.querySelector(".filename");return n?.textContent||"Unknown File"},d=async()=>{const e=Array.from(document.querySelectorAll(".attachment.selected")).map((e=>({id:e.getAttribute("data-id"),name:i(e)})));if(!e.length)return;const n=window.nfdPerformance?.imageOptimization?.bulkOptimizer?.apiUrl;if(!n)return;const{progressBar:o,modalTitle:d,currentFileName:a}=(()=>{t=!1;const{progressBar:e,modalTitle:n,currentFileName:o}=(()=>{const e=document.createElement("div");e.id="nfd-bulk-modal",e.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n ";const n=document.createElement("div");n.style.cssText="\n background: white;\n padding: 2rem;\n border-radius: 8px;\n text-align: center;\n width: 400px;\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n ";const o=document.createElement("h2");o.id="nfd-modal-title",o.textContent="Optimizing Images...";const i=document.createElement("p");i.id="nfd-current-file",i.textContent="Preparing files...";const d=document.createElement("div");d.style.cssText="\n width: 100%;\n height: 20px;\n background: #eee;\n border-radius: 10px;\n margin: 1rem 0;\n overflow: hidden;\n position: relative;\n ";const a=document.createElement("div");a.id="nfd-progress-bar",a.style.cssText="\n height: 100%;\n width: 0;\n background: #007cba;\n transition: width 0.3s ease;\n ";const c=document.createElement("button");return c.textContent="Cancel",c.className="button button-secondary",c.style.marginTop="1rem",c.addEventListener("click",(()=>{t=!0,r(),window.location.reload()})),d.appendChild(a),n.append(o,i,d,c),e.appendChild(n),document.body.appendChild(e),{modal:e,progressBar:a,modalTitle:o,currentFileName:i}})();return e.style.width="0%",o.textContent="",{progressBar:e,modalTitle:n,currentFileName:o}})();try{for(let r=0;r{const t=()=>{const t=document.querySelectorAll(".attachment.selected").length>0;e.disabled=!t},n=document.querySelector(".media-frame-content");n&&(new MutationObserver(t).observe(n,{childList:!0,subtree:!0}),t())},c=(e,t)=>e?.classList.length===t.length&&t.every((t=>e.classList.contains(t)));new MutationObserver((()=>{const t=document.querySelector(".button.media-button.select-mode-toggle-button");c(t,n)?(()=>{const t=document.getElementById(e);t&&t.remove()})():(()=>{if(document.getElementById(e))return;const t=document.querySelector(".button.media-button.button-primary.button-large.delete-selected-button");if(!c(t,o))return;const n=(()=>{const t=document.createElement("button");return t.id=e,t.className="button media-button button-large button-primary",t.textContent="Optimize",t.disabled=!0,t.addEventListener("click",d),t})();t.parentElement.insertBefore(n,t.nextSibling),a(n)})()})).observe(document.body,{childList:!0,subtree:!0})})); \ No newline at end of file +document.addEventListener("DOMContentLoaded",(()=>{const{__}=wp.i18n,e="nfd-bulk-optimize-btn";let t=!1;const n=["button","media-button","select-mode-toggle-button"],o=["button","media-button","button-primary","button-large","delete-selected-button"],r=e=>e.getAttribute("aria-label"),a=async()=>{const e=Array.from(document.querySelectorAll(".attachment.selected")).map((e=>({id:e.getAttribute("data-id"),name:r(e)})));if(!e.length)return;const n=window.nfdPerformance?.imageOptimization?.bulkOptimizer?.apiUrl;if(!n)return;const{progressBar:o,modalTitle:a,currentFileName:i,resultList:d,doneButton:s,progressContainer:l}=(()=>{t=!1;const{progressBar:e,modalTitle:n,currentFileName:o,resultList:r,doneButton:a,progressContainer:i}=(()=>{const e=document.createElement("div");e.id="nfd-bulk-modal",e.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n ";const t=document.createElement("div");t.style.cssText="\n background: white;\n padding: 2rem;\n border-radius: 8px;\n text-align: center;\n width: 400px;\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n ";const n=document.createElement("h2");n.id="nfd-modal-title",n.textContent=__("Optimizing Images...","wp-module-performance");const o=document.createElement("p");o.id="nfd-current-file",o.textContent=__("Preparing files...","wp-module-performance");const r=document.createElement("div");r.id="nfd-progress-container",r.style.cssText="\n width: 100%;\n height: 20px;\n background: #eee;\n border-radius: 10px;\n margin: 1rem 0;\n overflow: hidden;\n position: relative;\n ";const a=document.createElement("div");a.id="nfd-progress-bar",a.style.cssText="\n height: 100%;\n width: 0;\n background: #007cba;\n transition: width 0.3s ease;\n ";const i=document.createElement("ul");i.id="nfd-result-list",i.style.cssText="\n text-align: center;\n margin: 1rem auto;\n max-height: 200px;\n overflow-y: auto;\n ";const d=document.createElement("button");return d.textContent=__("Done","wp-module-performance"),d.className="button button-secondary",d.style.marginTop="1rem",d.style.display="none",d.addEventListener("click",(()=>{e.remove()})),r.appendChild(a),t.append(n,o,r,i,d),e.appendChild(t),document.body.appendChild(e),{modal:e,progressBar:a,modalTitle:n,currentFileName:o,resultList:i,doneButton:d,progressContainer:r}})();return e.style.width="0%",o.textContent="",{progressBar:e,modalTitle:n,currentFileName:o,resultList:r,doneButton:a,progressContainer:i}})(),c=[];try{for(let r=0;r{const n=document.createElement("li");n.textContent=`${e} - ${__("passed"===t?"Passed":"Failed","wp-module-performance")}`,d.appendChild(n)})),d.style.textAlign="center",s.style.display="block"}catch(e){a.textContent=__("An error occurred.","wp-module-performance")}},i=e=>{const t=()=>{const t=document.querySelectorAll(".attachment.selected").length>0;e.disabled=!t},n=document.querySelector(".media-frame-content");n&&(new MutationObserver(t).observe(n,{childList:!0,subtree:!0}),t())},d=(e,t)=>e?.classList.length===t.length&&t.every((t=>e.classList.contains(t)));new MutationObserver((()=>{const t=document.querySelector(".button.media-button.select-mode-toggle-button");d(t,n)?(()=>{const t=document.getElementById(e);t&&t.remove()})():(()=>{if(document.getElementById(e))return;const t=document.querySelector(".button.media-button.button-primary.button-large.delete-selected-button");if(!d(t,o))return;const n=(()=>{const t=document.createElement("button");return t.id=e,t.className="button media-button button-large button-primary",t.textContent=__("Optimize","wp-module-performance"),t.disabled=!0,t.addEventListener("click",a),t})();t.parentElement.insertBefore(n,t.nextSibling),i(n)})()})).observe(document.body,{childList:!0,subtree:!0})})); +//# sourceMappingURL=bulk-optimizer.min.js.map \ No newline at end of file diff --git a/scripts/bulk-optimizer.js b/scripts/bulk-optimizer.js index 0c735d7..619969b 100644 --- a/scripts/bulk-optimizer.js +++ b/scripts/bulk-optimizer.js @@ -4,7 +4,6 @@ document.addEventListener( 'DOMContentLoaded', () => { const bulkOptimizeButtonId = 'nfd-bulk-optimize-btn'; let cancelRequested = false; - // Exact class lists for Bulk Select and Delete Permanently buttons const bulkSelectButtonClasses = [ 'button', 'media-button', @@ -18,18 +17,12 @@ document.addEventListener( 'DOMContentLoaded', () => { 'delete-selected-button', ]; - /** - * Removes the "Bulk Optimize" button if present. - */ const removeBulkOptimizeButton = () => { const bulkOptimizeButton = document.getElementById( bulkOptimizeButtonId ); if ( bulkOptimizeButton ) bulkOptimizeButton.remove(); }; - /** - * Creates a modal with progress bar and filename display. - */ const createModal = () => { const modal = document.createElement( 'div' ); modal.id = 'nfd-bulk-modal'; @@ -71,6 +64,7 @@ document.addEventListener( 'DOMContentLoaded', () => { ); const progressContainer = document.createElement( 'div' ); + progressContainer.id = 'nfd-progress-container'; progressContainer.style.cssText = ` width: 100%; height: 20px; @@ -90,14 +84,22 @@ document.addEventListener( 'DOMContentLoaded', () => { transition: width 0.3s ease; `; - const cancelButton = document.createElement( 'button' ); - cancelButton.textContent = __( 'Cancel', 'wp-module-performance' ); - cancelButton.className = 'button button-secondary'; - cancelButton.style.marginTop = '1rem'; - cancelButton.addEventListener( 'click', () => { - cancelRequested = true; - closeModal(); - window.location.reload(); // Reload on cancel + const resultList = document.createElement( 'ul' ); + resultList.id = 'nfd-result-list'; + resultList.style.cssText = ` + text-align: center; + margin: 1rem auto; + max-height: 200px; + overflow-y: auto; + `; + + const doneButton = document.createElement( 'button' ); + doneButton.textContent = __( 'Done', 'wp-module-performance' ); + doneButton.className = 'button button-secondary'; + doneButton.style.marginTop = '1rem'; + doneButton.style.display = 'none'; // Hidden initially + doneButton.addEventListener( 'click', () => { + modal.remove(); } ); progressContainer.appendChild( progressBar ); @@ -105,49 +107,49 @@ document.addEventListener( 'DOMContentLoaded', () => { modalTitle, currentFileName, progressContainer, - cancelButton + resultList, + doneButton ); modal.appendChild( modalContent ); document.body.appendChild( modal ); - return { modal, progressBar, modalTitle, currentFileName }; + return { + modal, + progressBar, + modalTitle, + currentFileName, + resultList, + doneButton, + progressContainer, + }; }; - /** - * Opens the modal and resets its display. - */ const openModal = () => { cancelRequested = false; - const { progressBar, modalTitle, currentFileName } = createModal(); + const { + progressBar, + modalTitle, + currentFileName, + resultList, + doneButton, + progressContainer, + } = createModal(); progressBar.style.width = '0%'; currentFileName.textContent = ''; - return { progressBar, modalTitle, currentFileName }; - }; - - /** - * Closes the modal and reloads the page. - */ - const closeModal = () => { - const modal = document.getElementById( 'nfd-bulk-modal' ); - if ( modal ) modal.remove(); - window.location.reload(); // Reload on close + return { + progressBar, + modalTitle, + currentFileName, + resultList, + doneButton, + progressContainer, + }; }; - /** - * Extracts the file name from the attachment element. - */ const getFileName = ( attachment ) => { - const mediaContent = attachment.closest( '.media-frame-content' ); - const fileNameElement = mediaContent?.querySelector( '.filename' ); - return ( - fileNameElement?.textContent || - __( 'Unknown File', 'wp-module-performance' ) - ); + return attachment.getAttribute( 'aria-label' ); }; - /** - * Handles bulk optimization with progress bar and filename display. - */ const handleBulkOptimize = async () => { const selectedItems = Array.from( document.querySelectorAll( '.attachment.selected' ) @@ -165,8 +167,15 @@ document.addEventListener( 'DOMContentLoaded', () => { return; } - // Open modal and start progress - const { progressBar, modalTitle, currentFileName } = openModal(); + const { + progressBar, + modalTitle, + currentFileName, + resultList, + doneButton, + progressContainer, + } = openModal(); + const results = []; try { for ( let i = 0; i < selectedItems.length; i++ ) { @@ -190,32 +199,40 @@ document.addEventListener( 'DOMContentLoaded', () => { data: { media_id: parseInt( mediaId, 10 ) }, } ); - const progress = ( ( i + 1 ) / selectedItems.length ) * 100; - progressBar.style.width = `${ progress }%`; + results.push( { name: fileName, status: 'passed' } ); } catch ( error ) { - console.error( - __( - 'Error optimizing media ID:', - 'wp-module-performance' - ) + ` ${ mediaId }`, - error - ); + results.push( { name: fileName, status: 'failed' } ); } - } - if ( ! cancelRequested ) { - modalTitle.textContent = __( - 'Optimization Complete!', - 'wp-module-performance' - ); - setTimeout( closeModal, 2000 ); + const progress = ( ( i + 1 ) / selectedItems.length ) * 100; + progressBar.style.width = `${ progress }%`; } + + modalTitle.textContent = __( + 'Optimization Complete!', + 'wp-module-performance' + ); + progressContainer.style.display = 'none'; + currentFileName.style.display = 'none'; + + results.forEach( ( { name, status } ) => { + const listItem = document.createElement( 'li' ); + const statusText = + status === 'passed' + ? __( 'Passed', 'wp-module-performance' ) + : __( 'Failed', 'wp-module-performance' ); + + listItem.textContent = `${ name } - ${ statusText }`; + resultList.appendChild( listItem ); + } ); + + resultList.style.textAlign = 'center'; + doneButton.style.display = 'block'; } catch ( error ) { modalTitle.textContent = __( 'An error occurred.', 'wp-module-performance' ); - setTimeout( closeModal, 3000 ); } }; From 2a09574124b2fce43f4d9e61db00c9610f38bbf8 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 23 Dec 2024 21:58:51 +0530 Subject: [PATCH 6/6] Update build --- build/bulk-optimizer.min.asset.php | 2 +- build/bulk-optimizer.min.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build/bulk-optimizer.min.asset.php b/build/bulk-optimizer.min.asset.php index 00b2586..38c92a5 100644 --- a/build/bulk-optimizer.min.asset.php +++ b/build/bulk-optimizer.min.asset.php @@ -1 +1 @@ - array(), 'version' => '4dcdd6f17b25bd3e30f6'); + array(), 'version' => 'a6b819df1100d6726246'); diff --git a/build/bulk-optimizer.min.js b/build/bulk-optimizer.min.js index dff66eb..c09ad7a 100644 --- a/build/bulk-optimizer.min.js +++ b/build/bulk-optimizer.min.js @@ -1,2 +1 @@ -document.addEventListener("DOMContentLoaded",(()=>{const{__}=wp.i18n,e="nfd-bulk-optimize-btn";let t=!1;const n=["button","media-button","select-mode-toggle-button"],o=["button","media-button","button-primary","button-large","delete-selected-button"],r=e=>e.getAttribute("aria-label"),a=async()=>{const e=Array.from(document.querySelectorAll(".attachment.selected")).map((e=>({id:e.getAttribute("data-id"),name:r(e)})));if(!e.length)return;const n=window.nfdPerformance?.imageOptimization?.bulkOptimizer?.apiUrl;if(!n)return;const{progressBar:o,modalTitle:a,currentFileName:i,resultList:d,doneButton:s,progressContainer:l}=(()=>{t=!1;const{progressBar:e,modalTitle:n,currentFileName:o,resultList:r,doneButton:a,progressContainer:i}=(()=>{const e=document.createElement("div");e.id="nfd-bulk-modal",e.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n ";const t=document.createElement("div");t.style.cssText="\n background: white;\n padding: 2rem;\n border-radius: 8px;\n text-align: center;\n width: 400px;\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n ";const n=document.createElement("h2");n.id="nfd-modal-title",n.textContent=__("Optimizing Images...","wp-module-performance");const o=document.createElement("p");o.id="nfd-current-file",o.textContent=__("Preparing files...","wp-module-performance");const r=document.createElement("div");r.id="nfd-progress-container",r.style.cssText="\n width: 100%;\n height: 20px;\n background: #eee;\n border-radius: 10px;\n margin: 1rem 0;\n overflow: hidden;\n position: relative;\n ";const a=document.createElement("div");a.id="nfd-progress-bar",a.style.cssText="\n height: 100%;\n width: 0;\n background: #007cba;\n transition: width 0.3s ease;\n ";const i=document.createElement("ul");i.id="nfd-result-list",i.style.cssText="\n text-align: center;\n margin: 1rem auto;\n max-height: 200px;\n overflow-y: auto;\n ";const d=document.createElement("button");return d.textContent=__("Done","wp-module-performance"),d.className="button button-secondary",d.style.marginTop="1rem",d.style.display="none",d.addEventListener("click",(()=>{e.remove()})),r.appendChild(a),t.append(n,o,r,i,d),e.appendChild(t),document.body.appendChild(e),{modal:e,progressBar:a,modalTitle:n,currentFileName:o,resultList:i,doneButton:d,progressContainer:r}})();return e.style.width="0%",o.textContent="",{progressBar:e,modalTitle:n,currentFileName:o,resultList:r,doneButton:a,progressContainer:i}})(),c=[];try{for(let r=0;r{const n=document.createElement("li");n.textContent=`${e} - ${__("passed"===t?"Passed":"Failed","wp-module-performance")}`,d.appendChild(n)})),d.style.textAlign="center",s.style.display="block"}catch(e){a.textContent=__("An error occurred.","wp-module-performance")}},i=e=>{const t=()=>{const t=document.querySelectorAll(".attachment.selected").length>0;e.disabled=!t},n=document.querySelector(".media-frame-content");n&&(new MutationObserver(t).observe(n,{childList:!0,subtree:!0}),t())},d=(e,t)=>e?.classList.length===t.length&&t.every((t=>e.classList.contains(t)));new MutationObserver((()=>{const t=document.querySelector(".button.media-button.select-mode-toggle-button");d(t,n)?(()=>{const t=document.getElementById(e);t&&t.remove()})():(()=>{if(document.getElementById(e))return;const t=document.querySelector(".button.media-button.button-primary.button-large.delete-selected-button");if(!d(t,o))return;const n=(()=>{const t=document.createElement("button");return t.id=e,t.className="button media-button button-large button-primary",t.textContent=__("Optimize","wp-module-performance"),t.disabled=!0,t.addEventListener("click",a),t})();t.parentElement.insertBefore(n,t.nextSibling),i(n)})()})).observe(document.body,{childList:!0,subtree:!0})})); -//# sourceMappingURL=bulk-optimizer.min.js.map \ No newline at end of file +document.addEventListener("DOMContentLoaded",(()=>{const{__}=wp.i18n,e="nfd-bulk-optimize-btn";let t=!1;const n=["button","media-button","select-mode-toggle-button"],o=["button","media-button","button-primary","button-large","delete-selected-button"],r=e=>e.getAttribute("aria-label"),a=async()=>{const e=Array.from(document.querySelectorAll(".attachment.selected")).map((e=>({id:e.getAttribute("data-id"),name:r(e)})));if(!e.length)return;const n=window.nfdPerformance?.imageOptimization?.bulkOptimizer?.apiUrl;if(!n)return;const{progressBar:o,modalTitle:a,currentFileName:i,resultList:d,doneButton:s,progressContainer:l}=(()=>{t=!1;const{progressBar:e,modalTitle:n,currentFileName:o,resultList:r,doneButton:a,progressContainer:i}=(()=>{const e=document.createElement("div");e.id="nfd-bulk-modal",e.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n ";const t=document.createElement("div");t.style.cssText="\n background: white;\n padding: 2rem;\n border-radius: 8px;\n text-align: center;\n width: 400px;\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n ";const n=document.createElement("h2");n.id="nfd-modal-title",n.textContent=__("Optimizing Images…","wp-module-performance");const o=document.createElement("p");o.id="nfd-current-file",o.textContent=__("Preparing files…","wp-module-performance");const r=document.createElement("div");r.id="nfd-progress-container",r.style.cssText="\n width: 100%;\n height: 20px;\n background: #eee;\n border-radius: 10px;\n margin: 1rem 0;\n overflow: hidden;\n position: relative;\n ";const a=document.createElement("div");a.id="nfd-progress-bar",a.style.cssText="\n height: 100%;\n width: 0;\n background: #007cba;\n transition: width 0.3s ease;\n ";const i=document.createElement("ul");i.id="nfd-result-list",i.style.cssText="\n text-align: center;\n margin: 1rem auto;\n max-height: 200px;\n overflow-y: auto;\n ";const d=document.createElement("button");return d.textContent=__("Done","wp-module-performance"),d.className="button button-secondary",d.style.marginTop="1rem",d.style.display="none",d.addEventListener("click",(()=>{e.remove()})),r.appendChild(a),t.append(n,o,r,i,d),e.appendChild(t),document.body.appendChild(e),{modal:e,progressBar:a,modalTitle:n,currentFileName:o,resultList:i,doneButton:d,progressContainer:r}})();return e.style.width="0%",o.textContent="",{progressBar:e,modalTitle:n,currentFileName:o,resultList:r,doneButton:a,progressContainer:i}})(),c=[];try{for(let r=0;r{const n=document.createElement("li"),o=__("passed"===t?"Passed":"Failed","wp-module-performance");n.textContent=`${e} - ${o}`,d.appendChild(n)})),d.style.textAlign="center",s.style.display="block"}catch(e){a.textContent=__("An error occurred.","wp-module-performance")}},i=e=>{const t=()=>{const t=document.querySelectorAll(".attachment.selected").length>0;e.disabled=!t},n=document.querySelector(".media-frame-content");n&&(new MutationObserver(t).observe(n,{childList:!0,subtree:!0}),t())},d=(e,t)=>e?.classList.length===t.length&&t.every((t=>e.classList.contains(t)));new MutationObserver((()=>{const t=document.querySelector(".button.media-button.select-mode-toggle-button");d(t,n)?(()=>{const t=document.getElementById(e);t&&t.remove()})():(()=>{if(document.getElementById(e))return;const t=document.querySelector(".button.media-button.button-primary.button-large.delete-selected-button");if(!d(t,o))return;const n=(()=>{const t=document.createElement("button");return t.id=e,t.className="button media-button button-large button-primary",t.textContent=__("Optimize","wp-module-performance"),t.disabled=!0,t.addEventListener("click",a),t})();t.parentElement.insertBefore(n,t.nextSibling),i(n)})()})).observe(document.body,{childList:!0,subtree:!0})})); \ No newline at end of file