Changeset 33189
- Timestamp:
- 07/13/2015 08:39:17 AM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-nav-menus.js
r33094 r33189 677 677 678 678 populateControls: function() { 679 var section = this, menuNameControlId, menu Control, menuNameControl;679 var section = this, menuNameControlId, menuAutoAddControlId, menuControl, menuNameControl, menuAutoAddControl; 680 680 681 681 // Add the control for managing the menu name. … … 686 686 params: { 687 687 type: 'nav_menu_name', 688 content: '<li id="customize-control-' + section.id.replace( '[', '-' ).replace( ']', '' ) + '-name" class="customize-control customize-control-nav_menu_name"></li>', // @todo core should do this for us 688 content: '<li id="customize-control-' + section.id.replace( '[', '-' ).replace( ']', '' ) + '-name" class="customize-control customize-control-nav_menu_name"></li>', // @todo core should do this for us; see #30741 689 689 label: '', 690 690 active: true, … … 706 706 params: { 707 707 type: 'nav_menu', 708 content: '<li id="customize-control-' + section.id.replace( '[', '-' ).replace( ']', '' ) + '" class="customize-control customize-control-nav_menu"></li>', // @todo core should do this for us 708 content: '<li id="customize-control-' + section.id.replace( '[', '-' ).replace( ']', '' ) + '" class="customize-control customize-control-nav_menu"></li>', // @todo core should do this for us; see #30741 709 709 section: section.id, 710 priority: 99 9,710 priority: 998, 711 711 active: true, 712 712 settings: { … … 718 718 api.control.add( menuControl.id, menuControl ); 719 719 menuControl.active.set( true ); 720 } 721 722 // Add the control for managing the menu auto_add. 723 menuAutoAddControlId = section.id + '[auto_add]'; 724 menuAutoAddControl = api.control( menuAutoAddControlId ); 725 if ( ! menuAutoAddControl ) { 726 menuAutoAddControl = new api.controlConstructor.nav_menu_auto_add( menuAutoAddControlId, { 727 params: { 728 type: 'nav_menu_auto_add', 729 content: '<li id="customize-control-' + section.id.replace( '[', '-' ).replace( ']', '' ) + '-auto-add" class="customize-control customize-control-nav_menu_auto_add"></li>', // @todo core should do this for us 730 label: '', 731 active: true, 732 section: section.id, 733 priority: 999, 734 settings: { 735 'default': section.id 736 } 737 } 738 } ); 739 api.control.add( menuAutoAddControl.id, menuAutoAddControl ); 740 menuAutoAddControl.active.set( true ); 720 741 } 721 742 … … 1593 1614 1594 1615 /** 1616 * wp.customize.Menus.MenuAutoAddControl 1617 * 1618 * Customizer control for a nav menu's auto add. 1619 * 1620 * @constructor 1621 * @augments wp.customize.Control 1622 */ 1623 api.Menus.MenuAutoAddControl = api.Control.extend({ 1624 1625 ready: function() { 1626 var control = this, 1627 settingValue = control.setting(); 1628 1629 /* 1630 * Since the control is not registered in PHP, we need to prevent the 1631 * preview's sending of the activeControls to result in this control 1632 * being deactivated. 1633 */ 1634 control.active.validate = function() { 1635 return api.section( control.section() ).active(); 1636 }; 1637 1638 control.autoAddElement = new api.Element( control.container.find( 'input[type=checkbox].auto_add' ) ); 1639 1640 control.autoAddElement.bind(function( value ) { 1641 var settingValue = control.setting(); 1642 if ( settingValue && settingValue.name !== value ) { 1643 settingValue = _.clone( settingValue ); 1644 settingValue.auto_add = value; 1645 control.setting.set( settingValue ); 1646 } 1647 }); 1648 if ( settingValue ) { 1649 control.autoAddElement.set( settingValue.auto_add ); 1650 } 1651 1652 control.setting.bind(function( object ) { 1653 if ( object ) { 1654 control.autoAddElement.set( object.auto_add ); 1655 } 1656 }); 1657 } 1658 1659 }); 1660 1661 /** 1595 1662 * wp.customize.Menus.MenuControl 1596 1663 * … … 1662 1729 var control = this, 1663 1730 menuId = control.params.menu_id; 1664 1665 control.elements = {};1666 control.elements.auto_add = new api.Element( control.container.find( 'input[type=checkbox].auto_add' ) );1667 1668 control.elements.auto_add.bind(function( auto_add ) {1669 var settingValue = control.setting();1670 if ( settingValue && settingValue.auto_add !== auto_add ) {1671 settingValue = _.clone( settingValue );1672 settingValue.auto_add = auto_add;1673 control.setting.set( settingValue );1674 }1675 });1676 control.elements.auto_add.set( control.setting().auto_add );1677 control.setting.bind(function( object ) {1678 if ( ! object ) {1679 return;1680 }1681 control.elements.auto_add.set( object.auto_add );1682 });1683 1731 1684 1732 control.setting.bind( function( to ) { … … 2245 2293 nav_menu: api.Menus.MenuControl, 2246 2294 nav_menu_name: api.Menus.MenuNameControl, 2295 nav_menu_auto_add: api.Menus.MenuAutoAddControl, 2247 2296 new_menu: api.Menus.NewMenuControl 2248 2297 }); -
trunk/src/wp-includes/class-wp-customize-control.php
r33164 r33189 1604 1604 1605 1605 </ul> 1606 <?php endif; ?> 1607 <p> 1608 <label> 1609 <input type="checkbox" class="auto_add"> 1610 <?php _e( 'Automatically add new top-level pages to this menu' ) ?> 1611 </label> 1612 </p> 1613 <?php 1606 <?php endif; 1614 1607 } 1615 1608 … … 1887 1880 1888 1881 /** 1882 * Customize control to represent the auto_add field for a given menu. 1883 * 1884 * @since 4.3.0 1885 */ 1886 class WP_Customize_Nav_Menu_Auto_Add_Control extends WP_Customize_Control { 1887 1888 /** 1889 * Type of control, used by JS. 1890 * 1891 * @since 4.3.0 1892 * 1893 * @var string 1894 */ 1895 public $type = 'nav_menu_auto_add'; 1896 1897 /** 1898 * No-op since we're using JS template. 1899 * 1900 * @since 4.3.0 1901 */ 1902 protected function render_content() {} 1903 1904 /** 1905 * Render the Underscore template for this control. 1906 * 1907 * @since 4.3.0 1908 */ 1909 protected function content_template() { 1910 ?> 1911 <label> 1912 <span class="customize-control-title"><?php _e( 'Menu Options' ); ?></span> 1913 <input type="checkbox" class="auto_add" /> 1914 <?php _e( 'Automatically add new top-level pages to this menu' ); ?> 1915 </label> 1916 <?php 1917 } 1918 } 1919 1920 /** 1889 1921 * Customize control class for new menus. 1890 1922 * -
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r33167 r33189 406 406 $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Control' ); 407 407 $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Name_Control' ); 408 $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Auto_Add_Control' ); 408 409 $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Item_Control' ); 409 410
Note: See TracChangeset
for help on using the changeset viewer.