Getting the size of dynamically created content

View: New views
3 Messages — Rating Filter:   Alert me  

Getting the size of dynamically created content

by Andy Shipman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've got a contentPane whose content is being loaded via href. Once its loaded, I create a div and dojo.place that div into the contentPane content. Akin to this:

// in dojo.addOnLoad...

var  _contentPane  =  new dijit.layout.ContentPane({
            href: "/content",
            preload: true
        },
        "content-holder");

_contentPane.startup() ;

// note, the href /content contains a div with ID of content-text 
// the main page has a content-holder div

// in responding to a user event....

var _messageDiv = dojo.create("div", {
            "innerHTML": "Hello, world!",
            "class" : "message-text"
        });

// remove any previous text in the contentPane
dojo.query("#content-text .message-text", _contentPane.domNode).orphan();

// place the new div into the contentPane
dojo.place(_messageDiv, dojo.query("#content-text", _contentPane.domNode)[0]);

That all works fine and dandy, but I can't get the size of any of the content out of the elements. If I call dojo.contentBox on the _messageDiv, or the _contentPane, I get { 0,0,0,0 }.

Any ideas?

Andy Shipman





_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Getting the size of dynamically created content

by Bill Keese-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sounds like your ContentPane is hidden (it or an ancestor node has style="display: none").

Try making it visible first.   You can make it visible offscreen (position: absolute, top: -9999px) to avoid flashing.

On Thu, Nov 5, 2009 at 9:49 PM, Andy Shipman <andy@...> wrote:
I've got a contentPane whose content is being loaded via href. Once its loaded, I create a div and dojo.place that div into the contentPane content. Akin to this:

// in dojo.addOnLoad...

var  _contentPane  =  new dijit.layout.ContentPane({
            href: "/content",
            preload: true
        },
        "content-holder");

_contentPane.startup() ;

// note, the href /content contains a div with ID of content-text 
// the main page has a content-holder div

// in responding to a user event....

var _messageDiv = dojo.create("div", {
            "innerHTML": "Hello, world!",
            "class" : "message-text"
        });

// remove any previous text in the contentPane
dojo.query("#content-text .message-text", _contentPane.domNode).orphan();

// place the new div into the contentPane
dojo.place(_messageDiv, dojo.query("#content-text", _contentPane.domNode)[0]);

That all works fine and dandy, but I can't get the size of any of the content out of the elements. If I call dojo.contentBox on the _messageDiv, or the _contentPane, I get { 0,0,0,0 }.

Any ideas?

Andy Shipman





_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Getting the size of dynamically created content

by Andy Shipman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 7 Nov 2009, at 13:36, Bill Keese wrote:

> Sounds like your ContentPane is hidden (it or an ancestor node has  
> style="display: none").
>
> Try making it visible first.   You can make it visible offscreen  
> (position: absolute, top: -9999px) to avoid flashing.

Thanks Bill, that was it. Well, that plus I needed to attach the  
dynamically created div to a div in the contentPane as well, but all  
is working for me now.

Thanks again,
Andy

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest