@@ -204,7 +204,11 @@ class PlayerUI {
204204
205205 event . preventDefault ( )
206206
207- const $button = event . target as HTMLElement
207+ let $button = event . target as HTMLElement
208+
209+ if ( $button . localName === 'span' ) {
210+ $button = $button . parentElement
211+ }
208212
209213 if ( $button . id === 'js-first' ) {
210214 this . player . play ( { whichSound : 'first' } )
@@ -224,15 +228,30 @@ class PlayerUI {
224228 }
225229 }
226230
227- if ( $button . id === 'pause ' ) {
228- this . player . pause ( )
231+ if ( $button . id === 'js-stop ' ) {
232+ this . player . stop ( )
229233 }
230234
231- if ( $button . id === 'stop' ) {
232- this . player . stop ( )
235+ if ( $button . id === 'js-loop-song' ) {
236+ const currentSound = this . player . getCurrentSound ( )
237+ if ( currentSound . getLoop ( ) ) {
238+ currentSound . setLoop ( false )
239+ } else {
240+ currentSound . setLoop ( true )
241+ }
242+ this . _updateLoopSong ( )
233243 }
234244
235- if ( $button . id === 'disconnect' ) {
245+ if ( $button . id === 'js-loop-queue' ) {
246+ if ( this . player . getLoopQueue ( ) ) {
247+ this . player . setLoopQueue ( false )
248+ } else {
249+ this . player . setLoopQueue ( true )
250+ }
251+ this . _updateLoopQueue ( )
252+ }
253+
254+ if ( $button . id === 'js-disconnect' ) {
236255 this . player . disconnect ( )
237256 }
238257
@@ -310,6 +329,38 @@ class PlayerUI {
310329 this . _switchPlayerContext ( 'on' )
311330 }
312331
332+ protected _updateLoopQueue ( ) : void {
333+
334+ const isLoopQueue = this . player . getLoopQueue ( )
335+ const $loopQueueOn = document . getElementById ( 'js-loop-queue-on' )
336+ const $loopQueueOff = document . getElementById ( 'js-loop-queue-off' )
337+
338+ if ( isLoopQueue ) {
339+ $loopQueueOn . classList . remove ( 'hidden' )
340+ $loopQueueOff . classList . add ( 'hidden' )
341+ } else {
342+ $loopQueueOn . classList . add ( 'hidden' )
343+ $loopQueueOff . classList . remove ( 'hidden' )
344+ }
345+
346+ }
347+
348+ protected _updateLoopSong ( ) : void {
349+
350+ const isLoopSound = this . player . getCurrentSound ( ) . getLoop ( )
351+ const $loopSongOn = document . getElementById ( 'js-loop-song-on' )
352+ const $loopSongOff = document . getElementById ( 'js-loop-song-off' )
353+
354+ if ( isLoopSound ) {
355+ $loopSongOn . classList . remove ( 'hidden' )
356+ $loopSongOff . classList . add ( 'hidden' )
357+ } else {
358+ $loopSongOn . classList . add ( 'hidden' )
359+ $loopSongOff . classList . remove ( 'hidden' )
360+ }
361+
362+ }
363+
313364 protected _destroyListeners ( ) : void {
314365
315366 this . _buttonsBox . removeEventListener ( 'click' , this . _onClickButtonsBox . bind ( this ) )
@@ -326,6 +377,13 @@ class PlayerUI {
326377
327378 }
328379
380+ public refresh ( ) : void {
381+
382+ this . _updateLoopQueue ( )
383+ this . _updateLoopSong ( )
384+
385+ }
386+
329387 public deconstructor ( ) : void {
330388 this . _destroyListeners ( )
331389 }
0 commit comments