CoreFiles by mySites.guru
rotate.es6.js87 lines, 3,019 bytes, from Joomla_4.0.0-alpha8-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha7
md5
1a95b1142c3752125c3c8af4c8d82d10
sha1
48869c2dc385e7a6306588b4d87bec780b15474e
sha256
3a61fb605720624273262516c470d732c8522a98b4d5f7f5c5214f28fa6234b6
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
 * @copyright  Copyright (C) 2005 - 2019 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 || {};

(() => {
  'use strict'; // Update image

  const rotate = angle => {
    // The image element
    const image = document.getElementById('image-source'); // The canvas where we will resize the image

    const canvas = document.createElement('canvas'); // Pseudo rectangle calculation

    if (angle >= 0 && angle < 45 || angle >= 135 && angle < 225 || angle >= 315 && angle <= 360) {
      canvas.width = image.width;
      canvas.height = image.height;
    } else {
      // swap
      canvas.width = image.height;
      canvas.height = image.width;
    }

    const ctx = canvas.getContext('2d');
    ctx.translate(canvas.width / 2, canvas.height / 2);
    ctx.rotate(angle * Math.PI / 180);
    ctx.drawImage(image, -image.width / 2, -image.height / 2); // The format

    const format = Joomla.MediaManager.Edit.original.extension === 'jpg' ? 'jpeg' : 'jpg'; // The quality

    const quality = document.getElementById('jform_rotate_quality').value; // Creating the data from the canvas

    Joomla.MediaManager.Edit.current.contents = canvas.toDataURL("image/".concat(format), quality); // Updating the preview element

    const preview = document.getElementById('image-preview');
    preview.width = canvas.width;
    preview.height = canvas.height;
    preview.src = Joomla.MediaManager.Edit.current.contents; // Update the height input box

    document.getElementById('jform_rotate_a').value = angle; // Notify the app that a change has been made

    window.dispatchEvent(new Event('mediaManager.history.point'));
  };

  const initRotate = () => {
    const funct = () => {
      // The number input listener
      document.getElementById('jform_rotate_a').addEventListener('input', event => {
        rotate(parseInt(event.target.value, 10)); // Deselect all buttons

        const elements = [].slice.call(document.querySelectorAll('#jform_rotate_distinct label'));
        elements.forEach(element => {
          element.classList.remove('active');
          element.classList.remove('focus');
        });
      }); // The 90 degree rotate buttons listeners

      const elements = [].slice.call(document.querySelectorAll('#jform_rotate_distinct label'));
      elements.forEach(element => {
        element.addEventListener('click', event => {
          rotate(parseInt(event.target.querySelector('input').value, 10));
        });
      });
    };

    setTimeout(funct, 1000);
  }; // Register the Events


  Joomla.MediaManager.Edit.rotate = {
    Activate(mediaData) {
      // Initialize
      initRotate(mediaData);
    },

    Deactivate() {}

  };
})();

The same content is in 5 releases, Joomla 4.0.0-alpha8 to 4.0.0-alpha12. See them all, or every version of this file.