Created
February 27, 2015 12:46
-
-
Save tinybeans/06112793ebf6023302b7 to your computer and use it in GitHub Desktop.
flexibleSearch.js で本文の100文字だけ表示して、後ろに ... を付けるサンプル
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({ | |
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