Knowing when DOM is fully rendered after RichTextArea.setHTML() is called?

58 views
Skip to first unread message

TimOnGmail

unread,
Oct 11, 2012, 6:32:12 PM10/11/12
to google-we...@googlegroups.com
Hey folks...

So I have a need to make a call to RichTextArea.setHTML(), and then parse the rendered DOM in the IFRAME and add click listeners to some of the elements in it.

This works fine sometimes, but, depending on the browser, the DOM in the IFRAME appears "ready/finished" at different times.  It would be nice to know when the rendering is complete and the DOM ready to have event listeners added, but I can't seem to find any aspect of the RichTextArea that allows that.  I can override onLoad(), I can add InitializationListeners, etc. and I've tried all of that, but it doesn't always work.  It seems to be dependent on how long the given browser takes to get the DOM ready, but there is no hook to know precisely when that is.

Has anyone been able to figure out how to do this?  It seems like a natural feature everyone would want, but I can't find it.

- Tim

Andrei

unread,
Oct 11, 2012, 7:33:27 PM10/11/12
to google-we...@googlegroups.com
Use Scheduler's shceduleDeferred() method. It specifically waits for the browser to complete rendering (or whatever else it was doing), and then dispatches a new instruction - like to parse the rendered DOM. 

Why do you need to add listeners within the RichTextArea? A better approach may be to add a single click handler to the RichTextArea widget itself, and check the source of click within this handler.

TimOnGmail

unread,
Oct 11, 2012, 9:21:46 PM10/11/12
to google-we...@googlegroups.com
Thanks for the suggestion, Andrei - I'll give that a try!

I'm adding listeners to it because our project requires that users clicking on a certain section of text creates a popup for editing that section's properties.  We are delimiting these nominal sections like this:

<span ... various metadata>CLICK ON ME</span>

Clicking anywhere on the span or within it brings up the popup.  The popup has to know all the metadata, and the value of all the children of the <span>.
We don't gate what can be placed within the span - it can be any amount of arbitrary HTML.  This means that where they click could be N layers deep within a not-necessarily-well-formed HTML structure, so bubbling back up the DOM tree to the span we're looking for could be tough, if all we had was a screen position on the RichTextEditor.  It might be less hairy than I think it is, but I think it would be pretty hairy to do right.

- Tim
Reply all
Reply to author
Forward
0 new messages