Problems, need help? Have a tip or advice? Post it here.
17 posts Page 2 of 2
KK wrote: I suppose that is what your original query was.

Unfortunately not. I need both modes.
There a two scenarios:

1. A editor put content in a place, where no block elements are allowed:
Code: Select all
<h1><cms:show headline/></h1>
<p><cms:show text/></p>

A editor should only allowed to set attributes like <b>, <i> or set a <br> or link <a>.


2. A editor put content in a place, where block elements are allowed:
Code: Select all
<div class="rte"><cms:show text/></div>

A editor write paragraphs, unordered lists, headline and more. And he can set attributes like <b>, <i> or set a <br> or link <a>.

Most editors are not familiar with the difference between a paragraph and a line break. They will forget, in which case they have to press return or shift return. My solution was using nicedit for inline input and ckeditor for the rest. Nicedit is deprecated (and broken in newer browser) and richtext has no parameter for a config.js.

At the moment I have no solution to solve that problem.
How hard is it to attach a new ckeditor instance to an editable textarea with desired setting?
trendoman wrote: How hard is it to attach a new ckeditor instance to an editable textarea with desired setting?

Suggestion
I think, we could easily add the two parameter enterMode and shiftEnterMode to the function
https://github.com/CouchCMS/CouchCMS/blob/master/couch/field.php#L585
@SimonWpt, the two scenarios you posted made your dilemma clearer to me.

I have made some changes to fields.php - please get it from the latest commit on GitHub.
Next place the following in your addons/kfunctions.php -
Code: Select all
$FUNCS->add_event_listener( 'ckeditor_alter_config', function(&$config, $f){
    $classes = explode( ' ', $f->class );
    if( count($classes) ){
        $arr_enter = array( 'ck-enter-p'=>'CKEDITOR.ENTER_P',  'ck-enter-br'=>'CKEDITOR.ENTER_BR', 'ck-enter-div'=>'CKEDITOR.ENTER_DIV' );
        $arr_shift_enter = array( 'ck-shiftenter-p'=>'CKEDITOR.ENTER_P',  'ck-shiftenter-br'=>'CKEDITOR.ENTER_BR', 'ck-shiftenter-div'=>'CKEDITOR.ENTER_DIV' );

        foreach( $classes as $class ){
            if( array_key_exists($class, $arr_enter) ){
                $config['enterMode'] = $arr_enter[$class];
            }

            if( array_key_exists($class, $arr_shift_enter) ){
                $config['shiftEnterMode'] = $arr_shift_enter[$class];
            }
        }
    }
});

And now for the richtext region that you wish to use BR when enter is hit, amend its definition to add a class as follows -
Code: Select all
<cms:editable type='richtext' name='page_summary' label='Page Summary' class='ck-enter-br' />

Make sure to visit the modified template as super-admin for the change to be picked up by Couch.
And now you should get the desired behavior with that particular richtext editor.

For documentation sake -
To modify the behavior of a richtext (CKEditor) field with regards to the enter key, one can use one of the three classes below -
ck-enter-p // Default. Creates a new <p>
ck-enter-br // Breaks the line with <br>
ck-enter-div // Creates a new <div>

To modify how the field reacts to shift-enter combination, one can use one of the following classes -
ck-shiftenter-p //Creates a new <p>
ck-shiftenter-br // Default. Breaks the line with <br>
ck-shiftenter-div // Creates a new <div>

Hope this helps.
Do let me know.
KK wrote: Hope this helps. Do let me know.

Yes, it works and brings the perfect solution in combination with the custom_toolbar.

Thank you very much!
You are welcome. I am glad it helped.
17 posts Page 2 of 2
cron