Reputation: 8638
*UPDATE *: Demo here: http://jsfiddle.net/cEepx/
I have this code that adds an ellipsis to the end of a text row before wrap:
(function (e) {
e.fn.ellipsis = function (t) {
var n = {
row: 1,
"char": "..."
};
return t = e.extend(n, t), this.each(function () {
var n = e(this),
r = n.text(),
i = n.height();
n.text("a");
var s = n.height(),
o = s * t.row;
if (i <= o) {
n.text(r);
return
}
var u = 1,
a = r.length;
while (u < a) {
var f = Math.ceil((u + a) / 2);
n.text(r.slice(0, f) + t["char"]), n.height() <= o ? u = f : a = f - 1
}
n.text(r.slice(0, u) + t["char"])
}), this
}
})(jQuery);
It is applied simply as:
$("div.mydiv").ellipsis();
How can I modify it to add a second function to remove the ellipsis from mydiv once they are added?
Upvotes: 0
Views: 120
Reputation: 388406
I don't see a direct way to fix it, but you could probably use a hack..
Store the original text as data
$("div.mydiv").each(function(){
$(this).data('origtext', $(this).text())
}).ellipsis();
Then use it to reverse the content
$("div.mydiv").text(function(){
return $(this.data('origtext'))
})
Upvotes: 3