From 5def7a1d42ba8a243790aeb7c453916c949ae577 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 27 Dec 2024 17:22:49 +0530 Subject: [PATCH] Auto reload the page when the modal closes --- assets/image-bulk-optimizer/image-bulk-optimizer.js | 1 + build/image-bulk-optimizer/image-bulk-optimizer.min.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/image-bulk-optimizer/image-bulk-optimizer.js b/assets/image-bulk-optimizer/image-bulk-optimizer.js index f770424..6c17baf 100644 --- a/assets/image-bulk-optimizer/image-bulk-optimizer.js +++ b/assets/image-bulk-optimizer/image-bulk-optimizer.js @@ -67,6 +67,7 @@ document.addEventListener( 'DOMContentLoaded', () => { doneButton.style.display = 'none'; // Hidden initially doneButton.addEventListener( 'click', () => { modal.remove(); + window.location.reload(); } ); progressContainer.appendChild( progressBar ); diff --git a/build/image-bulk-optimizer/image-bulk-optimizer.min.js b/build/image-bulk-optimizer/image-bulk-optimizer.min.js index 68e0d0c..6edf5ff 100644 --- a/build/image-bulk-optimizer/image-bulk-optimizer.min.js +++ b/build/image-bulk-optimizer/image-bulk-optimizer.min.js @@ -1 +1 @@ -(()=>{"use strict";document.addEventListener("DOMContentLoaded",(()=>{const{__:e}=wp.i18n,t="nfd-bulk-optimize-btn";let n=!1;const o=["button","media-button","select-mode-toggle-button"],r=["button","media-button","button-primary","button-large","delete-selected-button"],a=()=>{n=!1;const{progressBar:t,modalTitle:o,currentFileName:r,resultList:a,doneButton:d,progressContainer:s}=(()=>{const t=document.createElement("div");t.id="nfd-bulk-modal",t.className="nfd-performance-image-modal";const n=document.createElement("div");n.className="nfd-performance-image-modal-content";const o=document.createElement("h2");o.id="nfd-modal-title",o.textContent=e("Optimizing Images…","wp-module-performance");const r=document.createElement("p");r.id="nfd-current-file",r.textContent=e("Preparing files…","wp-module-performance");const a=document.createElement("div");a.id="nfd-progress-container",a.className="nfd-performance-image-progress-container";const d=document.createElement("div");d.id="nfd-progress-bar",d.className="nfd-performance-image-progress-bar";const s=document.createElement("ul");s.id="nfd-result-list",s.className="nfd-performance-image-result-list";const i=document.createElement("button");return i.textContent=e("Done","wp-module-performance"),i.className="button button-secondary nfd-performance-image-done-button",i.style.display="none",i.addEventListener("click",(()=>{t.remove()})),a.appendChild(d),n.append(o,r,a,s,i),t.appendChild(n),document.body.appendChild(t),{modal:t,progressBar:d,modalTitle:o,currentFileName:r,resultList:s,doneButton:i,progressContainer:a}})();return t.style.width="0%",r.textContent="",{progressBar:t,modalTitle:o,currentFileName:r,resultList:a,doneButton:d,progressContainer:s}},d=e=>e.getAttribute("aria-label"),s=async()=>{const t=Array.from(document.querySelectorAll(".attachment.selected")).map((e=>({id:e.getAttribute("data-id"),name:d(e)})));if(!t.length)return;const o=window.nfdPerformance?.imageOptimization?.bulkOptimizer?.apiUrl;if(!o)return;const{progressBar:r,modalTitle:s,currentFileName:i,resultList:l,doneButton:c,progressContainer:m}=a(),u=[];try{for(let a=0;a{const o=document.createElement("li"),r=e("passed"===n?"Passed":"Failed","wp-module-performance");o.textContent=`${t} - ${r}`,l.appendChild(o)})),c.style.display="block"}catch(t){s.textContent=e("An error occurred.","wp-module-performance")}},i=()=>{if(document.getElementById(t))return;const n=document.querySelector(".button.media-button.button-primary.button-large.delete-selected-button");if(!c(n,r))return;const o=(()=>{const n=document.createElement("button");return n.id=t,n.className="button media-button button-large button-primary",n.textContent=e("Optimize","wp-module-performance"),n.disabled=!0,n.addEventListener("click",s),n})();n.parentElement.insertBefore(o,n.nextSibling),l(o)},l=e=>{const t=()=>{const t=document.querySelectorAll(".attachment.selected").length>0;e.disabled=!t},n=document.querySelector(".media-frame-content");if(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 e=document.querySelector(".button.media-button.select-mode-toggle-button");c(e,o)?(()=>{const e=document.getElementById(t);e&&e.remove()})():i()})).observe(document.body,{childList:!0,subtree:!0})}))})(); \ No newline at end of file +(()=>{"use strict";document.addEventListener("DOMContentLoaded",(()=>{const{__:e}=wp.i18n,t="nfd-bulk-optimize-btn";let n=!1;const o=["button","media-button","select-mode-toggle-button"],r=["button","media-button","button-primary","button-large","delete-selected-button"],a=()=>{n=!1;const{progressBar:t,modalTitle:o,currentFileName:r,resultList:a,doneButton:d,progressContainer:s}=(()=>{const t=document.createElement("div");t.id="nfd-bulk-modal",t.className="nfd-performance-image-modal";const n=document.createElement("div");n.className="nfd-performance-image-modal-content";const o=document.createElement("h2");o.id="nfd-modal-title",o.textContent=e("Optimizing Images…","wp-module-performance");const r=document.createElement("p");r.id="nfd-current-file",r.textContent=e("Preparing files…","wp-module-performance");const a=document.createElement("div");a.id="nfd-progress-container",a.className="nfd-performance-image-progress-container";const d=document.createElement("div");d.id="nfd-progress-bar",d.className="nfd-performance-image-progress-bar";const s=document.createElement("ul");s.id="nfd-result-list",s.className="nfd-performance-image-result-list";const i=document.createElement("button");return i.textContent=e("Done","wp-module-performance"),i.className="button button-secondary nfd-performance-image-done-button",i.style.display="none",i.addEventListener("click",(()=>{t.remove(),window.location.reload()})),a.appendChild(d),n.append(o,r,a,s,i),t.appendChild(n),document.body.appendChild(t),{modal:t,progressBar:d,modalTitle:o,currentFileName:r,resultList:s,doneButton:i,progressContainer:a}})();return t.style.width="0%",r.textContent="",{progressBar:t,modalTitle:o,currentFileName:r,resultList:a,doneButton:d,progressContainer:s}},d=e=>e.getAttribute("aria-label"),s=async()=>{const t=Array.from(document.querySelectorAll(".attachment.selected")).map((e=>({id:e.getAttribute("data-id"),name:d(e)})));if(!t.length)return;const o=window.nfdPerformance?.imageOptimization?.bulkOptimizer?.apiUrl;if(!o)return;const{progressBar:r,modalTitle:s,currentFileName:i,resultList:l,doneButton:c,progressContainer:m}=a(),u=[];try{for(let a=0;a{const o=document.createElement("li"),r=e("passed"===n?"Passed":"Failed","wp-module-performance");o.textContent=`${t} - ${r}`,l.appendChild(o)})),c.style.display="block"}catch(t){s.textContent=e("An error occurred.","wp-module-performance")}},i=()=>{if(document.getElementById(t))return;const n=document.querySelector(".button.media-button.button-primary.button-large.delete-selected-button");if(!c(n,r))return;const o=(()=>{const n=document.createElement("button");return n.id=t,n.className="button media-button button-large button-primary",n.textContent=e("Optimize","wp-module-performance"),n.disabled=!0,n.addEventListener("click",s),n})();n.parentElement.insertBefore(o,n.nextSibling),l(o)},l=e=>{const t=()=>{const t=document.querySelectorAll(".attachment.selected").length>0;e.disabled=!t},n=document.querySelector(".media-frame-content");if(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 e=document.querySelector(".button.media-button.select-mode-toggle-button");c(e,o)?(()=>{const e=document.getElementById(t);e&&e.remove()})():i()})).observe(document.body,{childList:!0,subtree:!0})}))})(); \ No newline at end of file