This is a migrated thread and some comments may be shown as answers.

[Solved] Check If User Clicked OK button in RadEditorFormatCodeBlock?

3 Answers 163 Views
Editor
This is a migrated thread and some comments may be shown as answers.
carlpro
Top achievements
Rank 1
carlpro asked on 19 Feb 2008, 02:14 AM
In the pervious version of the RadEditor, one could check if the user had clicked the OK button to insert code as follow:

<script type="text/javascript">    
var originalRadEditorFormatCodeBlock = RadEditorNamespace.radEditorFormatCodeBlock;    
RadEditorNamespace.radEditorFormatCodeBlock = function(returnValue, params)            
{         
    if (returnValue != undefined)  
    {  
        // <snip>
        originalRadEditorFormatCodeBlock(returnValue, params);  
    }  
};  
</script> 

How does one do this in 'Prometheus for ASP.NET'?

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 20 Feb 2008, 02:54 PM
Hi Carl,

In the Q1 2008 release of RadEditor "Prometheus", due in April, we will provide an easy way to attach to the callback function of the editor dialogs as it is in the classic RadEditor.

Currently, you can use the following code to attach to the Callback function of the FormatCodeBlock tool:


<telerik:radeditor runat="server" OnClientCommandExecuting="OnClientCommandExecuting" ID="RadEditor1">
<Tools>
    <telerik:EditorToolGroup>
        <telerik:EditorTool Name="FormatCodeBlock" />
    </telerik:EditorToolGroup>
</Tools>
</telerik:radeditor>
<script type="text/javascript">

function OnClientCommandExecuting(editor, args)
{
    var commandName = args.get_commandName();
    if (commandName != "FormatCodeBlock") return;
                           
    //Replace the showDialog function with a modified one   
    if (!editor.oldShowDialog)
    {
        editor.oldShowDialog = editor.showDialog;       
        editor.showDialog = function(dialogName, argument, callbackFunction)
        {
            if (commandName == "FormatCodeBlock")
            {
                callbackFunction = function(sender, args)
                {
                    var result = args.get_code();
                    alert("Dialog returned " + result);
                    editor.pasteHtml(args.get_code(), commandName);                                                                                 
                }               
            }
           
            //Call original dialog function
            editor.oldShowDialog(dialogName, argument, callbackFunction);           
        }
    }           
}
</script>

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
carlpro
Top achievements
Rank 1
answered on 22 Feb 2008, 06:12 PM
Note the above code works if one just clicks the Format Code Block button.  However, if one clicks Hyperlink Manager next, and then the Format Code Block again, the code fails.  So I ended up using the following code:

[UPDATED - Since we only have the Hyperlink and CodeBlock buttons on our RadEditor toolbar, we will always overriding the ShowDialog for both of these dialogs. Then we special case them in the call back function]

    if (!editor.oldShowDialog)  
    {  
        editor.oldShowDialog = editor.showDialog;          
        editor.showDialog = function(dialogName, argument, callbackFunction)  
        {  
            callbackFunction = function(sender, args)  
            {  
                var commandName = sender.get_name();  
                if (commandName.indexOf("FormatCodeBlock") != -1)  
                {  
                    var code = args.get_code();  
                    if (code != null)  
                    {  
                        // <snip>
                    }  
                      
                    editor.pasteHtml(code, commandName);  
                }  
                else if (commandName.indexOf("LinkManager") != -1)  
                {  
                    var realLink = args.realLink;  
                    if (realLink != null)  
                    {  
                        editor.pasteHtml(realLink.outerHTML, commandName);  
                    }  
                }  
            }  
              
            editor.oldShowDialog(dialogName, argument, callbackFunction);              
        }  
    }       
 
0
Tervel
Telerik team
answered on 25 Feb 2008, 12:06 PM
Hello carlpro,

That is correct. Thank you for pointing out this detail :)

Best regards,
Tervel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Editor
Asked by
carlpro
Top achievements
Rank 1
Answers by
Rumen
Telerik team
carlpro
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or