修订版 | 20d617b41561d5d93d6cf3ffd5ea22b038f290bf (tree) |
---|---|
时间 | 2017-09-18 08:00:36 |
作者 | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2433 Control Search Request interval
@@ -11,6 +11,7 @@ define('PLUGIN_SEARCH2_MAX_BASE', 16); // #search(1,2,3,...,15,16) | ||
11 | 11 | |
12 | 12 | define('PLUGIN_SEARCH2_RESULT_RECORD_LIMIT', 500); |
13 | 13 | define('PLUGIN_SEARCH2_RESULT_RECORD_LIMIT_START', 100); |
14 | +define('PLUGIN_SEARCH2_SEARCH_WAIT_MILLISECONDS', 1000); | |
14 | 15 | |
15 | 16 | // Show a search box on a page |
16 | 17 | function plugin_search2_convert() |
@@ -196,6 +197,7 @@ EOD; | ||
196 | 197 | } |
197 | 198 | $_search2_result_notfound = htmlsc($_msg_notfoundresult); |
198 | 199 | $_search2_result_found = htmlsc($_msg_andresult); |
200 | + $_search2_search_wait_milliseconds = PLUGIN_SEARCH2_SEARCH_WAIT_MILLISECONDS; | |
199 | 201 | $result_page_panel =<<<EOD |
200 | 202 | <div id="_plugin_search2_search_status"></div> |
201 | 203 | <div id="_plugin_search2_message"></div> |
@@ -203,6 +205,7 @@ EOD; | ||
203 | 205 | <input type="hidden" id="_plugin_search2_msg_searching" value="$_search_searching"> |
204 | 206 | <input type="hidden" id="_plugin_search2_msg_result_notfound" value="$_search2_result_notfound"> |
205 | 207 | <input type="hidden" id="_plugin_search2_msg_result_found" value="$_search2_result_found"> |
208 | +<input type="hidden" id="_search2_search_wait_milliseconds" value="$_search2_search_wait_milliseconds"> | |
206 | 209 | EOD; |
207 | 210 | if ($h_search_text == '') { |
208 | 211 | $result_page_panel = ''; |
@@ -10,7 +10,7 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
10 | 10 | var aroundLines = 2; |
11 | 11 | var maxResultLines = 20; |
12 | 12 | var minBlockLines = 5; |
13 | - var searchWaitMilliseconds = 100; | |
13 | + var minSearchWaitMilliseconds = 100; | |
14 | 14 | function escapeHTML (s) { |
15 | 15 | if(typeof s !== 'string') { |
16 | 16 | s = '' + s; |
@@ -114,9 +114,19 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
114 | 114 | ul.appendChild(fragment); |
115 | 115 | }); |
116 | 116 | if (!obj.search_done && obj.next_start_index) { |
117 | + var waitE = document.querySelector('#_search2_search_wait_milliseconds'); | |
118 | + var interval = minSearchWaitMilliseconds; | |
119 | + try { | |
120 | + interval = parseInt(waitE.value); | |
121 | + } catch (e) { | |
122 | + interval = minSearchWaitMilliseconds; | |
123 | + } | |
124 | + if (interval < minSearchWaitMilliseconds) { | |
125 | + interval = minSearchWaitMilliseconds; | |
126 | + } | |
117 | 127 | setTimeout(function(){ |
118 | 128 | doSearch(searchText, session, obj.next_start_index); |
119 | - }, searchWaitMilliseconds); | |
129 | + }, interval); | |
120 | 130 | } |
121 | 131 | } |
122 | 132 | function textToRegex(searchText) { |