Skip to content

Commit

Permalink
formatted value text for #71
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Aug 7, 2017
1 parent 002f67f commit ec81d19
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
33 changes: 33 additions & 0 deletions js/ohms-law/OhmsLawA11yStrings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2017, University of Colorado Boulder

/**
* Single location of all accessibility strings. These strings are not meant to be translatable yet. Rosetta needs
* some work to provide translators with context for these strings, and we want to receive some community feedback
* before these strings are submitted for translation.
*
* @author Jesse Greenberg
*/
define( function( require ) {
'use strict';

var ohmsLaw = require( 'OHMS_LAW/ohmsLaw' );

var OhmsLawA11yStrings = {
resistanceUnitsPatternString: '{{value}} Ohms',
voltageUnitsPatternString: '{{value}} Volts'

};

if ( phet.chipper.queryParameters.stringTest === 'xss' ) {
for ( var key in OhmsLawA11yStrings ) {
OhmsLawA11yStrings[ key ] += '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NkYGD4DwABCQEBtxmN7wAAAABJRU5ErkJggg==" onload="window.location.href=atob(\'aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQ==\')" />';
}
}

// verify that object is immutable, without the runtime penalty in production code
if ( assert ) { Object.freeze( OhmsLawA11yStrings ); }

ohmsLaw.register( 'OhmsLawA11yStrings', OhmsLawA11yStrings );

return OhmsLawA11yStrings;
} );
14 changes: 11 additions & 3 deletions js/ohms-law/view/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ define( function( require ) {
var OhmsLawConstants = require( 'OHMS_LAW/ohms-law/OhmsLawConstants' );
var Panel = require( 'SUN/Panel' );
var SliderUnit = require( 'OHMS_LAW/ohms-law/view/SliderUnit' );
var OhmsLawA11yStrings = require( 'OHMS_LAW/ohms-law/OhmsLawA11yStrings' );

// strings
var resistanceUnitsString = require( 'string!OHMS_LAW/resistanceUnits' );
Expand All @@ -24,6 +25,11 @@ define( function( require ) {
var voltageSymbolString = require( 'string!OHMS_LAW/voltageSymbol' );
var voltageString = require( 'string!OHMS_LAW/voltage' );

// a11y strings - these strings are not meant to be translatable until the translation utility
// can provide translators with context
var resistanceUnitsPatternString = OhmsLawA11yStrings.resistanceUnitsPatternString;
var voltageUnitsPatternString = OhmsLawA11yStrings.voltageUnitsPatternString;

/**
* @param {Property.<number>} voltageProperty
* @param {Property.<number>} resistanceProperty
Expand Down Expand Up @@ -51,7 +57,9 @@ define( function( require ) {
tandem.createTandem( 'voltageSlider' ),
{
keyboardStep: 0.5, // volts
shiftKeyboardStep: 0.1 // volts
shiftKeyboardStep: 0.1, // volts
accessibleDecimalPlaces: 1,
accessibleValuePattern: voltageUnitsPatternString
} );

// Create the resistance slider with readout and labels
Expand All @@ -63,9 +71,9 @@ define( function( require ) {
resistanceUnitsString,
tandem.createTandem( 'resistanceSlider' ),
{
numberDecimalPlaces: 0,
keyboardStep: 20, // ohms
shiftKeyboardStep: 1 // ohms
shiftKeyboardStep: 1, // ohms
accessibleValuePattern: resistanceUnitsPatternString
} );

// Use a content node so that the Panel can surround it fully
Expand Down
12 changes: 7 additions & 5 deletions js/ohms-law/view/SliderUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ define( function( require ) {
function SliderUnit( property, range, symbolString, nameString, unitString, tandem, options ) {

options = _.extend( {
numberDecimalPlaces: 1,
accessibleDecimalPlaces: 0,
keyboardStep: 1,
shiftKeyboardStep: 0.1
shiftKeyboardStep: 0.1,
accessibleValuePattern: '{{value}}' // string pattern used for formating the value read by the screen reader
}, options );

Node.call( this );
Expand All @@ -52,7 +53,8 @@ define( function( require ) {
trackSize: new Dimension2( OhmsLawConstants.SLIDER_HEIGHT, 4 ),
keyboardStep: options.keyboardStep,
shiftKeyboardStep: options.shiftKeyboardStep,
numberDecimalPlaces: options.numberDecimalPlaces,
accessibleDecimalPlaces: options.accessibleDecimalPlaces,
accessibleValuePattern: options.accessibleValuePattern,
tandem: tandem.createTandem( 'slider' )
} );

Expand All @@ -76,7 +78,7 @@ define( function( require ) {
children: [ symbolText, nameText ]
} );

var valueText = new Text( Util.toFixed( range.max, options.numberDecimalPlaces ), {
var valueText = new Text( Util.toFixed( range.max, options.accessibleDecimalPlaces ), {
font: OhmsLawConstants.READOUT_FONT,
fill: OhmsLawConstants.BLACK_COLOR,
tandem: tandem.createTandem( 'valueText' )
Expand Down Expand Up @@ -112,7 +114,7 @@ define( function( require ) {

// Update value of the readout. Present for the lifetime of the simulation; no need to unlink.
property.link( function( value ) {
valueText.text = Util.toFixed( value, options.numberDecimalPlaces );
valueText.text = Util.toFixed( value, options.accessibleDecimalPlaces );
readout.centerX = readoutBackground.selfBounds.centerX;
} );

Expand Down

0 comments on commit ec81d19

Please sign in to comment.