@@ -337,7 +337,7 @@ var ImageDiff = React.createClass({
337337 'blink' : ImageBlinker ,
338338 'onion-skin' : ImageOnionSkin ,
339339 'swipe' : ImageSwipe
340- } [ this . props . imageDiffMode ] ;
340+ } [ mode ] ;
341341 var image = component ( {
342342 filePair : this . props . filePair ,
343343 shrinkToFit : this . state . shrinkToFit
@@ -449,19 +449,31 @@ var ImageBlinker = React.createClass({
449449 filePair : React . PropTypes . object . isRequired ,
450450 shrinkToFit : React . PropTypes . bool
451451 } ,
452+ mixins : [ SetIntervalMixin ] ,
452453 getInitialState : function ( ) {
453- return { idx : 0 } ;
454+ return { idx : 0 , autoBlink : true } ;
455+ } ,
456+ toggleAutoBlink : function ( e ) {
457+ this . setState ( {
458+ autoBlink : $ ( this . refs . autoblink . getDOMNode ( ) ) . is ( ':checked' )
459+ } ) ;
454460 } ,
455461 render : function ( ) {
456462 var pair = this . props . filePair ;
457463 var side = [ 'a' , 'b' ] [ this . state . idx ] ;
458464 var path = [ pair . a , pair . b ] [ this . state . idx ] ;
459465 var maxWidth = this . props . shrinkToFit ? window . innerWidth - 30 : null ;
460- return < table id = "imagediff" >
461- < tr className = "image-diff-content" >
462- < td > < AnnotatedImage filePair = { pair } side = { side } maxWidth = { maxWidth } /> </ td >
463- </ tr >
464- </ table > ;
466+ return (
467+ < div >
468+ < input ref = "autoblink" type = "checkbox" id = "autoblink" checked = { this . state . autoBlink } onChange = { this . toggleAutoBlink } />
469+ < label htmlFor = "autoblink" > Auto-blink (hit ‘b’ to blink manually)</ label >
470+ < table id = "imagediff" >
471+ < tr className = "image-diff-content" >
472+ < td > < AnnotatedImage filePair = { pair } side = { side } maxWidth = { maxWidth } /> </ td >
473+ </ tr >
474+ </ table >
475+ </ div >
476+ ) ;
465477 } ,
466478 componentDidMount : function ( ) {
467479 var toggle = ( ) => {
@@ -473,9 +485,16 @@ var ImageBlinker = React.createClass({
473485 $ ( document ) . on ( 'keydown.blink' , ( e ) => {
474486 if ( ! isLegitKeypress ( e ) ) return ;
475487 if ( e . keyCode == 66 ) { // 'b'
476- toggle ( ) ;
488+ if ( this . isMounted ( ) ) {
489+ this . setState ( { autoBlink : false } ) ;
490+ toggle ( ) ;
491+ }
477492 }
478493 } ) . on ( 'click.blink' , 'a[value="blink"]' , toggle ) ;
494+
495+ this . setInterval ( ( ) => {
496+ if ( this . state . autoBlink ) toggle ( ) ;
497+ } , 500 ) ;
479498 } ,
480499 componentDidUnmount : function ( e ) {
481500 $ ( document ) . off ( 'keydown.blink' ) . off ( 'click.blink' ) ;
0 commit comments