Make WordPress Core

Ticket #37964: 37964.0.diff

File 37964.0.diff, 5.2 KB (added by westonruter, 10 years ago)
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 631df0b..0a88dca 100644
     
    14841484
    14851485                initialize: function( id, options ) {
    14861486                        var control = this,
    1487                                 nodes, radios, settings;
     1487                                nodes, radios, deferredSettingIds = [];
    14881488
    14891489                        control.params = {};
    14901490                        $.extend( control, options || {} );
     
    15041504
    15051505                        control.elements = [];
    15061506
    1507                         nodes  = control.container.find('[data-customize-setting-link]');
    1508                         radios = {};
    1509 
    1510                         nodes.each( function() {
    1511                                 var node = $( this ),
    1512                                         name;
    1513 
    1514                                 if ( node.is( ':radio' ) ) {
    1515                                         name = node.prop( 'name' );
    1516                                         if ( radios[ name ] ) {
    1517                                                 return;
    1518                                         }
    1519 
    1520                                         radios[ name ] = true;
    1521                                         node = nodes.filter( '[name="' + name + '"]' );
    1522                                 }
    1523 
    1524                                 api( node.data( 'customizeSettingLink' ), function( setting ) {
    1525                                         var element = new api.Element( node );
    1526                                         control.elements.push( element );
    1527                                         element.sync( setting );
    1528                                         element.set( setting() );
    1529                                 });
    1530                         });
    1531 
    15321507                        control.active.bind( function ( active ) {
    15331508                                var args = control.activeArgumentsQueue.shift();
    15341509                                args = $.extend( {}, control.defaultActiveArguments, args );
     
    15411516
    15421517                        api.utils.bubbleChildValueChanges( control, [ 'section', 'priority', 'active' ] );
    15431518
     1519                        control.settings = {};
     1520
    15441521                        /*
    15451522                         * After all settings related to the control are available,
    15461523                         * make them available on the control and embed the control into the page.
    15471524                         */
    1548                         settings = $.map( control.params.settings, function( value ) {
    1549                                 return value;
    1550                         });
     1525                        _.each( control.params.settings, function( setting, key ) {
     1526                                if ( _.isObject( setting ) ) {
     1527                                        control.settings[ key ] = setting;
     1528                                } else {
     1529                                        deferredSettingIds.push( setting );
     1530                                }
     1531                        } );
     1532                        control.setting = control.settings['default'] || null;
    15511533
    1552                         if ( 0 === settings.length ) {
     1534                        if ( _.isEmpty( control.params.settings ) ) {
    15531535                                control.setting = null;
    1554                                 control.settings = {};
     1536                                control.embed();
     1537                        } else if ( _.isEmpty( deferredSettingIds ) ) {
     1538                                control._linkElements();
     1539                                control._linkNotifications();
    15551540                                control.embed();
    15561541                        } else {
    1557                                 api.apply( api, settings.concat( function() {
     1542                                api.apply( api, deferredSettingIds.concat( function() {
    15581543                                        var key;
    15591544
    1560                                         control.settings = {};
    1561                                         for ( key in control.params.settings ) {
    1562                                                 control.settings[ key ] = api( control.params.settings[ key ] );
    1563                                         }
     1545                                        _.each( control.params.settings, function( settingId, key ) {
     1546                                                if ( _.isString( settingId ) ) {
     1547                                                        control.settings[ key ] = api( settingId );
     1548                                                }
     1549                                        } );
    15641550
    15651551                                        control.setting = control.settings['default'] || null;
    15661552
    1567                                         // Add setting notifications to the control notification.
    1568                                         _.each( control.settings, function( setting ) {
    1569                                                 setting.notifications.bind( 'add', function( settingNotification ) {
    1570                                                         var controlNotification, code, params;
    1571                                                         code = setting.id + ':' + settingNotification.code;
    1572                                                         params = _.extend(
    1573                                                                 {},
    1574                                                                 settingNotification,
    1575                                                                 {
    1576                                                                         setting: setting.id
    1577                                                                 }
    1578                                                         );
    1579                                                         controlNotification = new api.Notification( code, params );
    1580                                                         control.notifications.add( controlNotification.code, controlNotification );
    1581                                                 } );
    1582                                                 setting.notifications.bind( 'remove', function( settingNotification ) {
    1583                                                         control.notifications.remove( setting.id + ':' + settingNotification.code );
    1584                                                 } );
    1585                                         } );
    1586 
     1553                                        control._linkElements();
     1554                                        control._linkNotifications();
    15871555                                        control.embed();
    15881556                                }) );
    15891557                        }
     
    16101578                },
    16111579
    16121580                /**
     1581                 * Link elements.
     1582                 *
     1583                 * @private
     1584                 */
     1585                _linkElements: function() {
     1586                        var control = this, nodes, radios;
     1587
     1588                        nodes  = control.container.find('[data-customize-setting-link]');
     1589                        radios = {};
     1590
     1591                        nodes.each( function() {
     1592                                var node = $( this ),
     1593                                        name;
     1594
     1595                                if ( node.is( ':radio' ) ) {
     1596                                        name = node.prop( 'name' );
     1597                                        if ( radios[ name ] ) {
     1598                                                return;
     1599                                        }
     1600
     1601                                        radios[ name ] = true;
     1602                                        node = nodes.filter( '[name="' + name + '"]' );
     1603                                }
     1604
     1605                                api( node.data( 'customizeSettingLink' ), function( setting ) {
     1606                                        var element = new api.Element( node );
     1607                                        control.elements.push( element );
     1608                                        element.sync( setting );
     1609                                        element.set( setting() );
     1610                                });
     1611                        });
     1612                },
     1613
     1614                /**
     1615                 * Add setting notifications to the control notification.
     1616                 *
     1617                 * @private
     1618                 */
     1619                _linkNotifications: function() {
     1620                        var control = this;
     1621
     1622                        _.each( control.settings, function( setting ) {
     1623                                setting.notifications.bind( 'add', function( settingNotification ) {
     1624                                        var controlNotification, code, params;
     1625                                        code = setting.id + ':' + settingNotification.code;
     1626                                        params = _.extend(
     1627                                                {},
     1628                                                settingNotification,
     1629                                                {
     1630                                                        setting: setting.id
     1631                                                }
     1632                                        );
     1633                                        controlNotification = new api.Notification( code, params );
     1634                                        control.notifications.add( controlNotification.code, controlNotification );
     1635                                } );
     1636                                setting.notifications.bind( 'remove', function( settingNotification ) {
     1637                                        control.notifications.remove( setting.id + ':' + settingNotification.code );
     1638                                } );
     1639                        } );
     1640                },
     1641
     1642                /**
    16131643                 * Embed the control into the page.
    16141644                 */
    16151645                embed: function () {