Adding athena.LiveElement to an already-rendered LivePage
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? Regards, -- m
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak <michal.dtz@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. Jean-Paul
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak <michal.dtz@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.
Wiki FAQ updated, thanks! :-) -- m
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak <michal.dtz@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?
I want to append incoming LiveFragments to the page. Right now, I am doing something like this on the client: // import Divmod.Runtime What.Ever = Nevow.Athena.Widget.subclass('What.Ever'); What.Ever.methods =( function foo(self) { d = self.callRemote('getLiveFragment'); d.addCallback( function liveFragmentReceived(lf) { d2 = self.addChildWidgetFromWidgetInfo(lf); d2.addCallback( function added(res) { d = Divmod.Runtime.theRuntime.parseXHTMLString( lf.markup).documentElement; self.nodeById('lastNode').appendChild(d); }); }); }); Is this the official way of doing that, or am I missing something? -- m
On Sun, Nov 9, 2008 at 9:09 PM, Michał Pasternak <michal.dtz@gmail.com>wrote:
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak < michal.dtz@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; }, Harald
On Sun, 9 Nov 2008 21:50:45 +0100, Harald Blåtand <kozneb@gmail.com> wrote:
On Sun, Nov 9, 2008 at 9:09 PM, Michał Pasternak <michal.dtz@gmail.com>wrote:
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak < michal.dtz@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
On Sun, Nov 9, 2008 at 10:10 PM, Jean-Paul Calderone <exarkun@divmod.com>wrote:
On Sun, 9 Nov 2008 21:50:45 +0100, Harald Blåtand <kozneb@gmail.com> wrote:
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.
Don't feel confident enough yet in what I'm doing to report any bugs :) 1) Getting IE to buy script tags in the body... seems to require this kludge 2) Combining Nevow and jQuery, to get resizable/draggable widgets 3) Trying out a "Stan alternative" (see below) 4) Having fun :) In case you're interested - def makeDF(xmlDct, filling={}): return loaders.xmlstr(xmlFragments.dictToXML(xmlDct) % filling) class XhMain(athena.LiveFragment): XM = '''\ div xmlns:nevow="http://nevow.com/ns/nevow/0.1" xmlns:athena="http://divmod.org/ns/athena/0.7" nevow:render="liveFragment"''' class GeneralStuff(XhMain, SqlMethods, HtmlMethods): ht = [ {'script' : '''$(function(){ $(".initDraggable").draggable().resizable().bind("resize", resizeHandler).removeClass("initDraggable"); $(".initResult").addClass("autoScroll").removeClass("initResult"); $(".initClick").click().removeClass("initClick"); })'''}, {'div class="draggable initDraggable"' : [ ....... {'div class="menubar"' : [ {'a href="#" class="click initClick"' : [{'athena:handler event="onclick" handler="widget_action"' : ''}, {'span' : 'Refresh'},]}, ] }, {'div id="result" class="result initResult"' : ''}, ] }, ] def __init__(self, db): ..... self.jsClass = self.args['jsClass'] self.docFactory = makeDF({self.XM : self.ht}, self.args) super(GeneralStuff, self).__init__() class Abstract(GeneralStuff): def __init__(self, db, a={}): self.args = { 'jsClass' : u"XH.Abstract", 'widgetHeader' : "Abstract", } self.args.update(a) super(Abstract, self).__init__(db) self.addToMenu({'a href="#" class="click"' : [{'athena:handler event="onclick" handler="mark_for_deletion"' : ''}, {'span' : 'Delete'},]})
On Sun, 09 Nov 2008 21:09:41 +0100, Michał Pasternak <michal.dtz@gmail.com> wrote:
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak <michal.dtz@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?
I want to append incoming LiveFragments to the page.
Right now, I am doing something like this on the client:
// import Divmod.Runtime
What.Ever = Nevow.Athena.Widget.subclass('What.Ever'); What.Ever.methods =(
function foo(self) { d = self.callRemote('getLiveFragment');
d.addCallback(
function liveFragmentReceived(lf) {
d2 = self.addChildWidgetFromWidgetInfo(lf);
d2.addCallback(
function added(res) {
d = Divmod.Runtime.theRuntime.parseXHTMLString( lf.markup).documentElement;
self.nodeById('lastNode').appendChild(d);
});
});
You don't have to parse the markup. It's already parsed. The DOM element which results is the `node´ attribute of the Widget instance (which you get as `res´ - the result of the callback). You shouldn't use any attributes of `lf´, since it is an opaque handle: there is no API stability guarantee about it. The *only* thing you can do with it is pass it to `addChildWidgetFromWidgetInfo´. Jean-Paul
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 21:09:41 +0100, Michał Pasternak <michal.dtz@gmail.com> wrote:
Jean-Paul Calderone pisze:
On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak <michal.dtz@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?
I want to append incoming LiveFragments to the page.
Right now, I am doing something like this on the client:
// import Divmod.Runtime
What.Ever = Nevow.Athena.Widget.subclass('What.Ever'); What.Ever.methods =(
function foo(self) { d = self.callRemote('getLiveFragment');
d.addCallback(
function liveFragmentReceived(lf) {
d2 = self.addChildWidgetFromWidgetInfo(lf);
d2.addCallback(
function added(res) {
d = Divmod.Runtime.theRuntime.parseXHTMLString( lf.markup).documentElement;
self.nodeById('lastNode').appendChild(d);
});
});
You don't have to parse the markup. It's already parsed. The DOM element which results is the `node´ attribute of the Widget instance (which you get as `res´ - the result of the callback). You shouldn't use any attributes of `lf´, since it is an opaque handle: there is no API stability guarantee about it. The *only* thing you can do with it is pass it to `addChildWidgetFromWidgetInfo´.
Yes sir! To whom it may concern: I've created a short how-to page: http://divmod.org/trac/wiki/DivmodNevow/Athena/Tutorials/LiveElementsOnFly -- m
participants (3)
-
Harald Blåtand -
Jean-Paul Calderone -
Michał Pasternak