MR wrote:
> Hi everyone,
>
> I spent an awful lot of time last night learning that if I instantiate
> a widget and call it's render method that the javascript files
> referenced with "javascript = JSLink(...)" are apparently not made
> available in the serialized output (or any other way I could find) to
> be loaded into the document's head (or anywhere else for that
> matter)...But obviously the javascript is automatically loaded into the
> head for you when you call a widget's display() method from the kid
> template.
>
> What I was trying to do was use render() to get a widget's HTML so that
> I could shove it into a div at some point after a page had been loaded.
> The HTML arrived just fine, but the JavaScript did not. This was
> totally counter-intutive to me, so could someone please comment on why
> render() doesn't include the JavaScript in a <script> tag as part of
> the serialized output? I really am just trying to find a way to get a
> widget's JavaScript so that it can be loaded into a page *without*
> using display().

I would guess this happens because newly included scripts are
automatically executed and would step over any state variables they
contain. You should be able to programmatically get at a widget's
JSLink/JSSource with the widgets retrieve_javascript() method. From
there it gets a little more tricky, at least for JSLinks.

You should be able to build the address for a JSLink with the following
string interpolation:
"/%stg_widgets/%s/%s" % (turbogears.startup.webpath, <widget>.mod,
<widget>.name)

Returning the source of a JSSource is easy, it is stored as
<widget>.src

>
> Is there an approved way to get at the actual javascript with an
> existing mechanism, or is my assumption that it's a "good idea" to try
> and do this for purposes of loading JavaScript into the head after page
> load actually a bad idea?

>From what I have seen this isn't supported on Opera < 8.0. Might not be
supported on other platforms as well. I didn't spend much time looking
into it.

>
>
> An example (not tested, but serves the example)
>
> def FooWidget(Widget):
>
>     template  = "..."
>     javascript = [JSLink(...)]
>
>
> def someMethodInController():
>     foo = FooWidget()
>     html = foo.render()
>     #how to get javascript out of FooWidget with instantiation of
> FooWidget?
>     #I want to create a script element and shove it into a page after
> page load


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to