1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/* DISABLE_PHP_LINT_CHECKING */
|
4
|
/* ========================================================================== */
|
5
|
/*
|
6
|
menu.inc
|
7
|
Copyright (C) 2006 Daniel S. Haischt <me@daniel.stefan.haischt.name>
|
8
|
All rights reserved.
|
9
|
*/
|
10
|
/* ========================================================================== */
|
11
|
/*
|
12
|
Originally part of m0n0wall (http://m0n0.ch/wall)
|
13
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
14
|
All rights reserved.
|
15
|
|
16
|
Redistribution and use in source and binary forms, with or without
|
17
|
modification, are permitted provided that the following conditions are met:
|
18
|
|
19
|
1. Redistributions of source code must retain the above copyright notice,
|
20
|
this list of conditions and the following disclaimer.
|
21
|
|
22
|
2. Redistributions in binary form must reproduce the above copyright
|
23
|
notice, this list of conditions and the following disclaimer in the
|
24
|
documentation and/or other materials provided with the distribution.
|
25
|
|
26
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
27
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
28
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
29
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
30
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35
|
POSSIBILITY OF SUCH DAMAGE.
|
36
|
*/
|
37
|
/* ========================================================================== */
|
38
|
|
39
|
require("menu.inc");
|
40
|
|
41
|
define("TMENU_STUB", "
|
42
|
// set up drop downs anywhere in the body of the page. I think the bottom of the page is better..
|
43
|
// but you can experiment with effect on loadtime.
|
44
|
if (TransMenu.isSupported()) {
|
45
|
|
46
|
//==================================================================================================
|
47
|
// create a set of dropdowns
|
48
|
//==================================================================================================
|
49
|
// the first param should always be down, as it is here
|
50
|
//
|
51
|
// The second and third param are the top and left offset positions of the menus from their actuators
|
52
|
// respectively. To make a menu appear a little to the left and bottom of an actuator, you could use
|
53
|
// something like -5, 5
|
54
|
//
|
55
|
// The last parameter can be .topLeft, .bottomLeft, .topRight, or .bottomRight to inidicate the corner
|
56
|
// of the actuator from which to measure the offset positions above. Here we are saying we want the
|
57
|
// menu to appear directly below the bottom left corner of the actuator
|
58
|
//==================================================================================================
|
59
|
var ms = new TransMenuSet(TransMenu.direction.down, 1, 0, TransMenu.reference.bottomLeft);
|
60
|
|
61
|
//==================================================================================================
|
62
|
// create a dropdown menu
|
63
|
//==================================================================================================
|
64
|
// the first parameter should be the HTML element which will act actuator for the menu
|
65
|
//==================================================================================================
|
66
|
|
67
|
@@MENU_DEFINITIONS@@
|
68
|
|
69
|
//==================================================================================================
|
70
|
// write drop downs into page
|
71
|
//==================================================================================================
|
72
|
// this method writes all the HTML for the menus into the page with document.write(). It must be
|
73
|
// called within the body of the HTML page.
|
74
|
//==================================================================================================
|
75
|
TransMenu.renderAll();
|
76
|
}
|
77
|
");
|
78
|
|
79
|
class NervecenterMenu extends Menu {
|
80
|
private $menuJScript = "NOT-SET";
|
81
|
private $menuJScriptEvents = "NOT-SET";
|
82
|
private $menuID = "NOT-SET";
|
83
|
|
84
|
public function __construct($identification = "", $filename = "", Component $c = NULL) {
|
85
|
parent::__construct($identification, $filename, $c);
|
86
|
|
87
|
$id = "mnua_" . str_replace(" ", "", strtolower($this->getID()));
|
88
|
$this->menuID = $id;
|
89
|
|
90
|
if ($this->hasParent()) {
|
91
|
$this->menuJScript = "\tvar {$id} = ms.addMenu(document.getElementById('{$id}'));\n";
|
92
|
}
|
93
|
} // end __construct
|
94
|
|
95
|
public function getMenuID() {
|
96
|
return $this->menuID;
|
97
|
}
|
98
|
|
99
|
public function setMenuID($myMenuID) {
|
100
|
$this->menuID = $myMenuID;
|
101
|
}
|
102
|
|
103
|
public function getMenuJScript() {
|
104
|
$childJScript = "";
|
105
|
foreach ($this->getChildren() as $component) {
|
106
|
$childJScript .= $component->getMenuJScript();
|
107
|
}
|
108
|
|
109
|
if (! $this->hasParent()) {
|
110
|
$this->menuJScript = str_replace("@@MENU_DEFINITIONS@@", $childJScript, TMENU_STUB);
|
111
|
} else {
|
112
|
$this->menuJScript .= "\n$childJScript\n";
|
113
|
}
|
114
|
|
115
|
return $this->menuJScript;
|
116
|
}
|
117
|
|
118
|
public function getMenuJScriptEvents() {
|
119
|
return $this->menuJScriptEvents;
|
120
|
}
|
121
|
|
122
|
public function __toString() {
|
123
|
if (! $this->hasParent()) {
|
124
|
$menuMarkup =<<<EOD
|
125
|
<div id="menu">
|
126
|
@@CHILD_ELEMENTS@@
|
127
|
</div>
|
128
|
|
129
|
EOD;
|
130
|
} else {
|
131
|
$name = gettext($this->getID());
|
132
|
$id = "mnua_" . str_replace(" ", "", strtolower($this->getID()));
|
133
|
|
134
|
$menuMarkup =<<<EOD
|
135
|
<a id="{$id}" href="#">{$name}</a>
|
136
|
@@CHILD_ELEMENTS@@
|
137
|
EOD;
|
138
|
}
|
139
|
|
140
|
$childMarkup = "";
|
141
|
foreach ($this->getChildren() as $component) {
|
142
|
$childMarkup .= $component;
|
143
|
}
|
144
|
|
145
|
$menuMarkup = str_replace("@@CHILD_ELEMENTS@@", $childMarkup, $menuMarkup);
|
146
|
|
147
|
return $menuMarkup;
|
148
|
}
|
149
|
}
|
150
|
|
151
|
class NervecenterMenuItem extends MenuItem {
|
152
|
private $menuJScript = "NOT-SET";
|
153
|
private $menuJScriptEvents = "NOT-SET";
|
154
|
|
155
|
public function __construct($identification = "", $filename = "", $href = "", Component $c = NULL) {
|
156
|
parent::__construct($identification, $filename, $href, $c);
|
157
|
|
158
|
$href = $this->getHref() <> "" ? $this->getHref() : "{$this->getFile()}";
|
159
|
$name = gettext($this->getID());
|
160
|
$file = $this->getFile();
|
161
|
|
162
|
$this->menuJScript = $this->check_access("{$file}", "\t{$this->getParent()->getMenuID()}.addItem('{$name}', '{$href}');\n");
|
163
|
}
|
164
|
|
165
|
public function getMenuJScript() {
|
166
|
return $this->menuJScript;
|
167
|
}
|
168
|
|
169
|
public function getMenuJScriptEvents() {
|
170
|
return $this->menuJScriptEvents;
|
171
|
}
|
172
|
|
173
|
public function __toString() {
|
174
|
return "";
|
175
|
}
|
176
|
}
|
177
|
|
178
|
?>
|