Skip to content

Commit 4608077

Browse files
committed
introduce helper
1 parent e6a12ba commit 4608077

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

js/webui/src/elements.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export const Button = React.forwardRef(Button_);
7474

7575
const repeatInterval = 500;
7676

77+
function isLeftButtonOrTouch(e)
78+
{
79+
return e.button === 0 || typeof e.touches != 'undefined';
80+
}
81+
7782
export class RepeatingButton extends React.PureComponent
7883
{
7984
constructor(props)
@@ -112,26 +117,20 @@ export class RepeatingButton extends React.PureComponent
112117

113118
handleStart(e)
114119
{
115-
if (e.button !== 0 && typeof e.touches === 'undefined')
120+
if (!isLeftButtonOrTouch(e) || this.intervalId)
116121
return;
117122

118-
if (!this.intervalId)
119-
{
120-
this.hasInitialClick = false;
121-
this.intervalId = setInterval(this.handleTimer, repeatInterval);
122-
}
123+
this.hasInitialClick = false;
124+
this.intervalId = setInterval(this.handleTimer, repeatInterval);
123125
}
124126

125127
handleEnd(e)
126128
{
127-
if (e.button !== 0 && typeof e.touches === 'undefined')
129+
if (!isLeftButtonOrTouch(e) || !this.intervalId)
128130
return;
129131

130-
if (this.intervalId)
131-
{
132-
clearInterval(this.intervalId);
133-
this.intervalId = null;
134-
}
132+
clearInterval(this.intervalId);
133+
this.intervalId = null;
135134
}
136135

137136
render()

0 commit comments

Comments
 (0)