1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
<?php
// System for generating menus.
//
// webtrees: Web based Family History software
// Copyright (C) 2012 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// $Id$
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}
class WT_Menu {
var $label = ' ';
var $labelpos = 'right';
var $link = '#';
var $onclick = null;
var $flyout = 'down';
var $class = '';
var $id=null;
var $submenuclass = '';
var $iconclass = '';
var $target = null;
var $parentmenu = null;
var $submenus;
/**
* Constructor for the menu class
* @param string $label the label for the menu item (usually a wt_lang variable)
* @param string $link The link that the user should be taken to when clicking on the menuitem
* @param string $pos The position of the label relative to the icon (right, left, top, bottom)
* @param string $flyout The direction where any submenus should appear relative to the menu item (right, down)
*/
function __construct($label=' ', $link='#', $id=null, $labelpos='right', $flyout='down')
{
$this->label =$label;
$this->labelpos=$labelpos;
$this->link =$link;
$this->id =$id;
$this->flyout =$flyout;
$this->submenus=array();
}
function addLabel($label=' ', $pos='right')
{
if ($label) $this->label = $label;
$this->labelpos = $pos;
}
function addLink($link='#')
{
$this->link = $link;
}
function addOnclick($onclick)
{
$this->onclick = $onclick;
}
function addFlyout($flyout='down')
{
$this->flyout = $flyout;
}
function addClass($class, $submenuclass='', $iconclass='icon_general')
{
$this->class = $class;
$this->submenuclass = $submenuclass;
$this->iconclass = $iconclass;
}
function addTarget($target)
{
$this->target = $target;
}
function addSubMenu($obj)
{
$this->submenus[] = $obj;
}
//
public function __toString() {
return $this->getMenuAsList();
}
// Get the menu as a simple list - for accessible interfaces, search engines and CSS menus
function getMenuAsList() {
$link = '';
if ($this->link) {
if ($this->target !== null) {
$link .= ' target="'.$this->target.'"';
}
if ($this->link=='#') {
if ($this->onclick !== null) {
$link .= ' onclick="'.$this->onclick.'"';
}
$html='<a class="'.$this->iconclass.'" href="'.$this->link.'"'.$link.'>'.$this->label.'</a>';
} else {
$html='<a class="'.$this->iconclass.'" href="'.$this->link.'"'.$link.'>'.$this->label.'</a>';
}
} else {
$html=$this->label;
}
if ($this->submenus) {
$html.='<ul>';
foreach ($this->submenus as $submenu) {
if ($submenu) {
if ($submenu->submenus) {
$submenu->iconclass.=' icon_arrow';
}
$html.=$submenu->getMenuAsList();
}
}
$html.='</ul>';
}
if ($this->id) {
return '<li id="'.$this->id.'">'.$html.'</li>';
} else {
return '<li>'.$html.'</li>';
}
}
function getMenu() {
global $menucount, $TEXT_DIRECTION, $WT_IMAGES;
if (!isset($menucount)) {
$menucount = 0;
} else {
$menucount++;
}
$id = $menucount.rand();
$c = count($this->submenus);
$output = "<div id=\"menu{$id}\" class=\"{$this->class}\">";
$link = "<a href=\"{$this->link}\" onmouseover=\"";
if ($c >= 0) {
$link .= "show_submenu('menu{$id}_subs', 'menu{$id}', '{$this->flyout}');";
}
$link .= '" onmouseout="';
if ($c >= 0) {
$link .= "timeout_submenu('menu{$id}_subs');";
}
if ($this->onclick !== null) {
$link .= "\" onclick=\"{$this->onclick}";
}
if ($this->target !== null) {
$link .= '" target="'.$this->target;
}
$link .= "\">";
$output .= $link;
$output .= $this->label;
$output .= "</a>";
if ($c > 0) {
$submenuid = "menu{$id}_subs";
if ($TEXT_DIRECTION == 'ltr') {
$output .= '<div style="text-align: left;">';
} else {
$output .= '<div style="text-align: right;">';
}
$output .= "<div id=\"menu{$id}_subs\" class=\"{$this->submenuclass}\" style=\"position: absolute; visibility: hidden; z-index: 100;";
if ($this->flyout == 'right') {
if ($TEXT_DIRECTION == 'ltr') {
$output .= ' left: 80px;';
} else {
$output .= ' right: 50px;';
}
}
$output .= "\" onmouseover=\"show_submenu('{$this->parentmenu}'); show_submenu('{$submenuid}');\" onmouseout=\"timeout_submenu('menu{$id}_subs');\">";
foreach ($this->submenus as $submenu) {
$submenu->parentmenu = $submenuid;
$output .= $submenu->getMenu();
}
$output .= "</div></div>";
}
$output .= "</div>";
return $output;
}
/**
* returns the number of submenu's in this menu
* @return int
*/
function subCount() {
return count($this->submenus);
}
}
|