SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    direct drupal to script location

    In my Drupal site I want to include the swfobject.js script to my pages so added the location in the template.info file:

    Code:
    scripts[] = sites/all/libraries/swfobject/swfobject.js
    When I view my pages however, it is added to I guess a default script location, being the following
    Code:
    http://www.mysite.com/sites/all/themes/mytheme
    So when I view the source code of my site the complete line becomes:

    Code:
    <script type="text/javascript" src="http://www.mysite.com/sites/all/themes/mytheme/sites/all/libraries/swfobject/swfobject.js?m8l3lo"></script>
    How can I point it to the correct location:
    Code:
    http://www.mysite.com/sites/all/libraries/swfobject/swfobject.js
    I've tried using something like:
    Code:
    scripts[] = ..sites/all/libraries/swfobject/swfobject.js
    but those first two dots just get added to that default line:
    Code:
    <script type="text/javascript" src="<strong>http://www.mysite.com/sites/all/themes/mytheme</strong>/..sites/all/libraries/swfobject/swfobject.js?m8l3lo"></script>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Try
    Code:
    scripts[] = /sites/all/libraries/swfobject/swfobject.js
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that didn't work. It became:


    Code:
    <script type="text/javascript" src="http://www.mysite/sites/all/themes/mytheme//sites/all/libraries/swfobject/swfobject.js?m8mzzl"></script>
    It's like everything you place behind scripts[] is just added to the default theme location. In this case it now has two slashes behind www.mysite/sites/all/themes/mytheme.

    There doesn't seem to be a way to have it move up the directory tree when I use scripts[]?

    I now did it by placing a libraries folder inside my theme folder (where the other files/images etc. also are) and direct it simply to that directory. with scripts[] libraries/swfobject/swfobject.js.

    But how is it done with other scripts then which use this libraries folder which is at www.mysite.com/sites/all/libraries? It now has the nivo-slider script in it for example. I thought it might be convenient to place all javascripts in there, but how do they make it direct upwards from mytheme > themes to libraries then?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Oh, I see what you mean... The script line isn't parsed as a path, it's a piece of text that is attached to the site root + path to theme and printed to the html template. I didn't expect that.

    It's not as clean as adding it to the info file but you could add your file directly to html.tpl.php (D7) or add it using a block with the drupal_add_js(); function.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    The best method to add third party code like that would be to register it as a library implementing hook_library. Than use the function drupal_add_library() to actually add the library to the request output.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •