Make WordPress Core

Ticket #22502: 22502.4.diff

File 22502.4.diff, 7.4 KB (added by lessbloat, 12 years ago)
  • wp-includes/js/media-editor.js

     
    535535                                workflow.open();
    536536                        else
    537537                                workflow = wp.media.editor.add( id );
    538 
     538                       
     539                        // Add focus to modal
     540                        $( '.media-menu .active' ).focus();
     541                       
    539542                        return workflow;
    540543                }
    541544        };
  • wp-includes/js/media-views.js

     
    16481648                tagName:  'div',
    16491649                template: media.template('media-modal'),
    16501650
     1651                attributes: {
     1652                        tabindex: 0
     1653                },
     1654
    16511655                events: {
    1652                         'click .media-modal-backdrop, .media-modal-close' : 'closeHandler'
     1656                        'click .media-modal-backdrop, .media-modal-close': 'closeHandler',
     1657                        'keydown': 'keydown'
    16531658                },
    16541659
    16551660                initialize: function() {
     
    16591664                                container: document.body,
    16601665                                title:     ''
    16611666                        });
     1667
     1668                        _.bindAll( this, '_captureBodyKeydown' );
    16621669                },
    16631670
    16641671                render: function() {
     
    16911698                },
    16921699
    16931700                open: function() {
     1701                        document.addEventListener( 'keydown', this._captureBodyKeydown, true );
    16941702                        this.$el.show();
    16951703                        this.trigger('open');
    16961704                        return this;
    16971705                },
    16981706
    16991707                close: function() {
     1708                        document.removeEventListener( 'keydown', this._captureBodyKeydown, true );
    17001709                        this.$el.hide();
    17011710                        this.trigger('close');
    17021711                        return this;
     
    17151724                        // Set and render the content.
    17161725                        this.options.$content = ( $content instanceof Backbone.View ) ? $content.$el : $content;
    17171726                        return this.render();
     1727                },
     1728
     1729
     1730                // Thanks to jQuery UI dialog, which also limits tabbing to a modal
     1731                // window. The `:tabbable` expression, `$.ui.keyCode` object, and
     1732                // the overloaded `$.fn.focus( delay )` signature are all from the
     1733                // jQuery UI core.
     1734                keydown: function( event ) {
     1735                        var tabbables, first, last;
     1736
     1737                        // Close the modal when escape is pressed.
     1738                        if ( $.ui.keyCode.ESCAPE === event.which ) {
     1739                                event.preventDefault();
     1740                                this.close();
     1741                                return;
     1742                        }
     1743
     1744                        // Prevent tabbing outside of the modal.
     1745                        if ( event.keyCode !== $.ui.keyCode.TAB )
     1746                                return;
     1747
     1748                        tabbables = this.$(':tabbable');
     1749                        first     = tabbables.filter(':first');
     1750                        last      = tabbables.filter(':last');
     1751
     1752                        // If we attempt to tab past the last tabbable element, skip
     1753                        // straight to the first tabbable element (and vice versa).
     1754                        if ( event.target === last[0] && ! event.shiftKey ) {
     1755                                first.focus( 1 );
     1756                                return false;
     1757                        } else if ( event.target === first[0] && event.shiftKey ) {
     1758                                last.focus( 1 );
     1759                                return false;
     1760                        }
     1761                },
     1762
     1763                // If the focus somehow escapes the modal, restores focus to the
     1764                // first focusable element inside the modal.
     1765                //
     1766                // Captures the document's keydown event when the modal is open.
     1767                _captureBodyKeydown: function() {
     1768                        if ( event.keyCode !== $.ui.keyCode.TAB )
     1769                                return;
     1770
     1771                        if ( ! $.contains( this.el, document.activeElement ) )
     1772                                this.$(':tabbable').first().focus( 1 );
    17181773                }
    17191774        });
    17201775
     
    23472402         * wp.media.view.Menu
    23482403         */
    23492404        media.view.Menu = media.view.PriorityList.extend({
    2350                 tagName:   'ul',
    23512405                className: 'media-menu',
    23522406
    23532407                toView: function( options, state ) {
     
    23722426        });
    23732427
    23742428        media.view.MenuItem = media.View.extend({
    2375                 tagName:   'li',
     2429                tagName:   'a',
    23762430                className: 'media-menu-item',
    23772431
     2432                attributes: {
     2433                        href: '#'
     2434                },
     2435
    23782436                events: {
    23792437                        'click': 'click'
    23802438                },
    23812439
    2382                 click: function() {
     2440                click: function( event ) {
    23832441                        var options = this.options;
    23842442
     2443                        event.preventDefault();
     2444
    23852445                        if ( options.click )
    23862446                                options.click.call( this );
    23872447                        else if ( options.state )
     
    24172477
    24182478                events: {
    24192479                        'click .attachment-preview':      'toggleSelection',
     2480                        'keydown .attachment-preview':    'keydown',
    24202481                        'change [data-setting]':          'updateSetting',
    24212482                        'change [data-setting] input':    'updateSetting',
    24222483                        'change [data-setting] select':   'updateSetting',
     
    24932554                                this.$bar.width( this.model.get('percent') + '%' );
    24942555                },
    24952556
    2496                 toggleSelection: function( event ) {
     2557                keydown: function( event ) {
     2558                        if ( $.ui.keyCode.ENTER === event.keyCode )
     2559                                this.toggleSelection();
     2560                },
     2561
     2562                toggleSelection: function() {
    24972563                        var selection = this.options.selection,
    24982564                                model = this.model;
    24992565
     
    31813247                clear: function( event ) {
    31823248                        event.preventDefault();
    31833249                        this.collection.clear();
     3250                        $( '.attachments .attachment-preview' ).first().focus();
    31843251                }
    31853252        });
    31863253
     
    32573324                clear: function( event ) {
    32583325                        event.preventDefault();
    32593326                        this.collection.clear();
     3327                        $( '.attachments .attachment-preview' ).first().focus();
    32603328                }
    32613329        });
    32623330
  • wp-includes/media.php

     
    16031603        </script>
    16041604
    16051605        <script type="text/html" id="tmpl-attachment">
    1606                 <div class="attachment-preview type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}">
     1606                <div class="attachment-preview type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}" tabindex="0">
    16071607                        <# if ( data.uploading ) { #>
    16081608                                <div class="media-progress-bar"><div></div></div>
    16091609                        <# } else if ( 'image' === data.type ) { #>
     
    16241624                        <# } #>
    16251625
    16261626                        <# if ( data.buttons.check ) { #>
    1627                                 <a class="check" href="#" title="<?php _e('Deselect'); ?>"><div class="media-modal-icon"></div></a>
     1627                                <a class="check" href="#" tabindex="-1"><div class="media-modal-icon"></div></a>
    16281628                        <# } #>
    16291629                </div>
    16301630                <# if ( data.describe ) { #>
  • wp-includes/css/media-views.css

     
    103103        border: 1px dashed rgba( 255, 255, 255, 0.5 );
    104104}
    105105
    106 .media-modal-title,
    107 .media-modal-close {
     106.media-modal-title {
    108107        position: absolute;
    109108        height: 40px;
    110109}
     
    123122}
    124123
    125124.media-modal-close {
     125        position: absolute;
     126        height: 15px;
    126127        top: -27px;
    127128        right: 0;
    128129        width: 15px;
    129130        background-position: -80px 0;
    130131}
    131132
     133.media-modal-close:focus {
     134        outline: thin dotted gray;
     135}
     136
    132137.media-modal-close:active {
    133138        outline: 0;
    134139}
     
    366371        user-select: none;
    367372}
    368373
    369 .media-menu li {
     374.media-menu .media-menu-item {
     375        display: block;
    370376        position: relative;
    371377        padding: 4px 20px;
    372378        margin: 0;
    373379        line-height: 18px;
    374380        font-size: 14px;
    375         color: #21759B;
    376381        text-shadow: 0 1px 0 #fff;
     382        text-decoration: none;
    377383}
    378384
    379 .media-menu-item {
    380         cursor: pointer;
    381 }
    382 
    383 .media-menu li:hover {
     385.media-menu .media-menu-item:hover,
     386.media-menu .media-menu-item:focus {
     387        color: #21759B;
     388        background: #f1f1f1;
    384389        background: rgba( 0, 0, 0, 0.04 );
     390        outline: none;
    385391}
    386392
    387 .media-menu .active,
    388 .media-menu .active:hover {
     393.media-menu .media-menu-item.active,
     394.media-menu .media-menu-item.active:hover {
    389395        color: #333;
    390396        font-weight: bold;
    391397}
     
    517523        cursor: pointer;
    518524}
    519525
     526.attachment-preview:focus,
     527.media-selection .selected .attachment-preview:focus {
     528        box-shadow:
     529                0 0 0 1px #fff,
     530                0 0 0 2px #999;
     531}
     532
     533.selected .attachment-preview:focus,
     534.media-selection .selected.details .attachment-preview:focus {
     535        box-shadow: 0 0 0 0;
     536}
     537
    520538.attachment .icon {
    521539        margin: 0 auto;
    522540        overflow: hidden;
     
    13591377                width: 119px;
    13601378        }
    13611379
    1362         .media-menu li {
     1380        .media-menu .media-menu-item {
    13631381                padding: 4px 10px;
    13641382        }
    13651383