unibox
A Javascript Plugin for a universal search box with search suggestion without dependencies.
Demo
How it Looks Like
Example on the meal planner site spoonacular. Here you can see the instant visual feedback (images showing how you understood the query) within the search suggest.
Example on the semantic product search engine semknox.com (not public). Here, the instant visual feedback is shown prominently above the query.
Also unibox is now used by site search provider Site Search 360. Here's a sample implementation.
Installation
Download the unibox.min.js and unibox.min.css or simply install via bower writing bower install unibox
.
Configuration and Usage
For suggestions to work you have two parts. First, the unibox.min.js and unibox.min.css need to be included and configured on the page. Second, the server needs to give search suggest data for the plugin to show.
Client Side
<input id="searchBox">
sxQuery("#searchBox").unibox({
suggestUrl: '',
ivfImagePath: '',
ivfImageOffset: -80,
missingErrorImage: undefined,
queryVisualizationHeadline: '',
highlight: true,
throttleTime: 50,
animationSpeed: 300,
instantVisualFeedback: 'all',
showOnMobile: true,
callbacks: {
enter: undefined,
enterResult: undefined,
type: undefined,
focus: undefined,
blur: undefined,
line: undefined,
suggestsBuilt: undefined,
preSuggest: undefined,
suggestChange: undefined
},
trackingCallbacks: {
abandon: undefined,
select: undefined,
show: undefined,
change: undefined
},
placeholder: undefined,
extraHtml: undefined,
dataPoints: undefined,
noSuggests: undefined,
emptyQuerySuggests: undefined,
minChars: 3,
maxWidth: 'auto',
showDeleteAllButton: false,
showImagesSuggestions: true,
disableEventPropagationHtml: true,
suggestOrder: [],
suggestSelectionOrder: [],
viewAllLabel: undefined,
loaderSelector: undefined,
viewKeyMappings: undefined,
themeColor: '#1C5D7D',
enabled: true,
specialMobileSuggest: {
enabled: false,
breakpoint: 768,
placeholder: undefined,
customTopHtml: undefined,
searchBoxPlaceholder: undefined,
animateTransitions: true,
resizeSearchBoxOnScroll: true,
trigger: undefined,
autoHide: true,
hiddenCallback: undefined
},
accessibility: {
headingLevel: 2,
searchFieldLabel: "Search",
srSuggestionsHiddenText: "Search suggestions are hidden",
srNoSuggestionsText: 'No search suggestions',
srSuggestionsCountText: '#COUNT# search suggestions shown',
srOneSuggestionText: 'One search suggestion shown',
srSuggestBoxControlDescription: 'Use up and down arrows to select available result. Press enter to go to selected search result. Touch devices users can use touch and swipe gestures.',
},
searchBoxContainer: searchBox.parent()
});
Server Side
On the server side create code in whatever language you want. The URL of the service should be set as "suggestUrl" in the settings on the page. The json that needs to be generated must have the following structure:
{
"words": [
{
"name": "name",
"image": "http://...",
},
],
"suggests": {
"headline 1": [
{
"name": "name",
"image": "http://...",
"link": "http://...",
}
],
}
}
The field suggests
contains search suggests grouped under headlines. For example, on spoonacular.com you have an empty headline and a "Recipes" headline to group suggests.
The field words
is for the instant visual feedback. All the words or phrases that you recognized should be entered here so they can be shown to the user.
That's it already. If you use unibox and want to let me know, I include your usage example here. Happy coding.
Notes to keep in mind
Multi UniBoxes
If you want to initialize more that one UniBox in the same page you can wrap the initialization function in an event that triggers when the user switches between input boxes , such as focus
sxQuery(".usernameBox").focus(function(){
sxQuery(".usernameBox").unibox({
suggestUrl: 'path to your server-side',
});
sxQuery(".emailBox").focus(function(){
sxQuery(".emailBox").unibox({
suggestUrl: 'path to your server-side',
});
Bootstrap Fixes
If you are willing to use bootstrap along with Unibox keep in mind that unibox will mess your input-group-addon
's height,
use this css to fix it
#unibox-invisible{
position: absolute !important;
}