Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Re-apply Behavior/Delegator when DOM updates (after Request)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rolf-nl  
View profile  
 More options Mar 25 2012, 6:48 pm
From: Rolf-nl <plentyofr...@gmail.com>
Date: Sun, 25 Mar 2012 15:48:11 -0700 (PDT)
Local: Sun, Mar 25 2012 6:48 pm
Subject: Re-apply Behavior/Delegator when DOM updates (after Request)

I have Behavior setup in domready pretty much standard like:
var b = new Behavior();
b.passMethods({
  //nothing now

});

b.apply(document.body);
var d = new Delegator({
  getBehavior: function(){ return b; }

}).attach(document.body);

On some click events (using Delegator) I request (JSONP) additional data.
With the data that is returned I create new links that are injected into
the dom, and I also want to add delegator triggers for various things. How
do I re-init Behavior/Delegator correctly to get this working. If I just
do new Behavior().apply(document.body); it works, but doesn't look right.

The docs state: [..] It will only invoke a filter once, so it's safe to run
it more than once (if the DOM changes, for example).
But should I run Delegator too, is there a better way? TIA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Newton  
View profile  
 More options Mar 25 2012, 11:50 pm
From: Aaron Newton <anut...@gmail.com>
Date: Sun, 25 Mar 2012 20:50:27 -0700
Local: Sun, Mar 25 2012 11:50 pm
Subject: Re: Re-apply Behavior/Delegator when DOM updates (after Request)

Delegator attaches to the document.body and looks for events that bubble up
(like click for example). It doesn't need re-application.

Behavior flags elements that have been instantiated so when it encounters
them again it skips them (unless you force it).

In theory, you should be able to run b.apply(document.body) a dozen times
without ill-effect. When creating new DOM nodes (via Ajax or otherwise)
it's better to only do it to the container you are injecting it in instead
of the document.body as it does have to check, but that check isn't super
expensive. If you look at the examples on dev.clientcide.com of the
Delegator.Ajax triggers you'll see how it fetches new data and runs the new
elements through behavior. Don't forget to cleanup any elements you destroy.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rolf-nl  
View profile  
 More options Mar 26 2012, 6:30 am
From: Rolf-nl <plentyofr...@gmail.com>
Date: Mon, 26 Mar 2012 03:30:49 -0700 (PDT)
Local: Mon, Mar 26 2012 6:30 am
Subject: Re: Re-apply Behavior/Delegator when DOM updates (after Request)

Thanks. I haved looked at the Delegator source more than a few times, I'm
not sure why I asked about re-applying Delegator as it is "event
delegation" that I attach to the body.. hahaha

I will check the examples at the clientcide dev site for Behavior/ajax/etc.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »