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.

Built from https://develop.svn.wordpress.org/trunk@41958


git-svn-id: http://core.svn.wordpress.org/trunk@41792 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-10-20 21:48:46 +00:00
parent 81c87e7d5e
commit 47c555f8ed
3 changed files with 43 additions and 21 deletions

View File

@ -3341,23 +3341,6 @@
*
* @class
* @augments wp.customize.Class
*
* @param {string} id - Unique identifier for the control instance.
* @param {object} options - Options hash for the control instance.
* @param {object} options.type - Type of control (e.g. text, radio, dropdown-pages, etc.)
* @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.
* @param {string} [options.templateId] - Template ID for control's content.
* @param {string} [options.priority=10] - Order of priority to show the control within the section.
* @param {string} [options.active=true] - Whether the control is active.
* @param {string} options.section - The ID of the section the control belongs to.
* @param {mixed} [options.setting] - The ID of the main setting or an instance of this setting.
* @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.
* @param {mixed} options.settings.default - The ID of the setting the control relates to.
* @param {string} options.settings.data - @todo Is this used?
* @param {string} options.label - Label.
* @param {string} options.description - Description.
* @param {number} [options.instanceNumber] - Order in which this instance was created in relation to other instances.
* @param {object} [options.params] - Deprecated wrapper for the above properties.
*/
api.Control = api.Class.extend({
defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
@ -3369,6 +3352,27 @@
priority: 10
},
/**
* Initialize.
*
* @param {string} id - Unique identifier for the control instance.
* @param {object} options - Options hash for the control instance.
* @param {object} options.type - Type of control (e.g. text, radio, dropdown-pages, etc.)
* @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.
* @param {string} [options.templateId] - Template ID for control's content.
* @param {string} [options.priority=10] - Order of priority to show the control within the section.
* @param {string} [options.active=true] - Whether the control is active.
* @param {string} options.section - The ID of the section the control belongs to.
* @param {mixed} [options.setting] - The ID of the main setting or an instance of this setting.
* @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.
* @param {mixed} options.settings.default - The ID of the setting the control relates to.
* @param {string} options.settings.data - @todo Is this used?
* @param {string} options.label - Label.
* @param {string} options.description - Description.
* @param {number} [options.instanceNumber] - Order in which this instance was created in relation to other instances.
* @param {object} [options.params] - Deprecated wrapper for the above properties.
* @returns {void}
*/
initialize: function( id, options ) {
var control = this, deferredSettingIds = [], settings, gatherSettings;
@ -5113,6 +5117,20 @@
*/
api.CodeEditorControl = api.Control.extend({
/**
* Initialize.
*
* @since 4.9.0
* @param {string} id - Unique identifier for the control instance.
* @param {object} options - Options hash for the control instance.
* @returns {void}
*/
initialize: function( id, options ) {
var control = this;
api.Control.prototype.initialize.call( this, id, options );
control.deferred.codemirror = $.Deferred();
},
/**
* Initialize the editor when the containing section is ready and expanded.
*
@ -5272,6 +5290,8 @@
event.stopPropagation();
}
});
control.deferred.codemirror.resolveWith( control, [ control.editor.codemirror ] );
},
/**
@ -5380,6 +5400,8 @@
event.stopPropagation();
event.preventDefault();
});
control.deferred.codemirror.rejectWith( control );
}
});

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-beta3-41957';
$wp_version = '4.9-beta3-41958';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.