[Cosmo-dev] Programmatic widgets and page reflow
Matthew Eernisse
mde at osafoundation.org
Fri Dec 1 21:39:45 PST 2006
Just a quick note -- if you do programmatic instantation of widgets
without giving the widget parser a DOM node to hang it on, like so:
var w = dojo.widget.createWidget("foo:Minimal", { thisProp: 'bar' });
The parser just sticks it on document.body, which (naturally enough)
results in the rendering engine reflowing the page.
In the cal UI, this has the side-effect of causing the scrolling
timed-events canvas to reset scrollTop, making it to jump from 8am
(where we deliberately set it to) to back to the top -- 12am.
This just means if you don't actually intend to append the widget to the
document body, you may be better off either telling it as part of the
constructor where you actually do want it to go:
var w = dojo.widget.createWidget("foo:Minimal", { thisProp: 'bar' },
thingie.thisAttachPoint, 'last');
Or, alternatively you can use a throwaway element that's not actually on
the doc:
var s = document.createElement('span');
var w = dojo.widget.createWidget("foo:Minimal", { thisProp: 'bar' }, s,
'last');
s.removeChild(w.domNode);
// Later on, stick your widget DOM somewhere
someOtherNode.appendChild(w.domNode);
I'd be interested to know if there are better ways to deal with this.
Matthew
More information about the cosmo-dev
mailing list