xdan / jodit

Jodit - Best WYSIWYG Editor for You
https://xdsoft.net/jodit/
MIT License
1.71k stars 354 forks source link

improvement for image editor (event, ratio change) #820

Open coolibry opened 2 years ago

coolibry commented 2 years ago

Jodit Version: 3.16.5

Browser: Chrome & Firefox OS: Windows &Linux Is React App: False

Code for event afterImageEditor

var editor = new Jodit('#editor', {
    imageDefaultWidth: 600,
    events: {
        afterImageEditor: function(ev){ //this don't launch
            console.log(ev);
          },
        afterInsertImage: function(ev){
            Jodit.modules.resize_small_img(ev, "editor");
        },
    }
});

Jodit.modules.resize_small_img = function (img, jodit) {
    img.onload = function(){//wait img to load
        if (img.width >= img.naturalWidth){ //resize img if is smaller
            img.width = img.naturalWidth;
            img.height = img.naturalHeight;
        }
        jodit = window[jodit];
        jodit.synchronizeValues(); //sync to jodit
    }
}

Expected behavior: afterImageEditor event launch after resize or crop image afterInsertImage normally launch

Actual behavior: afterImageEditor event do not launch after resize or crop image

main goal to this :

coolibry commented 2 years ago

update about this request : in image properties, when i clic on input : imageWidth, imageHeight function changeSizes run and change value to keep ratio,

then is it possible to trigger changeSizes function after crop ? also if picture is smaller than imageDefaultWidth, then set to original value.