forked from 0x2620/oxjs
support highlighting in icon list text
This commit is contained in:
parent
4dba56ba87
commit
1ae47b761b
4 changed files with 41 additions and 37 deletions
|
|
@ -8,17 +8,18 @@ Ox.IconItem <f:Ox.Element> IconItem Object
|
|||
(options) -> <f> IconItem Object
|
||||
(options, self) -> <f> IconItem Object
|
||||
options <o> Options object
|
||||
borderRadius <n|0> border radius for icon images
|
||||
iconHeight <n|128> icon height
|
||||
iconWidth <n|128> icon width
|
||||
imageHeight <n|128> icon image height
|
||||
imageWidth <n|128> icon image width
|
||||
id <s> element id
|
||||
info <s> icon info
|
||||
size <n|128> icon size
|
||||
title <s> title
|
||||
url <s> icon url
|
||||
self <o> shared private variable
|
||||
borderRadius <n|0> Border radius for icon images
|
||||
find <s|''> String to be highlighted
|
||||
iconHeight <n|128> Icon height
|
||||
iconWidth <n|128> Icon width
|
||||
imageHeight <n|128> Icon image height
|
||||
imageWidth <n|128> Icon image width
|
||||
id <s> Element id
|
||||
info <s> Icon info
|
||||
size <n|128> Icon size
|
||||
title <s> Title
|
||||
url <s> Icon url
|
||||
self <o> Shared private variable
|
||||
@*/
|
||||
|
||||
Ox.IconItem = function(options, self) {
|
||||
|
|
@ -29,11 +30,11 @@ Ox.IconItem = function(options, self) {
|
|||
var that = Ox.Element({}, self)
|
||||
.defaults({
|
||||
borderRadius: 0,
|
||||
find: '',
|
||||
iconHeight: 128,
|
||||
iconWidth: 128,
|
||||
imageHeight: 128,
|
||||
imageWidth: 128,
|
||||
isInfoList: false,
|
||||
itemHeight: 192,
|
||||
itemWidth: 128,
|
||||
id: '',
|
||||
|
|
@ -43,6 +44,8 @@ Ox.IconItem = function(options, self) {
|
|||
})
|
||||
.options(options || {});
|
||||
|
||||
Ox.print('ICON ITEM FIND', self.options.find)
|
||||
|
||||
Ox.extend(self, {
|
||||
fontSize: self.options.itemWidth == 64 ? 6 : 9,
|
||||
infoIsObject: Ox.isObject(self.options.info),
|
||||
|
|
@ -75,8 +78,7 @@ Ox.IconItem = function(options, self) {
|
|||
that.$icon = $('<div>')
|
||||
.addClass('OxIcon')
|
||||
.css({
|
||||
top: self.options.________isInfoList
|
||||
? 0 : self.options.iconWidth == 64 ? -64 : -124,
|
||||
top: self.options.iconWidth == 64 ? -64 : -124,
|
||||
width: (self.options.iconWidth + 4) + 'px',
|
||||
height: (self.options.iconHeight + 4) + 'px'
|
||||
});
|
||||
|
|
@ -97,9 +99,7 @@ Ox.IconItem = function(options, self) {
|
|||
that.$textBox = $('<div>')
|
||||
.addClass('OxText')
|
||||
.css({
|
||||
top: self.options.________isInfoList
|
||||
? self.options.iconHeight
|
||||
: self.options.iconHeight - self.options.itemWidth / 2 + 'px',
|
||||
top: self.options.iconHeight - self.options.itemWidth / 2 + 'px',
|
||||
width: self.options.itemWidth + 4 + 'px',
|
||||
height: (self.options.itemWidth == 64 ? 30 : 58) + 'px'
|
||||
});
|
||||
|
|
@ -162,18 +162,21 @@ Ox.IconItem = function(options, self) {
|
|||
|
||||
function formatText(text, maxLines, maxLength) {
|
||||
text = Ox.isArray(text) ? text.join(', ') : text;
|
||||
var lines = Ox.wordwrap(text, maxLength, '<br/>', true, false).split('<br/>');
|
||||
return Ox.map(lines, function(line, i) {
|
||||
if (i < maxLines - 1) {
|
||||
return line;
|
||||
} else if (i == maxLines - 1) {
|
||||
return lines.length == maxLines ? line : Ox.truncate(lines.map(function(line, i) {
|
||||
return i < maxLines - 1 ? null : line;
|
||||
}).join(' '), maxLength, '...', 'center');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}).join('<br/>');
|
||||
var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n');
|
||||
return Ox.highlightHTML(
|
||||
Ox.map(lines, function(line, i) {
|
||||
if (i < maxLines - 1) {
|
||||
return line;
|
||||
} else if (i == maxLines - 1) {
|
||||
return lines.length == maxLines ? line : Ox.truncate(lines.map(function(line, i) {
|
||||
return i < maxLines - 1 ? null : line;
|
||||
}).join(' '), maxLength, '...', 'center');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}).join(' <br>'),
|
||||
self.options.find, 'OxHighlight', ['br']
|
||||
).replace(/ (<.*?>)?<br>/g, '$1<br>');
|
||||
}
|
||||
|
||||
function load() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue