Skip to content

Instantly share code, notes, and snippets.

@tinybeans
Created February 27, 2015 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinybeans/e979bfd4968d5a2c8b24 to your computer and use it in GitHub Desktop.
Save tinybeans/e979bfd4968d5a2c8b24 to your computer and use it in GitHub Desktop.
flexibleSearch.js で複数の JSON ファイルを切り替えて検索するサンプル
(function ($) {
$('#search').flexibleSearch({
searchFormCreation: false,
searchDataPath: {
search_A: "/flexibleSearch/search.json",
search_B: "/flexibleSearch/search2.json",
},
searchFormAction: "/flexibleSearch/search.html",
loadingImgPath: "/flexibleSearch/loading.gif",
resultItemTmpl: [
'<dl>',
'{{#items}}',
'<dt><a href="{{url}}" title="{{title}}">{{&title}}</a></dt>',
'<dd><span>{{&body}}...</span><a href="{{url}}">[続きを読む]</a></dd>',
'{{/items}}',
'</dl>'
].join(""),
modifyResultItemHTML: function(html){
return html.replace(/<span>.*?<\/span>/gi, function(match){
match = match.replace(/<\/?span>/g, '');
if (match.length > 100) {
match = match.substring(0, 100) + '...';
}
return '<span>' + match + '</span>';
});
},
dummy: null
});
})(jQuery);
<form action="/flexibleSearch/search.html" method="GET">
<input type="hidden" name="offset" value="0">
<input type="hidden" name="limit" value="10">
<p><label><input type="radio" name="dataId" value="search_A">search A</label></p>
<p><label><input type="radio" name="dataId" value="search_B">search B</label></p>
<p>
<input type="search" name="search" placeholder="Search words" class="fs-text fs-search">
<input type="submit" value="Search" class="fs-btn fs-submit">
</p>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment