Skip to content

Commit

Permalink
generate a11y-view for phetsims/scenery-phet#490
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Apr 16, 2019
1 parent 1382d77 commit f60bbb7
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions john-travoltage_a11y_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,38 +381,41 @@ <h3>PDOM & Descriptions for John Travoltage</h3>
function addLiveObserver( originalElement, listElement ) {
var liveObserver = new MutationObserver( function( mutations ) {
mutations.forEach( function( mutation ) {
var alertText = mutation.target.textContent;

// update the text content of the copied element to match the element in the iframe document
// create a list item to add to the alert list
if ( alertText.length > 0 ) {
var listItem = document.createElement( 'li' );
listItem.style.opacity = 1.0;
listItem.textContent = alertText;
listElement.insertBefore( listItem, listElement.children[ 0 ] );

// items fade out as they get older
for ( var j = 0; j < listElement.children.length; j++ ) {
listElement.children[ j ].style.opacity = 1.0 / ( j + 1 ) + 0.25;
}

// if the list is too large, remove the last items from the list
var childrenArray = Array.prototype.slice.call( listElement.children );
var fadeArray = childrenArray.slice( 5, childrenArray.length );

for ( var i = 0; i < fadeArray.length; i++ ) {
var fadeChild = fadeArray[ i ];

var fadeout = function() {
fadeChild.style.opacity = fadeChild.style.opacity * 0.95;

// stop animating and remove child
if ( listElement.contains( fadeChild ) && fadeChild.style.opacity < 0.1 ) {
window.clearInterval( intervalId );
listElement.removeChild( fadeChild );
}
};
var intervalId = window.setInterval( fadeout, 20 );
if ( mutation.addedNodes.length > 0 ) {
var alertText = mutation.target.textContent;

// update the text content of the copied element to match the element in the iframe document
// create a list item to add to the alert list
if ( alertText.length > 0 ) {
var listItem = document.createElement( 'li' );
listItem.style.opacity = 1.0;
listItem.textContent = alertText;
listElement.insertBefore( listItem, listElement.children[ 0 ] );

// items fade out as they get older
for ( var j = 0; j < listElement.children.length; j++ ) {
listElement.children[ j ].style.opacity = 1.0 / ( j + 1 ) + 0.25;
}

// if the list is too large, remove the last items from the list
var childrenArray = Array.prototype.slice.call( listElement.children );
var fadeArray = childrenArray.slice( 5, childrenArray.length );

for ( var i = 0; i < fadeArray.length; i++ ) {
var fadeChild = fadeArray[ i ];

var fadeout = function() {
fadeChild.style.opacity = fadeChild.style.opacity * 0.95;

// stop animating and remove child
if ( listElement.contains( fadeChild ) && fadeChild.style.opacity < 0.1 ) {
window.clearInterval( intervalId );
listElement.removeChild( fadeChild );
}
};
var intervalId = window.setInterval( fadeout, 20 );
}
}
}
} );
Expand Down

0 comments on commit f60bbb7

Please sign in to comment.