[jQuery] Re: Intercept javascript event

2009-09-15 Thread sirrocco

AOP is not really the answere here. As you can see there is a callback
function - so the user presses some other buttons and then I have to
replay the initial button's onclick functions.

On Sep 15, 3:12 am, Steven Black ste...@stevenblack.com wrote:
 One idea: have a look at the Aspect Oriented Programming plugin.

 Seehttp://plugins.jquery.com/project/AOP
 andhttp://code.google.com/p/jquery-aop/

 If this isn't exactly what you are looking for, then therin is code to
 pre- and post-hook existing events.

 I hope this helps.

 **--**  Steve

 On Sep 14, 1:05 pm, sirrocco xavier...@gmail.com wrote:

  Here's what I'm trying to do :

  I have a page with some links. Most links have a function attached to
  them on the onclick event.

  Now, I want to set a css class to some links and then whenever one of
  the links is clicked I want to execute a certain function - after it
  returns , I want the link to execute the onclick functions that were
  attached to it.

  Is there a way to do what I want ?

  Here's an attempt at an example :

  $(#link).click(function1);
  $(#link).click(function2);
  $(#link).click(function(){
     firstFunctionToBeCalled(function (){
        // ok, we're inside the callback - now execute function1 and
  function2
     });

  }); // somehow this needs to be the first one that is called

  function firstFunctionToBeCalled(callback){
      // here some user input is expected so function1 and function2
  must not get called
      callback();

  }

  All this is because I'm asked to put some confirmation boxes (using
  boxy) for a lot of buttons and I really don't want to be going through
  every button.


[jQuery] Get the onclick method of an element

2009-09-15 Thread sirrocco

Let's say you have a :

a href=# onclick='DoSomething(this);'asd/a

I want to get the onclick text in a variable - something like

var onclick = $('a').attr('onclick');

The problem is that the onclick variable now is a function and if I
try to execute , this   wil be the document instead of the link .

How can I get only the text, so I can later reattach it to the link ?


[jQuery] Re: Get the onclick method of an element

2009-09-15 Thread sirrocco

Well .. that's the problem - i tried it like that and it didn't work.

When setting the attribute back on the link, the this in DoSomething
(this); is not the link, but the window.

On Sep 15, 11:41 am, MiKiTiE mikiji...@googlemail.com wrote:
 Sorry I should have written

 $('a').attr('onclick',onclick);

 (setting the attribute value not the inner text!)

 On Sep 15, 9:09 am, sirrocco xavier...@gmail.com wrote:

  Let's say you have a :

  a href=# onclick='DoSomething(this);'asd/a

  I want to get the onclick text in a variable - something like

  var onclick = $('a').attr('onclick');

  The problem is that the onclick variable now is a function and if I
  try to execute , this   wil be the document instead of the link .

  How can I get only the text, so I can later reattach it to the link ?




[jQuery] Re: Get the onclick method of an element

2009-09-15 Thread sirrocco

Perhaps then you can extract it as text like I mentioned in my first
post, then store it in a variable?

How do I extract it like text ? Calling the .text() method, as
expected doesn't return what I need - DoSomething(this);

On Sep 15, 3:30 pm, MiKiTiE mikiji...@googlemail.com wrote:
 Perhaps then you can extract it as text like I mentioned in my first
 post, then store it in a variable?

 As I am not sure what your function does or why it needs to be applied
 this way, I can't solve the problem exactly - but why not just use an
 event instead of an onclick in the element? That is what jQuery is
 there for :-)

 On Sep 15, 9:50 am, sirrocco xavier...@gmail.com wrote:

  Well .. that's the problem - i tried it like that and it didn't work.

  When setting the attribute back on the link, the this in DoSomething
  (this); is not the link, but the window.

  On Sep 15, 11:41 am,MiKiTiEmikiji...@googlemail.com wrote:

   Sorry I should have written

   $('a').attr('onclick',onclick);

   (setting the attribute value not the inner text!)

   On Sep 15, 9:09 am, sirrocco xavier...@gmail.com wrote:

Let's say you have a :

a href=# onclick='DoSomething(this);'asd/a

I want to get the onclick text in a variable - something like

var onclick = $('a').attr('onclick');

The problem is that the onclick variable now is a function and if I
try to execute , this   wil be the document instead of the link .

How can I get only the text, so I can later reattach it to the link ?




[jQuery] Re: Get the onclick method of an element

2009-09-15 Thread sirrocco _
Damn ... I somehow thought this would be easy to achive .

The whole idea was to not change existing code 

Still .. if anyone has any more ideas :). Somehow it seems that this should
be doable.

On Tue, Sep 15, 2009 at 6:03 PM, MiKiTiE mikiji...@googlemail.com wrote:


 Ok, I've done some tests and here is my suggestion.

 First of all, should just ask - I assume you are calling it after the
 element? Probably is obvious, but thought I'd check.

 Ok, here's the deal: onclick is not really an attribute but a mouse
 event. Therefore jQuery will take the contents as a function and write
 it out as an event. The only alternative is to insert your DoSomething
 (this); into a standard attribute like title or alt and then take
 it from there. This way you should be able to insert it exactly as its
 written and not have it converted into an event.

 Hope this will help?

 On Sep 15, 2:31 pm, sirrocco xavier...@gmail.com wrote:
  Perhaps then you can extract it as text like I mentioned in my first
 
  post, then store it in a variable?
 
  How do I extract it like text ? Calling the .text() method, as
  expected doesn't return what I need - DoSomething(this);
 
  On Sep 15, 3:30 pm,MiKiTiEmikiji...@googlemail.com wrote:
 
   Perhaps then you can extract it as text like I mentioned in my first
   post, then store it in a variable?
 
   As I am not sure what your function does or why it needs to be applied
   this way, I can't solve the problem exactly - but why not just use an
   event instead of an onclick in the element? That is what jQuery is
   there for :-)
 
   On Sep 15, 9:50 am, sirrocco xavier...@gmail.com wrote:
 
Well .. that's the problem - i tried it like that and it didn't work.
 
When setting the attribute back on the link, the this in DoSomething
(this); is not the link, but the window.
 
On Sep 15, 11:41 am,MiKiTiEmikiji...@googlemail.com wrote:
 
 Sorry I should have written
 
 $('a').attr('onclick',onclick);
 
 (setting the attribute value not the inner text!)
 
 On Sep 15, 9:09 am, sirrocco xavier...@gmail.com wrote:
 
  Let's say you have a :
 
  a href=# onclick='DoSomething(this);'asd/a
 
  I want to get the onclick text in a variable - something like
 
  var onclick = $('a').attr('onclick');
 
  The problem is that the onclick variable now is a function and if
 I
  try to execute , this   wil be the document instead of the link .
 
  How can I get only the text, so I can later reattach it to the
 link ?
 



[jQuery] Intercept javascript event

2009-09-14 Thread sirrocco

Here's what I'm trying to do :

I have a page with some links. Most links have a function attached to
them on the onclick event.

Now, I want to set a css class to some links and then whenever one of
the links is clicked I want to execute a certain function - after it
returns , I want the link to execute the onclick functions that were
attached to it.

Is there a way to do what I want ?

Here's an attempt at an example :

$(#link).click(function1);
$(#link).click(function2);
$(#link).click(function(){
   firstFunctionToBeCalled(function (){
  // ok, we're inside the callback - now execute function1 and
function2
   });
}); // somehow this needs to be the first one that is called


function firstFunctionToBeCalled(callback){
// here some user input is expected so function1 and function2
must not get called
callback();

}

All this is because I'm asked to put some confirmation boxes (using
boxy) for a lot of buttons and I really don't want to be going through
every button.