@@ -688,6 +688,8 @@ let d = document,
688688 $$ = el => document . querySelectorAll ( el ) ,
689689 maxItemsInInput = 5 ;
690690
691+ let playlistCards = [ ] ;
692+ let playlistCardsOriginal = [ ] ;
691693let $inputPlaylist = $ ( '.playlist-container-form .playlist-input' ) ;
692694let $inputPlaylist2 = $ ( '.playlist-container-form-2 .playlist-input' ) ;
693695let regExP = / ^ (? ! [ \s 0 - 9 \- _ ] ) [ \w \s \- ] { 1 , 20 } (?< ! [ \s \- ] ) $ / ;
@@ -2191,6 +2193,9 @@ function renderPlaylistCards() {
21912193 playListSection . append ( fragmento ) ;
21922194 }
21932195
2196+ let playListSection = d . querySelector ( ".playlist-section-articles" ) ;
2197+ playlistCards = [ ...playListSection . querySelectorAll ( ".card-single" ) ] ;
2198+ playlistCardsOriginal = [ ...playlistCards ] ;
21942199 addFotoStars ( ) ;
21952200}
21962201
@@ -2274,23 +2279,63 @@ const amFragment = document.createDocumentFragment();
22742279
22752280function generarColorHex ( ) {
22762281 const hex = Math . floor ( Math . random ( ) * 0xffffff ) . toString ( 16 ) ;
2277- return "#" + hex . padStart ( 6 , "0" ) ;
2282+ return '#' + hex . padStart ( 6 , '0' ) ;
22782283}
22792284
22802285document . addEventListener ( 'click' , e => {
22812286 if ( e . target . matches ( '.open-all-artists' ) ) {
22822287 $modalAllArtists . classList . add ( 'modal-all-artist-open' ) ;
22832288 }
2284- } )
2289+ } ) ;
22852290
2286- bands . forEach ( ( band ) => {
2291+ bands . forEach ( band => {
22872292 const [ nameBand , hrefBand ] = band ;
22882293 const anchor = document . createElement ( 'a' ) ;
22892294 anchor . href = hrefBand ;
22902295 anchor . textContent = nameBand ;
2291- anchor . classList . add ( 'artist-link' ) ;
2292- anchor . style . setProperty ( '--colorin' , `${ generarColorHex ( ) } 88` )
2296+ anchor . classList . add ( 'artist-link' ) ;
2297+ anchor . style . setProperty ( '--colorin' , `${ generarColorHex ( ) } 88` ) ;
22932298 amFragment . appendChild ( anchor ) ;
22942299} ) ;
22952300
2296- $modalAllArtists . append ( amFragment ) ;
2301+ $modalAllArtists . append ( amFragment ) ;
2302+
2303+ /* ===========================Navbar of Buttons Playlist========================= */
2304+ document . addEventListener ( "click" , ( e ) => {
2305+ if ( ! e . target . matches ( ".am-button-nav-modal" ) ) return ;
2306+ if ( ! playlistCards || playlistCards . length === 0 ) return ;
2307+
2308+ let playListSection = d . querySelector ( ".playlist-section-articles" ) ;
2309+
2310+ if ( e . target . matches ( ".order" ) ) {
2311+ playlistCards = [ ...playlistCardsOriginal ] ;
2312+ }
2313+
2314+ if ( e . target . matches ( ".unorder" ) ) {
2315+ playlistCards = [ ...playlistCardsOriginal ] ;
2316+ playlistCards . reverse ( ) ;
2317+ }
2318+
2319+ if ( e . target . matches ( ".random" ) ) {
2320+ playlistCards . sort ( ( ) => Math . random ( ) - 0.5 ) ;
2321+ }
2322+
2323+ if ( e . target . matches ( ".a-to-z" ) ) {
2324+ playlistCards . sort ( ( a , b ) => {
2325+ let nameA = a . querySelector ( ".card-single-right h3" ) . textContent . toLowerCase ( ) ;
2326+ let nameB = b . querySelector ( ".card-single-right h3" ) . textContent . toLowerCase ( ) ;
2327+ return nameA . localeCompare ( nameB ) ;
2328+ } ) ;
2329+ }
2330+
2331+ if ( e . target . matches ( ".z-to-a" ) ) {
2332+ playlistCards . sort ( ( a , b ) => {
2333+ let nameA = a . querySelector ( ".card-single-right h3" ) . textContent . toLowerCase ( ) ;
2334+ let nameB = b . querySelector ( ".card-single-right h3" ) . textContent . toLowerCase ( ) ;
2335+ return nameB . localeCompare ( nameA ) ;
2336+ } ) ;
2337+ }
2338+
2339+ playListSection . innerHTML = "" ;
2340+ playlistCards . forEach ( ( card ) => playListSection . append ( card ) ) ;
2341+ } ) ;
0 commit comments