Make WordPress Core

Changeset 41958


Ignore:
Timestamp:
10/20/2017 09:47:13 PM (8 years ago)
Author:
westonruter
Message:

Customize: Add codemirror deferred object to CodeEditorControl which is resolved when CodeMirror is initialized.

CodeMirror gets initialized once the control's containing section is expanded. The deferred will be rejected if user preference for syntax highlighting is disabled.
Also move jsdoc from wp.customize.Control to intended wp.customize.Control#initialize().

See #41897, #12423.

File:
1 edited

Legend:

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

    r41957 r41958  
    33423342     * @class
    33433343     * @augments wp.customize.Class
    3344      *
    3345      * @param {string} id                       - Unique identifier for the control instance.
    3346      * @param {object} options                  - Options hash for the control instance.
    3347      * @param {object} options.type             - Type of control (e.g. text, radio, dropdown-pages, etc.)
    3348      * @param {string} [options.content]        - The HTML content for the control or at least its container. This should normally be left blank and instead supplying a templateId.
    3349      * @param {string} [options.templateId]     - Template ID for control's content.
    3350      * @param {string} [options.priority=10]    - Order of priority to show the control within the section.
    3351      * @param {string} [options.active=true]    - Whether the control is active.
    3352      * @param {string} options.section          - The ID of the section the control belongs to.
    3353      * @param {mixed}  [options.setting]        - The ID of the main setting or an instance of this setting.
    3354      * @param {mixed}  options.settings         - An object with keys (e.g. default) that maps to setting IDs or Setting/Value objects, or an array of setting IDs or Setting/Value objects.
    3355      * @param {mixed}  options.settings.default - The ID of the setting the control relates to.
    3356      * @param {string} options.settings.data    - @todo Is this used?
    3357      * @param {string} options.label            - Label.
    3358      * @param {string} options.description      - Description.
    3359      * @param {number} [options.instanceNumber] - Order in which this instance was created in relation to other instances.
    3360      * @param {object} [options.params]         - Deprecated wrapper for the above properties.
    33613344     */
    33623345    api.Control = api.Class.extend({
     
    33703353        },
    33713354
     3355        /**
     3356         * Initialize.
     3357         *
     3358         * @param {string} id                       - Unique identifier for the control instance.
     3359         * @param {object} options                  - Options hash for the control instance.
     3360         * @param {object} options.type             - Type of control (e.g. text, radio, dropdown-pages, etc.)
     3361         * @param {string} [options.content]        - The HTML content for the control or at least its container. This should normally be left blank and instead supplying a templateId.
     3362         * @param {string} [options.templateId]     - Template ID for control's content.
     3363         * @param {string} [options.priority=10]    - Order of priority to show the control within the section.
     3364         * @param {string} [options.active=true]    - Whether the control is active.
     3365         * @param {string} options.section          - The ID of the section the control belongs to.
     3366         * @param {mixed}  [options.setting]        - The ID of the main setting or an instance of this setting.
     3367         * @param {mixed}  options.settings         - An object with keys (e.g. default) that maps to setting IDs or Setting/Value objects, or an array of setting IDs or Setting/Value objects.
     3368         * @param {mixed}  options.settings.default - The ID of the setting the control relates to.
     3369         * @param {string} options.settings.data    - @todo Is this used?
     3370         * @param {string} options.label            - Label.
     3371         * @param {string} options.description      - Description.
     3372         * @param {number} [options.instanceNumber] - Order in which this instance was created in relation to other instances.
     3373         * @param {object} [options.params]         - Deprecated wrapper for the above properties.
     3374         * @returns {void}
     3375         */
    33723376        initialize: function( id, options ) {
    33733377            var control = this, deferredSettingIds = [], settings, gatherSettings;
     
    51155119
    51165120        /**
     5121         * Initialize.
     5122         *
     5123         * @since 4.9.0
     5124         * @param {string} id      - Unique identifier for the control instance.
     5125         * @param {object} options - Options hash for the control instance.
     5126         * @returns {void}
     5127         */
     5128        initialize: function( id, options ) {
     5129            var control = this;
     5130            api.Control.prototype.initialize.call( this, id, options );
     5131            control.deferred.codemirror = $.Deferred();
     5132        },
     5133
     5134        /**
    51175135         * Initialize the editor when the containing section is ready and expanded.
    51185136         *
     
    52735291                }
    52745292            });
     5293
     5294            control.deferred.codemirror.resolveWith( control, [ control.editor.codemirror ] );
    52755295        },
    52765296
     
    53815401                event.preventDefault();
    53825402            });
     5403
     5404            control.deferred.codemirror.rejectWith( control );
    53835405        }
    53845406    });
Note: See TracChangeset for help on using the changeset viewer.