Make WordPress Core

Changeset 23070


Ignore:
Timestamp:
12/05/2012 09:57:58 AM (11 years ago)
Author:
markjaquith
Message:

Implement tabbing between fields in the media modal. props lessbloat, koopersmith. fixes #22659

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-views.js

    r23069 r23070  
    19641964    });
    19651965
     1966    // wp.media.view.FocusManager
     1967    // ----------------------------
     1968    media.view.FocusManager = media.View.extend({
     1969        events: {
     1970            keydown: 'recordTab',
     1971            focusin: 'updateIndex'
     1972        },
     1973
     1974        focus: function() {
     1975            if ( _.isUndefined( this.index ) )
     1976                return;
     1977
     1978            // Update our collection of `$tabbables`.
     1979            this.$tabbables = this.$(':tabbable');
     1980
     1981            // If tab is saved, focus it.
     1982            this.$tabbables.eq( this.index ).focus();
     1983        },
     1984
     1985        recordTab: function( event ) {
     1986            // Look for the tab key.
     1987            if ( 9 !== event.keyCode )
     1988                return;
     1989
     1990            // First try to update the index.
     1991            if ( _.isUndefined( this.index ) )
     1992                this.updateIndex( event );
     1993
     1994            // If we still don't have an index, bail.
     1995            if ( _.isUndefined( this.index ) )
     1996                return;
     1997
     1998            var index = this.index + ( event.shiftKey ? -1 : 1 );
     1999
     2000            if ( index >= 0 && index < this.$tabbables.length )
     2001                this.index = index;
     2002            else
     2003                delete this.index;
     2004        },
     2005
     2006        updateIndex: function( event ) {
     2007            this.$tabbables = this.$(':tabbable');
     2008
     2009            var index = this.$tabbables.index( event.target );
     2010
     2011            if ( -1 === index )
     2012                delete this.index;
     2013            else
     2014                this.index = index;
     2015        }
     2016    });
     2017
    19662018    // wp.media.view.UploaderWindow
    19672019    // ----------------------------
     
    28052857
    28062858            this.views.render();
     2859
    28072860            return this;
    28082861        },
     
    39233976        },
    39243977
     3978        initialize: function() {
     3979            this.focusManager = new media.view.FocusManager({
     3980                el: this.el
     3981            });
     3982
     3983            media.view.Attachment.prototype.initialize.apply( this, arguments );
     3984        },
     3985
     3986        render: function() {
     3987            media.view.Attachment.prototype.render.apply( this, arguments );
     3988            this.focusManager.focus();
     3989            return this;
     3990        },
     3991
    39253992        deleteAttachment: function(event) {
    39263993            event.preventDefault();
     
    39464013
    39474014        initialize: function() {
     4015            this.focusManager = new media.view.FocusManager({
     4016                el: this.el
     4017            });
     4018
    39484019            this.model.on( 'change:compat', this.render, this );
    39494020        },
     
    39544025                return;
    39554026
     4027            this.views.detach();
    39564028            this.$el.html( compat.item );
     4029            this.views.render();
     4030
     4031            this.focusManager.focus();
    39574032            return this;
    39584033        },
Note: See TracChangeset for help on using the changeset viewer.