Make WordPress Core

Ticket #27403: 27403.2.diff

File 27403.2.diff, 3.9 KB (added by sirbrillig, 9 years ago)

Updated implementation with button icons, element-paired icons, and menu support

  • src/wp-includes/css/customize-preview.css

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

     
    8585                        var partial = this;
    8686                        _.each( _.pluck( partial.placements(), 'container' ), function( container ) {
    8787                                $( container ).attr( 'title', self.data.l10n.shiftClickToEdit );
     88                                partial.showEditIconForElement( container );
    8889                        } );
    8990                        $( document ).on( 'click', partial.params.selector, function( e ) {
    9091                                if ( ! e.shiftKey ) {
     
    100101                },
    101102
    102103                /**
     104                 * Create and show the edit icon for this element.
     105                 *
     106                 * Specifically:
     107                 *  - create icon element
     108                 *  - add icon to DOM
     109                 *  - position icon relative to target
     110                 *  - add click handler to icon
     111                 *  - monitor DOM for changes and reposition icon when changed
     112                 *  - monitor DOM for sidebar collapse and hide/show icon
     113                 */
     114                showEditIconForElement: function( element ) {
     115                        var partial = this;
     116                        var $icon = this.createEditIcon();
     117                        // TODO: remove the icon if the DOM node is removed
     118                        $( element ).before( $icon );
     119                        $icon.on( 'click', partial.showControl.bind( this ) );
     120                },
     121
     122                getIconClassName: function() {
     123                        var partial = this;
     124                        // TODO: simplify the id string to avoid brackets, etc
     125                        return 'customize-partial-icon-' + partial.id;
     126                },
     127
     128                createEditIcon: function() {
     129                        // TODO: get translated text for title/hover text
     130                        var 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>';
     131                        return $( '<button class="customize-partial-icon ' + this.getIconClassName() + '">' + editIconSource + '</button>' );
     132                },
     133
     134                /**
    103135                 * Find all placements for this partial int he document.
    104136                 *
    105137                 * @since 4.5.0
     
    180212                        if ( ! settingId ) {
    181213                                settingId = _.first( partial.settings() );
    182214                        }
     215                        if ( settingId.match( /^nav_menu_instance/ ) ) {
     216                                var menuSlug = partial.params.navMenuArgs.theme_location;
     217                                if ( menuSlug ) {
     218                                        settingId = 'nav_menu_locations[' + menuSlug + ']';
     219                                }
     220                        }
    183221                        api.preview.send( 'focus-control-for-setting', settingId );
    184222                },
    185223