| 1 | Index: wp-includes/js/media-views.js |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/js/media-views.js (revision 23066) |
|---|
| 4 | +++ wp-includes/js/media-views.js (working copy) |
|---|
| 5 | @@ -1991,6 +1991,58 @@ |
|---|
| 6 | } |
|---|
| 7 | }); |
|---|
| 8 | |
|---|
| 9 | + // wp.media.view.FocusManager |
|---|
| 10 | + // ---------------------------- |
|---|
| 11 | + media.view.FocusManager = media.View.extend({ |
|---|
| 12 | + events: { |
|---|
| 13 | + keydown: 'recordTab', |
|---|
| 14 | + focusin: 'updateIndex' |
|---|
| 15 | + }, |
|---|
| 16 | + |
|---|
| 17 | + focus: function() { |
|---|
| 18 | + if ( _.isUndefined( this.index ) ) |
|---|
| 19 | + return; |
|---|
| 20 | + |
|---|
| 21 | + // Update our collection of `$tabbables`. |
|---|
| 22 | + this.$tabbables = this.$(':tabbable'); |
|---|
| 23 | + |
|---|
| 24 | + // If tab is saved, focus it. |
|---|
| 25 | + this.$tabbables.eq( this.index ).focus(); |
|---|
| 26 | + }, |
|---|
| 27 | + |
|---|
| 28 | + recordTab: function( event ) { |
|---|
| 29 | + // Look for the tab key. |
|---|
| 30 | + if ( 9 !== event.keyCode ) |
|---|
| 31 | + return; |
|---|
| 32 | + |
|---|
| 33 | + // First try to update the index. |
|---|
| 34 | + if ( _.isUndefined( this.index ) ) |
|---|
| 35 | + this.updateIndex( event ); |
|---|
| 36 | + |
|---|
| 37 | + // If we still don't have an index, bail. |
|---|
| 38 | + if ( _.isUndefined( this.index ) ) |
|---|
| 39 | + return; |
|---|
| 40 | + |
|---|
| 41 | + var index = this.index + ( event.shiftKey ? -1 : 1 ); |
|---|
| 42 | + |
|---|
| 43 | + if ( index >= 0 && index < this.$tabbables.length ) |
|---|
| 44 | + this.index = index; |
|---|
| 45 | + else |
|---|
| 46 | + delete this.index; |
|---|
| 47 | + }, |
|---|
| 48 | + |
|---|
| 49 | + updateIndex: function( event ) { |
|---|
| 50 | + this.$tabbables = this.$(':tabbable'); |
|---|
| 51 | + |
|---|
| 52 | + var index = this.$tabbables.index( event.target ); |
|---|
| 53 | + |
|---|
| 54 | + if ( -1 === index ) |
|---|
| 55 | + delete this.index; |
|---|
| 56 | + else |
|---|
| 57 | + this.index = index; |
|---|
| 58 | + } |
|---|
| 59 | + }); |
|---|
| 60 | + |
|---|
| 61 | // wp.media.view.UploaderWindow |
|---|
| 62 | // ---------------------------- |
|---|
| 63 | media.view.UploaderWindow = media.View.extend({ |
|---|
| 64 | @@ -2832,6 +2884,7 @@ |
|---|
| 65 | this.updateSave(); |
|---|
| 66 | |
|---|
| 67 | this.views.render(); |
|---|
| 68 | + |
|---|
| 69 | return this; |
|---|
| 70 | }, |
|---|
| 71 | |
|---|
| 72 | @@ -3951,6 +4004,20 @@ |
|---|
| 73 | 'click .delete-attachment': 'deleteAttachment' |
|---|
| 74 | }, |
|---|
| 75 | |
|---|
| 76 | + initialize: function() { |
|---|
| 77 | + this.focusManager = new media.view.FocusManager({ |
|---|
| 78 | + el: this.el |
|---|
| 79 | + }); |
|---|
| 80 | + |
|---|
| 81 | + media.view.Attachment.prototype.initialize.apply( this, arguments ); |
|---|
| 82 | + }, |
|---|
| 83 | + |
|---|
| 84 | + render: function() { |
|---|
| 85 | + media.view.Attachment.prototype.render.apply( this, arguments ); |
|---|
| 86 | + this.focusManager.focus(); |
|---|
| 87 | + return this; |
|---|
| 88 | + }, |
|---|
| 89 | + |
|---|
| 90 | deleteAttachment: function(event) { |
|---|
| 91 | event.preventDefault(); |
|---|
| 92 | |
|---|
| 93 | @@ -3974,6 +4041,10 @@ |
|---|
| 94 | }, |
|---|
| 95 | |
|---|
| 96 | initialize: function() { |
|---|
| 97 | + this.focusManager = new media.view.FocusManager({ |
|---|
| 98 | + el: this.el |
|---|
| 99 | + }); |
|---|
| 100 | + |
|---|
| 101 | this.model.on( 'change:compat', this.render, this ); |
|---|
| 102 | }, |
|---|
| 103 | |
|---|
| 104 | @@ -3982,7 +4053,11 @@ |
|---|
| 105 | if ( ! compat || ! compat.item ) |
|---|
| 106 | return; |
|---|
| 107 | |
|---|
| 108 | + this.views.detach(); |
|---|
| 109 | this.$el.html( compat.item ); |
|---|
| 110 | + this.views.render(); |
|---|
| 111 | + |
|---|
| 112 | + this.focusManager.focus(); |
|---|
| 113 | return this; |
|---|
| 114 | }, |
|---|
| 115 | |
|---|