Make WordPress Core


Ignore:
Timestamp:
09/26/2012 03:30:21 AM (12 years ago)
Author:
azaozz
Message:

Main editor: maintain the height when switching Visual to Text and back, save the height when resizing as user state, output the height in the textarea tag when loading, (thanks @nacin for the help), fixes #21718

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-editor.php

    r21961 r22007  
    3333            'media_buttons' => true, // show insert/upload button(s)
    3434            'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
    35             'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
     35            'textarea_rows' => 20,
    3636            'tabindex' => '',
    3737            'tabfocus_elements' => ':prev,:next', // the previous and next element ID to move the focus to when pressing the Tab key in TinyMCE
     
    5353            self::$has_quicktags = true;
    5454
     55        if ( empty( $set['editor_height'] ) )
     56            return $set;
     57
     58        if ( 'content' === $editor_id ) {
     59            // A cookie (set when a user resizes the editor) overrides the height.
     60            $cookie = (int) get_user_setting( 'ed_size' );
     61
     62            // Upgrade an old TinyMCE cookie if it is still around, and the new one isn't.
     63            if ( ! $cookie && isset( $_COOKIE['TinyMCE_content_size'] ) ) {
     64                parse_str( $_COOKIE['TinyMCE_content_size'], $cookie );
     65                $cookie = $cookie['ch'];
     66            }
     67
     68            if ( $cookie )
     69                $set['editor_height'] = $cookie;
     70        }
     71
     72        if ( $set['editor_height'] < 50 )
     73            $set['editor_height'] = 50;
     74
    5575        return $set;
    5676    }
     
    6888        $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
    6989        $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
    70         $rows = ' rows="' . (int) $set['textarea_rows'] . '"';
    7190        $switch_class = 'html-active';
    7291        $toolbar = $buttons = '';
     92
     93        if ( ! empty( $set['editor_height'] ) )
     94            $height = ' style="height: ' . $set['editor_height'] . 'px"';
     95        else
     96            $height = ' rows="' . $set['textarea_rows'] . '"';
    7397
    7498        if ( !current_user_can( 'upload_files' ) )
     
    117141        }
    118142
    119         $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $rows . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
     143        $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $height . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
    120144        $content = apply_filters('the_editor_content', $content);
    121145
     
    404428            );
    405429
     430            // The main editor doesn't use the TinyMCE resizing cookie.
     431            $mceInit['theme_advanced_resizing_use_cookie'] = 'content' !== $editor_id || empty( $set['editor_height'] );
     432
    406433            if ( $first_run )
    407434                $mceInit = array_merge(self::$first_init, $mceInit);
     
    551578                echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
    552579        }
     580
     581        $mce = ( self::$has_tinymce && wp_default_editor() == 'tinymce' ) || ! self::$has_quicktags;
    553582?>
    554583
    555584    <script type="text/javascript">
     585        var wpActiveEditor;
     586
    556587        (function(){
    557             var init, ed, qt, first_init, mce = <?php echo wp_default_editor() == 'tinymce' ? 'true' : 'false'; ?>;
     588            var init, ed, qt, first_init, DOM, el, i, mce = <?php echo (int) $mce; ?>;
    558589
    559590            if ( typeof(tinymce) == 'object' ) {
     591                DOM = tinymce.DOM;
    560592                // mark wp_theme/ui.css as loaded
    561                 tinymce.DOM.files[tinymce.baseURI.getURI() + '/themes/advanced/skins/wp_theme/ui.css'] = true;
     593                DOM.files[tinymce.baseURI.getURI() + '/themes/advanced/skins/wp_theme/ui.css'] = true;
     594
     595                DOM.events.add( DOM.select('.wp-editor-wrap'), 'mousedown', function(e){
     596                    if ( this.id )
     597                        wpActiveEditor = this.id.slice(3, -5);
     598                });
    562599
    563600                for ( ed in tinyMCEPreInit.mceInit ) {
     
    571608                        try { tinymce.init(init); } catch(e){}
    572609                }
     610            } else {
     611                el = document.getElementsByClassName('wp-editor-wrap');
     612                for ( i in el ) {
     613                    if ( typeof(el[i]) == 'object' )
     614                        el[i].onmousedown = function(){ wpActiveEditor = this.id.slice(3, -5); }
     615                }
    573616            }
    574617
     
    579622            }
    580623        })();
    581 
    582         var wpActiveEditor;
    583 
    584         jQuery('.wp-editor-wrap').mousedown(function(e){
    585             wpActiveEditor = this.id.slice(3, -5);
    586         });
    587 
    588 <?php
     624        <?php
    589625
    590626        if ( self::$ext_plugins )
     
    592628
    593629        if ( ! $compressed && $tmce_on ) {
    594 ?>
    595         (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.ref.language,th=t.ref.theme,pl=t.ref.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');sl.markDone(t.base+'/themes/advanced/skins/wp_theme/ui.css');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();
    596 <?php
     630            ?>
     631            (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.ref.language,th=t.ref.theme,pl=t.ref.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');sl.markDone(t.base+'/themes/advanced/skins/wp_theme/ui.css');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();
     632            <?php
    597633        }
    598634
    599635        if ( !is_admin() )
    600636            echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
    601 ?>
    602     </script>
    603 <?php
     637
     638        ?>
     639        </script>
     640        <?php
    604641
    605642        if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) )
Note: See TracChangeset for help on using the changeset viewer.