diff --git src/wp-includes/js/customize-preview-widgets.js src/wp-includes/js/customize-preview-widgets.js
index 31f5aface7..17f565d557 100644
|
|
|
|
| 1 | 1 | /* global _wpWidgetCustomizerPreviewSettings */ |
| 2 | 2 | |
| 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 | */ |
| 4 | 17 | wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( $, _, wp, api ) { |
| 5 | 18 | |
| 6 | 19 | var self; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 19 | 32 | }; |
| 20 | 33 | |
| 21 | 34 | /** |
| 22 | | * Init widgets preview. |
| | 35 | * Initializes the widgets preview. |
| 23 | 36 | * |
| 24 | 37 | * @since 4.5.0 |
| | 38 | * |
| | 39 | * @returns {void} |
| 25 | 40 | */ |
| 26 | 41 | self.init = function() { |
| 27 | 42 | var self = this; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 67 | 82 | * |
| 68 | 83 | * @class |
| 69 | 84 | * @augments wp.customize.selectiveRefresh.Partial |
| | 85 | * |
| 70 | 86 | * @since 4.5.0 |
| 71 | 87 | */ |
| 72 | 88 | self.WidgetPartial = api.selectiveRefresh.Partial.extend(/** @lends wp.customize.widgetsPreview.WidgetPartial.prototype */{ |
| 73 | 89 | |
| 74 | 90 | /** |
| 75 | | * Constructor. |
| | 91 | * Initializes the widget partial. |
| 76 | 92 | * |
| 77 | 93 | * @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} |
| 81 | 100 | */ |
| 82 | 101 | initialize: function( id, options ) { |
| 83 | 102 | var partial = this, matches; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 101 | 120 | }, |
| 102 | 121 | |
| 103 | 122 | /** |
| 104 | | * Refresh widget partial. |
| | 123 | * Refreshes the widget partial. |
| 105 | 124 | * |
| 106 | | * @returns {Promise} |
| | 125 | * @since 4.5.0 |
| | 126 | * |
| | 127 | * @returns {Promise|void} Either a promise postponing the refresh, or void. |
| 107 | 128 | */ |
| 108 | 129 | refresh: function() { |
| 109 | 130 | var partial = this, refreshDeferred; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 118 | 139 | }, |
| 119 | 140 | |
| 120 | 141 | /** |
| 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. |
| 122 | 146 | * |
| 123 | | * @inheritdoc |
| 124 | | * @param {wp.customize.selectiveRefresh.Placement} placement |
| | 147 | * @returns {void} |
| 125 | 148 | */ |
| 126 | 149 | renderContent: function( placement ) { |
| 127 | 150 | var partial = this; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 145 | 168 | self.SidebarPartial = api.selectiveRefresh.Partial.extend(/** @lends wp.customize.widgetsPreview.SidebarPartial.prototype */{ |
| 146 | 169 | |
| 147 | 170 | /** |
| 148 | | * Constructor. |
| | 171 | * Initializes the sidebar partial. |
| 149 | 172 | * |
| 150 | 173 | * @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} |
| 154 | 180 | */ |
| 155 | 181 | initialize: function( id, options ) { |
| 156 | 182 | var partial = this, matches; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 179 | 205 | }, |
| 180 | 206 | |
| 181 | 207 | /** |
| 182 | | * Set up the partial. |
| | 208 | * Sets up the partial. |
| 183 | 209 | * |
| 184 | 210 | * @since 4.5.0 |
| | 211 | * |
| | 212 | * @returns {void} |
| 185 | 213 | */ |
| 186 | 214 | ready: function() { |
| 187 | 215 | var sidebarPartial = this; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 220 | 248 | }, |
| 221 | 249 | |
| 222 | 250 | /** |
| 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). |
| 224 | 252 | * |
| 225 | 253 | * Note that TreeWalker is not implemented in IE8. |
| 226 | 254 | * |
| 227 | 255 | * @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. |
| 229 | 260 | */ |
| 230 | 261 | findDynamicSidebarBoundaryNodes: function() { |
| 231 | 262 | var partial = this, regExp, boundaryNodes = {}, recursiveCommentTraversal; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 261 | 292 | }, |
| 262 | 293 | |
| 263 | 294 | /** |
| 264 | | * Get the placements for this partial. |
| | 295 | * Gets the placements for this partial. |
| 265 | 296 | * |
| 266 | 297 | * @since 4.5.0 |
| 267 | | * @returns {Array} |
| | 298 | * |
| | 299 | * @returns {Array} An array containing placement objects for each of the dynamic sidebar boundary nodes. |
| 268 | 300 | */ |
| 269 | 301 | placements: function() { |
| 270 | 302 | var partial = this; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 286 | 318 | * |
| 287 | 319 | * @since 4.5.0 |
| 288 | 320 | * |
| 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. |
| 290 | 326 | */ |
| 291 | 327 | getWidgetIds: function() { |
| 292 | 328 | var sidebarPartial = this, settingId, widgetIds; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 305 | 341 | }, |
| 306 | 342 | |
| 307 | 343 | /** |
| 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. |
| 309 | 345 | * |
| 310 | 346 | * @since 4.5.0 |
| 311 | 347 | * |
| 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. |
| 313 | 349 | */ |
| 314 | 350 | reflowWidgets: function() { |
| 315 | 351 | var sidebarPartial = this, sidebarPlacements, widgetIds, widgetPartials, sortedSidebarContainers = []; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 369 | 405 | }, |
| 370 | 406 | |
| 371 | 407 | /** |
| 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. |
| 373 | 409 | * |
| 374 | 410 | * @since 4.5.0 |
| 375 | 411 | * |
| 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. |
| 378 | 415 | */ |
| 379 | 416 | ensureWidgetPlacementContainers: function( widgetId ) { |
| 380 | 417 | var sidebarPartial = this, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']'; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 435 | 472 | }, |
| 436 | 473 | |
| 437 | 474 | /** |
| 438 | | * Handle change to the sidebars_widgets[] setting. |
| | 475 | * Handles changes to the sidebars_widgets[] setting. |
| 439 | 476 | * |
| 440 | 477 | * @since 4.5.0 |
| 441 | 478 | * |
| 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} |
| 444 | 483 | */ |
| 445 | 484 | handleSettingChange: function( newWidgetIds, oldWidgetIds ) { |
| 446 | 485 | var sidebarPartial = this, needsRefresh, widgetsRemoved, widgetsAdded, addedWidgetPartials = []; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 488 | 527 | }, |
| 489 | 528 | |
| 490 | 529 | /** |
| | 530 | * Refreshes the sidebar partial. |
| | 531 | * |
| 491 | 532 | * Note that the meat is handled in handleSettingChange because it has the context of which widgets were removed. |
| 492 | 533 | * |
| 493 | 534 | * @since 4.5.0 |
| | 535 | * |
| | 536 | * @returns {Promise} A promise postponing the refresh. |
| 494 | 537 | */ |
| 495 | 538 | refresh: function() { |
| 496 | 539 | var partial = this, deferred = $.Deferred(); |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 516 | 559 | api.selectiveRefresh.partialConstructor.widget = self.WidgetPartial; |
| 517 | 560 | |
| 518 | 561 | /** |
| 519 | | * Add partials for the registered widget areas (sidebars). |
| | 562 | * Adds partials for the registered widget areas (sidebars). |
| 520 | 563 | * |
| 521 | 564 | * @since 4.5.0 |
| | 565 | * |
| | 566 | * @returns {void} |
| 522 | 567 | */ |
| 523 | 568 | self.addPartials = function() { |
| 524 | 569 | _.each( self.registeredSidebars, function( registeredSidebar ) { |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 536 | 581 | }; |
| 537 | 582 | |
| 538 | 583 | /** |
| 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. |
| 540 | 585 | * |
| 541 | 586 | * @memberOf wp.customize.widgetsPreview |
| 542 | 587 | * |
| 543 | 588 | * @since 3.9.0 |
| | 589 | * |
| | 590 | * @returns {void} |
| 544 | 591 | */ |
| 545 | 592 | self.buildWidgetSelectors = function() { |
| 546 | 593 | var self = this; |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 576 | 623 | }; |
| 577 | 624 | |
| 578 | 625 | /** |
| 579 | | * Highlight the widget on widget updates or widget control mouse overs. |
| | 626 | * Highlights the widget on widget updates or widget control mouse overs. |
| 580 | 627 | * |
| 581 | 628 | * @memberOf wp.customize.widgetsPreview |
| 582 | 629 | * |
| 583 | 630 | * @since 3.9.0 |
| 584 | 631 | * @param {string} widgetId ID of the widget. |
| | 632 | * |
| | 633 | * @returns {void} |
| 585 | 634 | */ |
| 586 | 635 | self.highlightWidget = function( widgetId ) { |
| 587 | 636 | var $body = $( document.body ), |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 596 | 645 | }; |
| 597 | 646 | |
| 598 | 647 | /** |
| 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. |
| 601 | 650 | * |
| 602 | 651 | * @memberOf wp.customize.widgetsPreview |
| 603 | 652 | * |
| 604 | 653 | * @since 3.9.0 |
| | 654 | * |
| | 655 | * @returns {void} |
| 605 | 656 | */ |
| 606 | 657 | self.highlightControls = function() { |
| 607 | 658 | var self = this, |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 613 | 664 | } |
| 614 | 665 | |
| 615 | 666 | $( selector ).attr( 'title', this.l10n.widgetTooltip ); |
| 616 | | |
| | 667 | // Highlights widget when entering the widget editor. |
| 617 | 668 | $( document ).on( 'mouseenter', selector, function() { |
| 618 | 669 | self.preview.send( 'highlight-widget-control', $( this ).prop( 'id' ) ); |
| 619 | 670 | }); |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 630 | 681 | }; |
| 631 | 682 | |
| 632 | 683 | /** |
| 633 | | * Parse a widget ID. |
| | 684 | * Parses a widget ID. |
| 634 | 685 | * |
| 635 | 686 | * @memberOf wp.customize.widgetsPreview |
| 636 | 687 | * |
| 637 | 688 | * @since 4.5.0 |
| 638 | 689 | * |
| 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. |
| 641 | 694 | */ |
| 642 | 695 | self.parseWidgetId = function( widgetId ) { |
| 643 | 696 | var matches, parsed = { |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 657 | 710 | }; |
| 658 | 711 | |
| 659 | 712 | /** |
| 660 | | * Parse a widget setting ID. |
| | 713 | * Parses a widget setting ID. |
| 661 | 714 | * |
| 662 | 715 | * @memberOf wp.customize.widgetsPreview |
| 663 | 716 | * |
| 664 | 717 | * @since 4.5.0 |
| 665 | 718 | * |
| 666 | 719 | * @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. |
| 668 | 723 | */ |
| 669 | 724 | self.parseWidgetSettingId = function( settingId ) { |
| 670 | 725 | var matches, parsed = { |
| … |
… |
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( |
| 684 | 739 | }; |
| 685 | 740 | |
| 686 | 741 | /** |
| 687 | | * Convert a widget ID into a Customizer setting ID. |
| | 742 | * Converts a widget ID into a Customizer setting ID. |
| 688 | 743 | * |
| 689 | 744 | * @memberOf wp.customize.widgetsPreview |
| 690 | 745 | * |
| 691 | 746 | * @since 4.5.0 |
| 692 | 747 | * |
| 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. |
| 695 | 751 | */ |
| 696 | 752 | self.getWidgetSettingId = function( widgetId ) { |
| 697 | 753 | var parsed = this.parseWidgetId( widgetId ), settingId; |