Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:27
File Paths for JS and HTML Not Working
Poster: biographie
Dated: Monday June 23 2003 - 16:38:13 BST
This could probably go under the other post, but I wanted to detail my findings more, and understand what is happening. I use an extensive directory structure to keep my files (and my mind) in order. If you can imagine, my index.html sits at the top layer, with my menu_data.js file, my milonic_src.js file sits in a directory called jscripts. My old code for version 3 looked like the following:
<SCRIPT language=JavaScript src="jscripts/milonic_src.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="index_data.js" type=text/javascript></SCRIPT>
Version 4 does not like this one bit. I checked inside of milonic_src.js, saw that you can set the file path. But for what?!? Which file path are you talking about? The only way I could get my code to work was one of two methods:
1 - put all the files into the same directory, and leave the file path empty in the src.js file. Thus making my code in the index file as such:
<SCRIPT language=JavaScript src="milonic_src.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="index_data.js" type=text/javascript></SCRIPT>
2 - put the index.html and milonic_src.js files in the same directory, and the data.js file in a lower directory (for my testing I called it 'low'). I changed the file path in the src.js file to '/low/', but it did not seem to matter if it was empty or with this new path. It almost seemed that if the html file called the right js file, it worked:
<SCRIPT language=JavaScript src="milonic_src.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="low/index_data.js" type=text/javascript></SCRIPT>
But the minute I set-up three files in three layers nothing worked. It really seemed that the main factor is having the html calling the src.js file be in the same directory:
<SCRIPT language=JavaScript src="jscripts/milonic_src.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="jscripts/low/index_data.js" type=text/javascript></SCRIPT>
Do I have the completely wrong idea of how this file path stuff is suppose to work?!? Is the file path variable in the _scr.js file suppose to be the file path of the _src.js file; not the _data.js or html files? I guess I am just dumb or something, but I think a more detailed explaination of this is needed. I can see having the _data.js file for whatever html page it is being applied to sitting in the same directory. What I can't see is the having a _src.js for each page or directory.
Now for an idea that I had. I have no idea if this would work, but it is worth a shot:
Instead of having to make a special _data.js file each html page or pages located in that particular directory; would it be possible to make a master _data.js file, and have it grab relative file paths based on global variables running in the background. Let me explain (assuming Javascript has the capacity to do some of these features):
In the master_data.js you would put all your menu items with the url strictly to the page you want with no extra file path info. A function called 'path_finder' would need to run only once to build a few indexing list of arrays. This function would search the directories in a recursive manner (or a variable to could specified by the developer as to how many directory layers need to be searched) for the html pages listed in the menu. The results of this list would be an array of file paths for each menu item. Those file paths would be considered to be "absolute" with respect to the local website.
Now the trick, in each html page the developer would put a global variable called 'path_depth' or something of that nature. It is strictly a number, and it says how deep this file is in a directory structure with respect to the top layer. For example on my website:
/gallery/usa/az/phoenix/camelback.html
camelback.html - path_depth=4
This would effectivly tell the milonic_src.js that the page it is about to render a menu for is 4 directories down from the top, so build all the file paths in the menu with respect to that depth. The milonic_src.js file would add the approprate amount of ../../ etc in front of each path or such to build out each pages location. So you effectivly get away with only needing one _data.js file for the entire website. The developer simply has to add this one global variable to each page (much easier in my opinion).
This would not keep you from having more than one menu on a page. You could still have other menus on pages when needed, but I think most of us are using one master menu across the entire website.
Maybe this functionality is already in the menu, and I am just not smart enough to figure it out. But I think it is a cool idea. Having to change file paths or create new _data.js files for new directories that I add takes quite a bit of time. If I only had to add or switch a single number when I want to move locations or create a new page would save a lot of time.
Poster: gardenguy
Dated: Saturday July 5 2003 - 23:34:52 BST
I have just started trying the beta 5 today, and run into this same issue of directory structure. If I leave all milonic code in a subdirectory and try to call the two *.js files from an html doc in a higher directory I get js errors and no menus.
I see this original message is a few weeks old and mine is the first reply. Is there some official word about this??
Poster: John
Dated: Monday July 7 2003 - 15:16:06 BST
As Andy states in the comments...
Quote:
The scriptpath variable stores the path to your menu JS files.
This is used if you keep all your menu files in a directory other than your main html directory (which I happen to think is the proper way to do things).
For instance, I keep all menu files and arrays in /templates/menu5/ (for now, anyway). This way you can call the structure from any level and not have to worry about ../ stuff or multiple array files. To keep my server-relative addressing, milonic_src looks like this...
Code:
scriptpath="/sai/templates/menu5/";
...and my calls to the menu, which are contained in a <cfinclude>, are...
Code:
<script language="Javascript" src="/sai/templates/menu5/milonic_src.js" type="text/javascript"></script>
<script language="Javascript" src="/sai/templates/menu5/xp_data.cfm" type="text/javascript"></script>
<script language="Javascript" src="/sai/templates/menu5/xp_data.cfm" type="text/javascript"></script>
Note that my xp_data.cfm will, for most folks, be a .js file. Depends on what you are using to generate the arrays, so don't let that throw you.
Poster: gardenguy
Dated: Wednesday July 9 2003 - 1:53:26 BST
OK, I followed jgillett advice about the scriptpath and now I get the menu. But when I call from another level down, there are no arrows. They seem hard coded to images/arrowwhatever and can't be found by milonic_src. I tried absolute addressing, and then got NO arrows where there were some before.
Befuddled.
Poster: John
Dated: Wednesday July 9 2003 - 15:42:24 BST
"images/arrowwhatever" is not server relative addressing. That's why it's failing.
how can you do that?
Poster: biographie
Dated: Wednesday July 9 2003 - 21:25:42 BST
"For instance, I keep all menu files and arrays in /templates/menu5/ (for now, anyway). This way you can call the structure from any level and not have to worry about ../ stuff or multiple array files. To keep my server-relative addressing, milonic_src looks like this... "
If you are able to keep all your menu files in the same place, how does the browser know how to jump between where it is to where it needs to go? Do you have all your links absolute? I thought all the ../../ stuff was a 'necessary evil' to keep things working correctly. While I was learning the old version 3, I thought I realized that the links' information had to be relative to the current html's directory placement.
Do you mind giving a novice like myself a tutorial in how you are able to keep all your links working correctly if you do not have a specific js file for each directory level? This would seem like the brass-ring of my limited programming skills in reducing my time always making new files and figuring out directory relationships for other html files.
Poster: gardenguy
Dated: Thursday July 10 2003 - 1:20:02 BST
John,
I was too quick with my post and did not provide enough details. In the vertical_data.js script which I keep located in a subdirectory called code there are the following:
topbarimage = "images/arrow_down.gif";
subimage = "images/arrow.gif";
In the Milonic distribution there is all the .src code and a sub directory called images which contains the above .gif files.
How do I make the arrows appear when the .js files are called from a different sub directory?
xxx.com/code contains the required .js files
xxx.com/code/images contains the .gif files
when I call from xxx.com I get menus with arrows.
when I call from xxx.com/overhere I get menus, but no arrows.
I do not use include file to call the scripts.
Is that part of how it works for you and not for me?
Thanks a bunch.
David
Poster: John
Dated: Thursday July 10 2003 - 15:31:39 BST
OK, let's see what we can do here that might help both of you. Umm - 0701 Phoenix time __at__ $25/minute, we'll figure the bill at the end.
Here's my setup...
http://westcgi.west.asu.edu/ - base server address.
/sai/ - main sub-directory that contains my intranet.
/sai/templates/menu5/ - sub that contains all menu files and arrays except images. Only one copy of my array file(s) covers the entire site and it lives here, even though the site goes 2 or 3 levels deep.
/sai/graphics/ - sub that contains images for the entire intranet, including the menu.
Given that, milonic_src is...
Code:
scriptpath="/sai/templates/menu5/";
Server-relative addressing.
The menu calls, regardless of the depth of the calling page, are...
Code:
<script language="Javascript" src="/sai/templates/menu5/milonic_src.js" type="text/javascript"></script>
<script language="Javascript" src="/sai/templates/menu5/xp_data.cfm" type="text/javascript"></script>
<script language="Javascript" src="/sai/templates/menu5/xp_data.cfm" type="text/javascript"></script>
Again, disregard the .cfm on my array file. Yours will be .js or .asp or whatever you're using to generate the menu. Server-relative addressing again.
For the array, menu images are called as...
Code:
bgimage="/sai/graphics/winxp_back.gif";
(or whatever). Server-relative addressing again.
For the various aI statements it's the same server-relative addressing (unless you're going for a page that's off-server, of course!)...
Code:
aI("text=SAI Home;url=/sai/;image=/sai/graphics/xpwidth.gif;status=Student Affairs Intranet Home Page;");
or...
Code:
aI("text=ASU West;url=http://www.west.asu.edu/;image=/sai/graphics/xpblank.gif;status=ASU West Home Page;");
Hope that all makes some sense.
OK - 0724-0701=23x$25=$575. Cashier's check only, please.
Poster: gardenguy
Dated: Thursday July 10 2003 - 23:11:13 BST
John,
I will gladly send you the check as soon as you tell me where the menu is on your site.
On my Mac running IE5.1 there is NO menu I can see at http://westcgi.west.asu.edu/sai/
I see a nice Student Affairs Intranet, and the status bar makes reference to some .js files loading, but no menu appears that I can see. I ran my mouse all over and it only indicates links at blue underlined text.
Have you seen your site with a Mac?
Are you sure your menu is working?
Thanks
David
Poster: John
Dated: Thursday July 10 2003 - 23:24:45 BST
Yes, I've seen it on a Mac but don't have IE5.1. Just checked it with IE5.2.3 (current) under OS X and all is well.
There should be (are) 5 menu items in the blue area towards the top - Home, Staff, Tech., Edit, About/Help.
Menu There Now
Poster: gardenguy
Dated: Friday July 11 2003 - 11:17:35 BST
John,
Ok, today I see it. Not sure why it wasn't there yesterday.
And now finally I have read your post below enough times that I see what you do that I don't do which is making the difference.
The key is you make individual calls to the arrow image in each aI call. I was not noticing that nor did I even realize it could be done.
The light is ON !!!
Thanks for sticking with us on this one.
David
Further Musings
Poster: gardenguy
Dated: Friday July 11 2003 - 12:08:38 BST
Using the aI image=xxx only ends up adding an unwanted leading arrow for me. So I played around some more.
When I changed the subimage = definition from
/images/arrow.gif
to
../images.arrow.gif
then I started getting arrows in calls from main directory and from calls one layer down. I have not tried further down. This makes me happy.
During course of experimenting I noticed another anomoly.
The topbarimage variable is set to images/arrow_down.gif but the distribution file contains no such .gif, but rather arrowdn.gif. I think Andy needs to tweek this rather than each user renaming it.
I don't happen to see any arrow downs in my own usage but was using it to confirm I was changing the right stuff while I experimented.