Hello Telerik crew,
After the recent Chrome update (vers 125.0.6422.61), I am encountering strange behavior when opening a custom dialog from within a RadEditor control. I have not experienced the below issue in Firefox nor Edge, only latest version of Chrome.
If plain text is selected (i.e.: no html formatting), the custom dialog is launched and the text loses it's focus which in-turn causes a hyperlink to be pasted directly after the text I had selected. If an A tag is selected, the custom dialog is launched and the selected A tag doesn't lose focus.
I have included the code I am using to launch the custom dialog:
Telerik.Web.UI.Editor.CommandList["InsertHyperlink_FWText"] = function (commandName, editor, args) {
// only continue if we have actual text selected in <textarea>
var selected_text = editor.getSelection().getText();
if (selected_text != "" || editor.getSelectedElement().tagName == "A") {
var elem = editor.getSelectedElement(); //returns the selected element.
var flag = true;
var parent_elem = elem.parentElement;
if (elem.tagName == "A") {
if (elem.getAttribute('class') == "advbutton") {
flag = false;
}
editor.selectElement(elem);
argument = elem;
} else {
do { //set up the parent element and find the encapsulating A tag
parent_elem = parent_elem.parentElement;
if (parent_elem == null) { break; }
} while (parent_elem.tagName != "A");
if (parent_elem != null) {
if (parent_elem.tagName == "A") {
if (parent_elem.getAttribute('class') == "advbutton") {
flag = false;
}
selected_text = parent_elem.innerHTML;
editor.selectElement(parent_elem);
argument = parent_elem;
}
} else {
//remove links if present from the current selection - because of JS error thrown in IE
editor.fire("Unlink");
//remove Unlink command from the undo/redo list
var commandsManager = editor.get_commandsManager();
var commandIndex = commandsManager.getCommandsToUndo().length - 1;
commandsManager.removeCommandAt(commandIndex);
//
var content = editor.getSelectionHtml();
var link = editor.get_document().createElement("A");
link.innerHTML = content;
argument = link;
}
}
// only if dealing with a hyperlink advanced button, do we continue
if (flag == true) {
//---------------- Classic ASP Hyperlink Editor ---------------------------------------------
var doChooseLink = function (elem) {
var objEl = new Object();
if (elem.getAttribute("href") != null) {
objEl.href = elem.getAttribute("href");
objEl.target = elem.getAttribute("target");
objEl.title = elem.getAttribute("title");
} else {
objEl.href = ""
objEl.target = ""
objEl.title = ""
}
var args = new Array();
args["objEl"] = objEl;
args["Mode"] = "doclink"
flexDialog(620, 410, "/fw/_theditor/ed_links.asp", args, doChooseLink_CallBack, null);
}
var doChooseLink_CallBack = function (retValue, objEl) {
if (retValue.href == "") {
editor.pasteHtml(String.format(selected_text));
} else {
if (selected_text.charAt(selected_text.length - 1) == ' ') {
selected_text = selected_text.substring(0, selected_text.length - 1);
editor.pasteHtml(String.format("<a href='{0}' title='{1}' target='{2}'>" + selected_text + "</a> ", retValue.href, retValue.title, retValue.target));
} else {
editor.pasteHtml(String.format("<a href='{0}' title='{1}' target='{2}'>" + selected_text + "</a>", retValue.href, retValue.title, retValue.target));
}
}
}
doChooseLink(argument);
//---------------- END Classic ASP Hyperlink Editor ---------------------------------------------
}
}
};
Please let me know if you need any other information, or a clearer explanation of the issue I am experiencing in Chrome (vers.125) only).
Thank you!