Created
February 27, 2015 21:36
-
-
Save tinybeans/e979bfd4968d5a2c8b24 to your computer and use it in GitHub Desktop.
flexibleSearch.js で複数の JSON ファイルを切り替えて検索するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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