[jQuery] jQuery stylesheets

[jQuery] jQuery stylesheets

Recently I've been playing with loading of HTML into pages dynamically,
which lead to my script evaluation plugin, that I posted yesterday.
Now I've hit another problem:
I'd like to apply a common set of operations (ie. applying plugins)
to all elements on a page, whether they were there from the start,
or loaded dynamically.
The first part is easily handled by $(document).ready(), but loaded
content can only be processed by supplying a callback every time.
The solution I've considered is to register callback functions that
act like stylesheets, and are applied to dynamic content.
eg:
$.stylesheet(function() {
$('input').each(function() {
$(this).addClass(this.type);
});
});
This stylesheet adds the input type to the class name, so we can style
different input types individually (in browser that don't fully
implement CSS selectors, you know who you are! ;)
$.stylesheet is the registration function.
Within the 'load' function, or other places where content is added,
we call:
self.applyStylesheets();
Here is the implementation of these functions:
$.stylesheet = function(callback) {
    if ($.stylesheet.list === undefined)
        $.stylesheet.list = new Array();
    
    if (typeof callback == 'function')
        $.stylesheet.list.push(callback);
};
$.fn.applyStylesheets = function() {
    if (typeof $.stylesheet.list == 'object') {
        var self = this;
        $.each($.stylesheet.list, function() {
            if (typeof this == 'function') {
                this.call(self);
            }
        });
    }
    return this;
};
What do you think?
Cheers
- Mark Gibson
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/