Graeme Hackston
11-11-2002, 05:36 AM
This is a simple menu that degrades opened in non DOM or non javascript browsers. To do this it requires “.subs {display: none;}” to be removed from the page. DOM browsers require their own external CSS file with the style included.
It loads opened to the correct menu items in a page where the flag div is present. Change the number in “flag-4-menu” to the corresponding menu item you want opened onload. Give any new menu items ids in the same manner as the menu items in the example. This is obviously most useful with external JS files served to DOM browsers only. To do this see brothercake’s response in the link below. Hopefully Opera can be removed soon.
http://www.codingforums.com/showthread.php?s=&threadid=1328
I haven’t tested the IE5 cursor: “hand” fix. Any suggestions are welcome.
<html>
<head>
<title></title>
<style>
.subs, .page-flag {
display: none;
}
.link, a:visited, a:link, a:active {
color:black; background-color:transparent; text-decoration:none;
}
.link, .link-over {
cursor: pointer;
}
a:hover, .link-over {
color:blue; background-color:transparent; text-decoration:none;
}
</style>
<script>
nums = new Array (0)
IdsForIE5 = new Array ()
function Open(Sub) {
a = document.getElementById(Sub).style
if (a.display == 'block') {
a.display = 'none'
} else {
a.display = 'block'
}
}
IE5 = (parseInt(navigator.appVersion) == 4 && navigator.userAgent.toLowerCase().indexOf('msie 5.0') != -1);
onload = function() {
while (nums.length < 50) {
nums[nums.length] = nums.length + 1
}
for (var i=0;i<nums.length;i++) {
if (document.getElementById('open-' + nums[i])) {
IdsForIE5[IdsForIE5.length] = 'open-' + nums[i]
}
}
if (IE5) {
for (var i=0;i<IdsForIE5.length;i++) {
document.getElementById(IdsForIE5[i]).style.cursor = 'hand'
}
}
if (document.getElementById('flag')) {
str = document.getElementById('flag').innerHTML
SubId = 'sub-' + str.slice(str.indexOf('flag-')+5,str.indexOf('-menu'))
if (document.getElementById(SubId)) {
Open(SubId)
}
}
}
</script>
</head>
<body>
<div id="flag" class="page-flag"><div id="flag-4-menu" class="page-flag"></div></div>
<a href="page.htm">link 1</a><br />
<span id="open-2" class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onmousedown="return Open('sub-2')">open 2</span><br />
<div id="sub-2" class="subs">
<a href="page.htm">this is a sub link of 2</a><br />
<a href="page.htm">this is a sub link of 2</a>
</div>
<a href="page.htm">link 3</a><br />
<span id="open-4" class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onmousedown="return Open('sub-4')">open 4</span><br />
<div id="sub-4" class="subs">
<a href="page.htm">this is a sub link of 4</a><br />
<a href="page.htm">this is a sub link of 4</a><br />
<a href="page.htm">this is a sub link of 4</a>
</div>
<a href="page.htm">link 5</a><br />
<a href="page.htm">link 6</a><br />
<span id="open-7" class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onmousedown="return Open('sub-7')">open 7</span><br />
<div id="sub-7" class="subs">
<a href="page.htm">this is a sub link of 7</a><br />
<a href="page.htm">this is a sub link of 7</a><br />
<a href="page.htm">this is a sub link of 7</a>
</div>
</body>
</html>
Edit
This is a URL alternative to using the flag div to open the menu. Change the sub menu division ids to match a part of the URL.
Change the opening span(s) from this example.
onmousedown="return Open('sub-7')"
... to this
onmousedown="return Open('the-new-sub-id')"
Put this anywhere in your .js file. Add the part of the URL(s) that the divisions are named to the array.
MenuIds = new Array ('some_folder','page.htm')
Relpace this in the onload function
if (document.getElementById('flag')) {
str = document.getElementById('flag').innerHTML
SubId = 'sub-' + str.slice(str.indexOf('flag-')+5,str.indexOf('-menu'))
if (document.getElementById(SubId)) {
Open(SubId)
}
}
... with this
for (var i=0;i<MenuIds.length;i++) {
if (location.href.match(MenuIds[i])) {
str = MenuIds[i]
if (document.getElementById(str)) {
Open(str)
}
}
}
It loads opened to the correct menu items in a page where the flag div is present. Change the number in “flag-4-menu” to the corresponding menu item you want opened onload. Give any new menu items ids in the same manner as the menu items in the example. This is obviously most useful with external JS files served to DOM browsers only. To do this see brothercake’s response in the link below. Hopefully Opera can be removed soon.
http://www.codingforums.com/showthread.php?s=&threadid=1328
I haven’t tested the IE5 cursor: “hand” fix. Any suggestions are welcome.
<html>
<head>
<title></title>
<style>
.subs, .page-flag {
display: none;
}
.link, a:visited, a:link, a:active {
color:black; background-color:transparent; text-decoration:none;
}
.link, .link-over {
cursor: pointer;
}
a:hover, .link-over {
color:blue; background-color:transparent; text-decoration:none;
}
</style>
<script>
nums = new Array (0)
IdsForIE5 = new Array ()
function Open(Sub) {
a = document.getElementById(Sub).style
if (a.display == 'block') {
a.display = 'none'
} else {
a.display = 'block'
}
}
IE5 = (parseInt(navigator.appVersion) == 4 && navigator.userAgent.toLowerCase().indexOf('msie 5.0') != -1);
onload = function() {
while (nums.length < 50) {
nums[nums.length] = nums.length + 1
}
for (var i=0;i<nums.length;i++) {
if (document.getElementById('open-' + nums[i])) {
IdsForIE5[IdsForIE5.length] = 'open-' + nums[i]
}
}
if (IE5) {
for (var i=0;i<IdsForIE5.length;i++) {
document.getElementById(IdsForIE5[i]).style.cursor = 'hand'
}
}
if (document.getElementById('flag')) {
str = document.getElementById('flag').innerHTML
SubId = 'sub-' + str.slice(str.indexOf('flag-')+5,str.indexOf('-menu'))
if (document.getElementById(SubId)) {
Open(SubId)
}
}
}
</script>
</head>
<body>
<div id="flag" class="page-flag"><div id="flag-4-menu" class="page-flag"></div></div>
<a href="page.htm">link 1</a><br />
<span id="open-2" class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onmousedown="return Open('sub-2')">open 2</span><br />
<div id="sub-2" class="subs">
<a href="page.htm">this is a sub link of 2</a><br />
<a href="page.htm">this is a sub link of 2</a>
</div>
<a href="page.htm">link 3</a><br />
<span id="open-4" class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onmousedown="return Open('sub-4')">open 4</span><br />
<div id="sub-4" class="subs">
<a href="page.htm">this is a sub link of 4</a><br />
<a href="page.htm">this is a sub link of 4</a><br />
<a href="page.htm">this is a sub link of 4</a>
</div>
<a href="page.htm">link 5</a><br />
<a href="page.htm">link 6</a><br />
<span id="open-7" class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onmousedown="return Open('sub-7')">open 7</span><br />
<div id="sub-7" class="subs">
<a href="page.htm">this is a sub link of 7</a><br />
<a href="page.htm">this is a sub link of 7</a><br />
<a href="page.htm">this is a sub link of 7</a>
</div>
</body>
</html>
Edit
This is a URL alternative to using the flag div to open the menu. Change the sub menu division ids to match a part of the URL.
Change the opening span(s) from this example.
onmousedown="return Open('sub-7')"
... to this
onmousedown="return Open('the-new-sub-id')"
Put this anywhere in your .js file. Add the part of the URL(s) that the divisions are named to the array.
MenuIds = new Array ('some_folder','page.htm')
Relpace this in the onload function
if (document.getElementById('flag')) {
str = document.getElementById('flag').innerHTML
SubId = 'sub-' + str.slice(str.indexOf('flag-')+5,str.indexOf('-menu'))
if (document.getElementById(SubId)) {
Open(SubId)
}
}
... with this
for (var i=0;i<MenuIds.length;i++) {
if (location.href.match(MenuIds[i])) {
str = MenuIds[i]
if (document.getElementById(str)) {
Open(str)
}
}
}