Discussion:
Sending a signal to a DOM element
Eoghan
2008-10-29 10:41:20 UTC
Permalink
I have the following:
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
e.stop();
});

I also want to click the anchor on page load, so I have this
elsewhere:
signal('my-anchor-id', 'onclick');

Unfortunately this throws the error 'this._event is undefined' when it
encounters e.stop();
The following also throws the error
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e){ e.stop(); }
});

The only thing that works is the hacky:

connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e._event){ e.stop(); }
});

Is this a rough edge or am I doing it wrong?

Eoghan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
Per Cederberg
2008-10-29 12:04:18 UTC
Permalink
The documentation isn't very good at this point. But you probably want
to mock the browser event object:

var fakeEvent = {};
signal('my-anchor-id', 'onclick', fakeEvent);

You might have to add various properties to the fake event object in
order for your code to work. See the implementation of the
MochiKit.Signal.Event class:

http://trac.mochikit.com/browser/mochikit/trunk/MochiKit/Signal.js

Cheers,

/Per
Post by Eoghan
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
e.stop();
});
I also want to click the anchor on page load, so I have this
signal('my-anchor-id', 'onclick');
Unfortunately this throws the error 'this._event is undefined' when it
encounters e.stop();
The following also throws the error
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e){ e.stop(); }
});
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e._event){ e.stop(); }
});
Is this a rough edge or am I doing it wrong?
Eoghan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
Eoghan
2008-10-29 13:16:56 UTC
Permalink
Great,

What I came up with was:

signal('my-anchor-id', 'onclick', {stop: noop});

Maybe this would be a good edge case example to add to the docs under
Synopsis -> Signal for DOM events:

Eoghan
Post by Per Cederberg
The documentation isn't very good at this point. But you probably want
var fakeEvent = {};
signal('my-anchor-id', 'onclick', fakeEvent);
You might have to add various properties to the fake event object in
order for your code to work. See the implementation of the
http://trac.mochikit.com/browser/mochikit/trunk/MochiKit/Signal.js
Cheers,
/Per
  connect('my-anchor-id', 'onclick', function(e){
     // Do some stuff
     e.stop();
  });
I also want to click the anchor on page load, so I have this
   signal('my-anchor-id', 'onclick');
Unfortunately this throws the error 'this._event is undefined' when it
encounters e.stop();
The following also throws the error
  connect('my-anchor-id', 'onclick', function(e){
     // Do some stuff
     if(e){ e.stop(); }
  });
  connect('my-anchor-id', 'onclick', function(e){
     // Do some stuff
     if(e._event){ e.stop(); }
  });
Is this a rough edge or am I doing it wrong?
Eoghan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
Per Cederberg
2008-10-29 14:33:32 UTC
Permalink
Actually, I think the whole API for the signal() function needs to be
sanity-checked. It works rather poorly if you want to send non-DOM
signals to DOM objects for instance (if you've invented your own
signals for example).

Just waiting for that day when I have loads of spare time on my hands
again... :-)

Meanwhile, feel free to drop me a documentation patch. We are very
liberal with accepting those.

Cheers,

/Per
Post by Eoghan
Great,
signal('my-anchor-id', 'onclick', {stop: noop});
Maybe this would be a good edge case example to add to the docs under
Eoghan
Post by Per Cederberg
The documentation isn't very good at this point. But you probably want
var fakeEvent = {};
signal('my-anchor-id', 'onclick', fakeEvent);
You might have to add various properties to the fake event object in
order for your code to work. See the implementation of the
http://trac.mochikit.com/browser/mochikit/trunk/MochiKit/Signal.js
Cheers,
/Per
Post by Eoghan
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
e.stop();
});
I also want to click the anchor on page load, so I have this
signal('my-anchor-id', 'onclick');
Unfortunately this throws the error 'this._event is undefined' when it
encounters e.stop();
The following also throws the error
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e){ e.stop(); }
});
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e._event){ e.stop(); }
});
Is this a rough edge or am I doing it wrong?
Eoghan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
Per Cederberg
2008-11-24 12:17:16 UTC
Permalink
I finally got around to fixing the MochiKit.Signal.signal() function
when used with DOM elements. As of r1476, the implementation should
work more as expected, simply passing the specified arguments on to
the slot functions.

This will also make it possible to work with "fake" signals on DOM
elements, such as "onshow", "onhide", etc. As a side-note, this is the
first 1.5-only change to MochiKit so far.

Cheers,

/Per
Post by Per Cederberg
Actually, I think the whole API for the signal() function needs to be
sanity-checked. It works rather poorly if you want to send non-DOM
signals to DOM objects for instance (if you've invented your own
signals for example).
Just waiting for that day when I have loads of spare time on my hands
again... :-)
Meanwhile, feel free to drop me a documentation patch. We are very
liberal with accepting those.
Cheers,
/Per
Post by Eoghan
Great,
signal('my-anchor-id', 'onclick', {stop: noop});
Maybe this would be a good edge case example to add to the docs under
Eoghan
Post by Per Cederberg
The documentation isn't very good at this point. But you probably want
var fakeEvent = {};
signal('my-anchor-id', 'onclick', fakeEvent);
You might have to add various properties to the fake event object in
order for your code to work. See the implementation of the
http://trac.mochikit.com/browser/mochikit/trunk/MochiKit/Signal.js
Cheers,
/Per
Post by Eoghan
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
e.stop();
});
I also want to click the anchor on page load, so I have this
signal('my-anchor-id', 'onclick');
Unfortunately this throws the error 'this._event is undefined' when it
encounters e.stop();
The following also throws the error
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e){ e.stop(); }
});
connect('my-anchor-id', 'onclick', function(e){
// Do some stuff
if(e._event){ e.stop(); }
});
Is this a rough edge or am I doing it wrong?
Eoghan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...