In an effort to reduce clutter on the average user's node creation form, I wanted to hide the formatting tips when TinyMCE was active. There's little reason for them to see Web page addresses and e-mail addresses turn into links automatically. etc. when they have a nice wysiwyg running already. Turning the editor off, however, should bring the tips back.
This is a two-step process. The first is to add use hook_form_alter to wrap the whole formatting section in a classed div.
function tinymce_form_alter($form_id, &$form) {
if (isset($form['type']) && $form_id == $form['type']['#value'] .'_node_form') {
// give the formatting tips a div so tinymce can affect them
if (is_array($form['body_filter']['format'])) {
$form['body_filter']['format']['#prefix'] = '<div class="formatting-tips">';
$form['body_filter']['format']['#suffix'] = '</div>';
}
}
}
The next part requires a few alterations to the tinymce_process_textarea function in tinymce.module. Change $tinymce_invoke to :
$tinymce_invoke = <<<EOD
tinyMCE.init({
$tinymce_settings
});
// hide the formatting tips when TinyMCE loads
$(document).ready(function(){
$(".formatting-tips").hide();
});
EOD;
Change $js_toggle to:
$js_toggle = <<<EOD
function mceToggle(id, linkid) {
element = document.getElementById(id);
link = document.getElementById(linkid);
img_assist = document.getElementById('img_assist-link-'+ id);
if (tinyMCE.get(element.id) == null) {
tinyMCE.execCommand('mceAddControl',false, element.id);
element.togg = 'on';
link.innerHTML = '$disable';
link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";
if (img_assist)
img_assist.innerHTML = '';
link.blur();
//hide the formatting tips while TinyMCE is on
$(".formatting-tips").hide();
}
else {
tinyMCE.execCommand('mceRemoveControl',false,element.id);
element.togg = 'off';
link.innerHTML = '$enable';
link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";
if (img_assist)
img_assist.innerHTML = img_assist_default_link;
link.blur();
//show the formatting tips while TinyMCE is off
$(".formatting-tips").show();
}
}
EOD;
I grant a patch file would be better than all that pasted code. I will try to attach one later.
This method will only work if the user editing/creating the node only has access to one input format.
Comment | File | Size | Author |
---|---|---|---|
#2 | tinymce_tips.patch | 2.46 KB | chaldar |
Comments
Comment #1
pow CreditAttribution: pow commentedGreat!!!
Thank you :)
Comment #2
chaldar CreditAttribution: chaldar commentedThe form_alter piece looks good to me. I was trying to address the same problem by enclosing the formatting tips in a collapsible fieldset which is collapsed by default, but this is a much cleaner and intuitive solution.
I can't review the js code changes.
All the changes work for me as described. I tested with the latest tineMCE 3.2 release. Everything seems to work as described.
I made a patch combining all the 3 changes and tested with that. Works as expected. See attached. Patch is relative to the tinymce module directory.
Comment #3
Mupsi