From b34037865426033d3684fc58b7f65a7d1863a29e Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Mon, 18 May 2026 09:19:28 +0100 Subject: Rework ajax search in jquery to remove reliance on prototype --- ajax_search.php | 43 +++++++++++++++++++++++++++++++++++++++++++ modules/mod_ajax_search.php | 7 +++++++ modules/mod_ajax_search.tpl | 20 ++++++++------------ 3 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 ajax_search.php create mode 100644 modules/mod_ajax_search.php diff --git a/ajax_search.php b/ajax_search.php new file mode 100644 index 0000000..c144b0d --- /dev/null +++ b/ajax_search.php @@ -0,0 +1,43 @@ +verifyPackage( 'search' ); + +header( 'Content-Type: application/json; charset=utf-8' ); + +$words = isset( $_REQUEST['highlight'] ) ? strip_tags( trim( $_REQUEST['highlight'] ) ) : ''; +if( strlen( $words ) < 3 ) { + echo '[]'; + exit; +} + +$_REQUEST['words'] = $words; +$_REQUEST['max_records'] = 10; +LibertyContent::prepGetList( $_REQUEST ); + +$searchlib = new SearchLib(); +$results = $searchlib->find( $_REQUEST ); + +$out = []; +foreach( $results as $r ) { + $type = ''; + if( !empty( $r['content_type_guid'] ) ) { + $type = KernelTools::tra( $gLibertySystem->getContentTypeName( $r['content_type_guid'] ) ); + } + $out[] = [ + 'title' => $r['title'] ?? '', + 'href' => $r['href'] ?? '', + 'type' => $type, + ]; +} + +echo json_encode( $out, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); diff --git a/modules/mod_ajax_search.php b/modules/mod_ajax_search.php new file mode 100644 index 0000000..d83d3ce --- /dev/null +++ b/modules/mod_ajax_search.php @@ -0,0 +1,7 @@ +, but we don't have a way of doing that from a module yet. *} - - - -{* end of section *} - +{strip} {if $gBitSystem->isPackageActive( 'search' )} {bitmodule title="$moduleTitle" name="search_new"} - {form} - -
- {/form} + +
{/bitmodule} + + {/if} +{/strip} -- cgit v1.3