Skip to content

Commit

Permalink
detect slider track drags so sound isn't played every time, see #204
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Dec 28, 2018
1 parent 28dbf66 commit 9bfc580
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 6 additions & 7 deletions js/resistance-in-a-wire/view/ResistanceSoundGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ define( function( require ) {

/**
* @constructor
* TODO: document when finalized
* {Object} config
*/
function ResistanceSoundGenerator( config ) {
Expand Down Expand Up @@ -60,11 +59,11 @@ define( function( require ) {
var resistivityBin = resistivityBinSelector.selectBin( config.resistivityProperty.value );
config.resistivityProperty.lazyLink( function( resistivity ) {
var bin = resistivityBinSelector.selectBin( resistivity );
var changedViaKeyboard = !config.resistivitySlider.thumbDragging && !config.resistivitySlider.trackDragging;

// Play the sound if a change has occurred due to keyboard interaction, if the area value has moved to a new bin,
// or if a min or max has been reached.
if ( !config.resistivitySlider.thumbDragging || bin !== resistivityBin ||
resistivity === MIN_RESISTIVITY || resistivity === MAX_RESISTIVITY ) {
if ( changedViaKeyboard || bin !== resistivityBin || resistivity === MIN_RESISTIVITY || resistivity === MAX_RESISTIVITY ) {
playResistanceSound();
}
resistivityBin = bin;
Expand All @@ -75,11 +74,11 @@ define( function( require ) {
var lengthBin = lengthBinSelector.selectBin( config.lengthProperty.value );
config.lengthProperty.lazyLink( function( length ) {
var bin = lengthBinSelector.selectBin( length );
var changedViaKeyboard = !config.lengthSlider.thumbDragging && !config.lengthSlider.trackDragging;

// Play the sound if a change has occurred due to keyboard interaction, if the area value has moved to a new bin,
// or if a min or max has been reached.
if ( !config.lengthSlider.thumbDragging || bin !== lengthBin ||
length === MIN_LENGTH || length === MAX_LENGTH ) {
if ( changedViaKeyboard || bin !== lengthBin || length === MIN_LENGTH || length === MAX_LENGTH ) {
playResistanceSound();
}
lengthBin = bin;
Expand All @@ -90,11 +89,11 @@ define( function( require ) {
var areaBin = areaBinSelector.selectBin( config.areaProperty.value );
config.areaProperty.lazyLink( function( area ) {
var bin = areaBinSelector.selectBin( area );
var changedViaKeyboard = !config.areaSlider.thumbDragging && !config.areaSlider.trackDragging;

// Play the sound if a change has occurred due to keyboard interaction, if the area value has moved to a new bin,
// or if a min or max has been reached.
if ( !config.areaSlider.thumbDragging || bin !== areaBin ||
area === MIN_AREA || area === MAX_AREA ) {
if ( changedViaKeyboard || bin !== areaBin || area === MIN_AREA || area === MAX_AREA ) {
playResistanceSound();
}
areaBin = bin;
Expand Down
11 changes: 11 additions & 0 deletions js/resistance-in-a-wire/view/SliderUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ define( function( require ) {

// pass the value through from the actual slider component
return this.slider.thumbDragging;
},

/**
* flag indicating whether the slider thumb is being dragged
* @return {boolean}
*/
get trackDragging() {

// pass the value through from the actual slider component
return this.slider.track.trackDragging;
}

} );
} );

0 comments on commit 9bfc580

Please sign in to comment.