change the signature of Ox.truncate to allow for passing 'position' without having to pass 'padding', change default padding from '...' to a real ellipsis
This commit is contained in:
parent
3ec610076a
commit
9ce126263b
2 changed files with 12 additions and 13 deletions
|
@ -163,7 +163,7 @@ Ox.IconItem = function(options, self) {
|
||||||
// truncated rest (including the last line) and discard all extra lines
|
// truncated rest (including the last line) and discard all extra lines
|
||||||
if (lines.length > maxLines) {
|
if (lines.length > maxLines) {
|
||||||
lines[maxLines - 1] = Ox.truncate(
|
lines[maxLines - 1] = Ox.truncate(
|
||||||
lines.slice(maxLines - 1).join(' '), maxLength, '...', 'center'
|
lines.slice(maxLines - 1).join(' '), 'center', maxLength
|
||||||
);
|
);
|
||||||
lines = lines.slice(0, maxLines);
|
lines = lines.slice(0, maxLines);
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,22 +469,21 @@ Ox.toUnderscores = function(string) {
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.truncate <f> Truncate a string to a given length
|
Ox.truncate <f> Truncate a string to a given length
|
||||||
(string, length) <s> Truncated string
|
(string[, position], length[, padding]) -> Truncated string
|
||||||
(string, length, position) -> <s> Truncated string
|
|
||||||
(string, length, placeholder) -> <s> Truncated string
|
|
||||||
(string, length, position, placeholder) -> <s> Truncated string
|
|
||||||
> Ox.truncate('anticonstitutionellement', 16)
|
> Ox.truncate('anticonstitutionellement', 16)
|
||||||
|
'anticonstitutio…'
|
||||||
|
> Ox.truncate('anticonstitutionellement', 'left', 16)
|
||||||
|
'…itutionellement'
|
||||||
|
> Ox.truncate('anticonstitutionellement', 16, '...')
|
||||||
'anticonstitut...'
|
'anticonstitut...'
|
||||||
> Ox.truncate('anticonstitutionellement', 16, '...', 'left')
|
> Ox.truncate('anticonstitutionellement', 'center', 16, '...')
|
||||||
'...utionellement'
|
|
||||||
> Ox.truncate('anticonstitutionellement', 16, '>')
|
|
||||||
'anticonstitutio>'
|
|
||||||
> Ox.truncate('anticonstitutionellement', 16, '...', 'center')
|
|
||||||
'anticon...lement'
|
'anticon...lement'
|
||||||
@*/
|
@*/
|
||||||
Ox.truncate = function(string, length, padding, position) {
|
Ox.truncate = function(string, position, length, padding) {
|
||||||
padding = padding || '...';
|
var hasPosition = Ox.isString(arguments[1]), last = Ox.last(arguments);
|
||||||
position = position || 'right';
|
position = hasPosition ? arguments[1] : 'right';
|
||||||
|
length = hasPosition ? arguments[2] : arguments[1];
|
||||||
|
padding = Ox.isString(last) ? last : '…';
|
||||||
if (string.length > length) {
|
if (string.length > length) {
|
||||||
if (position == 'left') {
|
if (position == 'left') {
|
||||||
string = padding
|
string = padding
|
||||||
|
|
Loading…
Add table
Reference in a new issue