carhop__plugins__PROD-DEV/plugins/dynamiques-thumbnail-focal-point/build/focal-point-inline.js
Antoine M 17811c8091
All checks were successful
continuous-integration/drone/push Build is passing
FEATURE Introducing the thumbnail focal point plugin with its features
2025-10-16 11:47:35 +02:00

1 line
2.9 KiB
JavaScript

(()=>{"use strict";const e=window.wp.element,t=window.wp.components,n=(window.wp.apiFetch,window.ReactJSXRuntime),o=({postId:o,thumbnailUrl:i,initialFocalPoint:a})=>{const[l,d]=(0,e.useState)(a);return(0,e.useEffect)(()=>{let e=document.getElementById("thumbnail_focal_point_x"),t=document.getElementById("thumbnail_focal_point_y"),n=document.getElementById("thumbnail_focal_point_nonce");e||(e=document.createElement("input"),e.type="hidden",e.name="thumbnail_focal_point_x",e.id="thumbnail_focal_point_x",document.querySelector("form#post").appendChild(e)),t||(t=document.createElement("input"),t.type="hidden",t.name="thumbnail_focal_point_y",t.id="thumbnail_focal_point_y",document.querySelector("form#post").appendChild(t)),n||(n=document.createElement("input"),n.type="hidden",n.name="thumbnail_focal_point_nonce",n.id="thumbnail_focal_point_nonce",n.value=window.thumbnailFocalPointData?.nonce||"",document.querySelector("form#post").appendChild(n)),e.value=l.x,t.value=l.y},[l]),(0,n.jsxs)("div",{style:{marginTop:"15px",paddingTop:"15px",borderTop:"1px solid #dcdcde"},children:[(0,n.jsx)("div",{style:{marginBottom:"10px"},children:(0,n.jsx)("strong",{style:{fontSize:"13px",color:"#1d2327"},children:"Point focal de recadrage"})}),(0,n.jsx)("p",{style:{marginBottom:"12px",fontSize:"12px",color:"#646970",marginTop:"8px"},children:"Cliquez sur l'image pour définir le point focal utilisé lors du recadrage."}),(0,n.jsx)("div",{style:{marginBottom:"10px"},children:(0,n.jsx)(t.FocalPointPicker,{url:i,value:l,onChange:e=>{d(e)}})}),(0,n.jsxs)("p",{style:{fontSize:"12px",color:"#646970",marginTop:"8px"},children:["Position :"," ",(0,n.jsxs)("strong",{style:{color:"#2271b1"},children:[Math.round(100*l.x),"% / ",Math.round(100*l.y),"%"]})]})]})};if(window.addEventListener("DOMContentLoaded",()=>{!function(){const t=document.getElementById("postimagediv");if(!t)return;const i=t.querySelector("#set-post-thumbnail");if(!i||!window.thumbnailFocalPointData)return;if(!i.querySelector("img"))return;let a=document.getElementById("thumbnail-focal-point-inline-root");if(!a){a=document.createElement("div"),a.id="thumbnail-focal-point-inline-root";const e=t.querySelector(".inside");e?e.appendChild(a):t.appendChild(a)}const{postId:l,thumbnailUrl:d,focalPointX:c,focalPointY:r}=window.thumbnailFocalPointData;(0,e.render)((0,n.jsx)(o,{postId:l,thumbnailUrl:d,initialFocalPoint:{x:c,y:r}}),a)}(),"undefined"!=typeof jQuery&&(jQuery(document).on("ajaxSuccess",function(e,t,n){n.data&&"string"==typeof n.data&&-1!==n.data.indexOf("action=set-post-thumbnail")&&setTimeout(()=>{location.reload()},300)}),jQuery(document).on("click","#remove-post-thumbnail",function(){setTimeout(()=>{location.reload()},500)}))}),"undefined"!=typeof wp&&wp.media){const e=wp.media.featuredImage;if(e&&e.frame){const t=e.frame;wp.media.featuredImage.frame=function(){return this._frame||(this._frame=t.apply(this,arguments),this._frame.on("select",function(){})),this._frame}}}})();