Make WordPress Core

Ticket #27403: 27403.6.diff

File 27403.6.diff, 9.9 KB (added by sirbrillig, 9 years ago)

Update patch to hide icons when sidebar is collapsed (needs work since non-clicks can collapse sidebar)

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

     
    40394039
    40404040                $( '.collapse-sidebar' ).on( 'click', function() {
    40414041                        api.state( 'paneVisible' ).set( ! api.state( 'paneVisible' ).get() );
     4042                        api.previewer.send( 'collapse-sidebar', ! api.state( 'paneVisible' ).get() );
    40424043                });
    40434044
    40444045                api.state( 'paneVisible' ).bind( function( paneVisible ) {
  • src/wp-includes/class-wp-customize-manager.php

     
    837837                        'nonce' => $this->get_nonces(),
    838838                        'l10n' => array(
    839839                                'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
     840                                'clickIconToEdit' => __( 'Click to edit' ),
     841                                'clickEditMenu' => __( 'Click to edit this menu.' ),
     842                                'clickEditWidget' => __( 'Click to edit this widget.' ),
     843                                'clickEditTitle' => __( 'Click to edit the site title.' ),
     844                                'clickEditMisc' => __( 'Click to edit this element.' ),
    840845                        ),
    841846                        '_dirty' => array_keys( $this->unsanitized_post_values() ),
    842847                );
  • src/wp-includes/css/customize-preview.css

     
    1010        -webkit-box-shadow: none;
    1111        box-shadow: none;
    1212}
     13
     14.customize-partial-icon {
     15        float: left;
     16        position: relative;
     17        fill: #fff;
     18        width: 30px;
     19        height: 30px;
     20        font-size: 18px;
     21        z-index: 5;
     22        background: #0087BE;
     23        border-radius: 50%;
     24        border: 2px solid #fff;
     25        box-shadow: 0 2px 1px rgba(46,68,83,0.15);
     26        text-align: center;
     27        display: flex;
     28        flex-direction: row;
     29        justify-content: center;
     30        align-items: center;
     31        cursor: pointer;
     32        animation-name: bounce-appear;
     33        animation-delay: 0.8s;
     34        animation-duration: 1s;
     35        animation-fill-mode: both;
     36        animation-duration: .75s;
     37        padding: 0;
     38}
     39
     40.customize-partial-icon.hidden {
     41        opacity: 0;
     42}
     43
     44.customize-partial-icon svg {
     45        width: 18px;
     46        height: 18px;
     47}
     48
     49@keyframes bounce-appear {
     50        from, 20%, 40%, 60%, 80%, to {
     51                animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
     52        }
     53        0% {
     54                opacity: 0;
     55                transform: scale3d(.3, .3, .3);
     56        }
     57        20% {
     58                transform: scale3d(1.1, 1.1, 1.1);
     59        }
     60        40% {
     61                transform: scale3d(.9, .9, .9);
     62        }
     63        60% {
     64                opacity: 1;
     65                transform: scale3d(1.03, 1.03, 1.03);
     66        }
     67        80% {
     68                transform: scale3d(.97, .97, .97);
     69        }
     70        to {
     71                opacity: 1;
     72                transform: scale3d(1, 1, 1);
     73        }
     74}
  • src/wp-includes/customize/class-wp-customize-selective-refresh.php

     
    184184                        'renderQueryVar' => self::RENDER_QUERY_VAR,
    185185                        'l10n'           => array(
    186186                                'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
     187                                'clickEditMenu' => __( 'Click to edit this menu.' ),
     188                                'clickEditWidget' => __( 'Click to edit this widget.' ),
     189                                'clickEditTitle' => __( 'Click to edit the site title.' ),
     190                                'clickEditMisc' => __( 'Click to edit this element.' ),
    187191                                /* translators: %s: document.write() */
    188192                                'badDocumentWrite' => sprintf( __( '%s is forbidden' ), 'document.write()' ),
    189193                        ),
  • src/wp-includes/js/customize-preview-widgets.js

     
    357357                                widgetPartial = new self.WidgetPartial( partialId, {
    358358                                        params: {}
    359359                                } );
    360                                 api.selectiveRefresh.partial.add( widgetPartial.id, widgetPartial );
    361360                        }
    362361
    363362                        // Make sure that there is a container element for the widget in the sidebar, if at least a placeholder.
     
    400399                                wasInserted = true;
    401400                        } );
    402401
     402                        api.selectiveRefresh.partial.add( widgetPartial.id, widgetPartial );
     403
    403404                        if ( wasInserted ) {
    404405                                sidebarPartial.reflowWidgets();
    405406                        }
  • src/wp-includes/js/customize-selective-refresh.js

     
    1919
    2020        _.extend( self, api.Events );
    2121
     22        // Extend jQuery to notice element removal and call the 'destroyed' event
     23        $.event.special.destroyed = {
     24                remove: function( o ) {
     25                        if ( o.handler ) {
     26                                o.handler();
     27                        }
     28                }
     29        };
     30
    2231        /**
    2332         * A Customizer Partial.
    2433         *
     
    4352
    4453                id: null,
    4554
     55                editIconSource: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M13 6l5 5-9.507 9.507c-.686-.686-.69-1.794-.012-2.485l-.002-.003c-.69.676-1.8.673-2.485-.013-.677-.677-.686-1.762-.036-2.455l-.008-.008c-.694.65-1.78.64-2.456-.036L13 6zm7.586-.414l-2.172-2.172c-.78-.78-2.047-.78-2.828 0L14 5l5 5 1.586-1.586c.78-.78.78-2.047 0-2.828zM3 18v3h3c0-1.657-1.343-3-3-3z"/></g></svg>',
     56
    4657                 /**
    4758                 * Constructor.
    4859                 *
     
    8596                        var partial = this;
    8697                        _.each( _.pluck( partial.placements(), 'container' ), function( container ) {
    8798                                $( container ).attr( 'title', self.data.l10n.shiftClickToEdit );
     99                                partial.showEditIconForElement( container );
    88100                        } );
    89101                        $( document ).on( 'click', partial.params.selector, function( e ) {
    90102                                if ( ! e.shiftKey ) {
     
    100112                },
    101113
    102114                /**
     115                 * Create and show the edit icon for this element.
     116                 */
     117                showEditIconForElement: function( element ) {
     118                        var partial = this;
     119                        var $icon = this.createEditIcon();
     120                        var $element = $( element );
     121                        $element.before( $icon );
     122                        partial.positionEditIcon( $element, $icon );
     123                        $icon.on( 'click', partial.showControl.bind( this ) );
     124                        $element.on( 'destroyed', function() {
     125                                $icon.remove();
     126                                partial.editIcon = null;
     127                        } );
     128                        api.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
     129                                partial.refreshEditIcon( placement.container );
     130                        } );
     131                        api.selectiveRefresh.bind( 'partial-content-moved', function( placement ) {
     132                                partial.refreshEditIcon( placement.container );
     133                        } );
     134                        // When the sidebar collapses
     135                        api.preview.bind( 'collapse-sidebar', function( collapsed ) {
     136                                return collapsed ? $icon.hide() : $icon.show();
     137                        } );
     138                        partial.editIcon = $icon;
     139                },
     140
     141                refreshEditIcon: function( element ) {
     142                        var partial = this;
     143                        if ( ! partial.editIcon ) {
     144                                this.showEditIconForElement( element );
     145                        }
     146                },
     147
     148                positionEditIcon: function( $element, $icon ) {
     149                        var partial = this;
     150                        if ( $element.css( 'position' ) === 'absolute' ) {
     151                                $icon.css( 'position', 'absolute' );
     152                                $icon.css( partial.getCalculatedCssForIcon( $element ) );
     153                                partial.whenPageChanges( function() {
     154                                        $icon.css( partial.getCalculatedCssForIcon( $element ) );
     155                                } );
     156                        }
     157                },
     158
     159                whenPageChanges: function( callback ) {
     160                        var debouncedCallaback = _.debounce( function() {
     161                                // Timeout allows any page animations to finish
     162                                setTimeout( callback, 100 );
     163                        }, 350 );
     164                        // When window is resized
     165                        $( window ).resize( debouncedCallaback );
     166                        // When any customizer setting changes
     167                        api.bind( 'change', debouncedCallaback );
     168                        var $document = $( window.document );
     169                        // After scroll in case there are fixed position elements
     170                        $document.on( 'scroll', debouncedCallaback );
     171                        // After page click (eg: hamburger menus)
     172                        $document.on( 'click', debouncedCallaback );
     173                },
     174
     175                getCalculatedCssForIcon: function( $element ) {
     176                        var top, right, bottom, left;
     177                        if ( $element.css( 'top' ) ) {
     178                                top = $element.css( 'top' );
     179                        }
     180                        if ( $element.css( 'right' ) ) {
     181                                right = $element.css( 'right' );
     182                        }
     183                        if ( $element.css( 'bottom' ) ) {
     184                                bottom = $element.css( 'bottom' );
     185                        }
     186                        if ( $element.css( 'left' ) ) {
     187                                left = $element.css( 'left' );
     188                        }
     189                        return { top: top || '', right: right || '', bottom: bottom || '', left: left || '' };
     190                },
     191
     192                getIconClassName: function() {
     193                        var partial = this;
     194                        var cleanId = partial.id.replace( /\]/g, '' ).replace( /\[/g, '-' );
     195                        return 'customize-partial-icon-' + cleanId;
     196                },
     197
     198                getIconTitle: function() {
     199                        var l10n = self.data.l10n;
     200                        switch ( this.getType() ) {
     201                                case 'widget':
     202                                        return l10n.clickEditWidget;
     203                                case 'blogname':
     204                                        return l10n.clickEditTitle;
     205                                case 'blogdescription':
     206                                        return l10n.clickEditTitle;
     207                                case 'nav_menu':
     208                                        return l10n.clickEditMenu;
     209                                default:
     210                                        return l10n.clickEditMisc;
     211                        }
     212                },
     213
     214                getType: function() {
     215                        var partial = this;
     216                        var settingId = partial.params.primarySetting || _.first( partial.settings() ) || 'unknown';
     217                        if ( partial.params.type ) {
     218                                return partial.params.type;
     219                        }
     220                        if ( settingId.match( /^nav_menu_instance/ ) ) {
     221                                return 'nav_menu';
     222                        }
     223                        if ( settingId.match( /^widget_/ ) ) {
     224                                return 'widget';
     225                        }
     226                        return settingId;
     227                },
     228
     229                createEditIcon: function() {
     230                        var iconTitle = this.getIconTitle();
     231                        return $( '<button aria-label="' + iconTitle + '" title="' + iconTitle + '" type="button" class="customize-partial-icon ' + this.getIconClassName() + '">' + this.editIconSource + '</button>' );
     232                },
     233
     234                /**
    103235                 * Find all placements for this partial int he document.
    104236                 *
    105237                 * @since 4.5.0
     
    180312                        if ( ! settingId ) {
    181313                                settingId = _.first( partial.settings() );
    182314                        }
     315                        if ( this.getType() === 'nav_menu' ) {
     316                                var menuSlug = partial.params.navMenuArgs.theme_location;
     317                                if ( menuSlug ) {
     318                                        settingId = 'nav_menu_locations[' + menuSlug + ']';
     319                                }
     320                        }
    183321                        api.preview.send( 'focus-control-for-setting', settingId );
    184322                },
    185323