WordPress.org

Make WordPress Core

Changeset 42038


Ignore:
Timestamp:
10/29/2017 03:07:30 AM (4 years ago)
Author:
westonruter
Message:

Customize: Fix interface alignment between Setting and Control, adding defaults to wp.customize.Setting and using wp.customize.previewer as default previewer param.

Also move jsdoc from class to initialize method and correct the param types.

Amends [41726], [42037], [32681].
See #42083, #30737.

File:
1 edited

Legend:

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

    r42037 r42038  
    349349     * @see PHP class WP_Customize_Setting.
    350350     *
     351     * @since 3.4.0
    351352     * @class
    352353     * @augments wp.customize.Value
    353354     * @augments wp.customize.Class
    354      *
    355      * @param {object} id                The Setting ID.
    356      * @param {object} value             The initial value of the setting.
    357      * @param {object} options.previewer The Previewer instance to sync with.
    358      * @param {object} options.transport The transport to use for previewing. Supports 'refresh' and 'postMessage'.
    359      * @param {object} options.dirty
    360355     */
    361356    api.Setting = api.Value.extend({
     357
     358        /**
     359         * Default params.
     360         *
     361         * @since 4.9.0
     362         * @var {object}
     363         */
     364        defaults: {
     365            transport: 'refresh',
     366            dirty: false
     367        },
     368
     369        /**
     370         * Initialize.
     371         *
     372         * @since 3.4.0
     373         *
     374         * @param {string}  id                          - The setting ID.
     375         * @param {*}       value                       - The initial value of the setting.
     376         * @param {object}  [options={}]                - Options.
     377         * @param {string}  [options.transport=refresh] - The transport to use for previewing. Supports 'refresh' and 'postMessage'.
     378         * @param {boolean} [options.dirty=false]       - Whether the setting should be considered initially dirty.
     379         * @param {object}  [options.previewer]         - The Previewer instance to sync with. Defaults to wp.customize.previewer.
     380         */
    362381        initialize: function( id, value, options ) {
    363             var setting = this;
    364             api.Value.prototype.initialize.call( setting, value, options );
     382            var setting = this, params;
     383            params = _.extend(
     384                { previewer: api.previewer },
     385                setting.defaults,
     386                options || {}
     387            );
     388
     389            api.Value.prototype.initialize.call( setting, value, params );
    365390
    366391            setting.id = id;
    367             setting.transport = setting.transport || 'refresh';
    368             setting._dirty = options.dirty || false;
     392            setting._dirty = params.dirty; // The _dirty property is what the Customizer reads from.
    369393            setting.notifications = new api.Notifications();
    370394
Note: See TracChangeset for help on using the changeset viewer.