Issue #1044Opened April 15, 2018by adib182 reactions

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)

artfApril 15, 20181 reactions

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

adib18April 15, 20181 reactions

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.

StejsiSeptember 25, 20180 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.