views:

47

answers:

1

I have created a custom button using this code

setup : function(ed) {
ed.addButton('Tittle', {
            title : 'Tittle',
            image : './images/T.jpg',
            onclick : function() {
            ed.focus();
        var c = ed.selection.getNode().nodeName;
    if(c!="TITTLE")
    {
         ed.selection.setContent('<tittle>' + ed.selection.getContent() + '</tittle>');

    }
    else
    {

    }

} }); When a user select a text and click on the new button, i want to add a <title> tag at beginning and ending, if <tittle> tag is not their.If <tittle> tag is already their in the selected text i want to remove the tag

+2  A: 

try

selection.getContent({format : 'raw'});

or

selection.getContent({format : 'html'});

EDIT: To achieve what you want you could do:

if(c!="TITTLE") {

  node = ed.selection.getNode();

  with(document.getElementById(iframe_id).contentWindow){
      var newElement = document.createElement("tittle");
      newElement.innerHTML = node.innerHTML;
  }

  node.parentNode.replaceChild(newElement, node);

}
else {

  node = ed.selection.getNode();

  with(document.getElementById(iframe_id).contentWindow){
      var newElement = document.createTextNode(node.innerHTML);
  }

  node.parentNode.replaceChild(newElement, node);
}
Thariama
Thanks Thariama.But it is giving only the text if i select a text with same tag,if i select a textwith 2 different tags it will give the html with content
THOmas
hmm, that might be because the selection does only cotain text in the first case, but in the second there are tags in between (inside the selection). does it give you the full html (full tags)?
Thariama
ya am getting the full html with the tags
THOmas
a not very nice approach could be to widen the selection to get the tags and cut it afterwards
Thariama
The tag is not a html tag i have created the tag.if i select a content with valid html tag then the whole html will coming
THOmas
so, the second tag you selected has not been an info tag, but a valid html tag? could you please edit your question and show in detail what you did and what you got
Thariama
Thariama i edited my question
THOmas
i edited my answer
Thariama
`if(c!="TITTLE")` part is working.ie if the selected text didnt have `<tittle>` tag i am adding it with `ed.selection.setContent('<tittle>' + ed.selection.getContent() + '</tittle>');`.In the else part i want to remove the '<tittle>' tag from the content and replace in the editor.
THOmas
so you want to replace it with what?
Thariama
I want to remove the `<tittle>` tag.That is content without `<tittle> </tittle>` tag
THOmas
It is just like a bold button in tinymce.When i select a text and click on the button (new button) a new tag will added in the selected text.if i again click on the button the tag will remove from the selected text.
THOmas
It showing node.parntNode is undefined
THOmas
sry, its 'parentNode' nor 'prntNode'
Thariama
if i use `parentNode` then it is showing javascript expession error
THOmas
which error occurs?
Thariama