|
Revision 2, 1.3 kB
(checked in by nperriault, 2 years ago)
|
First commit of the extracted code from production, I hope no passwd has been forgotten :-)
|
| Line | |
|---|
| 1 |
/** |
|---|
| 2 |
* Text autotruncating plugin, by Brian Reindel http://www.reindel.com/truncate/ |
|---|
| 3 |
* Modified by Nicolas Perriault for Symfonians.net |
|---|
| 4 |
*/ |
|---|
| 5 |
jQuery.fn.truncate = function(max,settings) { |
|---|
| 6 |
settings = jQuery.extend({ |
|---|
| 7 |
chars: /\s/, |
|---|
| 8 |
leave: false, |
|---|
| 9 |
trail: [false, "...", ""] |
|---|
| 10 |
}, settings); |
|---|
| 11 |
return this.each(function() { |
|---|
| 12 |
if (!settings.leave || (settings.leave && jQuery(this).children().length == 0)) { |
|---|
| 13 |
var v = jQuery.trim(jQuery(this).text()); |
|---|
| 14 |
var d; |
|---|
| 15 |
while (max < v.length) { |
|---|
| 16 |
c = v.charAt(max); |
|---|
| 17 |
if (c.match(settings.chars)) { |
|---|
| 18 |
d = v.substring(0,max) + settings.trail[1]; |
|---|
| 19 |
jQuery(this).html(d); |
|---|
| 20 |
break; |
|---|
| 21 |
} |
|---|
| 22 |
max--; |
|---|
| 23 |
} |
|---|
| 24 |
if (settings.trail[0]) { |
|---|
| 25 |
if (!d) return; |
|---|
| 26 |
jQuery(this).html("<span>" + d + "</span>").append("<span>" + v + "</span>").find("span:eq(1)").append(settings.trail[2]).css("display","none"); |
|---|
| 27 |
jQuery("a:eq(0)",this).click(function() { |
|---|
| 28 |
jQuery(this).parent().css("display","none").parent().find("span:eq(1)").css("display","inline"); |
|---|
| 29 |
return false; |
|---|
| 30 |
}); |
|---|
| 31 |
jQuery("a:eq(1)",this).click(function() { |
|---|
| 32 |
jQuery(this).parent().css("display","none").parent().find("span:eq(0)").css("display","inline"); |
|---|
| 33 |
return false; |
|---|
| 34 |
}); |
|---|
| 35 |
} |
|---|
| 36 |
} |
|---|
| 37 |
}); |
|---|
| 38 |
}; |
|---|