CoreFiles by mySites.guru
crop.js93 lines, 3,361 bytes, from Joomla_4.0.0-alpha3-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha2
md5
0dc10463ce6afac7bf9e3e8659f6dd13
sha1
70ad9516d9c22b628afd0c971a5a5199c6dbdcd8
sha256
cbf8304584c7e7300cd7d2393bbc1b92d837e2fe893cf1c48cf1d6ea64d07ac8
/**
 * @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
Joomla = window.Joomla || {};

Joomla.MediaManager = Joomla.MediaManager || {};
Joomla.MediaManager.Edit = Joomla.MediaManager.Edit || {};

(function () {
	"use strict";

	var initCrop = function (mediaData) {
		var image = document.getElementById('image-preview');

		// Initiate the cropper
		Joomla.MediaManager.Edit.crop.cropper = new Cropper(image, {
			viewMode: 1,
			responsive: true,
			restore: true,
			autoCrop: true,
			movable: false,
			zoomable: false,
			rotatable: false,
			autoCropArea: 1,
			// scalable: false,
			minContainerWidth: image.offsetWidth,
			minContainerHeight: image.offsetHeight,
			crop: function (e) {
				document.getElementById('jform_crop_x').value = Math.round(e.detail.x);
				document.getElementById('jform_crop_y').value = Math.round(e.detail.y);
				document.getElementById('jform_crop_width').value = Math.round(e.detail.width);
				document.getElementById('jform_crop_height').value = Math.round(e.detail.height);

				var format = Joomla.MediaManager.Edit.original.extension === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension;

				var quality = document.getElementById('jform_crop_quality').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'));
			}
		});

		document.getElementById('jform_crop_x').addEventListener('change', function (e) {
			Joomla.MediaManager.Edit.crop.cropper.setData({x: parseInt(this.value)});
		});
		document.getElementById('jform_crop_y').addEventListener('change', function (e) {
			Joomla.MediaManager.Edit.crop.cropper.setData({y: parseInt(this.value)});
		});
		document.getElementById('jform_crop_width').addEventListener('change', function (e) {
			Joomla.MediaManager.Edit.crop.cropper.setData({width: parseInt(this.value)});
		});
		document.getElementById('jform_crop_height').addEventListener('change', function (e) {
			Joomla.MediaManager.Edit.crop.cropper.setData({height: parseInt(this.value)});
		});
		document.getElementById('jform_aspectRatio').addEventListener("change", function (e) {
			Joomla.MediaManager.Edit.crop.cropper.setAspectRatio(this.value);
		});

		// Wait for the image to load its data
		image.addEventListener('load', function() {

			// Get all option elements if future need
			var elements = [].slice.call(document.querySelectorAll(".crop-aspect-ratio-option"));

			// Set default aspect ratio after numeric check, option has a dummy value
			var defaultCropFactor = image.naturalWidth / image.naturalHeight;
			if (!isNaN(+defaultCropFactor) && isFinite(defaultCropFactor)){
				elements[0].value = defaultCropFactor;
			}
			Joomla.MediaManager.Edit.crop.cropper.setAspectRatio(elements[0].value);

		});
	};

	// Register the Events
	Joomla.MediaManager.Edit.crop = {
		Activate: function (mediaData) {
			// Initialize
			initCrop(mediaData);
		},
		Deactivate: function () {
			if (!Joomla.MediaManager.Edit.crop.cropper) {
				return;
			}
			// Destroy the instance
			Joomla.MediaManager.Edit.crop.cropper.destroy();
		}
	};
})();

No other release has this exact content. See every version of this file.