File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,46 @@ $(function() {
9999 this . on ( 'error' , function ( error ) {
100100 console . log ( 'error: ' + error . message ) ;
101101 } , this ) ;
102+ /* Keyboard */
103+ $ ( document ) . on ( 'keypress' , function ( e ) {
104+ console . log ( 'key: ' + e . which ) ;
105+ // Spacebar: Play/pause
106+ if ( e . which == 32 ) {
107+ var current = $ ( 'ol li.playing' ) ;
108+ if ( ! current . length ) {
109+ current = $ ( 'ol li' ) . first ( ) ;
110+ current . addClass ( 'playing' )
111+ audio5 . load ( $ ( 'a' , current ) . attr ( 'data-src' ) ) ;
112+ audio5 . on ( 'canplay' , function ( ) {
113+ audio5 . play ( ) ;
114+ } , this ) ;
115+ } else {
116+ audio5 . playPause ( ) ;
117+ }
118+ }
119+ // j: previous
120+ if ( e . which == 106 ) {
121+ audio5 . pause ( ) ;
122+ var prev = $ ( 'ol li.playing' ) . prev ( ) ;
123+ if ( ! prev . length ) prev = $ ( 'ol li' ) . first ( ) ;
124+ prev . addClass ( 'playing' ) . siblings ( ) . removeClass ( 'playing' ) ;
125+ audio5 . load ( $ ( 'a' , prev ) . attr ( 'data-src' ) ) ;
126+ audio5 . on ( 'canplay' , function ( ) {
127+ audio5 . play ( ) ;
128+ } , this ) ;
129+ }
130+ // k: next
131+ if ( e . which == 107 ) {
132+ audio5 . pause ( ) ;
133+ var next = $ ( 'ol li.playing' ) . next ( ) ;
134+ if ( ! next . length ) next = $ ( 'ol li' ) . first ( ) ;
135+ next . addClass ( 'playing' ) . siblings ( ) . removeClass ( 'playing' ) ;
136+ audio5 . load ( $ ( 'a' , next ) . attr ( 'data-src' ) ) ;
137+ audio5 . on ( 'canplay' , function ( ) {
138+ audio5 . play ( ) ;
139+ } , this ) ;
140+ }
141+ } ) ;
102142 }
103143 } ) ;
104144} ) ;
You can’t perform that action at this time.
0 commit comments