From 1c917ac28f4a1e4c58aed600c5b4c8bef4645cb5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 6 Jul 2011 18:40:02 -0400 Subject: [PATCH] start making more menu work --- lib/groupsnav.php | 2 +- lib/menu.php | 5 +- lib/moremenu.php | 121 +++++++++++++++++++++++++++++++++++++ theme/base/css/display.css | 4 ++ 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 lib/moremenu.php diff --git a/lib/groupsnav.php b/lib/groupsnav.php index b060153f88..5578c2fece 100644 --- a/lib/groupsnav.php +++ b/lib/groupsnav.php @@ -44,7 +44,7 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ -class GroupsNav extends Menu +class GroupsNav extends MoreMenu { protected $user; protected $groups; diff --git a/lib/menu.php b/lib/menu.php index b92b37dbb1..281ef7797b 100644 --- a/lib/menu.php +++ b/lib/menu.php @@ -104,7 +104,7 @@ class Menu extends Widget } } - function item($actionName, $args, $label, $description, $id=null) + function item($actionName, $args, $label, $description, $id=null, $cls=null) { if (empty($id)) { $id = $this->menuItemID($actionName, $args); @@ -116,7 +116,8 @@ class Menu extends Widget $label, $description, $this->isCurrent($actionName, $args), - $id); + $id, + $cls); } function isCurrent($actionName, $args) diff --git a/lib/moremenu.php b/lib/moremenu.php new file mode 100644 index 0000000000..e8c16b0d6e --- /dev/null +++ b/lib/moremenu.php @@ -0,0 +1,121 @@ +. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * A menu with a More... element to show more items + * + * @category General + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class MoreMenu extends Menu +{ + const SOFT_MAX = 5; + const HARD_MAX = 15; + + /** + * Show a menu with a limited number of elements + * + * @param + * + * @return + */ + + function show() + { + $items = $this->getItems(); + $tag = $this->tag(); + + $attrs = array('class' => 'nav'); + + if (!is_null($tag)) { + $attrs['id'] = 'nav_' . $tag; + } + + if (Event::handle('StartNav', array($this, &$tag, &$items))) { + + $this->out->elementStart('ul', $attrs); + + $total = count($items); + + if ($total <= self::SOFT_MAX + 1) { + $toShow = $items; + } else { + $toShow = array_slice($items, 0, self::SOFT_MAX); + } + + foreach ($toShow as $item) { + list($actionName, $args, $label, $description, $id) = $item; + $this->item($actionName, $args, $label, $description, $id); + } + + if ($total > self::SOFT_MAX + 1) { + $this->out->elementStart('li'); + $this->out->element('a', array('href' => '#'), + _('More ▼')); + $this->out->elementEnd('li'); + + $extended = array_slice($items, self::SOFT_MAX, self::HARD_MAX - self::SOFT_MAX); + + foreach ($extended as $item) { + list($actionName, $args, $label, $description, $id) = $item; + $this->item($actionName, $args, $label, $description, $id, 'extended_menu'); + } + + $seeAll = $this->seeAllItem(); + + if (!empty($seeAll)) { + list($actionName, $args, $label, $description, $id) = $seeAll; + $this->item($actionName, $args, $label, $description, $id, 'extended_menu see_all'); + } + } + + $this->out->elementEnd('ul'); + + Event::handle('EndNav', array($this, $tag, $items)); + } + } + + function seeAllItem() + { + return null; + } + +} diff --git a/theme/base/css/display.css b/theme/base/css/display.css index c9655d52c0..485b95cf0a 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -2229,6 +2229,10 @@ float:right; display:none; } +#site_nav_local_views li.extended_menu a { + display:none; +} + /*end of @media screen, projection, tv*/