| Current Path : /var/www/html/media/plg_media-action_rotate/js/ |
| Current File : /var/www/html/media/plg_media-action_rotate/js/rotate.min.js |
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/let activated=!1;const rotate=(a,e)=>{let t=document.createElement("canvas");a>=0&&a<45||a>=135&&a<225||a>=315&&a<=360?(t.width=e.naturalWidth,t.height=e.naturalHeight):(t.width=e.naturalHeight,t.height=e.naturalWidth);const r=t.getContext("2d");r.clearRect(0,0,t.width,t.height),r.translate(t.width/2,t.height/2),r.rotate(a*Math.PI/180),r.drawImage(e,-e.naturalWidth/2,-e.naturalHeight/2);const n=Joomla.MediaManager.Edit.original.extension.toLowerCase()==="jpg"?"jpeg":Joomla.MediaManager.Edit.original.extension.toLowerCase(),o=document.getElementById("jform_rotate_quality").value;Joomla.MediaManager.Edit.current.contents=t.toDataURL(`image/${n}`,o),e.width=t.width,e.height=t.height,e.src="",requestAnimationFrame(()=>requestAnimationFrame(()=>{e.src=Joomla.MediaManager.Edit.current.contents})),document.getElementById("jform_rotate_a").value=a,window.dispatchEvent(new Event("mediaManager.history.point")),t=null},initRotate=a=>{activated||(document.getElementById("jform_rotate_a").addEventListener("change",({target:e})=>{const t=parseInt(e.value,10);Number.isNaN(t)||(rotate(t,a),document.querySelectorAll("#jform_rotate_distinct label").forEach(r=>r.classList.remove("active","focus")))}),document.querySelectorAll("#jform_rotate_distinct [type=radio]").forEach(e=>{e.addEventListener("click",({target:t})=>{rotate(parseInt(t.value,10),a),document.querySelectorAll("#jform_rotate_distinct label").forEach(r=>r.classList.remove("active","focus"))})}),activated=!0)};window.addEventListener("media-manager-edit-init",()=>{Joomla.MediaManager.Edit.plugins.rotate={Activate(a){return new Promise(e=>{initRotate(a),e()})},Deactivate(){return new Promise(a=>{a()})}}},{once:!0});