Okay ... I've created a jQuery.fn.behavior() and jQuery.fn.unbehavior(). I haven't checked anything in yet but I have uploaded it to here: http://brandon.jquery.com/plugins/behavior/test/test.html
I also added a pretty rough $.behavior.find() so that unbehavior will work. The only extension I needed to make to the core was exposing the selector and context for the jQuery object. Index: src/jquery/jquery.js =================================================================== --- src/jquery/jquery.js (revision 1827) +++ src/jquery/jquery.js (working copy) @@ -43,8 +43,12 @@ a = jQuery.clean( [ m[1] ] ); // HANDLE: $(expr) - else - return new jQuery( c ).find( a ); + else { + var r = new jQuery( c ).find( a ); + r.selector = a; + r.context = c; + return r; + } } return this.setArray( -- Brandon Aaron On 4/30/07, Brandon Aaron <[EMAIL PROTECTED]> wrote:
Yeah I have an idea... I'm going to go see if it works. :) -- Brandon Aaron On 4/30/07, John Resig <[EMAIL PROTECTED]> wrote: > > Excellent Brandon, this is a great start. I suspect that in order to > get a full "behavior" plugin (one the feels natural) it'll require a > lot of code extensions. Hmm... I wonder if there's anything that can > be added to jQuery proper to ease the process. > > --John > > On 4/28/07, Brandon Aaron <[EMAIL PROTECTED]> wrote: > > > > 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? > > > > > > > > > > > > > >