Make WordPress Core

Ticket #30737: 30737.addendum.diff

File 30737.addendum.diff, 9.0 KB (added by westonruter, 10 years ago)

Additional changes: https://github.com/xwp/wordpress-develop/compare/8dfa3d5...d37d805 PR: https://github.com/xwp/wordpress-develop/pull/90

  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 2d7f3ba..5f9fbe6 100644
     
    165165                 * @param {Object} options
    166166                 */
    167167                initialize: function ( id, options ) {
    168                         var container = this;
     168                        var container = this, defaultParams;
    169169                        container.id = id;
    170                         container.params = {};
    171                         $.extend( container, options || {} );
     170                        options = options || {};
     171                        defaultParams = {
     172                                title: '',
     173                                description: '',
     174                                priority: 100,
     175                                type: 'default',
     176                                content: null,
     177                                active: true,
     178                                instanceNumber: null
     179                        };
     180                        if ( 'section' === container.containerType ) {
     181                                $.extend( defaultParams, {
     182                                        panel: null,
     183                                        customizeAction: ''
     184                                });
     185                        }
     186                        options.params = $.extend(
     187                                defaultParams,
     188                                options.params || {}
     189                        );
     190                        $.extend( container, options );
    172191                        container.templateSelector = 'customize-' + container.containerType + '-' + container.params.type;
    173192                        container.container = $( container.params.content );
    174193                        if ( 0 === container.container.length ) {
     
    202221
    203222                        api.utils.bubbleChildValueChanges( container, [ 'priority', 'active' ] );
    204223
    205                         container.priority.set( isNaN( container.params.priority ) ? 100 : container.params.priority );
     224                        container.priority.set( container.params.priority );
    206225                        container.active.set( container.params.active );
    207226                        container.expanded.set( false );
    208227                },
     
    386405
    387406                        if ( 0 !== $( '#tmpl-' + container.templateSelector ).length ) {
    388407                                template = wp.template( container.templateSelector );
    389                                 if ( template && container.container ) {
    390                                         return $.trim( template( container.params ) );
    391                                 }
     408                        } else {
     409                                template = wp.template( 'customize-' + container.containerType + '-default' );
     410                        }
     411                        if ( template && container.container ) {
     412                                return $.trim( template( container.params ) );
    392413                        }
    393414
    394415                        return '<li></li>';
     
    407428                /**
    408429                 * @since 4.1.0
    409430                 *
    410                  * @param {String} id
    411                  * @param {Array}  options
     431                 * @param {string}         id - The ID for the section.
     432                 * @param {object}         options - Object containing one property: params.
     433                 * @param {object}         options.params - Object containing the following properties.
     434                 * @param {string}         options.params.title - Title shown when section is collapsed and expanded.
     435                 * @param {string=}        [options.params.description] - Description shown at the top of the section.
     436                 * @param {number=100}     [options.params.priority] - The sort priority for the section.
     437                 * @param {string=default} [options.params.type] - The type of the section. See wp.customize.sectionConstructor.
     438                 * @param {string=}        [options.params.content] - The markup to be used for the section container. If empty, a JS template is used.
     439                 * @param {boolean=true}   [options.params.active] - Whether the section is active or not.
     440                 * @param {string}         options.params.panel - The ID for the panel this section is associated with.
     441                 * @param {string=}        [options.params.customizeAction] - Additional context information shown before the section title when expanded.
    412442                 */
    413443                initialize: function ( id, options ) {
    414444                        var section = this;
     
    10091039                /**
    10101040                 * @since 4.1.0
    10111041                 *
    1012                  * @param  {String} id
    1013                  * @param  {Object} options
     1042                 * @param {string}         id - The ID for the panel.
     1043                 * @param {object}         options - Object containing one property: params.
     1044                 * @param {object}         options.params - Object containing the following properties.
     1045                 * @param {string}         options.params.title - Title shown when panel is collapsed and expanded.
     1046                 * @param {string=}        [options.params.description] - Description shown at the top of the panel.
     1047                 * @param {number=100}     [options.params.priority] - The sort priority for the panel.
     1048                 * @param {string=default} [options.params.type] - The type of the panel. See wp.customize.panelConstructor.
     1049                 * @param {string=}        [options.params.content] - The markup to be used for the panel container. If empty, a JS template is used.
     1050                 * @param {boolean=true}   [options.params.active] - Whether the panel is active or not.
    10141051                 */
    10151052                initialize: function ( id, options ) {
    10161053                        var panel = this;
     
    12161253                        // Add the content to the container.
    12171254                        if ( 0 !== $( '#tmpl-' + panel.templateSelector + '-content' ).length ) {
    12181255                                template = wp.template( panel.templateSelector + '-content' );
    1219                                 if ( template && panel.container ) {
    1220                                         panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) );
    1221                                 }
     1256                        } else {
     1257                                template = wp.template( 'customize-panel-default-content' );
     1258                        }
     1259                        if ( template && panel.container ) {
     1260                                panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) );
    12221261                        }
    12231262                }
    12241263        });
  • tests/qunit/fixtures/customize-settings.js

    diff --git tests/qunit/fixtures/customize-settings.js tests/qunit/fixtures/customize-settings.js
    index 5ef44a1..bc92c4c 100644
    window._wpCustomizeSettings = { 
    5757                        'priority': 110,
    5858                        'title': 'Fixture titleless panel using template',
    5959                        'type': 'titleless'
    60                 }
     60                },
     61                'fixture-panel-reusing-default-template': {
     62                        'active': true,
     63                        'description': 'Lorem ipsum',
     64                        'instanceNumber': 3,
     65                        'priority': 110,
     66                        'title': 'Fixture panel of custom type re-using default template',
     67                        'type': 'reusing-default-template'
     68                },
     69                'fixture-panel-without-params': {}
    6170        },
    6271        'sections': {
    6372                'fixture-section': {
    window._wpCustomizeSettings = { 
    8796                        'priority': 20,
    8897                        'title': 'Fixture titleless section using template',
    8998                        'type': 'titleless'
    90                 }
     99                },
     100                'fixture-section-reusing-default-template': {
     101                        'active': true,
     102                        'description': '',
     103                        'instanceNumber': 4,
     104                        'panel': 'fixture-panel',
     105                        'priority': 20,
     106                        'title': 'Fixture section of custom type re-using default template',
     107                        'type': 'reusing-default-template'
     108                },
     109                'fixture-section-without-params': {}
    91110        },
    92111        'settings': {
    93112                'fixture-setting': {
  • tests/qunit/wp-admin/js/customize-controls.js

    diff --git tests/qunit/wp-admin/js/customize-controls.js tests/qunit/wp-admin/js/customize-controls.js
    index 215d468..6ca4908 100644
    jQuery( window ).load( function (){ 
    136136                ok( 0 === section.container.find( '> .accordion-section-title' ).length );
    137137                ok( 1 === section.container.find( '> .accordion-section-content' ).length );
    138138        } );
     139        module( 'Customizer Custom Type Section Lacking Specific Template' );
     140        test( 'Fixture section has expected content', function () {
     141                var id = 'fixture-section-reusing-default-template', section;
     142                section = wp.customize.section( id );
     143                ok( ! section.params.content );
     144                ok( !! section.container );
     145                ok( section.container.is( '.control-section.control-section-' + section.params.type ) );
     146                ok( 1 === section.container.find( '> .accordion-section-title' ).length );
     147                ok( 1 === section.container.find( '> .accordion-section-content' ).length );
     148        } );
     149        module( 'Customizer Section lacking any params' );
     150        test( 'Fixture section has default params supplied', function () {
     151                var id = 'fixture-section-without-params', section, defaultParams;
     152                section = wp.customize.section( id );
     153                defaultParams = {
     154                        title: '',
     155                        description: '',
     156                        priority: 100,
     157                        panel: null,
     158                        type: 'default',
     159                        content: null,
     160                        active: true,
     161                        instanceNumber: null,
     162                        customizeAction: ''
     163                };
     164                jQuery.each( defaultParams, function ( key, value ) {
     165                        ok( 'undefined' !== typeof section.params[ key ] );
     166                        equal( value, section.params[ key ] );
     167                } );
     168        } );
     169
    139170
    140171        // Begin panels.
    141172        module( 'Customizer Panel in Fixture' );
    jQuery( window ).load( function (){ 
    199230                ok( 1 === panel.container.find( '> .control-panel-content' ).length );
    200231        } );
    201232
     233        module( 'Customizer Custom Type Panel Lacking Specific Template' );
     234        test( 'Fixture panel has expected content', function () {
     235                var id = 'fixture-panel-reusing-default-template', panel;
     236                panel = wp.customize.panel( id );
     237                ok( ! panel.params.content );
     238                ok( !! panel.container );
     239                ok( panel.container.is( '.control-panel.control-panel-' + panel.params.type ) );
     240                ok( 1 === panel.container.find( '> .accordion-section-title' ).length );
     241                ok( 1 === panel.container.find( '> .control-panel-content' ).length );
     242        } );
     243        module( 'Customizer Panel lacking any params' );
     244        test( 'Fixture panel has default params supplied', function () {
     245                var id = 'fixture-panel-without-params', panel, defaultParams;
     246                panel = wp.customize.panel( id );
     247                defaultParams = {
     248                        title: '',
     249                        description: '',
     250                        priority: 100,
     251                        type: 'default',
     252                        content: null,
     253                        active: true,
     254                        instanceNumber: null
     255                };
     256                jQuery.each( defaultParams, function ( key, value ) {
     257                        ok( 'undefined' !== typeof panel.params[ key ] );
     258                        equal( value, panel.params[ key ] );
     259                } );
     260        } );
    202261
    203262        module( 'Dynamically-created Customizer Setting Model' );
    204263        settingId = 'new_blogname';