[ Klik-Kanan.com ]  
 Depan » Tutorial » PHP Info Banner   Tentang Kami   Buku Tamu   Kontak 

Membuat collapse menu

<html>
<?
echo '<font face="verdana" size="2">';
class submenu {

var $urls;
var $desps;
var $cot;
var $id;
//easily modify you menu symbols, can also use image tags
var $openSymbol = '(+)';
var $closedSymbol = '(--)';
var $itemBranch = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp|---';

function create($id) {
$this->cot=0;
$this->id=$id;
}

function add($url, $desp) {
$this->urls[$this->cot]=$url;
$this->desps[$this->cot]=$desp;
$this->cot++;
}

function open() {
$i=0;
while($i<$this->cot) {
if ($i==0) {
global $PHP_SELF;
echo '<b><a href="'.$PHP_SELF.'?action=close&id=">'.$this->closedSymbol.$this->desps[0].'</a></b><br>';
}
else {
echo $this->itemBranch.'<a href="'.$this->urls[$i].'">'.$this->desps[$i].'</a><br>';
}
$i++;
}

}

function close() {
global $PHP_SELF;
if (! $this->id){

} else {

echo '<b><a href="'.$PHP_SELF.'?action=open&id='.$this->id.'">'.$this->openSymbol.$this->desps[0].' </a></b><br>';

}

}

}

class menu {

var $submenus;
var $cot;
var $id;

function create() {
$this->cot=0;
$this->id=2;
}

function add($submenu) {
$this->submenus[$this->cot]=new submenu;
$this->submenus[$this->cot]=$submenu;
$this->cot++;
}

function show() {
$i=0;
$tmp = new submenu;
while ($i<$this->cot) {
$tmp=$this->submenus[$i];
if ($tmp->id==(string)$this->id) {
$tmp->open();
}
else {
$tmp->close();
}
$i++;
}
}

function hide() {
$tmp = new submenu;
$tmp->close();
}
}

$sm_1=new submenu;
$sm_1->create('1');
$sm_1->add('',' Download File');
$sm_1->add('http://www.winxpinfo.com','Windows XP');
$sm_1->add('http://www.freestuffhome.net','Gratisan');
$sm_1->add('http://www.adcsoft.com','ADC Software');
$sm_1->add('http://www.lutfian.com','Lutfian Software');

$sm_2=new submenu;
$sm_2->create('2');
$sm_2->add('',' Search Engine');
$sm_2->add('http://www.google.com','Google');
$sm_2->add('http://www.yahoo.com','Yahoo');
$sm_2->add('http://www.Altavista.com','Altavista');
$sm_2->add('http://www.searchindonesia.com','Search Indonesia');

$sm_3=new submenu;
$sm_3->create('3');
$sm_3->add('',' Tutorial Klik-Kanan.com');
$sm_3->add('http://www.klik-kanan.com/tutorial/perl/index.shtml','Perl');
$sm_3->add('http://www.klik-kanan.com/tutorial/registry/index.shtml','Registry');
$sm_3->add('http://www.klik-kanan.com/tutorial/php/index.shtml','PHP');
$sm_3->add('http://www.klik-kanan.com/desainweb/html/index.shtml','Desain Web');

$sm_4=new submenu;
$sm_4->create('4');
$sm_4->add('',' Berita');
$sm_4->add('http://www.detik.com','Detik');
$sm_4->add('http://www.detikinet.com','Detikinet');
$sm_4->add('http://www.kompas.com','Kompas');
$sm_4->add('http://www.Astaga.com','Astaga');

$m_1=new menu;
$m_1->create();
$m_1->add($sm_1);
$m_1->add($sm_2);
$m_1->add($sm_3);
$m_1->add($sm_4);

if ($action=='') {
$m_1->show();
}


if ($action=='open') {
$m_1->id=$id;
$m_1->show();
}

if ($action=='close') {
$m_1->id=$id;
$m_1->hide();
$m_1->show();
}

echo '</font>';
?>


sumber : http://phpclasses.upperdesign.com/

Download

2001 - 2006 Klik Kanan
Dilarang memperbanyak artikel yang terdapat pada situs ini tanpa seizin Klik Kanan.