Changeset 23070
- Timestamp:
- 12/05/2012 09:57:58 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r23069 r23070 1964 1964 }); 1965 1965 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 1966 2018 // wp.media.view.UploaderWindow 1967 2019 // ---------------------------- … … 2805 2857 2806 2858 this.views.render(); 2859 2807 2860 return this; 2808 2861 }, … … 3923 3976 }, 3924 3977 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 3925 3992 deleteAttachment: function(event) { 3926 3993 event.preventDefault(); … … 3946 4013 3947 4014 initialize: function() { 4015 this.focusManager = new media.view.FocusManager({ 4016 el: this.el 4017 }); 4018 3948 4019 this.model.on( 'change:compat', this.render, this ); 3949 4020 }, … … 3954 4025 return; 3955 4026 4027 this.views.detach(); 3956 4028 this.$el.html( compat.item ); 4029 this.views.render(); 4030 4031 this.focusManager.focus(); 3957 4032 return this; 3958 4033 },
Note: See TracChangeset
for help on using the changeset viewer.