]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added 4 methods to ElggMenuItem: get/setLinkClass() and get/setItemClass(). This...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 19 Feb 2011 04:18:15 +0000 (04:18 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 19 Feb 2011 04:18:15 +0000 (04:18 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8313 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggMenuItem.php
views/default/navigation/menu/elements/item.php

index 108cb56f23002b6bcce5bc8b3f4ff2c25112b55c..0de5feddbb5550a943b8796bac3e41a285e96a63 100644 (file)
@@ -23,6 +23,16 @@ class ElggMenuItem {
         */
        protected $url = null;
 
+       /**
+        * @var array Classes to apply to the anchor tag.
+        */
+       protected $linkClass = array();
+
+       /**
+        * @var array Classes to apply to the li tag.
+        */
+       protected $itemClass = array();
+
        /**
         * @var array Page context array
         */
@@ -231,6 +241,54 @@ class ElggMenuItem {
                return $this->tooltip;
        }
 
+       /**
+        * Set the anchor class
+        *
+        * @param mixed $class An array of class names, or a single string class name.
+        *
+        * @return void
+        */
+       public function setLinkClass($class) {
+               if (!is_array($class)) {
+                       $this->linkClass[] = $class;
+               } else {
+                       $this->linkClass = $class;
+               }
+       }
+
+       /**
+        * Get the anchor classes as text
+        *
+        * @return string
+        */
+       public function getLinkClass() {
+               return implode(' ', $this->linkClass);
+       }
+
+       /**
+        * Set the li classes
+        *
+        * @param mixed $class An array of class names, or a single string class name.
+        *
+        * @return void
+        */
+       public function setItemClass($class) {
+               if (!is_array($class)) {
+                       $this->itemClass[] = $class;
+               } else {
+                       $this->itemClass = $class;
+               }
+       }
+
+       /**
+        * Get the li classes as text
+        *
+        * @return string
+        */
+       public function getItemClass() {
+               return implode(' ', $this->itemClass);
+       }
+
        /**
         * Set the weight of the menu item
         *
@@ -354,6 +412,9 @@ class ElggMenuItem {
                if ($this->url) {
                        $vars['href'] = $this->url;
                }
+               if ($this->linkClass) {
+                       $vars['class'] = $this->linkClass;
+               }
 
                return elgg_view('output/url', $vars);
        }
index 5a9a8743dac94ca01aec740a474ea2bbe4ab29d0..7b07c9485c553a5c9c82c2c53bff517b95544376 100644 (file)
@@ -1,19 +1,28 @@
 <?php
+/**
+ * A single element of a menu.
+ *
+ * @package Elgg.Core
+ * @subpackage Navigation
+ */
 
 $item = $vars['item'];
 
-$class = '';
 $link_class = 'elgg-menu-closed';
 if ($item->getSelected()) {
-       $class = 'class="elgg-state-selected"';
+       $item->setItemClass('elgg-state-selected');
        $link_class = 'elgg-menu-opened';
 }
 
-$link_vars = array();
-
 $children = $item->getChildren();
 if ($children) {
-       $link_vars['class'] = "elgg-menu-parent $link_class";
+       $item->setLinkClass($link_class);
+       $item->setLinkClass('elgg-menu-parent');
+}
+
+$item_class = $item->getItemClass();
+if ($item_class) {
+       $class = "class=\"$item_class\"";
 }
 
 echo "<li $class>";