Project

General

Profile

Download (6.64 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/* ========================================================================== */
4
/*
5
  menu.inc
6
  Copyright (C) 2006 Daniel S. Haischt <me@daniel.stefan.haischt.name>
7
  All rights reserved.
8
                                                                              */
9
/* ========================================================================== */
10
/*
11
  Originally part of m0n0wall (http://m0n0.ch/wall)
12
  Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
  All rights reserved.
14

    
15
  Redistribution and use in source and binary forms, with or without
16
  modification, are permitted provided that the following conditions are met:
17

    
18
  1. Redistributions of source code must retain the above copyright notice,
19
     this list of conditions and the following disclaimer.
20

    
21
  2. Redistributions in binary form must reproduce the above copyright
22
     notice, this list of conditions and the following disclaimer in the
23
     documentation and/or other materials provided with the distribution.
24

    
25
  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
  AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
  POSSIBILITY OF SUCH DAMAGE.
35
                                                                              */
36
/* ========================================================================== */
37

    
38
require("menu.inc");
39

    
40
define("TMENU_STUB", "
41
	// set up drop downs anywhere in the body of the page. I think the bottom of the page is better.. 
42
	// but you can experiment with effect on loadtime.
43
	if (TransMenu.isSupported()) {
44

    
45
		//==================================================================================================
46
		// create a set of dropdowns
47
		//==================================================================================================
48
		// the first param should always be down, as it is here
49
		//
50
		// The second and third param are the top and left offset positions of the menus from their actuators
51
		// respectively. To make a menu appear a little to the left and bottom of an actuator, you could use
52
		// something like -5, 5
53
		//
54
		// The last parameter can be .topLeft, .bottomLeft, .topRight, or .bottomRight to inidicate the corner
55
		// of the actuator from which to measure the offset positions above. Here we are saying we want the 
56
		// menu to appear directly below the bottom left corner of the actuator
57
		//==================================================================================================
58
		var ms = new TransMenuSet(TransMenu.direction.down, 1, 0, TransMenu.reference.bottomLeft);
59
                
60
		//==================================================================================================
61
		// create a dropdown menu
62
		//==================================================================================================
63
		// the first parameter should be the HTML element which will act actuator for the menu
64
		//==================================================================================================
65
                
66
                @@MENU_DEFINITIONS@@
67
                
68
		//==================================================================================================
69
		// write drop downs into page
70
		//==================================================================================================
71
		// this method writes all the HTML for the menus into the page with document.write(). It must be
72
		// called within the body of the HTML page.
73
		//==================================================================================================
74
		TransMenu.renderAll();
75
	}
76
");
77

    
78
class NervecenterMenu extends Menu {
79
  private $menuJScript = "NOT-SET";
80
  private $menuJScriptEvents = "NOT-SET";
81
  private $menuID = "NOT-SET";
82
  
83
  public function __construct($identification = "", $filename = "", Component $c = NULL) {
84
    parent::__construct($identification, $filename, $c);
85
    
86
    $id = "mnua_" . str_replace(" ", "", strtolower($this->getID()));
87
    $this->menuID = $id;
88
    
89
    if ($this->hasParent()) {
90
      $this->menuJScript = "\tvar {$id} = ms.addMenu(document.getElementById('{$id}'));\n";
91
    }
92
  } // end __construct
93
    
94
  public function getMenuID() {
95
    return $this->menuID;
96
  }
97
  
98
  public function setMenuID($myMenuID) {
99
    $this->menuID = $myMenuID;
100
  }
101
  
102
  public function getMenuJScript() {
103
    $childJScript = "";
104
    foreach ($this->getChildren() as $component) {
105
      $childJScript .= $component->getMenuJScript();
106
    }
107
    
108
    if (! $this->hasParent()) {
109
      $this->menuJScript = str_replace("@@MENU_DEFINITIONS@@", $childJScript, TMENU_STUB);
110
    } else {
111
      $this->menuJScript .= "\n$childJScript\n";
112
    }
113
    
114
    return $this->menuJScript;
115
  }
116
  
117
  public function getMenuJScriptEvents() {
118
    return $this->menuJScriptEvents;
119
  }
120

    
121
  public function __toString() {
122
    if (! $this->hasParent()) {
123
      $menuMarkup =<<<EOD
124
        <div id="menu">
125
          @@CHILD_ELEMENTS@@
126
        </div>
127

    
128
EOD;
129
    } else {    
130
      $name = gettext($this->getID());
131
      $id = "mnua_" . str_replace(" ", "", strtolower($this->getID()));
132
      
133
      $menuMarkup =<<<EOD
134
        <a id="{$id}" href="#">{$name}</a>
135
        @@CHILD_ELEMENTS@@  
136
EOD;
137
    }
138
    
139
    $childMarkup = "";
140
    foreach ($this->getChildren() as $component) {
141
      $childMarkup .= $component;
142
    }
143

    
144
    $menuMarkup = str_replace("@@CHILD_ELEMENTS@@", $childMarkup, $menuMarkup);
145

    
146
    return $menuMarkup;
147
  }
148
}
149

    
150
class NervecenterMenuItem extends MenuItem {
151
  private $menuJScript = "NOT-SET";
152
  private $menuJScriptEvents = "NOT-SET";
153
  
154
  public function __construct($identification = "", $filename = "", $href = "", Component $c = NULL) {
155
    parent::__construct($identification, $filename, $href, $c);
156
    
157
    $href = $this->getHref() <> "" ? $this->getHref() : "{$this->getFile()}";
158
    $name = gettext($this->getID());
159
    $file = $this->getFile();
160
    
161
    $this->menuJScript = $this->check_access("{$file}", "\t{$this->getParent()->getMenuID()}.addItem('{$name}', '{$href}');\n");
162
  }
163
  
164
  public function getMenuJScript() {    
165
    return $this->menuJScript;
166
  }
167
  
168
  public function getMenuJScriptEvents() {
169
    return $this->menuJScriptEvents;
170
  }
171

    
172
  public function __toString() {
173
    return "";
174
  }
175
}
176

    
177
?>
(7-7/11)