Created
February 16, 2015 10:16
-
-
Save jnbt/e0ec48521efe5eece200 to your computer and use it in GitHub Desktop.
Nicer truncation for Batman.js using jquery.truncate
This file contains hidden or 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
// Truncates (HTML) content | |
// Requirements: jquery.truncate (https://github.com/pathable/truncate/blob/master/jquery.truncate.js) | |
// Usage: | |
// <p data-bind="message.content | truncateHTML 200 | raw"></p> | |
Batman.mixin(Batman.Filters, { | |
niceTruncate: function(content, length, stripTags, words, noBreak, ellipsis){ | |
if(typeof(content) === "undefined" || content === null) | |
return undefined; | |
if(length == null) length = Infinity; | |
if(stripTags == null) stripTags = false; | |
if(words == null) words = true; | |
if(noBreak == null) noBreak = false; | |
if(ellipsis == null) ellipsis = '\u2026'; | |
return $.truncate(content,{ | |
stripTags: stripTags, | |
length: length, | |
words: words, | |
noBreak: noBreak, | |
ellipsis: ellipsis | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment