Skip to content

Instantly share code, notes, and snippets.

@tinybeans
Created February 27, 2015 12:46
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/06112793ebf6023302b7 to your computer and use it in GitHub Desktop.
Save tinybeans/06112793ebf6023302b7 to your computer and use it in GitHub Desktop.
flexibleSearch.js で本文の100文字だけ表示して、後ろに ... を付けるサンプル
(function ($) {
$('#search').flexibleSearch({
searchDataPath: "/flexibleSearch/search.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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment