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

Mimic list insert logic for table insert

1 Answer 42 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 15 Jan 2009, 05:59 PM
In the editor if the bulleted or numbered list toolbar button is pressed while in a paragraph tag the resulting html will close the paragraph tag and the list element is inserted under the paragraph tag. Is there a way to copy the exact insert list logic so that tables inserted by the editor format the html in the sammer manner. The end result I am looking for is for no table element to be a child of a paragraph element.

Thanks,
Alex

1 Answer, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 19 Jan 2009, 09:58 AM
Hi Alex,

We did our best to write some code that will do what you need and this is what we came up with:

  <script> 
              function OnClientPasteHtml(editor, args) 
              { 
                if (!$telerik.isIE) return
                 
                if (args.get_commandName() == "InsertTable"
                { 
                    //For proper functioning we need to have selection - or else the whole paragraph is made to a list 
                    var tempID = "temp_span_id";             
                    editor.pasteHtml("<span id='" + tempID + "'>TEMP</span>");                                           
                    var innerSpan = editor.get_document().getElementById(tempID); 
                    editor.selectElement(innerSpan); 
                     
                    //Create a list                                                      
                    editor.fire("InsertUnorderedList"); 
                     
                    //Replace the list with the table 
                    var innerSpan = editor.get_document().getElementById(tempID); 
                    var ul = innerSpan.parentNode.parentNode;                    
                    ul.outerHTML = args.get_value(); 
                     
                    //Cancel the original paste operation 
                    args.set_cancel(true);                                                            
                }                
              } 
              </script> 
               
            Ticket #185047 
            <telerik:radeditor runat="server" ID="RadEditor1"  OnClientPasteHtml="OnClientPasteHtml"

It uses quite a number of hacks and assumptions on how the browser rich edit engine will behave, so there could be unexpected side effects. Our suggestion is to give it a try and fix it further if needed.


Best regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Alex
Top achievements
Rank 1
Answers by
Tervel
Telerik team
Share this question
or