Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Is it possible to execute behavior function for element from outside of this behavior?
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
  4 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:
Follow-up To:
Add Cc | Add Follow-up 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 that you hear
 
szimek  
View profile   Translate to Translated (View Original)
 More options 27 May, 10:33
From: szimek <szi...@gmail.com>
Date: Wed, 27 May 2009 02:33:12 -0700 (PDT)
Local: Wed 27 May 2009 10:33
Subject: Is it possible to execute behavior function for element from outside of this behavior?
Hi,

I made a behavior for span elements that simply toggle themselfes
between add/cancel state and additionally toggle some element on the
page (i.e. a form) on onclick event - http://gist.github.com/118542.

It works fine, but the problem is when this is used to show i.e. a
form. In this case I'd like onclick event handler to be executed when
the form is submitted, so that I can hide the form and update span
element. The main problem is that I can't simply fire onclick event on
span element, which would solve the problem.

Do you have any other ideas how to solve it?


    Reply to author    Forward  
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.
MRoderick  
View profile   Translate to Translated (View Original)
 More options 27 May, 12:33
From: MRoderick <roderick.mor...@gmail.com>
Date: Wed, 27 May 2009 04:33:10 -0700 (PDT)
Local: Wed 27 May 2009 12:33
Subject: Re: Is it possible to execute behavior function for element from outside of this behavior?
On 27 May, 11:33, szimek <szi...@gmail.com> wrote:

> Hi,

> I made a behavior for span elements that simply toggle themselfes
> between add/cancel state and additionally toggle some element on the
> page (i.e. a form) on onclick event -http://gist.github.com/118542.

> It works fine, but the problem is when this is used to show i.e. a
> form. In this case I'd like onclick event handler to be executed when
> the form is submitted, so that I can hide the form and update span
> element. The main problem is that I can't simply fire onclick event on
> span element, which would solve the problem.

> Do you have any other ideas how to solve it?

Assuming the form and the span tags are closely related, why not just
create the behavior on a containing element?

Then you can have an internal function in the behavior, that can be
called from both onclick and onsubmit events.

If you use event delegation with Low Pro, it's actually quite simple.

I recently gave a very brief intro to Low Pro at a local JavaScript
meetup, and for that purpose I created a small behavior for a form,
that has both an onsubmit event listener as well as an event delegate.
You can check out the details http://roderick.dk/blog/2009/05/07/introduction-to-low-pro-for-protot...
and from studying the example a bit, I am pretty sure it becomes clear
how to create behaviors that use containing elements.

/Morgan


    Reply to author    Forward  
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.
Nathan  
View profile   Translate to Translated (View Original)
 More options 31 May, 08:50
From: Nathan <XGamer...@gmail.com>
Date: Sun, 31 May 2009 00:50:07 -0700 (PDT)
Local: Sun 31 May 2009 08:50
Subject: Re: Is it possible to execute behavior function for element from outside of this behavior?
I agree with Morgan's take which is to use Event.delegate within a
container element to easily have access to both the span and the form
from a single behavior.

Otherwise, you can indeed execute a behavior outside the behavior. i.e

var example = new Link.Toggle($('some-element'));

then

example.onclick(event);

or you can access the instances of a behavior and find the right one
that way:

Link.Toggle.instances().first().onclick(event);


    Reply to author    Forward  
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.
szimek  
View profile   Translate to Translated (View Original)
 More options 31 May, 18:05
From: szimek <szi...@gmail.com>
Date: Sun, 31 May 2009 10:05:53 -0700 (PDT)
Local: Sun 31 May 2009 18:05
Subject: Re: Is it possible to execute behavior function for element from outside of this behavior?
Thanks for both tips and for the link to the presentation - I totally
forgot about Event.delegate and was using event.element().match
(selector) inside if/else statements - it's actually the same, but
Event.delegate is cleaner.

On 31 Maj, 09:50, Nathan <XGamer...@gmail.com> wrote:


    Reply to author    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google