PDA

View Full Version : PHP Collapsible Menu


xst
07-21-2007, 12:27 AM
Hello all, I'm wanting to make a collapsible menu for my php nuke platinum site
and all my searching finds nothing but xml, and html stuff. When I use anything that I find it shows and works but it shows above the block and the block it's self says nothing is there to display..

Any suggestions or tips would be appreciated..

Thanks

This was the source I used

http://simplythebest.net/scripts/DHTML_scripts/dhtml_script_100.html

This was how I added the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Menu</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/

var caution = false
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartInde x + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}
function item(parent, text, depth) {
this.parent = parent
this.text = text
this.depth = depth
}
function makeArray(length) {
this.length = length
}
function makeDatabase() {
outline = new makeArray(16)

outline[0] = new item(true, '<font class=body>SimplytheBest', 0)
outline[1] = new item(false, '<A HREF="http://simplythebest.net/software/" class=bodylink>Shareware & Freeware</A>', 1)
outline[2] = new item(true, 'Scripts', 1)
outline[3] = new item(false, '<A HREF="http://simplythebest.net/scripts/" class=bodylink>DHTML Scripts</A>', 2)
outline[4] = new item(false, '<A HREF="http://simplythebest.net/scripts/" class=bodylink>CGI Scripts</A>', 2)
outline[5] = new item(false, '<A HREF="http://info.simplythebest.net" class=bodylink>Information library</A>', 1)
outline[6] = new item(false, '<A HREF="http://info.simplythebest.net" class=bodylink>Device drivers</A>', 1)
outline[7] = new item(false, '<A HREF="http://simplythebest.net/fonts/" class=bodylink>Free fonts</A>', 1)
outline[8] = new item(false, '<A HREF="http://simplythebest.net/affiliate_programs/" class=bodylink>Affiliate programs</A>', 1)
outline[9] = new item(true, 'PlanMagic', 0)
outline[10] = new item(false, '<A HREF="http://planmagic.com" class=bodylink>Business software</A>', 1)
outline[11] = new item(false, '<A HREF="http://planmagic.com/business_planning.html" class=bodylink>Business plan</A>', 1)
outline[12] = new item(false, '<A HREF="http://planmagic.com/marketing_planning.html" class=bodylink>Marketing plan</A>', 1)
outline[13] = new item(false, '<A HREF="http://planmagic.com/financial_planning.html" class=bodylink>Financial plan</A>', 1)
outline[14] = new item(false, '<A HREF="http://plan-a-restaurant.com" class=bodylink>Restaurant plan</A>', 1)
outline[15] = new item(false, '<A HREF="http://planmagic.com/business_plan/hotel_business_plan.html" class=bodylink>Hotel plan</A>', 1)

setStates()
setImages()
}

function setStates() {
var storedValue = getCookie("outline")

if (!storedValue) {
for (var i = 0; i < outline.length; ++i) {
if (outline[i].depth == 0)
outline[i].state = true
else
outline[i].state = false
}
} else {
for (var i = 0; i < outline.length; ++i) {
if (storedValue.charAt(i) == '1')
outline[i].state = true
else
outline[i].state = false
}
}
}
function setImages() {
for (var i = 0; i < outline.length; ++i) {
if (outline[i].state)
if (outline[i].parent)
if (outline[i + 1].state)
outline[i].pic = '<A HREF="javascript:toggle(' + i + ')"><IMG SRC="dscript100/exploded.gif" BORDER=0></A>'
else
outline[i].pic = '<A HREF="javascript:toggle(' + i + ')"><IMG SRC="dscript100/collapsd.gif" BORDER=0></A>'
else
outline[i].pic = '<IMG SRC="dscript100/child.gif" BORDER=0>'
}
}
function toggle(num) {
for (var i = num + 1; i < outline.length && outline[i].depth >= outline[num].depth + 1; ++i) {
if (outline[i].depth == outline[num].depth + 1)
outline[i].state = !outline[i].state
}
setStorage()
history.go(0)
}
function setStorage() {
var text = ""
for (var i = 0; i < outline.length; ++i) {
text += (outline[i].state) ? "1" : "0"
}

setCookie("outline", text)
}
makeDatabase()
// -->
</SCRIPT>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
document.write('<PRE><font face=arial size=2>')
for (var i = 0; i < outline.length; ++i) {
if (outline[i].state) {
for (var j = 0; j < outline[i].depth * 5; ++j) {
document.write(' ')
}
document.write(outline[i].pic, ' ', outline[i].text, '<BR>')
} else {
var previous = i
for (var k = i + 1; k < outline.length && outline[k].depth >= outline[previous].depth; ++k) {
++i
}
}
}
document.write('</font></PRE>')
// -->
</SCRIPT>
</body>
</html>


then I saved it as block-menu.php

The result is

http://www.xst-hq.net/offsite_images/menu-error.PNG

UnlimitedMB
07-21-2007, 02:52 AM
That script sucks anyway, its not dhtml as it claims to be, it just reload the whole page every time you collapse a menu, it could be done better using dhtml.