Make WordPress Core

Ticket #38164: 38164.2.diff

File 38164.2.diff, 8.7 KB (added by celloexpressions, 7 years ago)

See comment.

  • src/wp-admin/css/customize-controls.css

     
    583583        display: block;
    584584        font-style: italic;
    585585        line-height: 18px;
     586        margin-top: 0;
    586587        margin-bottom: 5px;
    587588}
    588589
     
    670671        float: left;
    671672}
    672673
     674#available-menu-items .accordion-section-content .new-content-item,
     675.customize-control-dropdown-pages .new-content-item {
     676        width: -webkit-calc(100% - 30px);
     677        width: calc(100% - 30px);
     678        padding: 8px 15px;
     679        position: absolute;
     680        bottom: 0;
     681        z-index: 10;
     682        background: #eee;
     683        display: -webkit-box;
     684        display: -moz-box;
     685        display: -ms-flexbox;
     686        display: -webkit-flex;
     687        display: flex;
     688}
     689
     690.customize-control-dropdown-pages .new-content-item {
     691        width: 98%;
     692        padding: 5px 0 5px 1px;
     693        position: relative;
     694}
     695
     696#available-menu-items .new-content-item .create-item-input,
     697.customize-control-dropdown-pages .new-content-item .create-item-input {
     698        -webkit-box-flex: 10;
     699        -webkit-flex-grow: 10;
     700        -moz-box-flex: 10;
     701        -ms-flex-positive: 10;
     702        -ms-flex: 10;
     703        flex-grow: 10;
     704}
     705
     706#available-menu-items .new-content-item .add-content,
     707.customize-control-dropdown-pages .new-content-item .add-content {
     708        margin: 2px 0 2px 6px;
     709        -webkit-box-flex: 10;
     710        -webkit-flex-grow: 10;
     711        -moz-box-flex: 10;
     712        -ms-flex-positive: 10;
     713        -ms-flex: 10;
     714        flex-grow: 1;
     715}
     716
     717.customize-control-dropdown-pages .new-content-item .create-item-input.invalid {
     718        border: 1px solid #f00;
     719}
     720
    673721#customize-preview iframe {
    674722        width: 100%;
    675723        height: 100%;
  • src/wp-admin/css/customize-nav-menus.css

     
    572572        padding: 0 15px 15px 15px;
    573573}
    574574
    575 #available-menu-items .accordion-section-content .new-content-item {
    576         width: -webkit-calc(100% - 30px);
    577         width: calc(100% - 30px);
    578         padding: 8px 15px;
    579         position: absolute;
    580         bottom: 0;
    581         z-index: 10;
    582         background: #eee;
    583         display: -webkit-box;
    584         display: -moz-box;
    585         display: -ms-flexbox;
    586         display: -webkit-flex;
    587         display: flex;
    588 }
    589 
    590 #available-menu-items .new-content-item .create-item-input {
    591         -webkit-box-flex: 10;
    592         -webkit-flex-grow: 10;
    593         -moz-box-flex: 10;
    594         -ms-flex-positive: 10;
    595         -ms-flex: 10;
    596         flex-grow: 10;
    597         margin-left: 5px;
    598         padding: 4.5px;
    599 }
    600 #available-menu-items .new-content-item .add-content {
    601         padding-left: 6px;
    602         -webkit-box-flex: 10;
    603         -webkit-flex-grow: 10;
    604         -moz-box-flex: 10;
    605         -ms-flex-positive: 10;
    606         -ms-flex: 10;
    607         flex-grow: 1;
    608 }
    609 
    610575#available-menu-items .menu-item-tpl {
    611576        margin: 0;
    612577}
  • src/wp-admin/js/customize-controls.js

     
    25292529                 *
    25302530                 * @abstract
    25312531                 */
    2532                 ready: function() {},
     2532                ready: function() {
     2533                        if ( 'dropdown-pages' === this.params.type ) {
     2534                                var control = this;
     2535                                control.container.find( '.new-content-item' ).hide(); // Hide in JS to preserve flex display when showing.
     2536                                control.container.on( 'click', '.add-new-toggle', function( e ) {
     2537                                        $( e.currentTarget ).slideUp( 180 );
     2538                                        control.container.find( '.new-content-item' ).slideDown( 180 )
     2539                                                                                     .find( '.create-item-input' ).focus();
     2540                                });
     2541                                control.container.on( 'click', '.add-content', function() {
     2542                                        control.addNewPage();
     2543                                });
     2544                                control.container.on( 'keyup', '.create-item-input', function( e ) {
     2545                                        if ( 13 === e.which ) { // Enter
     2546                                                control.addNewPage();
     2547                                        }
     2548                                });
     2549                        }
     2550                },
    25332551
    25342552                /**
    25352553                 * Get the element inside of a control's container that contains the validation error message.
     
    27472765                                        control.container.html( template( control.params ) );
    27482766                                }
    27492767                        }
     2768                },
     2769
     2770                /**
     2771                 * Add a new page to a dropdown-pages control reusing menus code for this.
     2772                 *
     2773                 * @since 4.7.0
     2774                 */
     2775                addNewPage: function () {
     2776                        if ( 'dropdown-pages' !== this.params.type || ! api.Menus ) {
     2777                                return;
     2778                        }
     2779
     2780                        var control = this, promise,
     2781                            toggle = control.container.find( '.add-new-toggle' ),
     2782                            container = control.container.find( '.new-content-item' ),
     2783                            input = control.container.find( '.create-item-input' ),
     2784                            title = input.val();
     2785                            select = control.container.find( 'select' );
     2786
     2787                        if ( ! title ) {
     2788                                input.addClass( 'invalid' );
     2789                                return;
     2790                        }
     2791
     2792                        input.removeClass( 'invalid' );
     2793                        input.attr( 'disabled', 'disabled' );
     2794
     2795                        // The menus functions add the page, publish when appropriate, and also add the new page to the dropdown-pages controls.
     2796                        promise = api.Menus.insertAutoDraftPost( {
     2797                                post_title: title,
     2798                                post_type: 'page'
     2799                        } );
     2800                        promise.done( function( data ) {
     2801                                var availableItem, $content, itemTemplate;
     2802
     2803                                // Prepare the new page as an available menu item.
     2804                                // See api.Menus.submitNew().
     2805                                availableItem = new api.Menus.AvailableItemModel( {
     2806                                        'id': 'post-' + data.post_id, // Used for available menu item Backbone models.
     2807                                        'title': title,
     2808                                        'type': 'page',
     2809                                        'type_label': api.Menus.data.l10n.page_label,
     2810                                        'object': 'post_type',
     2811                                        'object_id': data.post_id,
     2812                                        'url': data.url
     2813                                } );
     2814
     2815                                // Add the new item to the list of available menu items.
     2816                                api.Menus.availableMenuItemsPanel.collection.add( availableItem );
     2817                                $content = $( '#available-menu-items-post_type-page' ).find( '.available-menu-items-list' );
     2818                                itemTemplate = wp.template( 'available-menu-item' );
     2819                                $content.prepend( itemTemplate( availableItem.attributes ) );
     2820
     2821                                // Focus the select control.
     2822                                select.focus();
     2823                                control.setting.set( String( data.post_id ) ); // Triggers a preview refresh and updates the setting.
     2824                                select.val( String( data.post_id ) );
     2825
     2826                                // Reset the create page form.
     2827                                container.slideUp( 180 );
     2828                                toggle.slideDown( 180 );
     2829                        } )
     2830                        .always( function() {
     2831                                input.val( '' ).removeAttr( 'disabled' );
     2832                        } );
    27502833                }
    27512834        });
    27522835
  • src/wp-includes/class-wp-customize-control.php

     
    115115        public $input_attrs = array();
    116116
    117117        /**
     118         * @access public
     119         * @var array
     120         */
     121        public $add_new = false;
     122
     123        /**
    118124         * @deprecated It is better to just call the json() method
    119125         * @access public
    120126         * @var array
     
    557563                                echo $dropdown;
    558564                                ?>
    559565                                </label>
    560                                 <?php
     566                                <?php if ( $this->add_new && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
     567                                        <button type="button" class="button add-new-toggle"><?php _e( 'Add new page' ); ?></button>
     568                                        <div class="new-content-item">
     569                                                <label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
     570                                                <input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title&hellip;' ); ?>">
     571                                                <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
     572                                        </div>
     573                                <?php endif;
    561574                                break;
    562575                        default:
    563576                                ?>
  • src/wp-includes/class-wp-customize-manager.php

     
    33763424                        'label' => __( 'Front page' ),
    33773425                        'section' => 'static_front_page',
    33783426                        'type' => 'dropdown-pages',
     3427                        'add_new' => true,
    33793428                ) );
    33803429
    33813430                $this->add_setting( 'page_for_posts', array(
     
    33873436                        'label' => __( 'Posts page' ),
    33883437                        'section' => 'static_front_page',
    33893438                        'type' => 'dropdown-pages',
     3439                        'add_new' => true,
    33903440                ) );
    33913441
    33923442                /* Custom CSS */
  • src/wp-includes/class-wp-customize-nav-menus.php

     
    370370                                'untitled'          => _x( '(no label)', 'missing menu item navigation label' ),
    371371                                'unnamed'           => _x( '(unnamed)', 'Missing menu name.' ),
    372372                                'custom_label'      => __( 'Custom Link' ),
     373                                'page_label'        => __( 'Page' ),
    373374                                /* translators: %s: menu location */
    374375                                'menuLocation'      => _x( '(Currently set to: %s)', 'menu' ),
    375376                                'menuNameLabel'     => __( 'Menu Name' ),