Changeset 3359922
- Timestamp:
- 09/11/2025 01:48:30 PM (7 months ago)
- Location:
- media-focus-point
- Files:
-
- 7 added
- 3 edited
-
tags/2.0.2 (added)
-
tags/2.0.2/admin.css (added)
-
tags/2.0.2/languages (added)
-
tags/2.0.2/languages/media-focus-point.pot (added)
-
tags/2.0.2/media-focus-point.php (added)
-
tags/2.0.2/readme.txt (added)
-
tags/2.0.2/script.js (added)
-
trunk/admin.css (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/script.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
media-focus-point/trunk/admin.css
r3308965 r3359922 1 1 .wpcmfp-overlay{ 2 display:none; 2 --wpcmfp-header-height: 50px; 3 --wpcmfp-container-max-height: 80vh; 4 --wpcmfp-container-max-width: 80vw; 5 display: none; 3 6 position: fixed; 4 top: 0;5 left: 0px;6 width: 100%;7 height: 100%;8 z-index: 9999;9 align-items: center;10 justify-content: center;11 flex-direction: column7 top: 0; 8 left: 0; 9 width: 100%; 10 height: 100%; 11 z-index: 9999; 12 align-items: center; 13 justify-content: center; 14 flex-direction: column 12 15 } 13 16 .wpcmfp-overlay.wpcmfp-show{ 14 display: flex;17 display: flex; 15 18 } 16 19 .wpcmfp-overlay:before { 17 content: '';18 display: block;19 width: 100%;20 height: 100%;21 z-index: 0;22 position: absolute;23 top: 0;24 left: 0;25 background: #000;26 opacity: 0.5;20 content: ''; 21 display: block; 22 width: 100%; 23 height: 100%; 24 z-index: 0; 25 position: absolute; 26 top: 0; 27 left: 0; 28 background: #000; 29 opacity: 0.5; 27 30 } 28 31 .wpcmfp-overlay h3{ 29 font-size: 15px;30 margin: 0px;32 font-size: 15px; 33 margin: 0; 31 34 } 32 35 .wpcmfp-overlay .wpcmfp-controls{ 33 display: flex;36 display: flex; 34 37 } 35 38 .wpcmfp-overlay .wpcmfp-controls span{ 36 margin: 0px5px;39 margin: 0 5px; 37 40 } 38 41 .wpcmfp-overlay .wpcmfp-close{ 39 z-index: 99;40 border: 1px solid;42 z-index: 99; 43 border: 1px solid; 41 44 } 42 45 .wpcmfp-overlay .wpcmfp-img-container{ 43 height: 610px; 44 width: 1000px; 45 background-color: #F7F7F7; 46 position: absolute; 47 left: 50%; 48 top: 50%; 49 margin-left: -500px; 50 margin-top: -305px; 46 max-height: var(--wpcmfp-container-max-height); 47 max-width: var(--wpcmfp-container-max-width); 48 background-color: #F7F7F7; 49 position: absolute; 50 display: flex; 51 flex-direction: column; 51 52 } 52 53 .wpcmfp-overlay .wpcmfp-img-container .wpcmfp-header{ 53 height: 50px;54 width: 100%;55 background-color: white;56 border-bottom: 1px solid #DCDCDD;54 height: var(--wpcmfp-header-height); 55 width: 100%; 56 background-color: white; 57 border-bottom: 1px solid #DCDCDD; 57 58 } 58 59 .wpcmfp-overlay .wpcmfp-img-container .wpcmfp-header .wpcmfp-wrapp{ 59 display: flex;60 align-items: center;61 justify-content: space-between;62 background: #fff;63 padding: 10px 15px;60 display: flex; 61 align-items: center; 62 justify-content: space-between; 63 background: #fff; 64 padding: 10px 15px; 64 65 border-bottom: 1px solid #DCDCDD; 65 66 } 66 67 .wpcmfp-overlay .wpcmfp-img-container .wpcmfp-container{ 67 68 background-color: #F7F7F7; 68 width: 100%;69 height: calc(100% - 50px);70 display: flex;71 align-items: center;72 justify-content: center;73 overflow: hidden;74 position: relative;69 width: 100%; 70 height: calc(100% - var(--wpcmfp-header-height)); 71 display: flex; 72 align-items: center; 73 justify-content: center; 74 overflow: hidden; 75 position: relative; 75 76 } 76 77 .wpcmfp-overlay img{ 77 78 cursor: crosshair; 78 max-height: 100%;79 height: 100%;80 max-width: 100%;81 width: auto;79 max-height: calc(var(--wpcmfp-container-max-height) - var(--wpcmfp-header-height)); 80 height: auto; 81 max-width: 100%; 82 width: auto; 82 83 } 83 84 84 85 .wpcmfp-overlay video { 85 cursor: crosshair;86 cursor: crosshair; 86 87 } 87 88 .wpcmfp-overlay .wpcmfp-pin{ 88 89 position: absolute; 89 top: 50%;90 left: 50%;91 width: 4px;92 aspect-ratio: 1 / 1;93 pointer-events: none;90 top: 50%; 91 left: 50%; 92 width: 4px; 93 aspect-ratio: 1 / 1; 94 pointer-events: none; 94 95 } 95 96 .wpcmfp-overlay .wpcmfp-pin::before { 96 content: "";97 position: absolute;98 top: 50%;99 left: 50%;100 width: 150px;101 aspect-ratio: 1 / 1;102 background-size: cover;103 background: transparent;104 border-radius: 50%;105 outline: 2px solid white;106 pointer-events: none;107 transform: translate(-50%, -50%);108 opacity: .3;109 box-shadow: 0 0 0 6000px #000000;97 content: ""; 98 position: absolute; 99 top: 50%; 100 left: 50%; 101 width: 150px; 102 aspect-ratio: 1 / 1; 103 background-size: cover; 104 background: transparent; 105 border-radius: 50%; 106 outline: 2px solid white; 107 pointer-events: none; 108 transform: translate(-50%, -50%); 109 opacity: .3; 110 box-shadow: 0 0 0 6000px #000000; 110 111 } 111 112 .wpcmfp-overlay .wpcmfp-pin::after { 112 content: "";113 position: absolute;114 top: 50%;115 left: 50%;116 width: 13px;117 aspect-ratio: 1 / 1;118 background-size: cover;119 background: #324cd9;120 border-radius: 50%;121 outline: 3px solid white;122 pointer-events: none;123 transform: translate(-50%, -50%);124 opacity: .6;113 content: ""; 114 position: absolute; 115 top: 50%; 116 left: 50%; 117 width: 13px; 118 aspect-ratio: 1 / 1; 119 background-size: cover; 120 background: #324cd9; 121 border-radius: 50%; 122 outline: 3px solid white; 123 pointer-events: none; 124 transform: translate(-50%, -50%); 125 opacity: .6; 125 126 } 126 127 127 128 .wpcmfp-focusp_label_holder{ 128 margin-bottom: 15px;129 margin-bottom: 15px; 129 130 } 130 131 #wpcmfp_desktop_value,#wpcmfp_mobile_value{ 131 margin: 6px 0px;132 margin: 6px 0; 132 133 } 133 134 #wpcmfp_desktop_value input[type="number"] { 134 width: calc(3ch + 28px);135 padding: 0 4px;135 width: calc(3ch + 28px); 136 padding: 0 4px; 136 137 } 137 138 .compat-field-background_position_desktop label span{ 138 font-size: 12px;139 font-size: 12px; 139 140 } 140 141 .media-frame-content.wpcmfp-show{ 141 z-index: 9999999999999999999;142 z-index: 9999999999999999999; 142 143 } 143 144 .wpcmfp-media-sidebar.wpcmfp-show,.wpcmfp-media-frame-content.wpcmfp-show{ 144 overflow: visible;145 overflow: visible; 145 146 } -
media-focus-point/trunk/readme.txt
r3308965 r3359922 3 3 Tags: focus, focal, image, background, video 4 4 Requires at least: 6.0 5 Tested up to: 6.8 5 Tested up to: 6.8.2 6 6 Requires PHP: 7.4 7 Stable tag: 2.0. 17 Stable tag: 2.0.2 8 8 License: GPLv3 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 110 110 == Changelog == 111 111 112 = 2.0.2 = 113 * Fixed aspect ratio of wide images while selecting a focus point 114 * Fixed setting a focus point by mouseclick sometimes resulting in a focus point just outside the image 115 112 116 = 2.0.1 = 113 117 * Added custom prefix to all classes to prevent style conflicts -
media-focus-point/trunk/script.js
r3308965 r3359922 11 11 let rec_top = 0; 12 12 13 14 13 // Replaces the custom HTML element with a standard video element 15 14 function replaceCustomVideoElements() { … … 27 26 } 28 27 29 30 28 function onNumberInputChange() { 31 const inputX = document.getElementById('wpcmfp_desktop_value_x');32 const inputY = document.getElementById('wpcmfp_desktop_value_y');33 const hidden_input = document.getElementById('wpcmfp_bg_pos_desktop_id') ;34 35 // As values are percentagesand it doesn't make sense to place focus outside of the image, we use 100 as a maximum value36 if (inputX.value > 100) {37 inputX.value = 100;38 }39 if (inputY.value > 100) {40 inputY.value = 100;41 }42 43 // Concatenate number input values to correct CSS syntax44 hidden_input.value = `${inputX.value}% ${inputY.value}%`;29 const inputX = document.getElementById('wpcmfp_desktop_value_x'); 30 const inputY = document.getElementById('wpcmfp_desktop_value_y'); 31 const hidden_input = document.getElementById('wpcmfp_bg_pos_desktop_id') ; 32 33 // As values are percentages, and it doesn't make sense to place focus outside of the image, we use 100 as a maximum value 34 if (inputX.value > 100) { 35 inputX.value = 100; 36 } 37 if (inputY.value > 100) { 38 inputY.value = 100; 39 } 40 41 // Concatenate number input values to correct CSS syntax 42 hidden_input.value = `${inputX.value}% ${inputY.value}%`; 45 43 } 46 44 … … 72 70 } 73 71 74 document.getElementById('wpcmfp_bg_pos_desktop_id').value = `${bgX}% ${bgY}%`; 75 document.getElementById('wpcmfp_desktop_value_x').value = bgX; 76 document.getElementById('wpcmfp_desktop_value_y').value = bgY; 77 // Trigger change event to save new values 72 // If a coordinate is somehow negative, set it to 0 instead 73 if (bgX < 0) bgX = 0; 74 if (bgY < 0) bgY = 0; 75 76 document.getElementById('wpcmfp_bg_pos_desktop_id').value = `${bgX}% ${bgY}%`; 77 document.getElementById('wpcmfp_desktop_value_x').value = bgX; 78 document.getElementById('wpcmfp_desktop_value_y').value = bgY; 79 // Trigger change event to save new values 78 80 triggerChange(document.getElementById('wpcmfp_bg_pos_desktop_id')); 79 81 … … 88 90 89 91 // Automatically save the page if editing an attachment directly (not via media modal) 90 if (!document.querySelector('.wpcmfp-media-modal-content')) {91 const postForm = document.getElementById('post');92 if (postForm) {93 postForm.submit();94 }95 }92 if (!document.querySelector('.wpcmfp-media-modal-content')) { 93 const postForm = document.getElementById('post'); 94 if (postForm) { 95 postForm.submit(); 96 } 97 } 96 98 } 97 99 98 100 function triggerChange(element) { 99 if (element) { 100 const changeEvent = new Event('change', { 101 'bubbles': true, 102 'cancelable': true 103 }); 104 105 element.dispatchEvent(changeEvent); 106 } 107 } 108 101 if (element) { 102 const changeEvent = new Event('change', { 103 'bubbles': true, 104 'cancelable': true 105 }); 106 107 element.dispatchEvent(changeEvent); 108 } 109 } 109 110 110 111 function waitForMediaLoad(media) { … … 125 126 }); 126 127 } 127 128 128 129 129 document.addEventListener('DOMContentLoaded', () => { … … 140 140 } 141 141 }); 142 143 142 }); 144 143 145 146 147 144 async function set_focus(e) { 148 149 145 replaceCustomVideoElements() 150 146 document.querySelectorAll(".wpcmfp-media-frame-content,.wpcmfp-media-sidebar").forEach(el => el.classList.add('show')); … … 163 159 164 160 await waitForMediaLoad(media); 165 const rect = media.getBoundingClientRect(); 166 containerHt = container.clientHeight; 167 containerWt = container.clientWidth; 168 // This part calculates the position of the point on the image 169 const marginLeft = (containerWt - rect.width) / 2; // Whitespace between the container and image 170 const marginTop = (containerHt - rect.height) / 2; 171 let relX = (e.clientX - rect.left) + marginLeft; // Calculate the location in px. + adding the margin so that the dot never goes outside the image 172 let relY = (e.clientY - rect.top) + marginTop; 173 174 // When the number is NaN. It means that the user has not interacted with the image. 175 // So we will calculate the position of the dot based on the input value. 176 if (Number.isNaN(relX) || Number.isNaN(relY)) { 177 const inputX = document.getElementById('wpcmfp_desktop_value_x'); // reading out the input values 178 const inputY = document.getElementById('wpcmfp_desktop_value_y'); 179 inputX.value = Math.max(0, Math.min(100, inputX.value)); 180 inputY.value = Math.max(0, Math.min(100, inputY.value)); 181 182 const inputX_px = (rect.width / 100) * inputX.value; // Convert the input value % to px 183 const inputY_px = (rect.height / 100) * inputY.value; 184 const marginX = (containerWt - rect.width) / 2; // get the offset of the left (this is in px) 185 const marginY = (containerHt - rect.height) / 2; 186 const totalX = inputX_px + marginX; // Combine the offset and the input value 187 const totalY = inputY_px + marginY; 188 relX = totalX; // Set the value of rel to total 189 relY = totalY; 190 } 191 192 // this part calculated the percentage that will be given to the image on websites. 193 bgX = Math.round(((e.clientX - rect.left) / containerWt) * 100); 194 bgY = Math.round(((e.clientY - rect.top) / containerHt) * 100); 195 rec_left = Math.round((relX / containerWt) * 100); // Converting the values to percentages 196 rec_top = Math.round((relY / containerHt) * 100); 197 198 199 document.querySelector('.wpcmfp-pin').style.left = `${rec_left}%`; 200 document.querySelector('.wpcmfp-pin').style.top = `${rec_top}%`; 161 const rect = media.getBoundingClientRect(); 162 containerHt = container.clientHeight; 163 containerWt = container.clientWidth; 164 // This part calculates the position of the point on the image 165 const marginLeft = (containerWt - rect.width) / 2; // Whitespace between the container and image 166 const marginTop = (containerHt - rect.height) / 2; 167 let relX = (e.clientX - rect.left) + marginLeft; // Calculate the location in px. + adding the margin so that the dot never goes outside the image 168 let relY = (e.clientY - rect.top) + marginTop; 169 170 // When the number is NaN. It means that the user has not interacted with the image. 171 // So we will calculate the position of the dot based on the input value. 172 if (Number.isNaN(relX) || Number.isNaN(relY)) { 173 const inputX = document.getElementById('wpcmfp_desktop_value_x'); // reading out the input values 174 const inputY = document.getElementById('wpcmfp_desktop_value_y'); 175 inputX.value = Math.max(0, Math.min(100, inputX.value)); 176 inputY.value = Math.max(0, Math.min(100, inputY.value)); 177 178 const inputX_px = (rect.width / 100) * inputX.value; // Convert the input value % to px 179 const inputY_px = (rect.height / 100) * inputY.value; 180 const marginX = (containerWt - rect.width) / 2; // get the offset of the left (this is in px) 181 const marginY = (containerHt - rect.height) / 2; 182 const totalX = inputX_px + marginX; // Combine the offset and the input value 183 const totalY = inputY_px + marginY; 184 relX = totalX; // Set the value of rel to total 185 relY = totalY; 186 } 187 188 // this part calculated the percentage that will be given to the image on websites. 189 bgX = Math.round(((e.clientX - rect.left) / containerWt) * 100); 190 bgY = Math.round(((e.clientY - rect.top) / containerHt) * 100); 191 rec_left = Math.round((relX / containerWt) * 100); // Converting the values to percentages 192 rec_top = Math.round((relY / containerHt) * 100); 193 194 document.querySelector('.wpcmfp-pin').style.left = `${rec_left}%`; 195 document.querySelector('.wpcmfp-pin').style.top = `${rec_top}%`; 201 196 } 202 197 … … 222 217 } 223 218 224 225 219 function attachMediaClickListener() { 226 220 const container = document.querySelector(".wpcmfp-overlay .wpcmfp-container");
Note: See TracChangeset
for help on using the changeset viewer.