SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    move inline script into external js file

    Hi there,

    the logic as outlined in the attached file is working however I would like to move the inline script (line 8 to 354) into an external js file. only how ?

    if I move the above to dtree.js, adjust function dTree(objName) for function dTree(objName, path) and adjust $path for path under icons and use
    $jsfile = $baselink.$this->template.'/js/dtree.js';
    <script type="text/javascript" src="$jsfile"></script>
    how am I to pass $path to the script?

    I am sorry if this is majorly basic but I'm only starting with learning js

    could somebody please help me figure how to achieve that?
    Attached Files Attached Files

  2. #2
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript" src="tree.php?path="<?php=$path ?>"></script>
    Note, the JS file is named php. The very first line of you JS file should have this,
    <?php header("Content-type: application/x-javascript");?>

    Right after that line you will want.
    $path = $_GET['path'];

    Since you are using Heredoc, I have no idea if (how) this will work. Another workaround would be to use an include.
    What I lack in acuracy I make up for in misteaks

  3. #3
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for getting back to me!

    unfortunately I'm not getting it to work.

    I created a new file called tree.php with the following snippet at the very top:

    Code:
    <?php header("Content-type: application/x-javascript");?>
    $path = $_GET['path'];
    followed by the lines 25-378 of the attached file

    in the attached file I have removed lines 25-378 and inserted above the heredoc snippet:
    Code:
    $js = '<script type="text/javascript" src="$path/tree.php?path="$path"></script>';
    $this->interface->addCustomHeadTag($js);
    while my IDE does not show any syntax errors and there are also no errors displayed on user side the tree is not being displayed anymore

    would you have any advice what I'm overlooking?

  4. #4
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm! the second snippet in my second post is wrong. should be:
    Code:
    $baselink = $this->interface->getCfg('live_site').'/components/com_component/templates/';
    $jsfile = $baselink.$config->template.'/js/tree.php';
    $js = '<script type="text/javascript" src="$jsfile?path=$path"></script>';
    $this->interface->addCustomHeadTag($js);
    that however still doesn't make it work


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
  •