BB.Net / ramblings / posts / JQuery Dotspinner

I while back I got fed up with trying to find a decent spinner gif for some AJAX pages. I gave up and just wrote one using ascii. This has the benefit of always fitting in with the page style and users font settings.

do_dotspinner = function (scope)
{
    var spin_element = function (el)
    {
        max = 5;
        var text = el.innerHTML
        if (text.length==max)
            text="";
        text += ".";
        el.innerHTML = text;
    }

    var els = $(".dotspinner",scope);

    if(!els.length) return;

    els.each(function(){
        spin_element(this);
    });

    var repeat = function(){
        do_dotspinner(scope);
    }

    setTimeout(repeat, 200);
}

download file "/ramblings/files/js/dotspinner.js"

And since I doubt it will work if I inline it into a blog post, here is a demo.

I've been trying to make it work like an actual plugin, but I haven't been able to get that to work yet.

I should be able to make something like this work:

$(".dotspinner").dotspinner();

But I need to figure out how to tell when an element goes away

For example, if I have

p=$("#foo");
//and do this:
$("body").html("Hi");
// then these still works like nothing happend:
p.text();
$(p).text();
//even though if I do this again, it is gone:
p=$("#foo");
//The one thing I know will work, but is probably wrong, is this:
p = $('#' + p.attr("id"));