@@ -8,13 +8,13 @@ import * as cg from './types';
88type MouchBind = ( e : cg . MouchEvent ) => void ;
99type StateMouchBind = ( d : State , e : cg . MouchEvent ) => void ;
1010
11- export function bindBoard ( s : State , onResize : ( ) => void ) : void {
11+ export function bindBoard ( s : State ) : void {
1212 const boardEl = s . dom . elements . board ;
1313
1414 // if ('ResizeObserver' in window) new ResizeObserver(onResize).observe(s.dom.elements.wrap);
1515
1616 if ( s . disableContextMenu || s . drawable . enabled ) {
17- boardEl . addEventListener ( 'contextmenu' , e => e . preventDefault ( ) ) ;
17+ boardEl . addEventListener ( 'contextmenu' , ( e ) => e . preventDefault ( ) ) ;
1818 }
1919
2020 if ( s . viewOnly ) return ;
@@ -36,51 +36,53 @@ export function bindDocument(s: State, onResize: () => void): cg.Unbind {
3636
3737 // Old versions of Edge and Safari do not support ResizeObserver. Send
3838 // chessground.resize if a user action has changed the bounds of the board.
39- if ( ! ( 'ResizeObserver' in window ) ) unbinds . push ( unbindable ( document . body , 'chessground.resize' , onResize ) ) ;
39+ if ( ! ( 'ResizeObserver' in window ) )
40+ unbinds . push ( unbindable ( document . body , 'chessground.resize' , onResize ) ) ;
4041
4142 if ( ! s . viewOnly ) {
4243 const onmove = dragOrDraw ( s , drag . move , draw . move ) ;
4344 const onend = dragOrDraw ( s , drag . end , draw . end ) ;
4445
4546 for ( const ev of [ 'touchmove' , 'mousemove' ] )
4647 unbinds . push ( unbindable ( document , ev , onmove as EventListener ) ) ;
47- for ( const ev of [ 'touchend' , 'mouseup' ] ) unbinds . push ( unbindable ( document , ev , onend as EventListener ) ) ;
48+ for ( const ev of [ 'touchend' , 'mouseup' ] )
49+ unbinds . push ( unbindable ( document , ev , onend as EventListener ) ) ;
4850
4951 const onScroll = ( ) => s . dom . bounds . clear ( ) ;
5052 unbinds . push ( unbindable ( document , 'scroll' , onScroll , { capture : true , passive : true } ) ) ;
5153 unbinds . push ( unbindable ( window , 'resize' , onScroll , { passive : true } ) ) ;
5254 }
5355
54- return ( ) => unbinds . forEach ( f => f ( ) ) ;
56+ return ( ) => unbinds . forEach ( ( f ) => f ( ) ) ;
5557}
5658
5759function unbindable (
5860 el : EventTarget ,
5961 eventName : string ,
6062 callback : EventListener ,
61- options ?: AddEventListenerOptions ,
63+ options ?: AddEventListenerOptions
6264) : cg . Unbind {
6365 el . addEventListener ( eventName , callback , options ) ;
6466 return ( ) => el . removeEventListener ( eventName , callback , options ) ;
6567}
6668
6769const startDragOrDraw =
6870 ( s : State ) : MouchBind =>
69- e => {
70- if ( s . draggable . current ) drag . cancel ( s ) ;
71- else if ( s . drawable . current ) draw . cancel ( s ) ;
72- else if ( e . shiftKey || isRightButton ( e ) ) {
73- if ( s . drawable . enabled ) draw . start ( s , e ) ;
74- } else if ( ! s . viewOnly ) {
75- if ( s . dropmode . active ) drop ( s , e ) ;
76- else drag . start ( s , e ) ;
77- }
78- } ;
71+ ( e ) => {
72+ if ( s . draggable . current ) drag . cancel ( s ) ;
73+ else if ( s . drawable . current ) draw . cancel ( s ) ;
74+ else if ( e . shiftKey || isRightButton ( e ) ) {
75+ if ( s . drawable . enabled ) draw . start ( s , e ) ;
76+ } else if ( ! s . viewOnly ) {
77+ if ( s . dropmode . active ) drop ( s , e ) ;
78+ else drag . start ( s , e ) ;
79+ }
80+ } ;
7981
8082const dragOrDraw =
8183 ( s : State , withDrag : StateMouchBind , withDraw : StateMouchBind ) : MouchBind =>
82- e => {
83- if ( s . drawable . current ) {
84- if ( s . drawable . enabled ) withDraw ( s , e ) ;
85- } else if ( ! s . viewOnly ) withDrag ( s , e ) ;
86- } ;
84+ ( e ) => {
85+ if ( s . drawable . current ) {
86+ if ( s . drawable . enabled ) withDraw ( s , e ) ;
87+ } else if ( ! s . viewOnly ) withDrag ( s , e ) ;
88+ } ;
0 commit comments