1

Topic: Removing "Paragraph" as the default formatting sel

This is an awesome tool, integration was a breeze.

I have one usability tip though as far as using the format blocks.  Since the formatting defaults to "paragraph" and the required action to set the formatting is "onChange" it gets a bit frustrating to have to set the selected text to something else and then back to "paragraph" so that you can set it to "paragraph".

To get around this i made the following changes.

File: editor_template.js

I changed

    // Select formatblock
    var selectElm = document.getElementById(editor_id + "_formatSelect");
    if (selectElm) {
        var elm = tinyMCE.getParentElement(node, "p,div,h1,h2,h3,h4,h5,h6,pre,address");
        if (elm) {
            selectByValue(selectElm, "<" + elm.nodeName.toLowerCase() + ">");
        } else
            selectByValue(selectElm, "<p>");
    }

to...

    // Select formatblock
    var selectElm = document.getElementById(editor_id + "_formatSelect");
    if (selectElm) {
        var elm = tinyMCE.getParentElement(node, "p,div,h1,h2,h3,h4,h5,h6,pre,address");
        if (elm) {
            selectByValue(selectElm, "<" + elm.nodeName.toLowerCase() + ">");
        } else
            selectByValue(selectElm, "<->");
    }

this is to prevent it from selecting the paragraph element by default.

I then created a place holder for our new bastardized "<->" tag in by replacing the following code (in the same file)

        case "formatselect":
            var html = '<select id="{$editor_id}_formatSelect" name="{$editor_id}_formatSelect" onchange="tinyMCE.execInstanceCommand('{$editor_id}','FormatBlock',false,this.options[this.selectedIndex].value);" class="mceSelectList">';
            var formats = tinyMCE.getParam("theme_advanced_blockformats", "address,pre,p,h1,h2,h3,h4,h5,h6", true).split(',');
            var lookup = [
                ['address', '{$lang_theme_address}'],
            ['p', '{$lang_theme_paragraph}'],
                ['pre', '{$lang_theme_pre}'],
                ['h1', '{$lang_theme_h1}'],
                ['h2', '{$lang_theme_h2}'],
                ['h3', '{$lang_theme_h3}'],
                ['h4', '{$lang_theme_h4}'],
                ['h5', '{$lang_theme_h5}'],
                ['h6', '{$lang_theme_h6}']
            ];

with

        case "formatselect":
            var html = '<select id="{$editor_id}_formatSelect" name="{$editor_id}_formatSelect" onchange="tinyMCE.execInstanceCommand('{$editor_id}','FormatBlock',false,this.options[this.selectedIndex].value);" class="mceSelectList">';
            var formats = tinyMCE.getParam("theme_advanced_blockformats", "-,address,pre,p,h1,h2,h3,h4,h5,h6", true).split(',');
            var lookup = [
            ['-','--Select'],
                ['address', '{$lang_theme_address}'],
            ['p', '{$lang_theme_paragraph}'],
                ['pre', '{$lang_theme_pre}'],
                ['h1', '{$lang_theme_h1}'],
                ['h2', '{$lang_theme_h2}'],
                ['h3', '{$lang_theme_h3}'],
                ['h4', '{$lang_theme_h4}'],
                ['h5', '{$lang_theme_h5}'],
                ['h6', '{$lang_theme_h6}']
            ];

This is sweet cuz since the execCommand method doesn't recognize the <-> as a valid FormatBlock tag, it will actually remove any formatting on the block of text as well.

So now instead of defaulting to "Paragraph" it shows "--Select" or whatever you define for your string.  I didn't bother adding it to the language file or anything, partly cuz i don't plan to use any other languages, but mostly cuz i'm lazy smile.

2

Re: Removing "Paragraph" as the default formatting sel

This is a great idea and have the same problem myself, but I cannot get the example above to work with advancedblockformats ... it still always defaults to 'paragraph' and selecting '--Select' results in the select list jumping back to 'paragraph automatically.

I have these set in my init as I would only like to offer the option of p, h1 or h2:
theme_advanced_blockformats : "-,p,h1,h2",

Any help would be very much appreciated.

theUKdude