WordPress.org

Make WordPress Core

Changeset 41957


Ignore:
Timestamp:
10/20/2017 04:38:35 PM (9 months ago)
Author:
westonruter
Message:

Code Editor: Improve ability to create Customizer CodeEditorControl instances in JS, lessening PHP dependencies.

Allow CodeEditorControl to be instantiated with a editor_settings param which is merged with wp.codeEditor.defaultSettings.

Also:

  • Turn redundant "CSS Code" control label into screen reader text for Additional CSS.
  • Remove code-editor as script dependency for custom-html-widgets since enqueueing is determined by wp_enqueue_code_editor().
  • Remove useless exporting of code_type param to JS in WP_Customize_Code_Editor_Control.
  • Add disabled class to Custom HTML widget's Save button when linting errors are present.
  • Remove redundant span inside CodeEditorControl's label.

See #41897, #12423, #41872.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r41952 r41957  
    51535153         */
    51545154        initEditor: function() {
    5155             var control = this, element;
     5155            var control = this, element, editorSettings = false;
     5156
     5157            // Obtain editorSettings for instantiation.
     5158            if ( wp.codeEditor && ( _.isUndefined( control.params.editor_settings ) || false !== control.params.editor_settings ) ) {
     5159
     5160                // Obtain default editor settings.
     5161                editorSettings = wp.codeEditor.defaultSettings ? _.clone( wp.codeEditor.defaultSettings ) : {};
     5162                editorSettings.codemirror = _.extend(
     5163                    {},
     5164                    editorSettings.codemirror,
     5165                    {
     5166                        indentUnit: 2,
     5167                        tabSize: 2
     5168                    }
     5169                );
     5170
     5171                // Merge editor_settings param on top of defaults.
     5172                if ( _.isObject( control.params.editor_settings ) ) {
     5173                    _.each( control.params.editor_settings, function( value, key ) {
     5174                        if ( _.isObject( value ) ) {
     5175                            editorSettings[ key ] = _.extend(
     5176                                {},
     5177                                editorSettings[ key ],
     5178                                value
     5179                            );
     5180                        }
     5181                    } );
     5182                }
     5183            }
    51565184
    51575185            element = new api.Element( control.container.find( 'textarea' ) );
     
    51605188            element.set( control.setting() );
    51615189
    5162             if ( control.params.editor_settings ) {
    5163                 control.initSyntaxHighlightingEditor( control.params.editor_settings );
     5190            if ( editorSettings ) {
     5191                control.initSyntaxHighlightingEditor( editorSettings );
    51645192            } else {
    51655193                control.initPlainTextareaEditor();
     
    88408868                var control = api.control( 'custom_css' );
    88418869
     8870                // Hide redundant label for visual users.
     8871                control.container.find( '.customize-control-title:first' ).addClass( 'screen-reader-text' );
     8872
    88428873                // Close the section description when clicking the close button.
    88438874                section.container.find( '.section-description-buttons .section-description-close' ).on( 'click', function() {
  • trunk/src/wp-admin/js/widgets/custom-html-widgets.js

    r41586 r41957  
    205205                 */
    206206                onUpdateErrorNotice: function onUpdateErrorNotice( errorAnnotations ) {
    207                     control.saveButton.toggleClass( 'validation-blocked', errorAnnotations.length );
     207                    control.saveButton.toggleClass( 'validation-blocked disabled', errorAnnotations.length );
    208208                    control.updateErrorNotice( errorAnnotations );
    209209                }
  • trunk/src/wp-includes/customize/class-wp-customize-code-editor-control.php

    r41586 r41957  
    7070    public function json() {
    7171        $json = parent::json();
    72         $json['code_type'] = $this->code_type;
    7372        $json['editor_settings'] = $this->editor_settings;
    7473        $json['input_attrs'] = $this->input_attrs;
     
    9291        <# var elementIdPrefix = 'el' + String( Math.random() ); #>
    9392        <# if ( data.label ) { #>
    94             <label for="{{ elementIdPrefix }}_editor">
    95                 <span class="customize-control-title">{{ data.label }}</span>
     93            <label for="{{ elementIdPrefix }}_editor" class="customize-control-title">
     94                {{ data.label }}
    9695            </label>
    9796        <# } #>
  • trunk/src/wp-includes/script-loader.php

    r41905 r41957  
    721721        $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo', 'wp-api-request' ) );
    722722        $scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'backbone', 'editor', 'wp-util', 'wp-a11y' ) );
    723         $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'code-editor', 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) );
     723        $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) );
    724724
    725725        $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y', 'customize-base' ), false, 1 );
  • trunk/tests/phpunit/tests/widgets/custom-html-widget.php

    r41858 r41957  
    264264
    265265        $this->assertTrue( wp_script_is( 'custom-html-widgets', 'enqueued' ) );
    266         $this->assertTrue( wp_script_is( 'code-editor', 'enqueued' ) );
    267         $this->assertTrue( wp_script_is( 'wp-codemirror', 'enqueued' ) );
     266        $this->assertFalse( wp_script_is( 'code-editor', 'enqueued' ) );
     267        $this->assertFalse( wp_script_is( 'wp-codemirror', 'enqueued' ) );
    268268        $this->assertFalse( wp_script_is( 'csslint', 'enqueued' ) );
    269269        $this->assertFalse( wp_script_is( 'jshint', 'enqueued' ) );
Note: See TracChangeset for help on using the changeset viewer.