franklamoureux
Newbie
Posts: 1
Registered: 3/18/2005
Location: Québec
Member Is Offline
|
| posted on 3/18/2005 at 01:19 PM |
|
|
Site map auto-generated by MENU_ITEMS
Here is a way to generate a site map automatically using your pre-configured menu variable MENU_ITEMS. Enjoy !!
In your site_map.html page, just use
-------------------------------------------
<script language="JavaScript" src="js/menu.js"></script>
<script language="JavaScript" src="menu_items.js"></script>
<script>
new ShowMap (MENU_ITEMS);
</script>
-------------------------------------------
And add the following to menu.js
-------------------------------------------
// This will produce a site map using MENU_ITEMS
function ShowMap (a_items) {
this.a_config = a_items;
this.a_children = [];
this.n_depth = -1;
// init items recursively
for (n_order = 0; n_order < a_items.length; n_order++)
new show_item(this, n_order);
}
// Recursive function that creates the map.
function show_item (o_parent, n_order) {
this.n_depth = o_parent.n_depth + 1;
this.a_config = o_parent.a_config[n_order + (this.n_depth ? 3 : 0)];
// return if required parameters are missing
if (!this.a_config) return;
// store info from parent item
this.o_parent = o_parent;
this.n_order = n_order;
// generate item's HMTL
if (n_order == 0) document.write("<ul>");
if (this.a_config[1] == null) {
html = this.a_config[0] + "<br>n";
} else {
html = '<a class=none href="' + this.a_config[1] + '"'
+ (this.a_config[2] && this.a_config[2]['tw'] ? ' target="'
+ this.a_config[2]['tw'] + '"' : '') + '>'
+ this.a_config[0] + "</a><br>";
}
document.write (html);
// no more initialization if leaf
if (this.a_config.length < 4)
return;
// node specific methods and properties
this.a_children = [];
// init downline recursively
for (var n_order = 0; n_order < this.a_config.length - 3; n_order++)
new show_item(this, n_order);
if (o_parent.n_depth < this.n_depth) document.write("</ul>");
if (this.n_depth== 0) document.write("<br>");
}
|
|
|
|