Skip to content

Commit

Permalink
regenerate a11y-view for phetsims/scenery#362
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Mar 27, 2018
1 parent 6ea25c4 commit 89d5a63
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions resistance-in-a-wire_a11y_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
background: #ccc;
}

.left{
position:fixed;
width:47%;
.left {
position: fixed;
width: 47%;
}

/* This class was found online as a way to preserve an iframe aspect ratio,
Expand Down Expand Up @@ -93,6 +93,10 @@
background-color: #9adaa6;
border-bottom: double 3px #000; /*or a border in dark green*/
}

.highlight {
border: thick double red;
}
</style>

</head>
Expand All @@ -108,7 +112,7 @@ <h3>Resistance in a Wire in iframe</h3>
<iframe id="iframe" allowfullscreen title="Interact with Resistance in a Wire"></iframe>
</div>
<div id="alerts">
<h3>Interactive alerts</h3>
<h3>Activity log - The most recent Interactive Alerts.</h3>
<div id=alert-copy-container class=alert_copy_container>
<div id='polite-element-container'>
<ul class='alert_copy' id='alert-list'></ul>
Expand All @@ -117,25 +121,25 @@ <h3>Interactive alerts</h3>
</div>
</div>


<!--The PDOM copy will be placed in this container, along with a section just for alerts -->
<div class="right">
<div id="intro">
<h1>Resistance in a Wire A11y View: Visual and Described content side by side</h1>
<p>
The accessible version of Resistance in a Wire is embedded in the iframe. As you interact with the visual sim in
the iframe with either a keyboard or mouse, the descriptions for the sim automatically update on the right in a
copy of the sim's structured Parallel Document Object Model, or PDOM.
</p>
<!--The PDOM copy will be placed in this container, along with a section just for alerts -->
<div class="right">
<div id="intro">
<h1>Resistance in a Wire A11y View: Visual and Described content side by side</h1>
<p>
The accessible version of Resistance in a Wire is embedded in the iframe. As you interact with the visual sim in
the iframe with either a keyboard or mouse, the descriptions for the sim automatically update on the right in
a
copy of the sim's structured Parallel Document Object Model, or PDOM.
</p>
</div>
<h2>Resistance in a Wire descriptions structured in a Parallel DOM</h2>
<h3>Static and Dynamic Descriptions</h3>
<div id="dom-copy-container" class="dom_copy_container" role="presentation"></div>
</div>
<h2>Resistance in a Wire descriptions structured in a Parallel DOM</h2>
<h3>Static and Dynamic Descriptions</h3>
<div id="dom-copy-container" class="dom_copy_container" role="presentation"></div>
</div>

<!--clear the blocks after the float effect-->
<div class="clearfix"></div>
</div>
<!--clear the blocks after the float effect-->
<div class="clearfix"></div>
</div>

</div>

Expand Down Expand Up @@ -202,8 +206,11 @@ <h3>Static and Dynamic Descriptions</h3>
var pDOM = innerDoc.getElementsByClassName( 'accessibility' )[ 0 ];
var pDOMCopy = pDOM.cloneNode( true );

// get the alert dom elements from the iframe's pDOM
var politeElement = innerDoc.getElementById( 'polite' );
// get the alert dom elements from the iframe's inner document
var politeElement1 = innerDoc.getElementById( 'polite-1' );
var politeElement2 = innerDoc.getElementById( 'polite-2' );
var politeElement3 = innerDoc.getElementById( 'polite-3' );
var politeElement4 = innerDoc.getElementById( 'polite-4' );

// get the alert dom elements from the pDOM copy
var alertList = document.getElementById( 'alert-list' );
Expand Down Expand Up @@ -300,7 +307,7 @@ <h3>Static and Dynamic Descriptions</h3>
function addLiveObserver( originalElement, listElement ) {
var liveObserver = new MutationObserver( function( mutations ) {
mutations.forEach( function( mutation ) {
var alertText = mutation.target.textContent
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
Expand All @@ -326,7 +333,7 @@ <h3>Static and Dynamic Descriptions</h3>
fadeChild.style.opacity = fadeChild.style.opacity * 0.95;

// stop animating and remove child
if( listElement.contains( fadeChild ) && fadeChild.style.opacity < 0.1 ) {
if ( listElement.contains( fadeChild ) && fadeChild.style.opacity < 0.1 ) {
window.clearInterval( intervalId );
listElement.removeChild( fadeChild );
}
Expand All @@ -340,10 +347,25 @@ <h3>Static and Dynamic Descriptions</h3>
liveObserver.observe( originalElement, config )
}

addLiveObserver( politeElement, alertList );
// observe each of the live elements and add new text content to the list view
addLiveObserver( politeElement1, alertList );
addLiveObserver( politeElement2, alertList );
addLiveObserver( politeElement3, alertList );
addLiveObserver( politeElement4, alertList );

// set focus to the loaded iframe
document.getElementById( 'iframe' ).focus();

// Provide fake focus highlighting to the PDOM copy based on what is actually highlighted in the sim.
var previousElement = null;
setInterval( function() {

if ( previousElement ) {
previousElement.classList.remove( 'highlight' );
}
previousElement = document.getElementById( 'iframe' ).contentWindow.document.activeElement;
previousElement.classList.add( 'highlight' );
}, 500 );
}
} );
</script>
Expand Down

0 comments on commit 89d5a63

Please sign in to comment.