change src for image element in model
Question
hello when a image block drop to editor i hide the default asset manager and display my custom asset manager:
editor.on('canvas:drop', function (e,result) {
if(result.attributes.type == 'image'){
modal.close();
jQuery('div.my_custom_asset_manager').show();
}
});
fot this i have no problem.but when a image select on my custom asset manager i change src from image element in the editor with jquery.
jQuery('iframe').contents().find('img.in_editor').attr('src','custom_url');
but when move the image element in the editor from a block to another block src attribute removed.I search and find out when change src with jquery only view changed but model must change for image element.now i want to know how i can change src for image element in model.
thanks
Answers (3)
Correct your custom asset manager implementation, it's not reliable (eg. if the user double click on the image you'll still see the default one). Follow this #491 and the problem with the src will be fixed
thanks a lot.i correct asset manager with this:
var assettarget ='';
editor.Commands.add('open-assets', {
run(editor, sender, opts = {}) {
const modal = editor.Modal;
assettarget = opts.target;
modal.setTitle('Add new image');
modal.setContent(jQuery('div.custom_asset_manager').html());
modal.open();
jQuery('div[id*="__wp-uploader-id"]').show();
}
});
and use this when select a image in custom asset manager
assettarget.set('src', 'src_image_from_custom_asset_manager');
thanks for your great work.
Hello, i am used this solution, and it works, but now i am not able to asset background-image in Style Manager. It use custom function spreadUrl(), but i dont know how to call it without modify Grapesjs core. Thanks for help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1573
Open modal after drop element
How to show custom modal dialog when drop element on editor? like asset modal dialog appears when drop image block to the editor.
Issue #1578
[Question] Custom request on "src" attributes
I implemented a small GrapesJS editor that allows to edit Django/Jinja2 templates. GrapesJS by default is trying to GET the image preview o...
Issue #930
[Question] Update resizer after asset changed
Hi! I trying to change default assets manager with ours custom manager. On double click the selected image is replaced with a new one with...
Issue #1218
[QUESTION] Asset Manager - Upload Image
Hey @artf , I have a question around Asset Manager. When uploading an image via computer or url the preview shows up at the asset collectio...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.