Using the Extensis 'makeNewPath.js' code for PortWeb v6

If you've not looked at the source JS code it is listed below, at the bottom of the page.

The function takes the form "function makeNewPath(inputRef, rootName, newRoot)" where:

Once you've seen the demos, try out your own data in Example #6.

If you'd like to run the makeNewPath code as an external JS file - instructions are included in the source code for this page

Note the function does not join the root and the substrng path it creates. This is deliberate. Issues you may need to figure out is where your pages are rooted. In Mac WebStar PortWeb pages are in the root whereas in Windows IIS they are - normally - in root/scripts/ so you may need to do a little extra scripting as the relative path from root to root/previews/ is "previews" wheras from root/scripts/ it is "/previews". So why does the default returned path fail on a Mac. The root is a special case - you can't go one folder up - so a relative path of "/previews/pic.jpg" from the root only. If you're lost be this go and read up on realitve web paths and use of the / and ../ notations (try Google).

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #1 - where source path is Mac style "::Vol:Folder:File or Vol:Folder:File.ext"

Desired Result:
From %path% string "::PortWebMac:PortWeb:TEST:Demo Site:PICS:HAR001:CS0002.JPG"
...we extract substring "/Demo%20Site/PICS/HAR001/CS0002.JPG" (i.e. break after 'TEST')
...web root is "http://www.mysite.com"
...web root plus substring
...gives valid web path "http://www.mysite.com/Demo%20Site/PICS/HAR001/CS0002.JPG"


Mac - Actual Catalogue %Path% data:

Resulting substring:




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #2 - where source path is Mac style "Vol:Folder:File or Vol:Folder:File.ext"

Desired Result:
From %path% string "PortWebMac:PortWeb:TEST:Demo Site:PICS:HAR001:CS0002.JPG"
...we extract substring "/Demo%20Site/PICS/HAR001/CS0002.JPG" (i.e. break after 'TEST')
...web root is "http://www.mysite.com"
...web root plus substring
...gives valid web path "http://www.mysite.com/Demo%20Site/PICS/HAR001/CS0002.JPG"


Windows - Actual Catalogue %Path% data:

Resulting substring:




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #3 - where source path is Windows style "DriveLetter:\Folder\:File.ext"

Desired Result:
From %path% string "C:\My Documents\Project\TEST\Demo Site\PICS\HAR001\CS0002.JPG"
...we extract substring "/Demo%20Site/PICS/HAR001/CS0002.JPG" (i.e. break after 'TEST')
...web root is "http://www.mysite.com"
...web root plus substring
...gives valid web path "http://www.mysite.com/Demo%20Site/PICS/HAR001/CS0002.JPG"


Windows - Actual Catalogue %Path% data:

Resulting substring:




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #4 - where source path is Windows style "\\ComputerName\DriveLetter\Folder\:File.ext"

Desired Result:
From %path% string "\\Bob\C\My Documents\Project\TEST\Demo Site\PICS\HAR001\CS0002.JPG"
...we extract substring "/Demo%20Site/PICS/HAR001/CS0002.JPG" (i.e. break after 'TEST')
...web root is "http://www.mysite.com"
...web root plus substring
...gives valid web path "http://www.mysite.com/Demo%20Site/PICS/HAR001/CS0002.JPG"


Windows - Actual Catalogue %Path% data:

Resulting substring:




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #5 - where source path is Portfolio default style "Vol:Folder:File or Vol:Folder:File.ext"

Desired Result:
From %path% string "PortWebMac:PortWeb:TEST:Demo Site:PICS:HAR001:CS0002.JPG"
...we extract substring "/Demo%20Site/PICS/HAR001/CS0002.JPG" (i.e. break after 'TEST')
...web root is "http://www.mysite.com"
...we need to add the subfolder "/previews" ...web root plus subfolder plus substring
...gives valid web path "http://www.mysite.com/previews/Demo%20Site/PICS/HAR001/CS0002.JPG"


Actual Catalogue %Path% data:

Resulting substring:




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example #6 - Try your own path data!

Your 'source' %Path% data:

Your 'rootName' value - e.g. 'folder' - may not be blank:

Your 'newName' value - e.g. 'pix' or '/images' or may be blank:




Resulting substring:






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The "makeNewPath.js" function code:

//IMPORTANT - don't forget there is a helper function listed below
// after the main function

function makeNewPath(inputRef, rootName, newRoot)
{
// inputRef = reference to a form element holding the path value
// rootName and newRoot are string values - confusing!
// do this: makeNewPath(myForm.theInputRef,myForm.theRootName.value,myForm.theNewRoot.value)
// not : makeNewPath(myForm.theInputRef.value,myForm.theRootName.value,myForm.theNewRoot.value)
// ... the difference is don't interrogate the inputRef's value - the makeNewPath does that

  var dPath;
  var startIdx, replaceIdx, endIdx;
  var strArr, idx;

  orgPath = getLastInput(inputRef);

  // clean the original path separators for the web
  var clnPath = (orgPath.split("\\")).join("/");
  clnPath = (clnPath.split(":")).join("/");

  startIdx = clnPath.indexOf(rootName);
  if (startIdx >= 0)
  {
    // strip off everything up to the root name
    startIdx = startIdx + rootName.length;
    dPath = newRoot + clnPath.substring(startIdx, clnPath.length);
    // Encode each part of the path into web-ready form
    strArr = dPath.split("/");
    for (idx=0; idx<strArr.length; idx++)
    {
     strArr[idx] = escape(strArr[idx]);
    }
    dPath = strArr.join("/");
  }
  else
  {
    dPath = "";
  }

  return dPath;
}

// Utility function for makeNewPath
function getLastInput(inputRef)
{
  if (inputRef.length == null)
  { return inputRef.value; }
  else
  {
      var curIdx = inputRef.length - 1;
      return inputRef[curIdx].value;
    }
  }

To top of page.

The alternative, path-based "makeNewPathStr" function code:

This code is included in the script in this page's <head> code.

//IMPORTANT - the previous version's helper function is now deleted

function makeNewPathStr(origPath, rootName, newRoot)
{
// origPath, rootName and newRoot are string valuess
// do this: makeNewPathStr(myForm.theInputRef.value,myForm.theRootName.value,myForm.theNewRoot.value)
// or just pass strings: makeNewPathStr(origPath, rootName, newRoot)

  // declare all the variables we'll use
  var dPath, startIdx, strArr, theIdx, clnPath;
  // clean the original path separators for the web
  clnPath = (origPath.split("\\")).join("/");
  clnPath = (clnPath.split(":")).join("/");
  startIdx = clnPath.indexOf(rootName);
  if (startIdx >= 0)
  {
    // strip off everything up to the root name
    startIdx = startIdx + rootName.length;
    dPath = newRoot + clnPath.substring(startIdx, clnPath.length);
    // Encode each part of the path into web-ready form
    strArr = dPath.split("/");
    for (theIdx=0; theIdx<strArr.length; theIdx++) {
      strArr[theIdx] = escape(strArr[theIdx]);
    }
    dPath = strArr.join("/");
  }
  else
  {
    dPath = "";
  }
  return dPath;
}

To top of page.