GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 393 forks source link

Manage images #493

Open Luc-cpl opened 6 years ago

Luc-cpl commented 6 years ago

Add the possibility to use images that is already in the system unstead upload a new image every time.

The image source is an array of strings with the src To set the images is just put this array in IMAGE_UPLOADER dialog new function "addImages"

PawelGlow commented 6 years ago

@Luc-cpl can you provide an example in JS how to add the images? I can then confirm I implemented it correctly and check if it works as expected.

Luc-cpl commented 6 years ago

Following the "Handling image uploads" tutorial.

function imageUploader(dialog) {
    var image, xhr, xhrComplete, xhrProgress;

    var myImages = [ '/image1.jpg', '/image2.jpg', '/image3;jpg', '/image4.jpg' ]; //or use any function that return an array with the urls

    dialog.addImages(myImages);

    // Set up the event handlers
    ... event handlers go here ...
}

ContentTools.IMAGE_UPLOADER = imageUploader;

Add one if statement in save event:

dialog.addEventListener('imageuploader.save', function () {
    if (!image){
        dialog.save();
        return;
    }

    // Rest of code ....

}