Просмотр исходного кода

#48 site search: live search improvement, go to full search upon enter key press

Alex Trofimov 12 лет назад
Родитель
Сommit
ccd48a1c55

+ 14 - 2
inc/js/functions.js

@@ -427,8 +427,20 @@ function bx_append_url_params (sUrl, mixedParams) {
     return sUrl + sParams;
 }
 
-function bx_search_on_type (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
-    bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults);
+function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
+    if ('undefined' != typeof(e) && 13 == e.keyCode) {
+        $(sFormSel).find('input[name=live_search]').val(0);
+        $(sFormSel).submit();
+        return false;
+    }
+
+    if ('undefined' != typeof(glBxSearchTimeoutHandler) && glBxSearchTimeoutHandler)
+        clearTimeout(glBxSearchTimeoutHandler);
+
+    glBxSearchTimeoutHandler = setTimeout(function () {
+        bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults);
+    }, 500);
+
     return true;
 }
 

+ 0 - 0
modules/base/text/template/unit_quick_search.html → modules/base/text/template/unit_live_search.html


+ 1 - 1
searchKeyword.php

@@ -18,7 +18,7 @@ $o->setLiveSearch(bx_get('live_search') ? 1 : 0);
 $sCode = '';
 if (bx_get('keyword')) {
     $sCode = $o->response();
-    if (mb_strlen($sCode) == 0)
+    if (!$sCode)
         $sCode = $o->getEmptyResult();
 }
 

+ 7 - 5
template/scripts/BxBaseSearch.php

@@ -41,9 +41,11 @@ class BxBaseSearch extends BxDolSearch
         $aForm = array(
             'form_attrs' => array(
                'id' => $sIdForm,
-               'action' => '',
-               'method' => 'post',
-               'onsubmit' => "return bx_search($sJsParams);",
+               'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
+               'method' => 'post',               
+            ),
+            'csrf' => array(
+                'disable' => true,
             ),
             'inputs' => array(
                 'live_search' => array(
@@ -62,6 +64,7 @@ class BxBaseSearch extends BxDolSearch
                     'type' => 'text',
                     'name' => 'keyword',
                     'caption' => _t('_Keyword'),
+                    'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
                 ),
                 'search' => array(
                     'type' => 'submit',
@@ -76,9 +79,8 @@ class BxBaseSearch extends BxDolSearch
             unset($aForm['inputs']['search']);
             unset($aForm['inputs']['keyword']['caption']);
             $aForm['inputs']['keyword']['attrs']['placeholder'] = _t('_sys_search_placeholder');
-            $aForm['inputs']['keyword']['attrs']['onkeypress'] = "return bx_search_on_type($sJsParams);";
+            $aForm['inputs']['keyword']['attrs']['onkeypress'] = "return bx_search_on_type(event, $sJsParams);";
             $aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeypress'];
-            $aForm['inputs']['keyword']['attrs']['oninput'] = $aForm['inputs']['keyword']['attrs']['onkeypress'];
         }
 
         bx_import('BxTemplFormView');