FormatBlock block doesnt work for custom tags

Last post 07-17-2010, 1:49 PM by mreric. 2 replies.
Sort Posts: Previous Next
  •  07-16-2010, 4:07 PM 62542

    FormatBlock block doesnt work for custom tags

    Has anyone got the FormatBlock drop down to work?
     
    I can not get the formatbock section to work via the config file or through code. No Matter what I do I cant get any custom tag to work!  i.e.
    <del>, <cite>, <address>, >strike>, etc ... 
     
    How can I get this working, I have this currently:
     
                If Not FCKeditorKB2.ToolControls("FormatBlock") Is Nothing Then
                    Dim dropdown As CuteEditor.RichDropDownList
                    Dim richitem As CuteEditor.RichListItem
                    dropdown = DirectCast(FCKeditorKB2.ToolControls("FormatBlock").Control, CuteEditor.RichDropDownList)

                    'the first item is the caption   
                    richitem = dropdown.Items(0)

                    'clear the items from configuration files   
                    dropdown.Items.Clear()

                    'add the caption   
                    dropdown.Items.Add(richitem)

                    'add text and value   
                    dropdown.Items.Add("Normal", "<p>")

                    'add value and value   
                    dropdown.Items.Add("Heading 1", "<h1>")

                    'Add html and text and value   
                    dropdown.Items.Add("<b style='font-size:9pt'>[[Heading 5]]</b>", "Heading 5", "<h5>")

                    'add value and value   
                    dropdown.Items.Add("Deleted Text", "<del>")

                End If
     
    Thanks!
     
    Eric
    Filed under:
  •  07-16-2010, 11:12 PM 62543 in reply to 62542

    Re: FormatBlock block doesnt work for custom tags

    Hi mieric,
     
    Please try the example below
     
    1. <%@ Page Language="VB" %>   
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5.   
    6. <script runat="server">   
    7.     
    8.     Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs)   
    9.         If Not FCKeditorKB2.ToolControls("FormatBlock"Is Nothing Then  
    10.             Dim dropdown As CuteEditor.RichDropDownList   
    11.             Dim richitem As CuteEditor.RichListItem   
    12.             dropdown = DirectCast(FCKeditorKB2.ToolControls("FormatBlock").Control, CuteEditor.RichDropDownList)   
    13.             'the first item is the caption      
    14.             richitem = dropdown.Items(0)   
    15.             'clear the items from configuration files      
    16.             dropdown.Items.Clear()   
    17.             'add the caption      
    18.             dropdown.Items.Add(richitem)   
    19.             'add text and value      
    20.             dropdown.Items.Add("Normal""<p>")   
    21.             'add value and value      
    22.             dropdown.Items.Add("Heading 1""<h1>")   
    23.             'Add html and text and value      
    24.             dropdown.Items.Add("<b style='font-size:9pt'>[[Heading 5]]</b>""Heading 5""<h5>")   
    25.             'add value and value      
    26.             dropdown.Items.Add("Deleted Text""<del>")   
    27.   
    28.         End If  
    29.   
    30.     End Sub  
    31. </script>   
    32.   
    33. <html xmlns="http://www.w3.org/1999/xhtml">   
    34. <head runat="server">   
    35.     <title>Untitled Page</title>   
    36. </head>   
    37. <body>   
    38.     <form id="form1" runat="server">   
    39.         <div>   
    40.             <CE:Editor ID="FCKeditorKB2" runat="server">   
    41.             </CE:Editor>   
    42.         </div>   
    43.     </form>   
    44. </body>   
    45. </html>   
    46. <script>   
    47. var editor1=document.getElementById("<%= FCKeditorKB2.ClientID %>");   
    48. function getSelectedHTML(){   
    49.       // get the active editor window   
    50.       var editwin = editor1.GetWindow();   
    51.       // get the active editor document   
    52.       var editdoc = editor1.GetDocument();   
    53.       var rng=null,html="";    
    54.       if (document.selection && document.selection.createRange){   
    55.         rng=editdoc.selection.createRange();   
    56.         html=rng.htmlText||"";   
    57.       }else if (window.getSelection){   
    58.         rng=editwin.getSelection();   
    59.         if (rng.rangeCount > 0 && window.XMLSerializer){   
    60.           rng=rng.getRangeAt(0);   
    61.           html=new XMLSerializer().serializeToString(rng.cloneContents());   
    62.         }   
    63.       }   
    64.       return html;   
    65.  }   
    66.   
    67. function CuteEditor_OnCommand(editor,command,ui,value)   
    68.  {   
    69.     if(command=="FormatBlock")   
    70.     {   
    71.         if(value=="<del>")   
    72.         {   
    73.             editor.PasteHTML("<del>"+getSelectedHTML()+"</del>");   
    74.          }     
    75.    }   
    76.      
    77. }   
    78. </script>  
    Regards,
     
    ken
  •  07-17-2010, 1:49 PM 62549 in reply to 62543

    Re: FormatBlock block doesnt work for custom tags

    Works like a charm!  for anyone else, this is what I did.
     
    Create a new JS File and put this in.
    --------------------------------------
    function getSelectedHTML(editor1){
          // get the active editor window   
          var editwin = editor1.GetWindow();   
          // get the active editor document   
          var editdoc = editor1.GetDocument();   
          var rng=null,html="";    
          if (document.selection && document.selection.createRange){   
            rng=editdoc.selection.createRange();   
            html=rng.htmlText||"";   
          }else if (window.getSelection){   
            rng=editwin.getSelection();   
            if (rng.rangeCount > 0 && window.XMLSerializer){   
              rng=rng.getRangeAt(0);   
              html=new XMLSerializer().serializeToString(rng.cloneContents());   
            }   
          }   
          return html;   
    }

    function CuteEditor_OnCommand(editor,command,ui,value)   
     {   
        if(command=="FormatBlock")   
        {   
            if(value=="<del>"){editor.PasteHTML("<del>"+getSelectedHTML(editor)+"</del>");}
            else if(value=="<ins>"){editor.PasteHTML("<ins>"+getSelectedHTML(editor)+"</ins>");}
            else if(value=="<code>"){editor.PasteHTML("<code>"+getSelectedHTML(editor)+"</code>");}
            else if(value=="<q>"){editor.PasteHTML("<q>"+getSelectedHTML(editor)+"</q>");}
            else if(value=="<tt>"){editor.PasteHTML("<tt>"+getSelectedHTML(editor)+"</tt>");}
            else if(value=="<kbd>"){editor.PasteHTML("<kbd>"+getSelectedHTML(editor)+"</kbd>");}
            else if(value=="<samp>"){editor.PasteHTML("<samp>"+getSelectedHTML(editor)+"</samp>");}
            else if(value=="<var>"){editor.PasteHTML("<var>"+getSelectedHTML(editor)+"</var>");}
            else if(value=="<cite>"){editor.PasteHTML("<cite>"+getSelectedHTML(editor)+"</cite>");}
       }
    }
     
    --------------------------------------
     
     In your Code file
    --------------------------------------
                    dropdown.Items.Add("<ins>Inserted Text</ins>", "Inserted Text", "<ins>")
                    dropdown.Items.Add("<del>Deleted Text</del>", "Deleted Text", "<del>")
                    dropdown.Items.Add("<code>Computer Code</code>", "Computer Code", "<code>")
                    dropdown.Items.Add("<q>Inline Quotation</q>", "Inline Quotation", "<q>")
                    dropdown.Items.Add("<tt>Typewriter</tt>", "Typewriter", "<tt>")
                    dropdown.Items.Add("<kbd>Keyboard Phrase</kbd>", "Keyboard Phrase", "<kbd>")
                    dropdown.Items.Add("<samp>Sample Text</samp>", "Sample Text", "<samp>")
                    dropdown.Items.Add("<var>Variable</var>", "Variable", "<var>")
                    dropdown.Items.Add("<cite>Cited Work</cite>", "Cited Work", "<cite>")
    --------------------------------------
     
    Cheers.
     
View as RSS news feed in XML