@@ -6,6 +6,7 @@ var isMouseOverSummary = false;
6
6
//Global Cache variables
7
7
var tablesProcesseds = 0 ;
8
8
var alreadyAddedListenerToSearchBar = false ;
9
+ var pendentSearchJob = undefined ;
9
10
10
11
//Events
11
12
window . onscroll = function ( ) {
@@ -98,98 +99,121 @@ function StartSearchJob() {
98
99
99
100
//Add the lister to searchbar
100
101
if ( alreadyAddedListenerToSearchBar == false )
101
- document . getElementById ( "summarySearchBar" ) . getElementsByTagName ( "input" ) [ 0 ] . addEventListener ( "input" , ( event ) => { DoTheSearchJob ( event . target . value . toLowerCase ( ) ) ; } ) ;
102
+ document . getElementById ( "summarySearchBar" ) . getElementsByTagName ( "input" ) [ 0 ] . addEventListener ( "input" , ( event ) => { DoTheSearchJob ( event . target . value . toLowerCase ( ) , true ) ; } ) ;
102
103
103
104
//Inform that is added a listener to the search bar
104
105
alreadyAddedListenerToSearchBar = true ;
105
106
106
107
//Do the first call to search job
107
108
document . getElementById ( "summarySearchMarkersForSubItems" ) . setAttribute ( "style" , "display: block;" ) ;
108
109
document . getElementById ( "summarySearchMarkersForItems" ) . setAttribute ( "style" , "display: block;" ) ;
109
- DoTheSearchJob ( document . getElementById ( "summarySearchBar" ) . getElementsByTagName ( "input" ) [ 0 ] . value . toLocaleLowerCase ( ) ) ;
110
+ DoTheSearchJob ( document . getElementById ( "summarySearchBar" ) . getElementsByTagName ( "input" ) [ 0 ] . value . toLocaleLowerCase ( ) , false ) ;
110
111
}
111
- function DoTheSearchJob ( searchKeywords ) {
112
- //Get needed elements
113
- var allSummarySubItems = document . getElementById ( "summary" ) . getElementsByTagName ( "ul" ) [ 0 ] . getElementsByClassName ( "summarySubItem" ) ;
114
- var allSummaryItems = document . getElementById ( "summary" ) . getElementsByTagName ( "ul" ) [ 0 ] . getElementsByClassName ( "summaryItem" ) ;
115
-
116
- //Prepare the search results
117
- var searchResults = 0 ;
118
- var summarySearchResult = document . getElementById ( "summarySearchResult" ) ;
119
- var searchResultsForSubItemsPositions = [ ] ;
120
- var searchResultsForItemsPositions = [ ] ;
121
- var summarySearchMarkersForSubItems = document . getElementById ( "summarySearchMarkersForSubItems" ) ;
122
- var summarySearchMarkersForItems = document . getElementById ( "summarySearchMarkersForItems" ) ;
123
- var summaryTotalHeight = document . getElementById ( "summary" ) . getElementsByTagName ( "ul" ) [ 0 ] . offsetHeight ;
124
-
125
- //If search keywords is not empty
126
- if ( searchKeywords != "" ) {
127
- //First hide all
128
- for ( var i = 0 ; i < allSummarySubItems . length ; i ++ )
129
- allSummarySubItems [ i ] . setAttribute ( "style" , "list-style-type: circle; opacity: 0.2;" ) ;
130
- for ( var i = 0 ; i < allSummaryItems . length ; i ++ )
131
- allSummaryItems [ i ] . parentElement . setAttribute ( "style" , "opacity: 0.2;" ) ;
132
-
133
- //Now, show only that matches
134
- for ( var i = 0 ; i < allSummarySubItems . length ; i ++ )
135
- if ( allSummarySubItems [ i ] . innerHTML . toLowerCase ( ) . includes ( searchKeywords ) == true ) {
136
- allSummarySubItems [ i ] . setAttribute ( "style" , "list-style-type: circle; opacity: 1.0;" ) ;
137
- searchResultsForSubItemsPositions . push ( allSummarySubItems [ i ] . offsetTop / summaryTotalHeight * 100.0 ) ;
138
- searchResults += 1 ;
139
- }
140
- for ( var i = 0 ; i < allSummaryItems . length ; i ++ )
141
- if ( allSummaryItems [ i ] . innerHTML . toLowerCase ( ) . includes ( searchKeywords ) == true ) {
142
- allSummaryItems [ i ] . parentElement . setAttribute ( "style" , "opacity: 1.0;" ) ;
143
- searchResultsForItemsPositions . push ( allSummaryItems [ i ] . parentElement . offsetTop / summaryTotalHeight * 100.0 ) ;
144
- searchResults += 1 ;
145
- }
146
- }
147
- //If search keywords is empty
148
- if ( searchKeywords == "" ) {
149
- for ( var i = 0 ; i < allSummarySubItems . length ; i ++ )
150
- allSummarySubItems [ i ] . setAttribute ( "style" , "list-style-type: circle;" ) ;
151
- for ( var i = 0 ; i < allSummaryItems . length ; i ++ )
152
- allSummaryItems [ i ] . parentElement . removeAttribute ( "style" ) ;
153
- }
154
-
155
- //Publish the search results in the search markers
156
- //----- Publish on Search Markers for Summary SubItems -------
157
- var generatedGradientForSubItems = "linear-gradient(top, transparent 0%," ;
158
- for ( var i = 0 ; i < searchResultsForSubItemsPositions . length ; i ++ ) {
159
- //Get the current percent fixed
160
- var currentPercent = Math . round ( searchResultsForSubItemsPositions [ i ] ) ;
161
- if ( currentPercent > 100.0 )
162
- currentPercent = 100.0 ;
163
- if ( currentPercent < 0.0 )
164
- currentPercent = 0.0 ;
165
-
166
- //Add the current percent to backgroud image
167
- generatedGradientForSubItems += " transparent " + ( currentPercent - 0.5 ) + "%, red " + ( currentPercent - 0.5 ) + "%, red " + currentPercent + "%, transparent " + currentPercent + "%," ;
168
- }
169
- generatedGradientForSubItems += " transparent 100%)" ;
170
- summarySearchMarkersForSubItems . setAttribute ( "style" , "position: absolute; top: 0px; right: 2px; width: 2px; height: 100%; opacity: 0.8; pointer-events: none; background-image: " + generatedGradientForSubItems + "; background-image: -webkit-" + generatedGradientForSubItems + ";" ) ;
171
- //----- Publish on Search Markers for Summary Items -------
172
- var generatedGradientForItems = "linear-gradient(top, transparent 0%," ;
173
- for ( var i = 0 ; i < searchResultsForItemsPositions . length ; i ++ ) {
174
- //Get the current percent fixed
175
- var currentPercent = Math . round ( searchResultsForItemsPositions [ i ] ) ;
176
- if ( currentPercent > 100.0 )
177
- currentPercent = 100.0 ;
178
- if ( currentPercent < 0.0 )
179
- currentPercent = 0.0 ;
180
-
181
- //Add the current percent to backgroud image
182
- generatedGradientForItems += " transparent " + ( currentPercent - 0.5 ) + "%, red " + ( currentPercent - 0.5 ) + "%, red " + currentPercent + "%, transparent " + currentPercent + "%," ;
183
- }
184
- generatedGradientForItems += " transparent 100%)" ;
185
- summarySearchMarkersForItems . setAttribute ( "style" , "position: absolute; top: 0px; right: 2px; width: 2px; height: 100%; opacity: 0.8; pointer-events: none; background-image: " + generatedGradientForItems + "; background-image: -webkit-" + generatedGradientForItems + ";" ) ;
186
- //Publish the search results below search box
187
- if ( searchResults > 0 ) {
188
- summarySearchResult . style . opacity = "0.7" ;
189
- summarySearchResult . innerHTML = "Found " + searchResults + " results" ;
190
- }
191
- if ( searchResults == 0 )
192
- summarySearchResult . style . opacity = "0" ;
112
+ function DoTheSearchJob ( searchKeywords , waitDelay ) {
113
+ //Time to wait
114
+ var delayForSearchMillis = - 1 ;
115
+
116
+ //Define the time to wait
117
+ if ( waitDelay == true )
118
+ delayForSearchMillis = 1500 ;
119
+ if ( waitDelay == false )
120
+ delayForSearchMillis = 100 ;
121
+
122
+ //If have a pendent search job, cancel it
123
+ if ( pendentSearchJob !== undefined )
124
+ clearTimeout ( pendentSearchJob ) ;
125
+
126
+ //Create a new search task
127
+ pendentSearchJob = setTimeout ( function ( ) {
128
+ //Get needed elements
129
+ var allSummarySubItems = document . getElementById ( "summary" ) . getElementsByTagName ( "ul" ) [ 0 ] . getElementsByClassName ( "summarySubItem" ) ;
130
+ var allSummaryItems = document . getElementById ( "summary" ) . getElementsByTagName ( "ul" ) [ 0 ] . getElementsByClassName ( "summaryItem" ) ;
131
+
132
+ //Prepare the search results
133
+ var searchResults = 0 ;
134
+ var summarySearchResult = document . getElementById ( "summarySearchResult" ) ;
135
+ var searchResultsForSubItemsPositions = [ ] ;
136
+ var searchResultsForItemsPositions = [ ] ;
137
+ var summarySearchMarkersForSubItems = document . getElementById ( "summarySearchMarkersForSubItems" ) ;
138
+ var summarySearchMarkersForItems = document . getElementById ( "summarySearchMarkersForItems" ) ;
139
+ var summaryTotalHeight = document . getElementById ( "summary" ) . getElementsByTagName ( "ul" ) [ 0 ] . offsetHeight ;
140
+
141
+ //If search keywords is not empty
142
+ if ( searchKeywords != "" ) {
143
+ //First hide all
144
+ for ( var i = 0 ; i < allSummarySubItems . length ; i ++ )
145
+ allSummarySubItems [ i ] . setAttribute ( "style" , "list-style-type: circle; opacity: 0.2;" ) ;
146
+ for ( var i = 0 ; i < allSummaryItems . length ; i ++ )
147
+ allSummaryItems [ i ] . parentElement . setAttribute ( "style" , "opacity: 0.2;" ) ;
148
+
149
+ //Now, show only that matches
150
+ for ( var i = 0 ; i < allSummarySubItems . length ; i ++ )
151
+ if ( allSummarySubItems [ i ] . innerHTML . toLowerCase ( ) . includes ( searchKeywords ) == true ) {
152
+ allSummarySubItems [ i ] . setAttribute ( "style" , "list-style-type: circle; opacity: 1.0;" ) ;
153
+ searchResultsForSubItemsPositions . push ( allSummarySubItems [ i ] . offsetTop / summaryTotalHeight * 100.0 ) ;
154
+ searchResults += 1 ;
155
+ }
156
+ for ( var i = 0 ; i < allSummaryItems . length ; i ++ )
157
+ if ( allSummaryItems [ i ] . innerHTML . toLowerCase ( ) . includes ( searchKeywords ) == true ) {
158
+ allSummaryItems [ i ] . parentElement . setAttribute ( "style" , "opacity: 1.0;" ) ;
159
+ searchResultsForItemsPositions . push ( allSummaryItems [ i ] . parentElement . offsetTop / summaryTotalHeight * 100.0 ) ;
160
+ searchResults += 1 ;
161
+ }
162
+ }
163
+ //If search keywords is empty
164
+ if ( searchKeywords == "" ) {
165
+ for ( var i = 0 ; i < allSummarySubItems . length ; i ++ )
166
+ allSummarySubItems [ i ] . setAttribute ( "style" , "list-style-type: circle;" ) ;
167
+ for ( var i = 0 ; i < allSummaryItems . length ; i ++ )
168
+ allSummaryItems [ i ] . parentElement . removeAttribute ( "style" ) ;
169
+ }
170
+
171
+ //Publish the search results in the search markers
172
+ //----- Publish on Search Markers for Summary SubItems -------
173
+ var generatedGradientForSubItems = "linear-gradient(top, transparent 0%," ;
174
+ for ( var i = 0 ; i < searchResultsForSubItemsPositions . length ; i ++ ) {
175
+ //Get the current percent fixed
176
+ var currentPercent = Math . round ( searchResultsForSubItemsPositions [ i ] ) ;
177
+ if ( currentPercent > 100.0 )
178
+ currentPercent = 100.0 ;
179
+ if ( currentPercent < 0.0 )
180
+ currentPercent = 0.0 ;
181
+
182
+ //Add the current percent to backgroud image
183
+ generatedGradientForSubItems += " transparent " + ( currentPercent - 0.5 ) + "%, red " + ( currentPercent - 0.5 ) + "%, red " + currentPercent + "%, transparent " + currentPercent + "%," ;
184
+ }
185
+ generatedGradientForSubItems += " transparent 100%)" ;
186
+ summarySearchMarkersForSubItems . setAttribute ( "style" , "position: absolute; top: 0px; right: 2px; width: 2px; height: 100%; opacity: 0.8; pointer-events: none; background-image: " + generatedGradientForSubItems + "; background-image: -webkit-" + generatedGradientForSubItems + ";" ) ;
187
+ //----- Publish on Search Markers for Summary Items -------
188
+ var generatedGradientForItems = "linear-gradient(top, transparent 0%," ;
189
+ for ( var i = 0 ; i < searchResultsForItemsPositions . length ; i ++ ) {
190
+ //Get the current percent fixed
191
+ var currentPercent = Math . round ( searchResultsForItemsPositions [ i ] ) ;
192
+ if ( currentPercent > 100.0 )
193
+ currentPercent = 100.0 ;
194
+ if ( currentPercent < 0.0 )
195
+ currentPercent = 0.0 ;
196
+
197
+ //Add the current percent to backgroud image
198
+ generatedGradientForItems += " transparent " + ( currentPercent - 0.5 ) + "%, red " + ( currentPercent - 0.5 ) + "%, red " + currentPercent + "%, transparent " + currentPercent + "%," ;
199
+ }
200
+ generatedGradientForItems += " transparent 100%)" ;
201
+ summarySearchMarkersForItems . setAttribute ( "style" , "position: absolute; top: 0px; right: 2px; width: 2px; height: 100%; opacity: 0.8; pointer-events: none; background-image: " + generatedGradientForItems + "; background-image: -webkit-" + generatedGradientForItems + ";" ) ;
202
+ //Publish the search results below search box
203
+ if ( searchResults > 0 ) {
204
+ summarySearchResult . style . opacity = "0.7" ;
205
+ summarySearchResult . innerHTML = "Found " + searchResults + " results" ;
206
+ }
207
+ if ( searchResults == 0 )
208
+ summarySearchResult . style . opacity = "0" ;
209
+
210
+ //Reset the pendent serach job
211
+ pendentSearchJob = undefined ;
212
+ } , delayForSearchMillis ) ;
213
+
214
+ //Update the UI, while wait for search task execution
215
+ summarySearchResult . innerHTML = ( searchKeywords != "" ) ? "Searching" : "" ;
216
+ summarySearchResult . style . opacity = "0.7" ;
193
217
}
194
218
function FinishSearchJob ( ) {
195
219
//Change the buttons visibility
@@ -216,7 +240,7 @@ function FinishSearchJob() {
216
240
} , 300 ) ;
217
241
218
242
//Do the last call to search job, to reset the summary
219
- DoTheSearchJob ( "" ) ;
243
+ DoTheSearchJob ( "" , false ) ;
220
244
document . getElementById ( "summarySearchMarkersForSubItems" ) . setAttribute ( "style" , "display: none;" ) ;
221
245
document . getElementById ( "summarySearchMarkersForItems" ) . setAttribute ( "style" , "display: none;" ) ;
222
246
}
0 commit comments