rewrite formatText for clarity, and use new Ox.highlightHTML
This commit is contained in:
parent
40d1d021d4
commit
fef07dff6f
1 changed files with 10 additions and 10 deletions
|
@ -159,17 +159,17 @@ Ox.IconItem = function(options, self) {
|
|||
function formatText(text, maxLines, maxLength) {
|
||||
text = Ox.isArray(text) ? text.join(', ') : text;
|
||||
var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n');
|
||||
return Ox.highlightHTML(
|
||||
lines.slice(0, maxLines).map(function(line, i) {
|
||||
return i < maxLines - 1 || lines.length == maxLines
|
||||
? line
|
||||
: Ox.truncate(
|
||||
lines.slice(maxLines).join(' '),
|
||||
maxLength, '...', 'center'
|
||||
// if the text has too many lines, replace the last line with the
|
||||
// truncated rest (including the last line) and discard all extra lines
|
||||
if (lines.length > maxLines) {
|
||||
lines[maxLines - 1] = Ox.truncate(
|
||||
lines.slice(maxLines - 1).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() {
|
||||
|
|
Loading…
Reference in a new issue