GetmeUK / ContentTools

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

Troubles with custom image uploader #454

Closed raphale closed 6 years ago

raphale commented 6 years ago

Hi! I've try to implement a custom image uploader. I've follow recommandation found on other issue (https://github.com/GetmeUK/ContentTools/issues/199) but it's not working for me. I've also look at your default tool ContentTools.Tools.Image code.

Image is finally added but with class ce-element--type-static and not ce-element--type-image. I can't select image tag and edit properties. I can't delete the image once inserted. This is the code of the callback function called by my custom dialog (Gallery is the name of my custom tool):

var insertImage = function(myId, asset, replace) {
    if (replace) {
        element.src(asset.src);
        element.attr('id', asset.id);
        return callback(true);
    }

    var image, imageAttrs, index, node, _ref;
    imageAttrs = {
        src: asset.src,
        width: asset.width,
        height: asset.height,
        id: asset.id
    };
    image = new ContentEdit.Image(imageAttrs);
    _ref = Gallery._insertAt(element), node = _ref[0], index = _ref[1];
    node.parent().attach(image, index);   
    image.focus();
    return callback(true);
};

Another thing, when editor is init with empty content, the parent element is null. I need to type at least one character to have a Region referenced in parent attribute of element.

anthonyjb commented 6 years ago

Hi @raphale - that's really odd, is there any chance you could post a JSFiddle example so I could take a look at exactly what's happening?