Make WordPress Core

Ticket #42954: customize-preview-widget-documentation.diff

File customize-preview-widget-documentation.diff, 12.2 KB (added by ireneyoast, 7 years ago)
  • src/wp-includes/js/customize-preview-widgets.js

    diff --git src/wp-includes/js/customize-preview-widgets.js src/wp-includes/js/customize-preview-widgets.js
    index 31f5aface7..17f565d557 100644
     
    11/* global _wpWidgetCustomizerPreviewSettings */
    22
    3 /** @namespace wp.customize.widgetsPreview */
     3/**
     4 * Handles the initialization, refreshing and rendering of widget partials and sidebar widgets.
     5 *
     6 * @since 4.5.0
     7 *
     8 * @namespace wp.customize.widgetsPreview
     9 *
     10 * @param {jQuery} $   The jQuery object.
     11 * @param {Object} _   The utilities library.
     12 * @param {Object} wp  Current WordPress environment instance.
     13 * @param {Object} api Information from the API.
     14 *
     15 * @returns {Object} Widget-related variables.
     16 */
    417wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( $, _, wp, api ) {
    518
    619        var self;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    1932        };
    2033
    2134        /**
    22          * Init widgets preview.
     35         * Initializes the widgets preview.
    2336         *
    2437         * @since 4.5.0
     38         *
     39         * @returns {void}
    2540         */
    2641        self.init = function() {
    2742                var self = this;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    6782         *
    6883         * @class
    6984         * @augments wp.customize.selectiveRefresh.Partial
     85         *
    7086         * @since 4.5.0
    7187         */
    7288        self.WidgetPartial = api.selectiveRefresh.Partial.extend(/** @lends wp.customize.widgetsPreview.WidgetPartial.prototype */{
    7389
    7490                /**
    75                  * Constructor.
     91                 * Initializes the widget partial.
    7692                 *
    7793                 * @since 4.5.0
    78                  * @param {string} id - Partial ID.
    79                  * @param {Object} options
    80                  * @param {Object} options.params
     94                 *
     95                 * @param {string} id             The partial's ID.
     96                 * @param {Object} options        Options used to initialize the partial's instance.
     97                 * @param {Object} options.params The options parameters.
     98                 *
     99                 * @returns {void}
    81100                 */
    82101                initialize: function( id, options ) {
    83102                        var partial = this, matches;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    101120                },
    102121
    103122                /**
    104                  * Refresh widget partial.
     123                 * Refreshes the widget partial.
    105124                 *
    106                  * @returns {Promise}
     125                 * @since 4.5.0
     126                 *
     127                 * @returns {Promise|void} Either a promise postponing the refresh, or void.
    107128                 */
    108129                refresh: function() {
    109130                        var partial = this, refreshDeferred;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    118139                },
    119140
    120141                /**
    121                  * Send widget-updated message to parent so spinner will get removed from widget control.
     142                 * Sends the widget-updated message to the parent so the spinner will get removed from the widget control.
     143                 *
     144                 * @inheritDoc
     145                 * @param {wp.customize.selectiveRefresh.Placement} placement The placement function.
    122146                 *
    123                  * @inheritdoc
    124                  * @param {wp.customize.selectiveRefresh.Placement} placement
     147                 * @returns {void}
    125148                 */
    126149                renderContent: function( placement ) {
    127150                        var partial = this;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    145168        self.SidebarPartial = api.selectiveRefresh.Partial.extend(/** @lends wp.customize.widgetsPreview.SidebarPartial.prototype */{
    146169
    147170                /**
    148                  * Constructor.
     171                 * Initializes the sidebar partial.
    149172                 *
    150173                 * @since 4.5.0
    151                  * @param {string} id - Partial ID.
    152                  * @param {Object} options
    153                  * @param {Object} options.params
     174                 *
     175                 * @param {string} id             The partial's ID.
     176                 * @param {Object} options        Options used to initialize the partial's instance.
     177                 * @param {Object} options.params The options parameters.
     178                 *
     179                 * @returns {void}
    154180                 */
    155181                initialize: function( id, options ) {
    156182                        var partial = this, matches;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    179205                },
    180206
    181207                /**
    182                  * Set up the partial.
     208                 * Sets up the partial.
    183209                 *
    184210                 * @since 4.5.0
     211                 *
     212                 * @returns {void}
    185213                 */
    186214                ready: function() {
    187215                        var sidebarPartial = this;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    220248                },
    221249
    222250                /**
    223                  * Get the before/after boundary nodes for all instances of this sidebar (usually one).
     251                 * Gets the before/after boundary nodes for all instances of this sidebar (usually one).
    224252                 *
    225253                 * Note that TreeWalker is not implemented in IE8.
    226254                 *
    227255                 * @since 4.5.0
    228                  * @returns {Array.<{before: Comment, after: Comment, instanceNumber: number}>}
     256                 *
     257                 * @returns {Array.<{before: Comment, after: Comment, instanceNumber: number}>} An array with an object
     258                 * for each sidebar instance, containing the node before and after the sidebar instance and its instance
     259                 * number.
    229260                 */
    230261                findDynamicSidebarBoundaryNodes: function() {
    231262                        var partial = this, regExp, boundaryNodes = {}, recursiveCommentTraversal;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    261292                },
    262293
    263294                /**
    264                  * Get the placements for this partial.
     295                 * Gets the placements for this partial.
    265296                 *
    266297                 * @since 4.5.0
    267                  * @returns {Array}
     298                 *
     299                 * @returns {Array} An array containing placement objects for each of the dynamic sidebar boundary nodes.
    268300                 */
    269301                placements: function() {
    270302                        var partial = this;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    286318                 *
    287319                 * @since 4.5.0
    288320                 *
    289                  * @returns {Array}
     321                 * @throws {Error} If there's no settingId.
     322                 * @throws {Error} If the setting doesn't exist in the API.
     323                 * @throws {Error} If the API doesn't pass an array of widget ids.
     324                 *
     325                 * @returns {Array} A shallow copy of the array containing widget IDs.
    290326                 */
    291327                getWidgetIds: function() {
    292328                        var sidebarPartial = this, settingId, widgetIds;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    305341                },
    306342
    307343                /**
    308                  * Reflow widgets in the sidebar, ensuring they have the proper position in the DOM.
     344                 * Reflows widgets in the sidebar, ensuring they have the proper position in the DOM.
    309345                 *
    310346                 * @since 4.5.0
    311347                 *
    312                  * @return {Array.<wp.customize.selectiveRefresh.Placement>} List of placements that were reflowed.
     348                 * @returns {Array.<wp.customize.selectiveRefresh.Placement>} List of placements that were reflowed.
    313349                 */
    314350                reflowWidgets: function() {
    315351                        var sidebarPartial = this, sidebarPlacements, widgetIds, widgetPartials, sortedSidebarContainers = [];
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    369405                },
    370406
    371407                /**
    372                  * Make sure there is a widget instance container in this sidebar for the given widget ID.
     408                 * Makes sure there is a widget instance container in this sidebar for the given widget ID.
    373409                 *
    374410                 * @since 4.5.0
    375411                 *
    376                  * @param {string} widgetId
    377                  * @returns {wp.customize.selectiveRefresh.Partial} Widget instance partial.
     412                 * @param {string} widgetId The widget ID.
     413                 *
     414                 * @returns {wp.customize.selectiveRefresh.Partial} The widget instance partial.
    378415                 */
    379416                ensureWidgetPlacementContainers: function( widgetId ) {
    380417                        var sidebarPartial = this, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    435472                },
    436473
    437474                /**
    438                  * Handle change to the sidebars_widgets[] setting.
     475                 * Handles changes to the sidebars_widgets[] setting.
    439476                 *
    440477                 * @since 4.5.0
    441478                 *
    442                  * @param {Array} newWidgetIds New widget ids.
    443                  * @param {Array} oldWidgetIds Old widget ids.
     479                 * @param {Array} newWidgetIds New widget IDs.
     480                 * @param {Array} oldWidgetIds Old widget IDs.
     481                 *
     482                 * @returns {void}
    444483                 */
    445484                handleSettingChange: function( newWidgetIds, oldWidgetIds ) {
    446485                        var sidebarPartial = this, needsRefresh, widgetsRemoved, widgetsAdded, addedWidgetPartials = [];
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    488527                },
    489528
    490529                /**
     530                 * Refreshes the sidebar partial.
     531                 *
    491532                 * Note that the meat is handled in handleSettingChange because it has the context of which widgets were removed.
    492533                 *
    493534                 * @since 4.5.0
     535                 *
     536                 * @returns {Promise} A promise postponing the refresh.
    494537                 */
    495538                refresh: function() {
    496539                        var partial = this, deferred = $.Deferred();
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    516559        api.selectiveRefresh.partialConstructor.widget = self.WidgetPartial;
    517560
    518561        /**
    519          * Add partials for the registered widget areas (sidebars).
     562         * Adds partials for the registered widget areas (sidebars).
    520563         *
    521564         * @since 4.5.0
     565         *
     566         * @returns {void}
    522567         */
    523568        self.addPartials = function() {
    524569                _.each( self.registeredSidebars, function( registeredSidebar ) {
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    536581        };
    537582
    538583        /**
    539          * Calculate the selector for the sidebar's widgets based on the registered sidebar's info.
     584         * Calculates the selector for the sidebar's widgets based on the registered sidebar's info.
    540585         *
    541586         * @memberOf wp.customize.widgetsPreview
    542587         *
    543588         * @since 3.9.0
     589         *
     590         * @returns {void}
    544591         */
    545592        self.buildWidgetSelectors = function() {
    546593                var self = this;
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    576623        };
    577624
    578625        /**
    579          * Highlight the widget on widget updates or widget control mouse overs.
     626         * Highlights the widget on widget updates or widget control mouse overs.
    580627         *
    581628         * @memberOf wp.customize.widgetsPreview
    582629         *
    583630         * @since 3.9.0
    584631         * @param  {string} widgetId ID of the widget.
     632         *
     633         * @returns {void}
    585634         */
    586635        self.highlightWidget = function( widgetId ) {
    587636                var $body = $( document.body ),
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    596645        };
    597646
    598647        /**
    599          * Show a title and highlight widgets on hover. On shift+clicking
    600          * focus the widget control.
     648         * Shows a title and highlights widgets on hover. On shift+clicking
     649         * focuses the widget control.
    601650         *
    602651         * @memberOf wp.customize.widgetsPreview
    603652         *
    604653         * @since 3.9.0
     654         *
     655         * @returns {void}
    605656         */
    606657        self.highlightControls = function() {
    607658                var self = this,
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    613664                }
    614665
    615666                $( selector ).attr( 'title', this.l10n.widgetTooltip );
    616 
     667                // Highlights widget when entering the widget editor.
    617668                $( document ).on( 'mouseenter', selector, function() {
    618669                        self.preview.send( 'highlight-widget-control', $( this ).prop( 'id' ) );
    619670                });
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    630681        };
    631682
    632683        /**
    633          * Parse a widget ID.
     684         * Parses a widget ID.
    634685         *
    635686         * @memberOf wp.customize.widgetsPreview
    636687         *
    637688         * @since 4.5.0
    638689         *
    639          * @param {string} widgetId Widget ID.
    640          * @returns {{idBase: string, number: number|null}}
     690         * @param {string} widgetId The widget ID.
     691         *
     692         * @returns {{idBase: string, number: number|null}} An object containing the idBase
     693         * and number of the parsed widget ID.
    641694         */
    642695        self.parseWidgetId = function( widgetId ) {
    643696                var matches, parsed = {
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    657710        };
    658711
    659712        /**
    660          * Parse a widget setting ID.
     713         * Parses a widget setting ID.
    661714         *
    662715         * @memberOf wp.customize.widgetsPreview
    663716         *
    664717         * @since 4.5.0
    665718         *
    666719         * @param {string} settingId Widget setting ID.
    667          * @returns {{idBase: string, number: number|null}|null}
     720         *
     721         * @returns {{idBase: string, number: number|null}|null} Either an object containing the idBase
     722         * and number of the parsed widget setting ID, or null.
    668723         */
    669724        self.parseWidgetSettingId = function( settingId ) {
    670725                var matches, parsed = {
    wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( 
    684739        };
    685740
    686741        /**
    687          * Convert a widget ID into a Customizer setting ID.
     742         * Converts a widget ID into a Customizer setting ID.
    688743         *
    689744         * @memberOf wp.customize.widgetsPreview
    690745         *
    691746         * @since 4.5.0
    692747         *
    693          * @param {string} widgetId Widget ID.
    694          * @returns {string} settingId Setting ID.
     748         * @param {string} widgetId The widget ID.
     749         *
     750         * @returns {string} The setting ID.
    695751         */
    696752        self.getWidgetSettingId = function( widgetId ) {
    697753                var parsed = this.parseWidgetId( widgetId ), settingId;