Skip to content

Commit

Permalink
feat(search): ✨ search template namespace when template syntax {{}} i…
Browse files Browse the repository at this point in the history
…s used
  • Loading branch information
alistair3149 committed Aug 26, 2023
1 parent 96f6361 commit 2f2dc33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions resources/skins.citizen.search/searchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ function searchQuery() {
checkValid: function ( s ) {
return s.length > 0;
},
removeCommand: function ( s ) {
this.setValue( this.value.replace( `/${s} `, '' ) );
replace: function ( pattern, s ) {
this.setValue( this.value.replace( pattern, s ) );
},
remove: function ( pattern ) {
this.replace( pattern, '' );
}
};
}
Expand Down
10 changes: 9 additions & 1 deletion resources/skins.citizen.search/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const typeahead = {
// Multi-search clients experiment
if ( searchClientData ) {
searchClient.setActive( searchClientData.id );
searchQuery.removeCommand( command );
searchQuery.remove( `/${command} ` );
}
}
}
Expand All @@ -237,7 +237,15 @@ const typeahead = {
if ( searchQuery.value === typeahead.input.element.value ) {
return Promise.reject( `Search query has not changed: ${searchQuery.value}.` );
}

searchQuery.setValue( typeahead.input.element.value );

// Template syntax should trigger template search
// TODO: Perhaps this should be integrated into the searchQuery module
if ( searchQuery.value.startsWith( '{{' ) ) {
searchQuery.replace( /{{(.[^}]*)}?}?/, 'Template:$1' );
}

return Promise.resolve( `Search query updated to ${searchQuery.value}.` );
},
afterSeachQueryInput: function () {
Expand Down

0 comments on commit 2f2dc33

Please sign in to comment.