Hi Randall,

Fear not, there will be docs for this stuff.

First thing: you don't want to append to widget.javascript. Maybe
those should be replaced by immutable versions for safety. If that
widget is a label, for example, appending to widget.javascript will
make *all* labels require that JavaScript henceforth.

I don't know all of your requirements, but my approach would likely be
to back up and do things the straightforward way.

<a href="mylocation" target="_blank">My link</a>

is certainly the most straightforward way to open a link in a new window.

If there's something special that requires JS, you can do this: in
your template's <head>, I'd add

<script src="${std.url('/static/js/openwin.js')}" type="text/javascript"/>

(the std.url call isn't absolutely necessary, but it makes your app
more portable)

Then, from within the page, call whatever function you need to from
the openwin file.

If this is something that you really need to use differently in
different contexts, then you make a widget. Likely your own subclass
of some widget that then defines the JavaScripts to include.

Kevin

On 1/18/06, Randall <[EMAIL PROTECTED]> wrote:
>
> I've been trying to figure out how best to use javascript with
> TurboGears.  tgadmin quickstart creates a "static/javascript"
> directory.  I'm guessing this is where custom javascripts should go.  I
> found in the wiki these lines need to be inserted into a kid template
> to be able to have javascript links.
>
>     <link py:strip="1" py:for="css in tg_css">${css.insert()}</link>
>     <link py:strip="1" py:for="js in tg_js_head">${js.insert()}</link>
>
> And there is MochiKit.  I've looked at the intro video, but not much
> more yet.
>
> So I'm creating a widget label that will display a hyperlink that opens
> a new window.  I created a javascript file called openwin.js and put it
> in static/javascript.  I think I need to do something like this:
>
>     widget.javascript.append(JSLink(?, "openwin.js"))
>
> I don't know what goes in place of ?.  I'm not even sure this is a good
> approach.  Is MochiKit of any use here?
>
> I haven't found much in the docs, wiki, or mailing list on this
> subject.  Once I learn this stuff, I'll be glad to write a wiki entry.
>
> Randall
>
>


--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Reply via email to