menu-ulli-structuur

Gesponsorde koppelingen

PHP script bestanden

  1. menu-ulli-structuur

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
/**
 * @version 0.9
 * @author Kees Schepers <[email protected]>
 * @package SB Framework
 * @copyright ScooterBase.net
 */  

/**
 * Exception which will be thrown when something happends with the menu building
 */

class Site_Menu_Exception extends Exception {}

/**
 * Drawes and takes care for the whole menu, but not the contents
 * @version 0.9
 */

class Site_Menu {    
    /**
     * Map with items first key is the parentid
     *
     * @var array
     */

    private $items;
    /**
     * HTML id of the first <ul> tag
     *
     * @var string
     */

    private $elementId;
    /**
     * Constructor, construct a menu
     *
     * @param string $elementId id of the root UL element
     * @return void
     */

    public function __construct($elementId) {
        $this->items = array();
        if(preg_match('/^[a-z]{1,}[a-z0-9]*/i',$elementId)) {
            $this->elementId = $elementId;
        }
else {
            throw new Site_Menu_Exception('Element id ('.$elementId.') is not XHTML valid');
        }
    }

    /**
     * Add an list item
     *
     * @param Site_Menu_Item $item
     * @return void
     */

    public function addItem(Site_Menu_Item $item) {        
        $this->items[$item->parent][] = $item;
    }

    /**
     * Recursively loop all items
     *
     * @param string $parent
     * @return string HTML contents
     */

    private function getItems($parent) {
        $str = '';
        
        foreach ($this->items[$parent] as $item) {
            $str .= '<li><a '.(!is_null($item->class) ? 'class="'.$item->class.'"' : '').' href="'.$item->href.'" title="'.$item->title.'">'.$item->title.'</a>';
                        
            if(array_key_exists($item->title,$this->items)) {                
                $str .= '<ul>';
                $str .= $this->getItems($item->title);
                $str .= '</ul>';
            }

            
            $str .= '</li>';
        }

        
        return $str;
    }

    public function getHTML() {
        return '<ul id="'.$this->elementId.'">'.$this->getItems('root').'</ul>';
    }
}


/**
 * Just an single menu item (link)
 *
 */

class Site_Menu_Item {
    /**
     * An map with properties (href, class, title, etc)
     *
     * @var array
     */

    private $properties;
    /**
     * Create a new menu item
     *
     * @param string $title
     * @param string $href
     * @param string $parent
     * @return void
     */

    public function __construct($title,$href,$parent='root') {
        $this->properties = array();
        
        $this->__set('title',$title);
        $this->__set('href',$href);
        $this->__set('parent',$parent);
        $this->__set('class',null);
                
    }

    /**
     * Get the properties of an menu element
     *
     * @param string $key
     * @return mixed
     */

    public function __get($key) {
        if(array_key_exists($key,$this->properties)) {
            return $this->properties[$key];
        }
else {
            throw new Site_Menu_Exception('Cannot get property '.$key);
        }
    }

    /**
     * Set the properties of an menu element
     *
     * @param string $key
     * @param mixed $value
     * @return boolean
     */

    public function __set($key,$value) {
        switch ($key) {
            case
'href' :
            case
'title' :
            case
'parent' :
            case
'class' :
                $this->properties[$key] = $value;
                return true;
            default :

                throw new Site_Menu_Exception('Cannot set property '.$key);
                return false;
        }
    }
}

?>

CSS:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
#nav {
    z-index:100;
    position:absolute;        
    margin-top:1px;
}

#nav, #nav ul, #nav ul li {
    list-style:none;
    display:block;        
}

#nav li {
  position: relative;
  float:left;
    width:145px;  
  color:#fff;
  font-size:14px;    
}
#nav li:hover {
    background-color:#dbdbdb;
    color:#000;    
  background-image:url('/bmvv/images/layout/menu_background_right.jpg');
  background-repeat:no-repeat;
  background-position:top right;    
}
#nav ul li {
    background-color:#fff;
    color:#000;
    font-size:12px;
    border-left:1px solid #dbdbdb;
    border-right:1px solid #dbdbdb;
    width:140px;
    font-weight:bold;
    text-transform:capitalize;
    padding:5px 0px 5px 3px;        
}
#nav a {
  text-decoration:none;
  display:block;    
  color:#000;  
  background-image:none;
}
#nav a.root {
    color:#fff;
}
#nav a.root:hover {
    color:black;
}
#nav ul li:hover, #nav ul li a:hover{
    background-color:#dbdbdb;
    color:#000;
    background-image:none;
}

#nav ul{
  display:none;  
}
#nav ul ul, #nav ul ul ul{
    display:none;
    border-top:1px solid #dbdbdb;
  position:absolute;
}
  
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul, #nav li:hover ul ul ul ul ul{
  display:none;
}

#nav li:hover ul, #nav ul li:hover ul, #nav ul ul li:hover ul, #nav ul ul ul li:hover ul, #nav ul ul ul ul li:hover ul{
  display:block;
}

li>ul {
    top:0px;
    left:144px;
}

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.