Reputation: 5316
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
Upvotes: 16
Views: 28036
Reputation: 533
var node = tinyMCE.activeEditor.selection.getContent();
tinyMCE.execCommand('mceReplaceContent', false, %your value, can use node%");
Upvotes: 9
Reputation: 50840
try
selection.getContent({format : 'text'});
or
selection.getContent({format : 'html'});
http://www.tinymce.com/wiki.php/API3:method.tinymce.dom.Selection.getContent
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);
}
Upvotes: 19