<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UsingCustomDialog.aspx.cs" Inherits="usingCustomDialog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="ScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadEditor ID="RadEditor1" runat="server">
            <Tools>
                <telerik:EditorToolGroup>
                    <telerik:EditorTool Name="CustomLinkDialog" />
                </telerik:EditorToolGroup>
            </Tools>
        </telerik:RadEditor>
    </div>
    <script type="text/javascript">
        //<![CDATA[
        Telerik.Web.UI.Editor.CommandList["CustomLinkDialog"] = function(commandName, editor, args) {
            var elem = editor.getSelectedElement(); //returns the selected element.

            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;
            }

            var myCallbackFunction = function(sender, args) {
                editor.pasteHtml(String.format("<a href={0} target='{1}' class='{2}'>{3}</a> ", args.href, args.target, args.className, args.name))
            }

            editor.showExternalDialog(
            'InsertLink.aspx',
            argument,
            270,
            300,
            myCallbackFunction,
            null,
            'Insert Link',
            true,
            Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
            false,
            true);
        };
        //]]>        
    </script>
    </form>
</body>
</html>
