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
The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.
To save the page, you have to insert TinyMCE in a HTML form and add a submit button. Then you'll have to handle the submitted form with a language like PHP. A call to the file_put_contents() function should do it.
You can use the activeEditor for that, or if (for some reason) you have the original element that created the editor in a jQuery object, you can use that jQuery object to get the id of the original element and use that in order to get the content of the TinyMCE (using the TinyMCE editor).
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With