primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,117 @@
import Cropper from 'cropper-module';
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
let formElements;
let activated = false;
let instance;
const addListeners = () => {
formElements.cropX.addEventListener('change', ({
currentTarget
}) => {
instance.setData({
x: parseInt(currentTarget.value, 10)
});
});
formElements.cropY.addEventListener('change', ({
currentTarget
}) => {
instance.setData({
y: parseInt(currentTarget.value, 10)
});
});
formElements.cropWidth.addEventListener('change', ({
currentTarget
}) => {
instance.setData({
width: parseInt(currentTarget.value, 10)
});
});
formElements.cropHeight.addEventListener('change', ({
currentTarget
}) => {
instance.setData({
height: parseInt(currentTarget.value, 10)
});
});
formElements.aspectRatio.addEventListener('change', ({
currentTarget
}) => {
instance.setAspectRatio(currentTarget.value);
});
activated = true;
};
const init = image => {
// Set default aspect ratio after numeric check, option has a dummy value
const defaultCropFactor = image.naturalWidth / image.naturalHeight;
if (!Number.isNaN(defaultCropFactor) && Number.isFinite(defaultCropFactor)) {
formElements.cropAspectRatioOption.value = defaultCropFactor;
}
// Initiate the cropper
instance = new Cropper(image, {
viewMode: 1,
responsive: true,
restore: true,
autoCrop: true,
movable: false,
zoomable: false,
rotatable: false,
autoCropArea: 1,
// scalable: false,
crop(e) {
formElements.cropX.value = Math.round(e.detail.x);
formElements.cropY.value = Math.round(e.detail.y);
formElements.cropWidth.value = Math.round(e.detail.width);
formElements.cropHeight.value = Math.round(e.detail.height);
const format = Joomla.MediaManager.Edit.original.extension.toLowerCase() === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension.toLowerCase();
const quality = formElements.cropQuality.value;
// Update the store
Joomla.MediaManager.Edit.current.contents = this.cropper.getCroppedCanvas().toDataURL(`image/${format}`, quality);
// Notify the app that a change has been made
window.dispatchEvent(new Event('mediaManager.history.point'));
}
});
// Add listeners
if (!activated) {
addListeners();
}
instance.setAspectRatio(formElements.cropAspectRatioOption.value);
};
// Register the Events
window.addEventListener('media-manager-edit-init', () => {
formElements = {
aspectRatio: document.getElementById('jform_aspectRatio'),
cropHeight: document.getElementById('jform_crop_height'),
cropWidth: document.getElementById('jform_crop_width'),
cropY: document.getElementById('jform_crop_y'),
cropX: document.getElementById('jform_crop_x'),
cropQuality: document.getElementById('jform_crop_quality'),
cropAspectRatioOption: document.querySelector('.crop-aspect-ratio-option')
};
Joomla.MediaManager.Edit.plugins.crop = {
Activate(image) {
return new Promise((resolve /* , reject */) => {
init(image);
resolve();
});
},
Deactivate(image) {
return new Promise((resolve /* , reject */) => {
if (image.cropper) {
image.cropper.destroy();
instance = null;
}
resolve();
});
}
};
}, {
once: true
});

View File

@ -0,0 +1,4 @@
import p from"cropper-module";/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/let t,n=!1,a;const d=()=>{t.cropX.addEventListener("change",({currentTarget:e})=>{a.setData({x:parseInt(e.value,10)})}),t.cropY.addEventListener("change",({currentTarget:e})=>{a.setData({y:parseInt(e.value,10)})}),t.cropWidth.addEventListener("change",({currentTarget:e})=>{a.setData({width:parseInt(e.value,10)})}),t.cropHeight.addEventListener("change",({currentTarget:e})=>{a.setData({height:parseInt(e.value,10)})}),t.aspectRatio.addEventListener("change",({currentTarget:e})=>{a.setAspectRatio(e.value)}),n=!0},s=e=>{const o=e.naturalWidth/e.naturalHeight;!Number.isNaN(o)&&Number.isFinite(o)&&(t.cropAspectRatioOption.value=o),a=new p(e,{viewMode:1,responsive:!0,restore:!0,autoCrop:!0,movable:!1,zoomable:!1,rotatable:!1,autoCropArea:1,crop(r){t.cropX.value=Math.round(r.detail.x),t.cropY.value=Math.round(r.detail.y),t.cropWidth.value=Math.round(r.detail.width),t.cropHeight.value=Math.round(r.detail.height);const i=Joomla.MediaManager.Edit.original.extension.toLowerCase()==="jpg"?"jpeg":Joomla.MediaManager.Edit.original.extension.toLowerCase(),c=t.cropQuality.value;Joomla.MediaManager.Edit.current.contents=this.cropper.getCroppedCanvas().toDataURL(`image/${i}`,c),window.dispatchEvent(new Event("mediaManager.history.point"))}}),n||d(),a.setAspectRatio(t.cropAspectRatioOption.value)};window.addEventListener("media-manager-edit-init",()=>{t={aspectRatio:document.getElementById("jform_aspectRatio"),cropHeight:document.getElementById("jform_crop_height"),cropWidth:document.getElementById("jform_crop_width"),cropY:document.getElementById("jform_crop_y"),cropX:document.getElementById("jform_crop_x"),cropQuality:document.getElementById("jform_crop_quality"),cropAspectRatioOption:document.querySelector(".crop-aspect-ratio-option")},Joomla.MediaManager.Edit.plugins.crop={Activate(e){return new Promise(o=>{s(e),o()})},Deactivate(e){return new Promise(o=>{e.cropper&&(e.cropper.destroy(),a=null),o()})}}},{once:!0});

Binary file not shown.