WordPress.org

Make WordPress Core

Changeset 42037


Ignore:
Timestamp:
10/29/2017 12:14:06 AM (2 years ago)
Author:
westonruter
Message:

Customize: Support instantiation of partials with flat/unwrapped params for parity with controls, sections, and panels in [41726].

  • Passing options.params when constructing Partial is now deprecated in favor of just passing options.
  • Improve usage of jsdoc in JS Partial class.
  • Also add defaults property to wp.customize.selectiveRefresh.Partial class for parity with Control.

See #42083.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r42035 r42037  
    34023402        defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
    34033403
     3404        /**
     3405         * Default params.
     3406         *
     3407         * @since 4.9.0
     3408         * @var {object}
     3409         */
    34043410        defaults: {
    34053411            label: '',
  • trunk/src/wp-includes/js/customize-selective-refresh.js

    r41868 r42037  
    3333     * @augments wp.customize.Class
    3434     * @since 4.5.0
    35      *
    36      * @param {string} id                              Unique identifier for the control instance.
    37      * @param {object} options                         Options hash for the control instance.
    38      * @param {object} options.params
    39      * @param {string} options.params.type             Type of partial (e.g. nav_menu, widget, etc)
    40      * @param {string} options.params.selector         jQuery selector to find the container element in the page.
    41      * @param {array}  options.params.settings         The IDs for the settings the partial relates to.
    42      * @param {string} options.params.primarySetting   The ID for the primary setting the partial renders.
    43      * @param {bool}   options.params.fallbackRefresh  Whether to refresh the entire preview in case of a partial refresh failure.
    4435     */
    4536    Partial = self.Partial = api.Class.extend(/** @lends wp.customize.SelectiveRefresh.Partial.prototype */{
     
    4839
    4940        /**
     41         * Default params.
     42         *
     43         * @since 4.9.0
     44         * @var {object}
     45         */
     46        defaults: {
     47            selector: null,
     48            primarySetting: null,
     49            containerInclusive: false,
     50            fallbackRefresh: true // Note this needs to be false in a front-end editing context.
     51        },
     52
     53        /**
    5054         * Constructor.
    5155         *
    5256         * @since 4.5.0
    5357         *
    54          * @param {string} id - Partial ID.
    55          * @param {Object} options
    56          * @param {Object} options.params
     58         * @param {string} id                      - Unique identifier for the partial instance.
     59         * @param {object} options                 - Options hash for the partial instance.
     60         * @param {string} options.type            - Type of partial (e.g. nav_menu, widget, etc)
     61         * @param {string} options.selector        - jQuery selector to find the container element in the page.
     62         * @param {array}  options.settings        - The IDs for the settings the partial relates to.
     63         * @param {string} options.primarySetting  - The ID for the primary setting the partial renders.
     64         * @param {bool}   options.fallbackRefresh - Whether to refresh the entire preview in case of a partial refresh failure.
     65         * @param {object} [options.params]        - Deprecated wrapper for the above properties.
    5766         */
    5867        initialize: function( id, options ) {
     
    6372            partial.params = _.extend(
    6473                {
    65                     selector: null,
    66                     settings: [],
    67                     primarySetting: null,
    68                     containerInclusive: false,
    69                     fallbackRefresh: true // Note this needs to be false in a front-end editing context.
     74                    settings: []
    7075                },
    71                 options.params || {}
     76                partial.defaults,
     77                options.params || options
    7278            );
    7379
     
    918924            if ( ! partial ) {
    919925                Constructor = self.partialConstructor[ data.type ] || self.Partial;
    920                 partial = new Constructor( id, { params: data } );
     926                partial = new Constructor(
     927                    id,
     928                    _.extend( { params: data }, data ) // Inclusion of params alias is for back-compat for custom partials that expect to augment this property.
     929                );
    921930                self.partial.add( partial );
    922931            } else {
Note: See TracChangeset for help on using the changeset viewer.