I am trying to debug an event handling bug in a complicated web
application, but the effect I'm seeing can be reproduced by this
simple example (based one of the Raphaël examples):
https://gist.github.com/965efd95d3b5fffe9f23
That version works as expected — you can drag the red circle
around — but uncommenting the e.stopPropagation() line breaks
dragging. If you have Firebug or Chrome and uncomment the
console.log lines, you can see that the move function is
never called - somehow the mousemove handler for the body
element is being called before the event gets to the circle's
handler.
I don't understand how this can be, since the mousemove
handler on the body element is set in the bubble phase of
event handling. If I understand the order in which events are
processed, as explained here:
http://www.quirksmode.org/js/events_order.html
... the order in which mousemove handlers would be called here
is approximately:
1. the body element's mousemove in the capture phase (null)
2. the svg element's mousemove in the capture phase (null)
3. the circle's mousemove in the capture phase (null)
4. the circle's mousemove in the bubble phase (set by Raphaël
when dragging starts, and which calls the move function)
5. the svg element's mousemove in the bubble phase (null)
6. the body element's mousemove in the bubble phase (set in
the example code, and which stops propagation)
If that's right, I don't understand how stopping propagation of
the event in the mousemove handler of body in the bubble phase
could break dragging, since it should happen *after* the circle
has already dealt with the event.
It would be great if someone could explain what's going on in
this example - have I misunderstood something about the event
model or does Raphaël implement drag() in a surprising way?
Many thanks for any help,
Mark
regards,
mark