@@ -17,12 +17,14 @@ export var FeatureIndex = L.Layer.extend({
1717 this . _container = L . DomUtil . create ( "div" , "mapml-feature-index-box" , map . _container ) ;
1818 this . _container . innerHTML = svgInnerHTML ;
1919
20- this . _table = L . DomUtil . create ( "table" , "mapml-feature-index" , map . _container ) ;
21- this . _title = L . DomUtil . create ( "caption" , "mapml-feature-index-header" , this . _table ) ;
22- this . _title . innerHTML = "Feature Index" ;
23- this . _body = L . DomUtil . create ( "tbody" , "mapml-feature-index-content" , this . _table ) ;
20+ this . _output = L . DomUtil . create ( "output" , "mapml-feature-index" , map . _container ) ;
21+ this . _body = L . DomUtil . create ( "span" , "mapml-feature-index-content" , this . _output ) ;
22+ this . _moreContent = L . DomUtil . create ( "span" , "mapml-feature-index-content more-content" , this . _output ) ;
23+ this . _moreContent . style . display = "none" ;
24+
2425 map . on ( "layerchange layeradd layerremove overlayremove" , this . _toggleEvents , this ) ;
2526 map . on ( 'moveend focus' , this . _checkOverlap , this ) ;
27+ map . on ( "keydown" , this . _toggleMoreContent , this ) ;
2628 this . _addOrRemoveFeatureIndex ( ) ;
2729 } ,
2830
@@ -46,58 +48,41 @@ export var FeatureIndex = L.Layer.extend({
4648
4749 body . innerHTML = "" ;
4850
51+ let moreContent = this . _moreContent ;
52+ moreContent . innerHTML = "" ;
53+
4954 keys . forEach ( i => {
5055 if ( layers [ i ] . featureAttributes && featureIndexBounds . overlaps ( layers [ i ] . _bounds ) ) {
5156 let label = layers [ i ] . group . getAttribute ( "aria-label" ) ;
52-
5357 if ( index === 9 ) {
54- body . appendChild ( this . _updateCell ( "More results" , 9 ) ) ;
55- body . querySelector ( "tr:nth-child(9) > td" ) . addEventListener ( 'focus' , this . _showMoreResults ( body ) ) ;
58+ body . appendChild ( this . _updateOutput ( "More results" , 9 ) ) ;
5659 index += 1 ;
5760 }
61+
5862 if ( index > 9 ) {
59- this . _moreResults ( label , index , body ) ;
63+ moreContent . appendChild ( this . _updateOutput ( label , index ) ) ;
6064 } else {
61- body . appendChild ( this . _updateCell ( label , index ) ) ;
65+ body . appendChild ( this . _updateOutput ( label , index ) ) ;
6266 }
6367 index += 1 ;
6468
6569 }
6670 } ) ;
6771 } ,
68-
69- _updateCell : function ( label , index ) {
70- let row = document . createElement ( "tr" ) ;
71- let cell = document . createElement ( "td" ) ;
72-
73- row . setAttribute ( "row" , index ) ;
74- cell . setAttribute ( "tabindex" , index ) ;
75- cell . setAttribute ( "aria-label" , label ) ;
76- cell . innerHTML = index + " " + label ;
77- row . appendChild ( cell ) ;
78- return row ;
72+ _updateOutput : function ( label , index ) {
73+ let span = document . createElement ( "span" ) ;
74+ span . innerHTML = `<kbd>${ index } </kbd>` + " " + label ;
75+ return span ;
7976 } ,
80-
81- _moreResults :function ( label , index , body ) {
82- let multiplier = Math . floor ( ( index - 1 ) / 9 ) ;
83- let row = body . querySelector ( `[row='${ index - ( 9 * multiplier ) } ']` ) ;
84- let cell = document . createElement ( "td" ) ;
85-
86- cell . className = "more-results" ;
87- cell . style . display = "none" ;
88- cell . setAttribute ( "tabindex" , index ) ;
89- cell . setAttribute ( "aria-label" , label ) ;
90- cell . innerHTML = index + " " + label ;
91- row . appendChild ( cell ) ;
92- } ,
93-
94- _showMoreResults : function ( body ) {
95- return function ( ) {
96- let hiddenCells = body . getElementsByClassName ( "more-results" ) ;
97- for ( let i = 0 ; i < hiddenCells . length ; i ++ ) {
98- hiddenCells [ i ] . style . display = "" ;
77+ _toggleMoreContent : function ( e ) {
78+ let display = this . _moreContent . style . display ;
79+ if ( e . originalEvent . keyCode === 57 ) {
80+ if ( display === "none" ) {
81+ this . _moreContent . style . display = "inline-block" ;
82+ } else {
83+ this . _moreContent . style . display = "none" ;
9984 }
100- } ;
85+ }
10186 } ,
10287
10388 _toggleEvents : function ( ) {
@@ -108,21 +93,18 @@ export var FeatureIndex = L.Layer.extend({
10893 _addOrRemoveFeatureIndex : function ( e ) {
10994 let obj = this ;
11095 setTimeout ( function ( ) {
111- if ( obj . _table . contains ( obj . _map . options . mapEl . shadowRoot . activeElement ) ) {
112- return ;
113- }
11496 if ( e && e . type === "focus" ) {
11597 obj . _container . querySelector ( 'rect' ) . style . display = "inline" ;
116- obj . _table . style . display = "block" ;
98+ obj . _output . style . display = "block" ;
11799 } else if ( e && e . type === "blur" ) {
118100 obj . _container . querySelector ( 'rect' ) . style . display = "none" ;
119- obj . _table . style . display = "none" ;
101+ obj . _output . style . display = "none" ;
120102 } else if ( obj . _map . isFocused ) {
121103 obj . _container . querySelector ( 'rect' ) . style . display = "inline" ;
122- obj . _table . style . display = "block" ;
104+ obj . _output . style . display = "block" ;
123105 } else {
124106 obj . _container . querySelector ( 'rect' ) . style . display = "none" ;
125- obj . _table . style . display = "none" ;
107+ obj . _output . style . display = "none" ;
126108 }
127109 } , 0 ) ;
128110
0 commit comments