Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't access method of XBL binding after programmatically adding stylesheet

0 views
Skip to first unread message

Jaywalker

unread,
Jul 23, 2009, 11:11:13 AM7/23/09
to
Hey,

it's me again.

Using my own protocolhandler I am generating xul-code on the fly.
After code generation (when the document is shown in the browser) i
want to be able to manipulate the DOM and insert a new XBL widget.
This XBL widget may be given from an extension and thus its stylesheet
has to be added after code-creation. The following code works. but not
always ...

------------------------------------------------------------------------------------------------
var contentDoc = gBrowser.selectedBrowser.contentDocument;

var stylesheet = "chrome://filebrowser_cooliris/content/bindings/
bindings.css";

// check if stylesheet already exists (isStyleSheetExisting isn't
shown here)
if(!isStyleSheetExisting(contentDoc, stylesheet))
{
// add stylesheet
var pi = contentDoc.createProcessingInstruction('xml-stylesheet',
'href="' + stylesheet + '" type="text/css"');
contentDoc.insertBefore(pi, contentDoc.getElementsByTagName("window")
[0]);
}

var container = contentDoc.getElementById("fileview").wrappedJSObject;

// delete all children
while(container.hasChildNodes())
container.removeChild(container.firstChild);

// create and append the view
var view = container.ownerDocument.createElement("fileview_cooliris");
container.appendChild(view);
view.flex = "1";

// load the view
view.loadFromURI(container.URI);
------------------------------------------------------------------------------------------------

When calling this code. it says: view.loadFromURI is not a function.
but only the first time i click on the button that calls this code.
the second time it works. it even works the first time, whenever i
insert an alert("foo") before the call of loadFromURI.It also works,
when I just add the stylesheet at content-creation time.

Obviously the stylesheet that associates the binding with the tag name
is the reason. It seems the association isn't kind of "registered" at
the time i create the element (or at the time i call loadFromURI).

Is there a way to make sure that the element is created/called with
the correct binding? can i somehow wait for the stylesheet to be
completely loaded, so that i can create the element afterwards?

otherwise, i guess i have to implement an algorithm that lets the
extensions register stylesheets that should be added at the time of
the document-creation in the protocol handler.

Any ideas?

Thanks a lot!

Boris Zbarsky

unread,
Jul 23, 2009, 11:54:04 AM7/23/09
to
Jaywalker wrote:
> contentDoc.insertBefore(pi, contentDoc.getElementsByTagName("window")
> [0]);

So this starts an asynchronous load of the stylesheet. Is the relevant
-moz-binding rule in that stylesheet? If so, it won't apply (and hence
the binding won't be attached) until after the stylesheet is loaded.

> Obviously the stylesheet that associates the binding with the tag name
> is the reason. It seems the association isn't kind of "registered" at
> the time i create the element (or at the time i call loadFromURI).

Right; it's not "registered" until the stylesheet loads.

> Is there a way to make sure that the element is created/called with
> the correct binding? can i somehow wait for the stylesheet to be
> completely loaded, so that i can create the element afterwards?

You can wait and keep polling on the cssRules of the sheet. Once that's
not throwing, you can flush layout and proceed...

-Boris

Jaywalker

unread,
Jul 23, 2009, 1:38:48 PM7/23/09
to
> You can wait and keep polling on the cssRules of the sheet.  Once that's
> not throwing, you can flush layout and proceed...
>
> -Boris

Ah. okay. that is basically what i wanted to know. So I gotta keep
polling. Thought there might be a StyleSheetLoad event or something
like that ...

Great!

Thanks for your quick answer.

Cheers. :)

0 new messages