From fef07dff6f9cc34f4b7a65d9a4c082809a956ce9 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 27 May 2012 12:38:14 +0200 Subject: [PATCH] rewrite formatText for clarity, and use new Ox.highlightHTML --- source/Ox.UI/js/List/Ox.IconItem.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/Ox.UI/js/List/Ox.IconItem.js b/source/Ox.UI/js/List/Ox.IconItem.js index e7faa0bf..d2853550 100644 --- a/source/Ox.UI/js/List/Ox.IconItem.js +++ b/source/Ox.UI/js/List/Ox.IconItem.js @@ -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'); + // 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.slice(0, maxLines).map(function(line, i) { - return i < maxLines - 1 || lines.length == maxLines - ? line - : Ox.truncate( - lines.slice(maxLines).join(' '), - maxLength, '...', 'center' - ); - }).join('
'), - self.options.find, 'OxHighlight', ['br'] - ).replace(/ (<.*?>)?/g, ' $1'); + lines.join('
'), self.options.find, 'OxHighlight', true + ); } function load() {