rewrite formatText for clarity, and use new Ox.highlightHTML

This commit is contained in:
rolux 2012-05-27 12:38:14 +02:00
parent 40d1d021d4
commit fef07dff6f

View file

@ -159,17 +159,17 @@ Ox.IconItem = function(options, self) {
function formatText(text, maxLines, maxLength) { function formatText(text, maxLines, maxLength) {
text = Ox.isArray(text) ? text.join(', ') : text; text = Ox.isArray(text) ? text.join(', ') : text;
var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n'); var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n');
return Ox.highlightHTML( // if the text has too many lines, replace the last line with the
lines.slice(0, maxLines).map(function(line, i) { // truncated rest (including the last line) and discard all extra lines
return i < maxLines - 1 || lines.length == maxLines if (lines.length > maxLines) {
? line lines[maxLines - 1] = Ox.truncate(
: Ox.truncate( lines.slice(maxLines - 1).join(' '), maxLength, '...', 'center'
lines.slice(maxLines).join(' '), );
maxLength, '...', 'center' lines = lines.slice(0, maxLines);
}
return Ox.highlightHTML(
lines.join(' <br/>'), self.options.find, 'OxHighlight', true
); );
}).join(' <br/>'),
self.options.find, 'OxHighlight', ['br']
).replace(/ (<.*?>)?<br\/>/g, ' $1<br\/>');
} }
function load() { function load() {