Completed
Last Updated: 01 Jun 2021 12:49 by ADMIN
ADMIN
Rumen
Created on: 16 Sep 2011 01:49
Category: UI for ASP.NET AJAX
Type: Feature Request
0
ADD Support for Full HTML Page insertion from the Template manager

		
1 comment
ADMIN
Rumen
Posted on: 01 Jun 2021 12:49

You can insert full HTML page content via the Template manager by implementing the steps below:

  1. Copy the EditorDialogs installation folder to the root of your web application.
  2. Set the ExternalDialogsPath property to point to the EditorDialogs folder, e.g.

    <telerik:RadEditor ID="RadEditor1" ExternalDialogsPath="~/EditorDialogs"
    OnClientPasteHtml="OnClientPasteHtml"  runat="server">
        <Content>
        </Content>
      <TemplateManager ViewPaths="~/files" UploadPaths="~/files" />
    </telerik:RadEditor>


  3. Open the \EditorDialogs\TemplateManager.ascx dialog file and modify the getResult function:

        getResult : function()
        {
            if (this._currentItem && this._currentItem.type == Telerik.Web.UI.Widgets.FileItemType.File && this.isValidExtension())
            {
                //OLD
                //this._currentTemplateItem.contentWindow.getElementsByTagName("HTML")[0].innerHTML;
               
                //NEW
                var test = "<html>" + document.getElementsByTagName("IFRAME")[0].contentWindow.document.getElementsByTagName("HTML")[0].innerHTML + "</html>";
                return test;
            }
            return null;
        },
    ...

    This change will return full html content to the editor on the parent window.
  4. Since the browser itself will strip the <html>, <head> and <body> tags, we need to capture the supplied content from the Template Manager and paste it in the editor with the set_html() method. We can do that by attaching to the OnClientPasteHtml event property of RadEditor, e.g.

    <telerik:RadEditor ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml" ExternalDialogsPath="~/EditorDialogs" runat="server">
        <Content>
        </Content>
      <TemplateManager ViewPaths="~/files" UploadPaths="~/files" />
    </telerik:RadEditor>
    <script type="text/javascript">
    function OnClientPasteHtml(editor, args)
    {
        var commandName = args.get_commandName(); //returns the command name
        var value = args.get_value(); //returns the content / value of the fired command
    
        if (commandName == "TemplateManager")
        {
            editor.set_html(value);
        }
    
    }
    </script>