@@ -38,12 +38,10 @@ export enum SearchResultType {
38
38
* about the current search state.
39
39
*/
40
40
export class SearchManager {
41
- private resultsOpen_ = false ;
41
+ isSearchOpen = false ;
42
+ isResultsOpen = false ;
42
43
private lastResultGroup_ = < ObjectGroup > null ;
43
44
private uiManager_ : UiManager ;
44
- private isSearchOpen = false ;
45
- private forceClose = false ;
46
- private forceOpen = false ;
47
45
48
46
constructor ( uiManager : UiManager ) {
49
47
this . uiManager_ = uiManager ;
@@ -73,7 +71,6 @@ export class SearchManager {
73
71
keepTrackApi . getPlugin ( SelectSatManager ) ?. selectSat ( satId ) ;
74
72
}
75
73
} ) ;
76
-
77
74
getEl ( 'search-results' ) ?. addEventListener ( 'mouseover' , ( evt ) => {
78
75
let satId = SearchManager . getSatIdFromSearchResults_ ( evt ) ;
79
76
if ( isNaN ( satId ) || satId === - 1 ) return ;
@@ -85,14 +82,17 @@ export class SearchManager {
85
82
keepTrackApi . getHoverManager ( ) . setHoverId ( - 1 ) ;
86
83
this . uiManager_ . searchHoverSatId = - 1 ;
87
84
} ) ;
88
-
89
85
getEl ( 'search' ) ?. addEventListener ( 'input' , ( ) => {
90
86
const searchStr = ( < HTMLInputElement > getEl ( 'search' ) ) . value ;
91
87
this . doSearch ( searchStr ) ;
92
88
} ) ;
93
-
89
+ getEl ( 'search' ) ?. addEventListener ( 'blur' , ( ) => {
90
+ if ( this . isSearchOpen && this . getCurrentSearch ( ) . length === 0 ) {
91
+ this . toggleSearch ( ) ;
92
+ }
93
+ } ) ;
94
94
getEl ( 'search-icon' ) ?. addEventListener ( 'click' , ( ) => {
95
- this . searchToggle ( ) ;
95
+ this . toggleSearch ( ) ;
96
96
} ) ;
97
97
}
98
98
@@ -122,7 +122,7 @@ export class SearchManager {
122
122
* Returns the current search string entered by the user.
123
123
*/
124
124
getCurrentSearch ( ) : string {
125
- if ( this . resultsOpen_ ) {
125
+ if ( this . isResultsOpen ) {
126
126
const searchDom = < HTMLInputElement > getEl ( 'search' , true ) ;
127
127
if ( searchDom ) {
128
128
return searchDom . value ;
@@ -132,10 +132,6 @@ export class SearchManager {
132
132
return '' ;
133
133
}
134
134
135
- isResultsOpen ( ) : boolean {
136
- return this . resultsOpen_ ;
137
- }
138
-
139
135
/**
140
136
* Hides the search results box and clears the selected satellite group.
141
137
* Also updates the color scheme if necessary.
@@ -149,7 +145,7 @@ export class SearchManager {
149
145
150
146
slideOutUp ( getEl ( 'search-results' ) , 1000 ) ;
151
147
groupManagerInstance . clearSelect ( ) ;
152
- this . resultsOpen_ = false ;
148
+ this . isResultsOpen = false ;
153
149
154
150
settingsManager . lastSearch = '' ;
155
151
settingsManager . lastSearchResults = [ ] ;
@@ -543,7 +539,7 @@ export class SearchManager {
543
539
if ( satInfoboxDom ) SatInfoBox . resetMenuLocation ( satInfoboxDom , false ) ;
544
540
545
541
slideInDown ( getEl ( 'search-results' ) , 1000 ) ;
546
- this . resultsOpen_ = true ;
542
+ this . isResultsOpen = true ;
547
543
548
544
if (
549
545
colorSchemeManagerInstance . currentColorScheme === colorSchemeManagerInstance . groupCountries ||
@@ -555,51 +551,49 @@ export class SearchManager {
555
551
}
556
552
}
557
553
558
- searchToggle ( force ?: boolean ) {
559
- // Reset Force Options
560
- this . forceClose = false ;
561
- this . forceOpen = false ;
562
-
563
- // Pass false to force close and true to force open
564
- if ( typeof force != 'undefined' ) {
565
- if ( ! force ) this . forceClose = true ;
566
- if ( force ) this . forceOpen = true ;
554
+ toggleSearch ( ) {
555
+ if ( ! this . isSearchOpen ) {
556
+ this . openSearch ( ) ;
557
+ } else {
558
+ this . closeSearch ( ) ;
567
559
}
560
+ }
568
561
569
- if ( ( ! this . isSearchOpen && ! this . forceClose ) || this . forceOpen ) {
570
- this . isSearchOpen = true ;
571
- getEl ( 'search-holder' ) ?. classList . remove ( 'search-slide-up' ) ;
572
- getEl ( 'search-holder' ) ?. classList . add ( 'search-slide-down' ) ;
573
- getEl ( 'search-icon' ) ?. classList . add ( 'search-icon-search-on' ) ;
574
- getEl ( 'fullscreen-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
575
- getEl ( 'tutorial-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
576
- getEl ( 'legend-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
577
- getEl ( 'sound-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
578
-
579
- const searchDom = < HTMLInputElement > getEl ( 'search' ) ;
580
- if ( searchDom ) {
581
- const curSearch = searchDom . value ;
582
- if ( curSearch . length > settingsManager . minimumSearchCharacters ) {
583
- this . doSearch ( curSearch ) ;
584
- }
562
+ closeSearch ( isForce = false ) {
563
+ if ( ! this . isSearchOpen && ! isForce ) return ;
564
+
565
+ this . isSearchOpen = false ;
566
+ getEl ( 'search-holder' ) ?. classList . remove ( 'search-slide-down' ) ;
567
+ getEl ( 'search-holder' ) ?. classList . add ( 'search-slide-up' ) ;
568
+ getEl ( 'search-icon' ) ?. classList . remove ( 'search-icon-search-on' ) ;
569
+ setTimeout ( function ( ) {
570
+ getEl ( 'fullscreen-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
571
+ getEl ( 'tutorial-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
572
+ getEl ( 'legend-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
573
+ getEl ( 'sound-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
574
+ } , 500 ) ;
575
+ this . uiManager_ . hideSideMenus ( ) ;
576
+ this . hideResults ( ) ;
577
+ }
578
+
579
+ openSearch ( isForce = false ) {
580
+ if ( this . isSearchOpen && ! isForce ) return ;
581
+
582
+ this . isSearchOpen = true ;
583
+ getEl ( 'search-holder' ) ?. classList . remove ( 'search-slide-up' ) ;
584
+ getEl ( 'search-holder' ) ?. classList . add ( 'search-slide-down' ) ;
585
+ getEl ( 'search-icon' ) ?. classList . add ( 'search-icon-search-on' ) ;
586
+ getEl ( 'fullscreen-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
587
+ getEl ( 'tutorial-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
588
+ getEl ( 'legend-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
589
+ getEl ( 'sound-icon' ) ?. classList . add ( 'top-menu-icons-search-on' ) ;
590
+
591
+ const searchDom = < HTMLInputElement > getEl ( 'search' ) ;
592
+ if ( searchDom ) {
593
+ const curSearch = searchDom . value ;
594
+ if ( curSearch . length > settingsManager . minimumSearchCharacters ) {
595
+ this . doSearch ( curSearch ) ;
585
596
}
586
- } else {
587
- this . isSearchOpen = false ;
588
- getEl ( 'search-holder' ) ?. classList . remove ( 'search-slide-down' ) ;
589
- getEl ( 'search-holder' ) ?. classList . add ( 'search-slide-up' ) ;
590
- getEl ( 'search-icon' ) ?. classList . remove ( 'search-icon-search-on' ) ;
591
- setTimeout ( function ( ) {
592
- getEl ( 'fullscreen-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
593
- getEl ( 'tutorial-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
594
- getEl ( 'legend-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
595
- getEl ( 'sound-icon' ) ?. classList . remove ( 'top-menu-icons-search-on' ) ;
596
- } , 500 ) ;
597
- this . uiManager_ . hideSideMenus ( ) ;
598
- this . hideResults ( ) ;
599
- // getEl('menu-space-stations').classList.remove('bmenu-item-selected');
600
- // This is getting called too much. Not sure what it was meant to prevent?
601
- // colorSchemeManagerInstance.setColorScheme(colorSchemeManagerInstance.default, true);
602
- // this.uiManager_.colorSchemeChangeAlert(settingsManager.currentColorScheme);
603
597
}
604
598
}
605
599
}
0 commit comments