Changeset 3456951
- Timestamp:
- 02/09/2026 10:33:03 AM (8 weeks ago)
- Location:
- media-focus-point/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
script.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
media-focus-point/trunk/readme.txt
r3432587 r3456951 110 110 == Changelog == 111 111 112 = 2.0.5 = 113 * Correctly decodes Base64 UTF-8 strings for opening in modal (Example: ExampleImagewithCopyright©.png) 114 112 115 = 2.0.4 = 113 116 * Weird bug when setting focus point for Featured Image or ACF Image fields -
media-focus-point/trunk/script.js
r3432587 r3456951 110 110 } 111 111 112 // Decodes a base64 string and handles UTF-8 characters correctly 113 function b64DecodeUTF8(str) { 114 try { 115 const binString = atob(str); 116 const bytes = new Uint8Array(binString.length); 117 for (let i = 0; i < binString.length; i++) { 118 bytes[i] = binString.charCodeAt(i); 119 } 120 return new TextDecoder('utf-8').decode(bytes); 121 } catch (e) { 122 console.error("Media Focus Point: Error decoding media tag:", e); 123 return atob(str); // Fallback to standard atob 124 } 125 } 126 112 127 function waitForMediaLoad(media) { 113 return new Promise((resolve ) => {128 return new Promise((resolve, reject) => { 114 129 if (media.tagName.toLowerCase() === "video") { 115 130 if (media.readyState >= 2) { … … 117 132 } else { 118 133 media.onloadeddata = () => resolve(media); 134 media.onerror = () => reject(new Error("Video failed to load")); 119 135 } 120 136 } else { 121 if (media.complete ) {137 if (media.complete && media.naturalWidth !== 0) { 122 138 resolve(media); 123 139 } else { 124 140 media.onload = () => resolve(media); 125 } 126 } 141 media.onerror = () => reject(new Error("Image failed to load")); 142 } 143 } 144 145 // Add a timeout to prevent absolute hanging 146 setTimeout(() => reject(new Error("Media load timeout")), 5000); 127 147 }); 128 148 } … … 156 176 mediaPreviewContainer.classList.add('wpcmfp-media-preview-container'); 157 177 // Fetch data-attribute data-media-tag, which should contain a base64 encoded string of the media tag 158 mediaPreviewContainer.innerHTML = atob(hiddenInput.dataset.mediaTag);178 mediaPreviewContainer.innerHTML = b64DecodeUTF8(hiddenInput.dataset.mediaTag); 159 179 // Save pin to add back again later 160 180 const pin = mediaContainer.querySelector('.wpcmfp-pin'); … … 167 187 168 188 replaceCustomVideoElements() 169 document.querySelectorAll(".wpcmfp-media-frame-content,.wpcmfp-media-sidebar").forEach(el => el.classList.add(' show'));189 document.querySelectorAll(".wpcmfp-media-frame-content,.wpcmfp-media-sidebar").forEach(el => el.classList.add('wpcmfp-show')); 170 190 document.querySelectorAll(".wpcmfp-media-toolbar,.wpcmfp-media-menu-item").forEach(el => el.style.zIndex = 0); 171 191 set_bg_values(); … … 181 201 } 182 202 183 await waitForMediaLoad(media); 203 try { 204 await waitForMediaLoad(media); 205 } catch (error) { 206 console.warn("Media load error, proceeding anyway:", error); 207 } 184 208 const rect = media.getBoundingClientRect(); 185 209 containerHt = container.clientHeight;
Note: See TracChangeset
for help on using the changeset viewer.