Skip to content

Commit

Permalink
sorting of HTMLElements in AccessibleInstance more efficient, #715
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jun 19, 2018
1 parent f7139ad commit 73bf610
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions js/accessibility/AccessibleInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,19 @@ define( function( require ) {
// Reorder DOM elements in a way that doesn't do any work if they are already in a sorted order.
var primarySibling = this.peer.primarySibling;

for ( var i = 0; i < this.children.length; i++ ) {
var peerDOMElements = this.children[ i ].peer.topLevelElements;
var i = primarySibling.childNodes.length - 1;
for ( var peerIndex = this.children.length - 1; peerIndex >= 0; peerIndex-- ) {
var peer = this.children[ peerIndex ].peer;
for ( var elementIndex = peer.topLevelElements.length - 1; elementIndex >= 0; elementIndex-- ) {
var element = peer.topLevelElements[ elementIndex ];

// no need to reinsert if `element` is already in the right order
if ( primarySibling.childNodes[ i ] !== element ) {
primarySibling.insertBefore( element, primarySibling.childNodes[ i + 1 ] );
}

// TODO: effeciency check, will this hold up a scenery code review? see https://github.com/phetsims/scenery/issues/715
AccessibilityUtil.insertElements( primarySibling, peerDOMElements );
i--;
}
}
},

Expand Down

0 comments on commit 73bf610

Please sign in to comment.