0

*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?

6
  • What are you trying to do? Because I don't see the point. Commented Aug 5, 2013 at 3:55
  • 1
    That looks like reindented obfuscated code. Do you have the original uncompressed source? Commented Aug 5, 2013 at 4:03
  • Original source here: github.com/STAR-ZERO/jquery-ellipsis/blob/master/dist/… Commented Aug 5, 2013 at 4:08
  • I am resizing divs on user input and need to remove the ellipsis created, hence my question Commented Aug 5, 2013 at 4:09
  • why not using ellipsis in CSS property? Commented Aug 5, 2013 at 4:10

1 Answer 1

3

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'))
})
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, how would I use this in practice? Should I update the original code or is this a separate script?
You need to update your original script with the first part then call the second part when you want to reset the values
@alias51 there were few problems with that see jsfiddle.net/arunpjohny/6tHXV
thanks. So if I have more than one div this applies to, what have I missed in this update?: jsfiddle.net/kTGpr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.