Skip to content

Instantly share code, notes, and snippets.

@samuelsolis
Created February 3, 2016 12:50
Show Gist options
  • Save samuelsolis/dd2a8a50cb382a126e82 to your computer and use it in GitHub Desktop.
Save samuelsolis/dd2a8a50cb382a126e82 to your computer and use it in GitHub Desktop.
Custom tinyMCE buttons
(function() {
tinymce.PluginManager.add('stylebuttons', function(editor, url) {
/**
* Uppercase & bold button.
*/
editor.addButton('stylebuttons', {
text: 'Resalt',
tooltip: 'Uppercase and bold at time.',
icon: true,
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABiklEQVQ4T52TvUoDQRDHZ/ZEtMgpvoBYaBvyAOKRSuGyJkV6QUgULARbg4g+gKDGECx8A3NLIFqo5wsoYuFHIT6B6KXJmWRH9rg7jnhJxG2WnZn/b3ZmZxF6Fuc8RaQVESktpZxWbsbgHQCvpWSVev38ISrB4JDP58ddt30IAKu90MiZiLDabE5s2vZZS9k9gC++BID5AeKIS946ztSigngAzrOnQzLHcKkihLWOqmYAdtcnc8m378URpMQUZjK5CiIVYwJKQtT2/RtuA8AvCCKUkfPsKwDM9gBCcWDnPBsDoWc0Te4yxkYjgF3H+fQy27bdUbthGCNq1/VJBdmJxLpxgNAvRC1oMvXpkaua+ALA5uIChgGIuk/I+fIJAK79BwAAR2iauSRjdB8MVRQ05AaESEmvxgFPOWiqj4WwNjyAYayM6frHBQBb+MsoE+FNp9NaajQabviZFCSR+DpApEJcOT6YAKjcbn9vKXH4maJZVU80jQpElAbAGeUj6r4haleIVLUs6zEa/wMGdqGMo9K2vQAAAABJRU5ErkJggg==',
onclick: function() {
seleccion = editor.selection.getContent({format : 'html'});
if(seleccion != ""){
editor.formatter.toggle('resalted');
}else{
editor.windowManager.alert('Fist have to make a text selection.');
}
},
});
/**
* Restaltar Caracteres especiales
*/
editor.addButton('buscarsimbolos', {
text: 'Search strange symbols',
tooltip: 'Strange symbol were be put in red color.',
icon: true,
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABAklEQVQ4T7WToS+FYRSHn9+ZzSQKQZIkhahQhNv9A0iCCaawCTaKCSZI+Ad0NoVyI0WSJIGi3QnOz77tDXffru+yO2854T3vs+ec8x4x4NGA7/lXwAgwXgzfgU4v214GY8BaRMzariBI6mTmI3AOfHSDegG2I2I6M3eBt5I8EREHmfkMHDUCJF3ZvgdOa8obkhZsLzcCIuIiM1+A/RpgLyKmMnO1XwlLkrZsnwDXJbkladP2MXDbD1DdL0o6tD1fmti2vQPc1SfRq4nrQFvSpe25AniwvQJUwLMmg1HgBpgsSTMlPpX4CrS6R1k3qADDwNAPX/wL+GwC/Hk1/nUXfmXzDTffTBH1vZg6AAAAAElFTkSuQmCC',
onclick: function() {
var text = editor.getContent({format: 'raw'});
//Remove elements
if(text.indexOf('specialsymbol') >= 0) {
//We need a DOM object for replacing correctly.
$text = jQuery(text);
text = '';
$text.each(function(){
//$text is a list of dom elements. Each has to be analized.
jQuery('.specialsymbol', jQuery(this)).replaceWith(function(a) {
return jQuery(this).text();
});
//Build the new content
text += jQuery(this).prop("outerHTML");
});
//Resalt in red the special chars
}else {
text = text.replace(/[®αβδλπσςΣεημ≤≥√≠]/g, function replaceit(found) {
return '<strong style="color:red" class="specialsymbol">' + found + '</strong>';
});
}
editor.setContent(text);
},
});
/**
* Remove line breaks.
*/
editor.addButton('removebr', {
text: 'Remove brs',
tooltip: 'Remove line breaks in the current selection.',
icon: false,
image: '',
onclick: function() {
seleccion = editor.selection.getContent({format : 'html'});
seleccion = seleccion.replace(/<br \/>/g, '');
editor.selection.setContent(seleccion);
},
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment