Request for Aid: Javascript Event Dominance and Submission
I’m having trouble with a GMail reverse-engineering problem and I thought I’d post it here in case anyone had some ideas for breaking through my little impasse. Here’s the problem: I’m adding (decorating, in GoF-speak) an event handler to a GMail control — specifically, the Send button. My objective is for the existing Send button, or one that looks just like it, to fire off my javascript event which manipulates the message body, and then fire the original GMail “send” event.
The original event that Send invokes is an onKeyDown event (it’s a button), and its body is:
top.js._CM_OnSendButtonKeyDown(window,this,event). Here’s where it gets strange.
Google apparently decorates DOM nodes with event handlers based on node IDs. Witness: injecting a new node into the GMail DOM with an ID attribute set to “snd” (the ID of the original “Send” button), automagically sets the onkeydown property of the new node to the _CM_OnSendButtonKeyDown() call. This is both strange, interesting, and really annoying to me.
It’s annoying in that, to make a button do what the built-in Send button does, i apparently need to call _CM_OnSendButtonKeyDown(...), but thusfar, I’ve not been able to invoke that function successfully from any DOM node other than a button whose ID is “snd” — thus invoking GMail’s automatic event handler re-writing and killing my customized, appended event handler.
What i want is a block of code that wraps that handler — something that i can inject some code before the handler that will run, and then the original handler will run. The closest analog I can offer here is the Elisp concept of Advice (read it — it’s cool). Although I’m almost positive there are more modern Javascript analogs I could employ here, I’m not aware of what they would be.
Any help with either A. calling _CM_OnSendButtonKeyDown() from another function / object which fools _CM_OnSendButtonKeyDown() into thinking it was invoked by the “real” Send button, or B. calling the equivalent internal GMail function that does a mesage send (via Venkman, it appears that _CM_OnSendButtonKeyDown() is an alias for the internal jM() function — geeks click here for GMail source dump ).
Feel free to send replies as comments to this post.
Thanks!