Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Javascript Menu via Patrick's demo ?

Via TK : Patrick's demo on a dynamic JavascriptMenu.
*.cty download here : http://tk-jk.net/city/JavaScriptDemo.zip

"The archive contains the naviation system (in top of each page with links to folders higher up) and some dynamic form. I guess good use of foreach. I've quickly translated it to English. Hope it is useful. Best regards, Adriaan van den Brand"...


I'm not a programmer just a simple user, trying to follow and do the exercise in French. Amazing. Just a small question, I'm not a geek and would be interested in changing the path Of the script ?

that's to say Add "demo" in the URL Path

I've translated the demo in French here and it does not work...

Any trick to add "demo" in the Javascript path ;-)

If you've got 1 minute this we or later.
> readme URL : http://www.elanceur.org/demo/readme.html
> code : http://www.elanceur.org/demo/menustuff/menuscript.html

> demo : http://www.elanceur.org/demo/index.html

But the menu bar still displays an URL without the "/demo/" path. If you've an idea it could help for fun like selling good wine on the internet...

Kind regards and thanks in advance...

christophe ducamp
Friday, June 14, 2002

Glad someone finds it useful ;-)

You will need to change the javascript slightly.

I would propose to add a variable to citydesk, e.g.

PublishPath  (which you would set to demo/

In the article menuscript, you'll find
{$foreach a in (and (filename "index2") (folder "")) $}
  "/{$a.abslink$}","Home",{$next$}
{$foreach a in (and (filename "index") (not (folder ""))) $}
  "/{$a.abslink$}","{$a.headline$}",{$next$}
  "","");

(the first index2 should be index ; sorry for that)

anyway, the /{$a.abslink$} should then be replaced by
{$.PublishPath$}{$a.abslink$}

where PublishPath can be set to / for root or
/demo/ for your purpose.

I will update the cty; I have made some fixes in it. The index2 was a leftover from the original site (http://www.aas.nl)

Hope this helps,

Adriaan van den Brand
Sunday, June 16, 2002

Update of javascript:

This should be everything you need; the swap-image stuff is not used in the demo.
Use variable {$.PublishPath$} (must be set manually ;-( in CityDesk). Use / for root or /path/

Replace pijl=<IMG src="/mnu/pijl.gif">
by the image or character you wish to use.


// menu in title bar
var arMenu=new Array (
{$foreach a in (and (filename "index") (folder "")) $}
  "{$.PublishPath$}{$a.abslink$}","Home",{$next$}
{$foreach a in (and (filename "index") (not (folder ""))) $}
  "{$.PublishPath$}/{$a.abslink$}","{$a.headline$}",{$next$}
  "","");

// arMenu[][2] contains all paths\index.html with known header names

var arrow=' <IMG src="/mnu/pijl.gif"> ';
var topMenu="";

function FindMenu(path,linkit)
{
  path=unescape(path);
  path=path.replace(/\\/gi,"/");
  for (var index=0;index<arMenu.length;index+=2)
  {
    cmp= arMenu[index].substring(0,arMenu[index].lastIndexOf("/"));
    if (path == cmp)
    {
      if (linkit)
      {
        if(index<(arMenu.length-2)) {
            if (topMenu != "") topMenu=topMenu+arrow;
            topMenu=topMenu + '<A class="nav" href="'+arMenu[index]+'">'+arMenu[index+1]+"</A>";
        }
      }
      else
      {
        if (topMenu != "") topMenu=topMenu+arrow;
        topMenu=topMenu + arMenu[index+1];
      }
      return 1;
    }
  }
  if ((path==arMenu[arMenu.length-2]) && (path.indexOf("index.")<0) )
  {
      topMenu=topMenu + arrow + arMenu[arMenu.length-1];
      return 1;
  }
  return 0;
}

function createNavMenu(path,headline)
{
    topMenu="";
    if (path.indexOf("index")<0)
    {
      arMenu[arMenu.length-2]=path;
      arMenu[arMenu.length-1]=headline; 
    }
    var menu="";
    var myString=unescape(location.pathname);
    myString=myString.replace(/\\/gi,"/"); 
    var lastindex=0;
    var index = 0;
    var einde=0;
    var startindex=lastindex+1;
    var lastSlashPos=(myString.indexOf("index")>=0)?myString.lastIndexOf("/"):-1;
    // iterate trough path; check every directory from root till filename
    do {
      index = myString.indexOf("/", lastindex);   
      if (index<0)
      {
        FindMenu(myString.substring(startindex-1,1000));
      }
      else
      {
        if (!FindMenu(myString.substring(startindex-1, index),(index!=lastSlashPos)))
        {
          startindex=index+1;
        }
      }
      lastindex=index+1;
    } while (index != -1);
}

Adriaan van den Brand
Monday, June 17, 2002

Thanks a lot Adriaan. I'll make correction on the first name which appeared in the cty file ;-) I have to understand first :) regards xtof

christophe ducamp
Monday, June 17, 2002

A new french translation (v2.0) could be maintained here
if I have enough time. Thanks Adriaaan.


http://www.elanceur.fr/DemoAdriaaan/

christophe ducamp
Thursday, July 04, 2002

*  Recent Topics

*  Fog Creek Home