Hello Ramakrishna,
You can create custom tools in the editor that open your own dialogs, for example, RadWindow instances whose ContentTemplate is used to host your controls/logic. Instead of calling editor.showExternalDialog(), you can show the desired RadWindow, and then upon the desired user action (e.g., selection from a dropdown or a button click), directly call the pasteHtml() method of the editor, without relying on callback functions.
Here's a basic example:
<telerik:RadEditor RenderMode=
"Lightweight"
runat=
"server"
ID=
"re1"
>
<Tools>
<telerik:EditorToolGroup>
<telerik:EditorTool Name=
"InsertSpecialLink"
Text=
"Insert Special Link"
/>
</telerik:EditorToolGroup>
</Tools>
<Content>
Sample Content
</Content>
</telerik:RadEditor>
<telerik:RadWindow runat=
"server"
ID=
"rw1"
RenderMode=
"Lightweight"
Modal=
"true"
Behaviors=
"Close, Move"
Title=
"Insert Custom Link"
>
<ContentTemplate>
<asp:TextBox runat=
"server"
ID=
"tb1"
/>
<asp:Button Text=
"paste contents"
ID=
"button1"
OnClientClick=
"pasteInEditor(this); return false;"
runat=
"server"
/>
</ContentTemplate>
</telerik:RadWindow>
<script type=
"text/javascript"
>
function
getEditor() {
return
$find(
"<%=re1.ClientID%>"
);
}
function
getCustomLinkDialog() {
return
$find(
"<%=rw1.ClientID%>"
);
}
function
pasteInEditor(btn) {
var
tbValue = $telerik.$(btn).parent().find(
"input"
).first().val();
//one way to get the value through traversing the DOM
var
editor = getEditor();
editor.pasteHtml(String.format(
"<a href='{0}' target='{0}' class='{0}'>{0}</a> "
, tbValue));
getCustomLinkDialog().close();
}
Telerik.Web.UI.Editor.CommandList[
"InsertSpecialLink"
] =
function
(commandName, editor, args) {
//sample logic for selecting and creating an anchor, taken from demo
var
elem = editor.getSelectedElement();
//returns the selected element.
if
(elem) {
if
(elem.tagName ==
"A"
) {
editor.selectElement(elem);
argument = elem;
}
else
{
var
content = editor.getSelectionHtml();
var
link = editor.get_document().createElement(
"A"
);
link.innerHTML = content;
argument = link;
}
}
getCustomLinkDialog().show();
};
</script>
Regards,
Marin Bratanov
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.