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) {
|
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');
|
||||||
|
// 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(
|
return Ox.highlightHTML(
|
||||||
lines.slice(0, maxLines).map(function(line, i) {
|
lines.join(' <br/>'), self.options.find, 'OxHighlight', true
|
||||||
return i < maxLines - 1 || lines.length == maxLines
|
);
|
||||||
? line
|
|
||||||
: Ox.truncate(
|
|
||||||
lines.slice(maxLines).join(' '),
|
|
||||||
maxLength, '...', 'center'
|
|
||||||
);
|
|
||||||
}).join(' <br/>'),
|
|
||||||
self.options.find, 'OxHighlight', ['br']
|
|
||||||
).replace(/ (<.*?>)?<br\/>/g, ' $1<br\/>');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
|
|
Loading…
Reference in a new issue