Česky
Kamil Dudka

QuickMenu (Javascript, PHP)

File detail

Name:Downloadindex.php [Download]
Location: QuickMenu > QuickMenu-with-example
Size:1.6 KB
Last modification:2022-09-09 13:06

Source code

<?php
// Load configuration
require_once('config.php');
LangSelect::singleton()->handleLangSelect();
 
// Page header
echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>QuickMenu demo</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="default.css" type="text/css" rel="stylesheet"></link>
  <script type="text/javascript" src="base.js"></script>
<?php
 
// Import Quickmenu class
ClassFactory::importClass('QuickMenu');
 
// Create instance of QuickMenu
$qm = new QuickMenu;
 
// You can experiment here
// Recomended values: 1-3
$qm->setMinimalInputLength(1);
 
// You can experiment here
// Recomended values: 1-3
$qm->setVisibleDepth(2);
 
// Generate head part of QuickMenu output
$qm->genHead();
 
/// @attention Do not forget generate Javascript onload list
JSOnloadList::instance()->generate();
?>
</head>
<body>
<h1>QuickMenu demo</h1>
<?php
 
// Add menu items using XML menu template
$qm->loadXmlTemplate('QmTemplate.xml');
 
// Add menu items using addItem method (pseudo-random genrator)
$stack = Array();
for ($i=0; $i<50; $i++) {
  $parent = array_pop($stack);
  $id = $qm->addItem('Item '.$i, 'index.php?item='.$i, isset($parent)?$parent:0);
  if ($i%5)
    array_push($stack, $parent);
  if (0==$i%4)
    array_push($stack, $id);
}
 
// Highlight active menu item
$qm->setActiveItemHREF('index.php?item='.@$_GET['item']);
 
// Generate body part of QuickMenu output
$qm->genMenu();
?>
</body>
</html>