I had some down time this afternoon so I thought I would throw something together real quick. I just checked it in: http://dev.jquery.com/browser/trunk/plugins/behavior
This allows you to register any number of behaviors that will run any jQuery method/plugin with any number of arguments. It also allows a plugin developer to register their method so that behavior will auto run when it is done. It also allows the developer to manually run/remove a specific behavior or all behaviors. It seems to be pretty flexible but with behavior auto running after a DOM update, I could see it getting pretty out of hand with performance if lots of behaviors are used. Here is the test/example page that adds three behaviors; an append, click and addClass. I also remove the addClass behavior before doing the last two appendTo and prependTo calls. http://brandon.jquery.com/plugins/behavior/test/test.html -- Brandon Aaron On 4/26/07, John Resig <[EMAIL PROTECTED]> wrote:
.behavior() does not exist - but it could (without too much effort) the current solution with jQuery is shown in the previous slide (which is, unfortunately, rather verbose). I hope that it'll exist one day - I probably should've made that more explicit. You would, "simply", have to override append/prepend/before/after and after the injection has occurred, re-run all "behavior"ed expressions. Of course, you'd also have to cache all expressions for future use (and that's another nut, entirely). If someone feels compelled, you can hack on it - otherwise, I may take a stab at it. --John On 4/26/07, Starbow <[EMAIL PROTECTED]> wrote: > > I was just watching the video of John Resig at Yahoo, and in one slide > he talked about behaviors, as jquery bindings that act like css rules > and apply themselves to html fragments asynchronously loaded into the > page. The code sample looked like this: > > $(document).ready( function() { > $('li").behavior( "click", function() { > $(this).load("menu.html"); > }); > }); > > Is behavior a special jQuery function, something that is in the works, > or is it just a regular function and the code for it was missing from > the slide set? > >