Re: FormatBlock block doesnt work for custom tags

  •  07-17-2010, 1:49 PM

    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 Complete Thread