Update the Canvas with a custom function
Question
I'm trying to create a function that replaces all the attributes of link, these make the change in the canvas, but don't save it when I try it with the editor.storage() function;
here the code:
$("button#replace_url").on("click", function(e) {
e.preventDefault();
var body = editor.Canvas.getBody().ownerDocument;
body.querySelectorAll('a').forEach(function(el) {
var ahref = el;
ahref.setAttribute('href', "http://facebook.com");
ahref.setAttribute("target", "_blank");
});
editor.store();
modal.close();
});
Answers (2)
@chiqui3d in this way you're just updating the view, the output code is generated by the model instead (when you update the model changes are reflected in the view) So your example will be something like this
const wrapper = editor.DomComponents.getWrapper();
wrapper.find('a').forEach(aModel => aModel.addAttributes({ href: '.../...' }))
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1669
[Question] Custom link modal doesn't update the current text but add another text with link
Hello Artur, I'm trying to have a custom modal when clicked link button in RTE. but it doesn't convert selected text to link but what it do...
Issue #1639
[Question]: Would it be possible to have change settings under style manager in a way that it has href when a link is created?
I'm using preset newsletter with built-in RTE (do not want to use ck editor like the demo) In order to make any text to link, i need to cli...
Issue #1511
[QUESTION] Change the html content of the selected component
I am trying to replace the html of the basic Text componet using the below code const component = editor.getSelected(); component.set('cont...
Issue #1044
change src for image element in model
hello when a image block drop to editor i hide the default asset manager and display my custom asset manager: fot this i have no problem.bu...
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.