[Ur] Grabbing focus
Edward Z. Yang
ezyang at MIT.EDU
Tue May 22 15:30:10 EDT 2012
Playing with this a little, I realized this FFI code is a round about
way of implementing (it does use some internal Ur/Web functions though.)
function addOnload(contents, func) {
// func is a string function name; there's probably a better way of doing it
nid = fresh();
return cat(cat("<div id=\"" + nid + "\">", contents), "</div><script type=\"text/javascript\">" + func + "(\"" + nid + "\");</script>");
}
Note that when <script> runs, the node hasn't actually been inserted into
the document yet, so getElementById won't work; but if you do a setTimeout
things work well.
So, I think what I want is the ability to put <script> sections in
documents, and the ability to uniquely reference fragments of xml.
Edward
Excerpts from Edward Z. Yang's message of Sat May 19 00:24:56 -0400 2012:
> I realized that this generalizes a little. Consider the <body onload>
> attribute: this is some client-side code that runs when the page
> finishes rendering. Let's suppose that I want to divide up an Ur/Web
> page into multiple sections, each of which has their own onload fragment.
> There is no way to do this currently (onload is not compositional).
> But you end up in the same place as figuring out when something should
> "grab focus" (in this regime, I need a way of getting a source associated
> with focusing, and then I have some code in the onload which triggers
> the source.)
>
> I want this ability for something else: I'm building a widget which
> should be able to be incorporated into a page multiple times, but
> which must be rendered client-side because it uses higher-order
> functions (so we currently instantiate it from onload).
>
> Edward
>
> Excerpts from Edward Z. Yang's message of Thu May 17 14:23:13 -0400 2012:
> > Excerpts from Adam Chlipala's message of Thu May 17 08:50:51 -0400 2012:
> > > What about a pseudo-attribute (of type [bool] or [unit]) for focus-able
> > > elements, asking to give them focus upon creation? Maybe this is your
> > > first suggestion above.
> >
> > Unfortunately, it's not clear if "on creation" is well defined or
> > has the desired semantics. If I generate an XML fragment but don't
> > put it on the page, it shouldn't grab focus.
> >
> > > What would be a usual way of implementing this in HTML/JavaScript?
> >
> > Let 'el' be a DOMElement that is focusable, then you can focus it
> > by doing 'el.focus()'.
> >
> > Cheers,
> > Edward
More information about the Ur
mailing list