On 2 Dec 2011, at 21:15, Ross Laird wrote:

> I'm rebuilding one of my Radiant sites using the latest version, and
> I've decided to incorporate my JavaScripts into the Design -->
> Javascripts area rather than load them from a subdirectory. However, I
> haven't been able to find any documentation about how to do this
> properly (and, being seemingly one of the few Radiant users who is not
> a programmer, I need documentation). Do I just place each of the
> scripts into new JavaScripts pages? And, if I do that, how do I refer
> to the scripts on the pages? For example, here is some sample code
> that I currently place in the header snippet:
> <script src="/js/signup.js" type="text/javascript"></script>
> <script type="text/javascript" src="http://downloads.mailchimp.com/js/
> jquery.form-n-validate.js"></script>
> <script language="javascript" src="/js/jquery.tweet.js" type="text/
> javascript"></script>
> <script src="/javascripts/hyphenator/Hyphenator.js" type="text/
> javascript"></script>
>  <script type="text/javascript">
>                Hyphenator.config({
>                        displaytogglebox : false,
>                        orphancontrol: 2
>                });
>                Hyphenator.run();
>        </script>
> How do I use scripts like these (and the links to which they point),
> in the same way as they are currently being used in the header
> snippet, in the Design --> Javascripts area of the admin interface?

It's probably much simpler than it looks. 

Scripts that come from elsewhere should be left alone so that the service 
provider (e.g. mailchimp) can continue to do what they do. 

Scripts that you've downloaded from somewhere (eg. the jquery tweet plugin) can 
be considered static and left in the filesystem.

Radiant's javascript-editing mechanism is the right place for scripts that you 
create or intend to edit. In your example, that may only be the final inline 
script in which you invoke the hyphenator.

In that case you'll end up with something like this in your layout:

    <script src="/javascripts/signup.js" type="text/javascript"></script>
    <script src="http://downloads.mailchimp.com/js/jquery.form-n-validate.js"; 
    <script src="/javascripts/jquery.tweet.js" type="text/javascript"></script>
    <script src="/javascripts/hyphenator/Hyphenator.js" 
    <r:javascript slug="site.js" as="inline" />

And a single javascript page called 'site.js' in which you can put this:

      displaytogglebox : false,
      orphancontrol: 2

The script tags and CDATA wrappers and so on are done for you.

If you also want to bring the signup.js script into an editable place, the 
procedure is the same: create a javascript page called signup.js, paste in the 
javascript code from that file and then change the tag in your layout to this:

<r:script slug="signup.js" as="link" />

Note that the javascript machinery will create a path within radiant that 
matches /js/. It's probably a good idea to move all your static javascript 
files to /javascripts/ to avoid collisions.



> This seems like such a simple question (probably the answer is just to
> copy and paste the code), but there may be factors to consider, such
> as how (and from where) Javascript links are loaded.
> Is this as simple as it sounds?
> Thanks in advance.
> Ross

Reply via email to