<br><div><span class="gmail_quote">On 10/11/06, <b class="gmail_sendername">Jean-Paul Calderone</b> <<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, 11 Oct 2006 12:35:42 +0200, Fabio Forno <<a href="mailto:fabio.forno@gmail.com">fabio.forno@gmail.com</a>> wrote:<br>>Widgets.ChatWidget = Nevow.Athena.Widget.subclass('Widgets.ChatWidget');<br>><br>>
Widgets.ChatWidget.methods(<br>><br>> function keyPressed (self, event) {<br>> if(event.key()["string"] == "KEY_ENTER") {<br>> text_area = window.document.getElementById
("chat_area");<br>> d = self.callRemote('got_text', text_area.value);<br>> d.addCallback(self.text_sent);<br>> }<br>> }<br>>)</blockquote><div> [...]</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
><br>>Then in the xml template I try to get a reference to the just defined<br>>method in this way:<br>><br>>widget = Nevow.Athena.Widget.get(<br>> document.getElementById("athena:1");
<br>> );<br>><br>>widget.keyPressed<br><br>Likewise, "athena:1" is an implementation detail, and you can't rely on<br>your widget getting id "1" all the time. Instead, try using the<br>
athena:handler feature:<br><br> <div nevow:render="liveFragment"><br> ...<br> <textarea><br> <athena:handler event="onkeypress" handler="keyPressed" />
<br> </textarea><br> </div><br><br></blockquote></div>The problem is he needs to examine the event details after it's received, and athena:handler only gives the event handler access to the node where it happened, not the event object.
<br><br>I suggest this:<br><br>YourNS.YourWidget.methods(<br> function __init__(self, node) { // {{{<br> YourNS.YourWidget.upcall(self, '__init__', node);<br> DeanEdwards.addEvent(node, 'keyPressed', <br>
function onKeyPressed(event) { return self.onKeyPressed(event) });<br> }, // }}}<br><br><br>What's DeanEdwards, you ask? <br><br><a href="http://rafb.net/paste/results/57Orqx27.html">http://rafb.net/paste/results/57Orqx27.html
</a><br><br>Dean Edwards came up with a nifty cross-browser event handling solution, but there are others that could work here. I adapted his solution to the Divmod namespace style, and added line 63 so .target and .srcElement mean the same thing. The above URL will rot pretty quickly, so just google for <dean edwards event handling>.
<br><br><br>