I just need some help in creating filters for tinyMCE editor
Published by drupal on February 11th, 2009 in Drupal Modules
hey,
I just need some help in creating filters for tinyMCE editor, because in mozilla when we paste some content in textarea from MS Word it adds some tags, words and styles.
I just wanna create a filter which will remove all these from content.
drupal_developer on February 11th 2009
U just need to do simple two step.
1) Just paste the below code in your theme template file.
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko')) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape')) {
$browser = 'Netscape (Gecko/Netscape)';
} else
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
$browser = 'Mozilla Firefox (Gecko/Firefox)';
} else {
$browser = 'Mozilla (Gecko/Mozilla)';
}
}
else {
$browser = 'Others browsers';
}
/* Example, add some extra features when using the advanced theme.*/
// If $init is available, we can extend it
if (isset ($init)) {
if ($browser != 'Others browsers') {
if (!in_array("paste", $init['plugins'])) {
array_push($init['plugins'], "paste");
}
$init['paste_auto_cleanup_on_paste'] = true;
//$init['paste_insert_word_content_callback'] = "convertWord";
}
}
// Always return $init
return $init;
}
2) And in sites\all\modules\tinymce\tinymce\jscripts\tiny_mce\plugins\paste\editor_plugin.js file search this block of code
if (!tinymce.isIE && ed.getParam("paste_auto_cleanup_on_paste", false)) {
// Force paste dialog if non IE browser
ed.onKeyDown.add(function(ed, e) {
if (e.ctrlKey && e.keyCode == 86) { window.setTimeout(function() { ed.execCommand("mcePasteText", true);
}, 1);
Event.cancel(e);
}
});
}
And change ed.execCommand ("mcePasteText", true); to ed.execCommand ("mcePasteWord", true);
To make PASTE FROM WORD option as default that will take care of all these extra words,styles.
Hope this would solve your problem. :)