[Twisted-web] Adding athena.LiveElement to an already-rendered LivePage

Jean-Paul Calderone exarkun at divmod.com
Sun Nov 9 16:10:46 EST 2008


On Sun, 9 Nov 2008 21:50:45 +0100, Harald Blåtand <kozneb at gmail.com> wrote:
>On Sun, Nov 9, 2008 at 9:09 PM, Michał Pasternak <michal.dtz at gmail.com>wrote:
>
>> Jean-Paul Calderone pisze:
>>
>>> On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak <
>>> michal.dtz at gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I want to be able to add athena.LiveElement to an already rendered
>>>> LivePage. Quick Googling revealed this blog entry:
>>>>
>>>>   http://techblog.ironfroggy.com/2006/01/nevow-post-render-injection-of.html
>>>>
>>>> I'd like to know, if there are any other, simpler ways to do that - or,
>>>> maybe, is there a preferred method to do that in the API already?
>>>>
>>>
>>> See Nevow.Athena.Widget.addChildWidgetFromWidgetInfo.
>>>
>> This method will not add the markup automatically. Am I right?
>
>
>Yep, I think you're right.
>
>
>>
>> Is this the official way of doing that, or am I missing something?
>>
>
>
>I'm on a similar track - here's what I use (don't know if it's "official"
>either :) -
>
>    function createDynamicWidget(self, className, left, top, args, kw) {
>        var result = self.callRemote('getDynamicWidget', className, left,
>top, args, ((kw) ? kw : {}));
>        result.addCallback(
>            function(widgetInfo) {
>                return self.addChildWidgetFromWidgetInfo(widgetInfo);
>            });
>        result.addCallback(
>            function(widget) {
>                var insertedNode =
>document.body.children(0).insertAdjacentElement('beforeBegin', widget.node);
>                var s = insertedNode.getElementsByTagName('script');
>                if (s.length == 1) {
>                    var js = new Function(s[0].text);
>                    js.apply(insertedNode);
>                }
>                insertedNode.style.zIndex = ++max_zIndex;
>                return widget.objectID;
>            });
>        return result;
>    },

I'm not sure why you're re-evaluating the contents of the script node.
Athena has already evaluated that script.  If you find some case where
this isn't true, please report a bug.

Jean-Paul



More information about the Twisted-web mailing list