@@ -620,21 +620,14 @@ $(function(){
620620 // consoles menu
621621 $ ( '.mct-consoles' ) . on ( 'click' , function ( ) { window . open ( 'consoles.html' , '_blank' ) } ) ;
622622 // ports dropdown menu management
623- ( function ( ) {
624- var ports = $ ( '.mct-ports' )
625- var title = ports . find ( 'a.btn' )
626- ports . find ( '.dropdown-menu' ) . on ( 'click' , function ( ev ) {
627- title . text ( $ ( ev . target ) . text ( ) ) ;
628- } )
629-
623+ ( function ( ports ) {
630624 function createPort ( p ) {
631- _add ( $ ( 'template._ports' ) )
632- . text ( p . comName )
625+ ports . append ( `<a class="dropdown-item" href="#">${ p . comName } </a>` )
633626 }
634627 function removePort ( p ) {
635- ports . find ( '.dropdown-item ' ) . filter ( function ( i , el ) { return $ ( el ) . text ( ) == p . comName } ) . remove ( )
636- if ( title . text ( ) == p . comName )
637- title . text ( 'Auto port' ) ;
628+ ports . find ( 'a ' ) . filter ( function ( i , el ) { return $ ( el ) . text ( ) == p . comName } ) . remove ( )
629+ if ( ! ports . find ( '.bg-info' ) . length )
630+ ports . find ( 'a' ) . eq ( 0 ) . addClass ( 'bg-info' )
638631 }
639632 var source = new EventSource ( "/ports" ) ;
640633 source . addEventListener ( 'list' , function ( event ) {
@@ -645,12 +638,10 @@ $(function(){
645638 } ) ;
646639 } ) ;
647640 source . addEventListener ( 'error' , function ( event ) {
648- $ ( '.mct-consoles' ) . attr ( 'disabled' , '' )
649- $ ( '.mct-ports a' ) . addClass ( 'disabled' )
641+ $ ( '.mct-consoles,.mct-pio-ports' ) . attr ( 'disabled' , '' )
650642 } ) ;
651643 source . addEventListener ( 'open' , function ( event ) {
652- $ ( '.mct-consoles' ) . removeAttr ( 'disabled' )
653- $ ( '.mct-ports a' ) . removeClass ( 'disabled' )
644+ $ ( '.mct-consoles,.mct-pio-ports' ) . removeAttr ( 'disabled' )
654645 } ) ;
655646 source . addEventListener ( 'created' , function ( event ) {
656647 var port = JSON . parse ( event . data ) ;
@@ -684,7 +675,7 @@ $(function(){
684675 }
685676 lastChanged = '' ;
686677 } ) ;
687- } ( ) ) ;
678+ } ( $ ( '.mct-ports' ) ) ) ;
688679 // info menu
689680 ( function ( btn ) {
690681 var base = $ ( '#mct-log-modal' ) ;
@@ -711,14 +702,14 @@ $(function(){
711702 }
712703 proc . log = function ( text ) { p . append ( text ) ; p . prop ( 'scrollTop' , p . prop ( 'scrollHeight' ) ) ; }
713704 var cmd ;
714- $ ( '.mct-pio-compile, .mct-pio-flash, .mct-ports a ' )
705+ $ ( '.mct-pio-compile, .mct-pio-flash, .mct-pio- ports' )
715706 . toggleClass ( 'disabled' , ! config . pio )
716707 . attr ( ! config . pio ?'title' :'null' , 'PlatformIO not installed' )
717708 . eq ( 0 ) . on ( 'click' , function ( ) {
718- cmd = stream_cmd ( '/pio/' + $ ( '.mct-pio-env .bg-info' ) . text ( ) , proc ) ( )
709+ cmd = stream_cmd ( '/pio/' + $ ( '.mct-pio-env .bg-info' ) . text ( ) . trim ( ) , proc ) ( )
719710 } ) . end ( )
720711 . eq ( 1 ) . on ( 'click' , function ( ) {
721- cmd = stream_cmd ( '/pio-flash /' + encodeURI ( btoa ( $ ( '.mct-ports a.btn ' ) . text ( ) . trim ( ) ) ) , proc ) ( )
712+ cmd = stream_cmd ( '/pio/' + $ ( '.mct-pio-env .bg-info' ) . text ( ) . trim ( ) + ' /'+ encodeURI ( btoa ( $ ( '.mct-ports .bg-info ' ) . text ( ) . trim ( ) ) ) , proc ) ( )
722713 } ) . end ( )
723714 r . on ( 'hide.bs.modal' , function ( ) {
724715 cmd . abort ( ) ;
@@ -729,8 +720,9 @@ $(function(){
729720 $ . each ( config . env || [ ] , function ( i , name ) {
730721 $ ( '.mct-pio-env' ) . append ( `<a class="dropdown-item" href="#">${ name } </a>` )
731722 } )
732- $ ( '.mct-pio-env' ) . on ( 'click' , function ( ev ) {
733- $ ( ev . target ) . addClass ( 'bg-info' ) . siblings ( ) . removeClass ( 'bg-info' )
723+ $ ( '.mct-pio-env,.mct-ports' ) . on ( 'click' , function ( ev ) {
724+ if ( $ ( ev . target ) . hasClass ( 'dropdown-item' ) )
725+ $ ( ev . target ) . addClass ( 'bg-info' ) . siblings ( ) . removeClass ( 'bg-info' )
734726 } )
735727 } ( ) ) ;
736728 // issue menu
0 commit comments