From 954fcf034238458f292c9f5ec72c6d4b101aac0d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 7 Dec 2008 19:45:46 +0000 Subject: Merge gallery3/branches/menus back into gallery3/trunk --- core/helpers/core_block.php | 5 ++ core/helpers/core_menu.php | 50 +++++++++++++++++++ core/helpers/menus.php | 42 ++++++++++++++++ core/js/menu.js | 24 +++++++++ core/libraries/Menu.php | 111 ++++++++++++++++++++++++++++++++++++++++++ core/libraries/Theme_View.php | 6 +++ core/tests/Menu_Test.php | 73 +++++++++++++++++++++++++++ 7 files changed, 311 insertions(+) create mode 100644 core/helpers/core_menu.php create mode 100644 core/helpers/menus.php create mode 100644 core/js/menu.js create mode 100644 core/libraries/Menu.php create mode 100644 core/tests/Menu_Test.php (limited to 'core') diff --git a/core/helpers/core_block.php b/core/helpers/core_block.php index 801ffb82..1a90d466 100644 --- a/core/helpers/core_block.php +++ b/core/helpers/core_block.php @@ -19,6 +19,11 @@ */ class core_block_Core { + public static function head($theme) { + $url = url::file("core/js/menu.js"); + return ""; + } + public static function page_bottom($theme) { // @todo: guard this with permissions if (Session::instance()->get("user", false)) { diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php new file mode 100644 index 00000000..e43c7762 --- /dev/null +++ b/core/helpers/core_menu.php @@ -0,0 +1,50 @@ +append(new Menu(_("HOME"), url::base())); + $menus->append(new Menu(_("BROWSE"), url::site("albums/1"))); + + $user = Session::instance()->get('user', null); + if ($user) { + $upload_menu = new Menu(_("UPLOAD")); + $upload_menu->append( + new Menu(_("File Upload"), "#photo/form/file_upload/" . $theme->item()->id)); + $upload_menu->append( + new Menu(_("Local Upload"), "#photo/form/local_upload/" . $theme->item()->id)); + $menus->append($upload_menu); + + $admin_menu = new Menu(_("ADMIN")); + + // @todo need to do a permission check here + $admin_menu->append( + new Menu(_("Edit Item"), "#photo/form/local_upload/" . $theme->item()->id)); + + if ($user->admin) { + $admin_menu->append( + new Menu(_("Site Admin"), url::site("admin"))); + } + + $menus->append($admin_menu); + } + } + +} diff --git a/core/helpers/menus.php b/core/helpers/menus.php new file mode 100644 index 00000000..28b34781 --- /dev/null +++ b/core/helpers/menus.php @@ -0,0 +1,42 @@ +name == "core") { + continue; + } + self::_get_module_menu_items($module->name, $menu, $theme); + } + + return $menu; + } + + static function _get_module_menu_items($module_name, $menu, $theme) { + $class = "{$module_name}_menu"; + if (method_exists($class, "items")) { + call_user_func_array(array($class, "items"), array(&$menu, $theme)); + } + } +} \ No newline at end of file diff --git a/core/js/menu.js b/core/js/menu.js new file mode 100644 index 00000000..b5f0a6ee --- /dev/null +++ b/core/js/menu.js @@ -0,0 +1,24 @@ +$("document").ready(function() { + $("#gSiteMenu ul:not(:first)").css("display", "none"); + $("#gSiteMenu li").mouseover(function (ev) { + $(this).children("ul").css("display", "block"); + $(this).children("ul").find("li").css("clear", "both"); + + this.dropdown_open = true; + }); + $("#gSiteMenu li").mouseout(function (ev) { + $(this).children("ul").css("display", "none"); + this.dropdown_open = false; + }); + + $("#gSiteMenu li a").click(function () { + var href = $(this).attr("href"); + if (href == "#") { + return false; + } else if (href.match("^#") == "#") { + alert("Display href: " + href.substring(1) + "in a popup"); + return false; + } + return true; + }); +}); diff --git a/core/libraries/Menu.php b/core/libraries/Menu.php new file mode 100644 index 00000000..4f4530a7 --- /dev/null +++ b/core/libraries/Menu.php @@ -0,0 +1,111 @@ +_text = $text; + $this->_url = $url; + } + + function __toString() { + return "
  • _url\">$this->_text
  • "; + } +} + +class Menu_Core { + protected $_text; + protected $_url; + protected $_items = array(); + + public function __construct($text="", $url="#") { + $this->_text = $text; + $this->_url = $url; + } + + public function append($menu_item) { + $this->_items[] = $menu_item; + } + + public function get($text) { + foreach ($this->_items as $item) { + if ($item->_text == $text) { + return $item; + } + } + return false; + } + + private function _get_index($text) { + foreach ($this->_items as $idx => $item) { + if ($item->_text == $text) { + return (int)$idx; + } + } + return false; + } + + public function insert_before($text, $menu_item) { + $offset = $this->_get_index($text); + + $front_part = ($offset == 0) ? array() : array_splice($this->_items, 0, $offset); + $back_part = ($offset == 0) ? $this->_items : array_splice($this->_items, $offset - 1); + $this->_items = array_merge($front_part, array($menu_item), $back_part); + } + + public function insert_after($text, $menu_item) { + $offset = $this->_get_index($text); + $last_offset = count($this->_items) - 1; + // If not found, then append to the end + if ($offset == false) { + $offset = $last_offset; + } + + $front_part = ($offset == $last_offset) ? $this->_items : array_splice($this->_items, 0, $offset + 1); + Kohana::log("debug", print_r($front_part, 1)); + $back_part = ($offset == $last_offset) ? array() : array_splice($this->_items, $offset - 1); + Kohana::log("debug", print_r($back_part, 1)); + $this->_items = array_merge($front_part, array($menu_item), $back_part); + } + + public function __toString() { + $items_html = array(); + if (!empty($this->_text)) { + $items_html[] = "
  • _url\">$this->_text"; + } + + if (!empty($this->_items)) { +// $items_html[] = "