[Twisted-web] athena widgets and IE

Cory Dodt corydodt at gmail.com
Wed Oct 11 10:50:13 CDT 2006


On 10/11/06, Jean-Paul Calderone <exarkun at divmod.com> wrote:
>
> On Wed, 11 Oct 2006 12:35:42 +0200, Fabio Forno <fabio.forno at gmail.com>
> wrote:
> >Widgets.ChatWidget = Nevow.Athena.Widget.subclass('Widgets.ChatWidget');
> >
> >Widgets.ChatWidget.methods(
> >
> >    function keyPressed (self, event) {
> >        if(event.key()["string"] == "KEY_ENTER") {
> >            text_area = window.document.getElementById("chat_area");
> >            d = self.callRemote('got_text', text_area.value);
> >            d.addCallback(self.text_sent);
> >        }
> >    }
> >)

 [...]

> >
> >Then in the xml template I try to get a reference to the just defined
> >method in this way:
> >
> >widget = Nevow.Athena.Widget.get(
> >            document.getElementById("athena:1");
> >        );
> >
> >widget.keyPressed
>
> Likewise, "athena:1" is an implementation detail, and you can't rely on
> your widget getting id "1" all the time.  Instead, try using the
> athena:handler feature:
>
>     <div nevow:render="liveFragment">
>       ...
>       <textarea>
>           <athena:handler event="onkeypress" handler="keyPressed" />
>       </textarea>
>     </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.

I suggest this:

YourNS.YourWidget.methods(
    function __init__(self, node) { // {{{
        YourNS.YourWidget.upcall(self, '__init__', node);
        DeanEdwards.addEvent(node, 'keyPressed',
            function onKeyPressed(event) { return self.onKeyPressed(event)
});
    }, // }}}


What's DeanEdwards, you ask?

http://rafb.net/paste/results/57Orqx27.html

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>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20061011/ed892c29/attachment.htm


More information about the Twisted-web mailing list