diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-07-04 05:37:30 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-07-04 05:37:30 +0000 |
commit | 7f1606632dd96aff2aea73c95faf50cd35e454a4 (patch) | |
tree | fec81a59bbaa36870bb160156e65f45623cf3848 /modules | |
parent | b9f4e59c5a4655595e3254560febbdb01d599fd1 (diff) | |
download | brdo-7f1606632dd96aff2aea73c95faf50cd35e454a4.tar.gz brdo-7f1606632dd96aff2aea73c95faf50cd35e454a4.tar.bz2 |
- Patch #484820 by Gábor Hojtsy, yhahn, markboulton, leisareichelt, et al: initial version of the new administration toolbar.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/toolbar/toolbar.css | 177 | ||||
-rw-r--r-- | modules/toolbar/toolbar.info | 8 | ||||
-rw-r--r-- | modules/toolbar/toolbar.install | 57 | ||||
-rw-r--r-- | modules/toolbar/toolbar.js | 89 | ||||
-rw-r--r-- | modules/toolbar/toolbar.module | 186 | ||||
-rw-r--r-- | modules/toolbar/toolbar.png | bin | 0 -> 960 bytes | |||
-rw-r--r-- | modules/toolbar/toolbar.tpl.php | 29 |
7 files changed, 546 insertions, 0 deletions
diff --git a/modules/toolbar/toolbar.css b/modules/toolbar/toolbar.css new file mode 100644 index 000000000..e90d85feb --- /dev/null +++ b/modules/toolbar/toolbar.css @@ -0,0 +1,177 @@ +/* $Id$ */ + +body.toolbar { + padding-top: 30px; +} + +body.toolbar-shortcuts { + padding-top: 80px; +} + +/** + * Aggressive resets so we can achieve a consistent look in hostile CSS + * environments. + */ +div#toolbar, +div#toolbar * { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-size: 100%; + vertical-align: baseline; + line-height: inherit; + text-align: left; + list-style: none; +} + +/** + * Base styles. + */ +div#toolbar { + font: normal 11px/20px "Lucida Grande", Verdana, sans-serif; + background: #666; + color: #ccc; + position: fixed; + left: 0; + right: 0; + top: 0; + z-index: 100; +} + +div#toolbar .collapsed { + display: none; +} + +div#toolbar div.shadow { + position: absolute; + left: 0; + right: 0; + bottom: -15px; + height: 15px; + background: url(toolbar.png) 0 -85px repeat-x; +} + +div#toolbar a { + text-decoration: none; + color: #fff; +} + +div#toolbar ul li, +div#toolbar ul li a { + float: left; +} + +/** + * Administration menu. + */ +div#toolbar div.toolbar-menu { + background: url(toolbar.png) 0 -20px repeat-x; + height: 25px; + line-height: 20px; + padding: 5px 10px 0; + overflow: hidden; + position: relative; +} + +div#toolbar div.toolbar-menu #toolbar-user { + position: absolute; + right: 35px; +} + +div#toolbar div.toolbar-menu #toolbar-menu { + position: absolute; + left: 10px; +} + +div#toolbar div.toolbar-menu span.toggle { + position: absolute; + right: 10px; + cursor: pointer; + background: url(toolbar.png) 0 -60px no-repeat; + text-indent: -9999px; + overflow: hidden; + width: 25px; + height: 25px; +} + +div#toolbar div.toolbar-menu span.toggle-active { + background-position: -25px -60px; +} + +div#toolbar div.toolbar-menu ul li a { + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + padding: 0 10px; +} + +div#toolbar div.toolbar-menu ul li a:hover { + background: #444; +} + +div#toolbar div.toolbar-menu ul li a.active:hover, +div#toolbar div.toolbar-menu ul li a.active { + text-shadow: #333 0 1px 0; + background: url(toolbar.png) 0 0 repeat-x; +} + +/** + * Administration shortcuts. + */ +div#toolbar div.toolbar-shortcuts { + position: relative; + padding: 0 10px; +} + +div#toolbar div.toolbar-shortcuts ul { + padding: 5px 0; + height: 40px; + line-height: 30px; + overflow: hidden; + float: left; +} + +div#toolbar div.toolbar-shortcuts ul li a { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + padding: 5px 10px 5px 5px; + margin-right: 5px; +} + +div#toolbar div.toolbar-shortcuts ul li a:hover { + background: #555; +} + +div#toolbar div.toolbar-shortcuts ul li a.active:hover, +div#toolbar div.toolbar-shortcuts ul li a.active { + background: url(toolbar.png) 0 -20px repeat-x; +} + +div#toolbar div.toolbar-shortcuts span.icon { + float: left; + background: #444; + width: 30px; + height: 30px; + margin-right: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; +} + +/** + * IE 6 Fixes. + * + * Since IE 6 has severe problems interpreting fixed positioning, we downgrade + * the behavior of the admin toolbar entirely to static positioning. + */ +* html body.toolbar, +* html body.toolbar-shortcuts { + padding-top: 0; +} + +* html div#toolbar { + position: static; +} + +* html div#toolbar div.shadow { + display: none; +} diff --git a/modules/toolbar/toolbar.info b/modules/toolbar/toolbar.info new file mode 100644 index 000000000..2e3fe6870 --- /dev/null +++ b/modules/toolbar/toolbar.info @@ -0,0 +1,8 @@ +; $Id$ +name = Toolbar +description = Toolbar exposing the top level administration menu items +core = 7.x +package = Core +version = VERSION +files[] = toolbar.install +files[] = toolbar.module diff --git a/modules/toolbar/toolbar.install b/modules/toolbar/toolbar.install new file mode 100644 index 000000000..25442eaeb --- /dev/null +++ b/modules/toolbar/toolbar.install @@ -0,0 +1,57 @@ +<?php +// $Id$ + +/** + * @file + * Installation functions for admin toolbar. + */ + +/** + * Implementation of hook_install(). + * + * @todo + * Implement role based shortcut bars. + */ +function toolbar_install() { + $t = get_t(); + $query = db_insert('menu_custom') + ->fields(array( + 'menu_name' => 'admin_shortcuts', + 'title' => $t('Administration shortcuts'), + 'description' => $t('The <em>Admininstration shortcuts</em> menu contains commonly used links for administrative tasks.') + )) + ->execute(); + + // Add starter convenience shortcuts. + menu_rebuild(); + $items = array( + 'node/add' => 'Add', + 'admin/content/node' => 'Find content', + 'admin' => 'Dashboard', + ); + $weight = -20; + foreach ($items as $path => $title) { + $link = array( + 'mlid' => 0, + 'link_title' => $title, + 'link_path' => $path, + 'router_path' => $path, + 'menu_name' => 'admin_shortcuts', + 'module' => 'menu', + 'weight' => $weight, + ); + + // Check for an existing menu item before attempting to create a new one. + $menu_link = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name", array( + ':path' => $link['link_path'], + ':menu_name' => $link['menu_name'] + )) + ->fetchField(); + if (!$menu_link) { + menu_link_save($link); + } + + // Increment weight so items can be displayed in desired order. + $weight++; + } +} diff --git a/modules/toolbar/toolbar.js b/modules/toolbar/toolbar.js new file mode 100644 index 000000000..7b804182f --- /dev/null +++ b/modules/toolbar/toolbar.js @@ -0,0 +1,89 @@ +// $Id$ +(function ($) { + +/** + * Implementation of Drupal.behaviors for admin. + */ +Drupal.behaviors.admin = { + attach: function() { + + // Set the intial state of the toolbar. + $('#toolbar:not(.processed)').each(function() { + Drupal.admin.toolbar.init(); + $(this).addClass('processed'); + }); + + // Toggling of admin shortcuts visibility. + $('#toolbar span.toggle:not(.processed)').each(function() { + $(this).click(function() { + Drupal.admin.toolbar.toggle(); + return false; + }); + $(this).addClass('processed'); + }); + } +}; + +/** + * Initialize cautiously to avoid collisions with other modules. + */ +Drupal.admin = Drupal.admin || {}; +Drupal.admin.toolbar = Drupal.admin.toolbar || {}; + +/** + * Retrieve last saved cookie settings and set up the initial toolbar state. + */ +Drupal.admin.toolbar.init = function() { + // Retrieve the collapsed status from a stored cookie. + var collapsed = $.cookie('Drupal.admin.toolbar.collapsed'); + + // Expand or collapse the toolbar based on the cookie value. + if (collapsed == 1) { + Drupal.admin.toolbar.collapse(); + } + else { + Drupal.admin.toolbar.expand(); + } +} + +/** + * Collapse the admin toolbar. + */ +Drupal.admin.toolbar.collapse = function() { + $('#toolbar div.toolbar-shortcuts').addClass('collapsed'); + $('#toolbar span.toggle').removeClass('toggle-active'); + $('body').removeClass('toolbar-shortcuts'); + $.cookie( + 'Drupal.admin.toolbar.collapsed', + 1, + {path: Drupal.settings.basePath} + ); +} + +/** + * Expand the admin toolbar. + */ +Drupal.admin.toolbar.expand = function() { + $('#toolbar div.toolbar-shortcuts').removeClass('collapsed'); + $('#toolbar span.toggle').addClass('toggle-active'); + $('body').addClass('toolbar-shortcuts'); + $.cookie( + 'Drupal.admin.toolbar.collapsed', + 0, + {path: Drupal.settings.basePath} + ); +} + +/** + * Toggle the admin toolbar. + */ +Drupal.admin.toolbar.toggle = function() { + if ($('#toolbar div.toolbar-shortcuts').is('.collapsed')) { + Drupal.admin.toolbar.expand(); + } + else { + Drupal.admin.toolbar.collapse(); + } +} + +})(jQuery); diff --git a/modules/toolbar/toolbar.module b/modules/toolbar/toolbar.module new file mode 100644 index 000000000..cf38e738b --- /dev/null +++ b/modules/toolbar/toolbar.module @@ -0,0 +1,186 @@ +<?php +// $Id$ + +/** + * @file + * Administration toolbar for quick access to top level administration items. + */ + +/** + * Implementation of hook_perm(). + */ +function toolbar_perm() { + return array( + 'access toolbar' => array( + 'title' => t('Access administration toolbar'), + 'description' => t('Access the persistent administration toolbar displayed on all pages.'), + ), + ); +} + +/** + * Implementation of hook_theme(). + */ +function toolbar_theme($existing, $type, $theme, $path) { + $items['toolbar'] = array( + 'arguments' => array('toolbar' => array()), + 'template' => 'toolbar', + 'path' => drupal_get_path('module', 'toolbar'), + ); + return $items; +} + +/** + * Implementation of hook_page_alter(). + * + * Add admin toolbar to the page_top region automatically. + */ +function toolbar_page_alter(&$page) { + if (user_access('access toolbar')) { + $page['page_top']['toolbar'] = toolbar_build(); + } +} + +/** + * Implementation of hook_preprocess_page(). + * + * Add some page classes, so global page theming can adjust to the toolbar. + */ +function toolbar_preprocess_page(&$vars) { + if (user_access('access toolbar')) { + $vars['classes_array'][] = 'toolbar'; + } +} + +/** + * Build the admin menu as a structured array ready for drupal_render(). + */ +function toolbar_build() { + global $user; + + $module_path = drupal_get_path('module', 'toolbar'); + $build = array( + '#theme' => 'toolbar', + '#attached_js' => array( + $module_path . '/toolbar.js', + array('data' => 'misc/jquery.cookie.js', 'weight' => JS_LIBRARY + 2), + ), + '#attached_css' => array( + $module_path . '/toolbar.css', + ), + ); + + // Retrieve the admin menu from the database. + $links = toolbar_menu_navigation_links(toolbar_get_menu_tree()); + $build['toolbar_menu'] = array( + '#theme' => 'links', + '#links' => $links, + '#attributes' => array('id' => 'toolbar-menu'), + ); + + // Add logout & user account links + $build['toolbar_user'] = array( + '#theme' => 'links', + '#links' => array( + 'account' => array( + 'title' => t('Hello <strong>@username</strong>', array('@username' => $user->name)), + 'href' => 'user', + 'html' => TRUE, + ), + 'logout' => array( + 'title' => t('Logout'), + 'href' => 'user/logout', + ), + ), + '#attributes' => array('id' => 'toolbar-user'), + ); + + // Add convenience shortcut links. + $shortcuts = menu_tree_all_data('admin_shortcuts'); + $shortcuts = toolbar_menu_navigation_links($shortcuts); + $build['toolbar_shortcuts'] = array( + '#theme' => 'links', + '#links' => $shortcuts, + '#attributes' => array('id' => 'toolbar-shortcuts'), + ); + + return $build; +} + +/** + * Get only the top level items below the 'admin' path. + */ +function toolbar_get_menu_tree() { + $tree = menu_tree_all_data('management'); + foreach ($tree as $item) { + if ($item['link']['link_path'] == 'admin' && !empty($item['below'])) { + // Only take items right below the 'admin' path. All other management + // items are discarded. + $tree = $item['below']; + break; + } + } + foreach ($tree as $key => $item) { + // Get rid of subitems to have a leaner data structure. + unset($tree[$key]['below']); + } + return $tree; +} + +/** + * Generate a links array from a menu tree array. + * + * Based on menu_navigation_links(). Adds in path based IDs, icon placeholders + * and overlay classes for the links. + */ +function toolbar_menu_navigation_links($tree) { + $links = array(); + foreach ($tree as $item) { + if (!$item['link']['hidden'] && $item['link']['access']) { + $class = ''; + // Make sure we have a path specific ID in place, so we can attach icons + // and behaviors to the items. + $id = str_replace(array('/', '<', '>'), array('-', '', ''), $item['link']['href']); + + $link = $item['link']['localized_options']; + $link['href'] = $item['link']['href']; + // Add icon placeholder. + $link['title'] = '<span class="icon"></span>' . $item['link']['title']; + // Add admin link ID and to-overlay class for the overlay. + $link['attributes'] = array('id' => 'toolbar-link-' . $id, 'class' => 'to-overlay'); + $link['html'] = TRUE; + + $class = ' path-' . $id; + if (toolbar_in_active_trail($item['link']['href'])) { + $class .= ' active-trail'; + } + $links['menu-' . $item['link']['mlid'] . $class] = $link; + } + } + return $links; +} + +/** + * Checks whether an item is in the active trail. + * + * Useful when using a menu generated by menu_tree_all_data() which does + * not set the 'in_active_trail' flag on items. + * + * @todo + * Look at migrating to a menu system level function. + */ +function toolbar_in_active_trail($path) { + $active_paths = &drupal_static(__FUNCTION__); + + // Gather active paths. + if (!isset($active_paths)) { + $active_paths = array(); + $trail = menu_get_active_trail(); + foreach ($trail as $item) { + if (!empty($item['href'])) { + $active_paths[] = $item['href']; + } + } + } + return in_array($path, $active_paths); +} diff --git a/modules/toolbar/toolbar.png b/modules/toolbar/toolbar.png Binary files differnew file mode 100644 index 000000000..652a6e56b --- /dev/null +++ b/modules/toolbar/toolbar.png diff --git a/modules/toolbar/toolbar.tpl.php b/modules/toolbar/toolbar.tpl.php new file mode 100644 index 000000000..f36273f50 --- /dev/null +++ b/modules/toolbar/toolbar.tpl.php @@ -0,0 +1,29 @@ +<?php +// $Id$ + +/** + * @file + * Default template for admin toolbar. + * + * Available variables: + * - $toolbar['toolbar_user']: User account / logout links. + * - $toolbar['toolbar_menu']: Top level management menu links. + * - $toolbar['toolbar_shortcuts']: Convenience shortcuts. + * + * @see template_preprocess() + * @see template_preprocess_admin_toolbar() + */ +?> +<div id="toolbar" class="clearfix"> + <div class="toolbar-menu clearfix"> + <span class="toggle toggle-active"><?php print t('Show shortcuts'); ?></span> + <?php print render($toolbar['toolbar_user']); ?> + <?php print render($toolbar['toolbar_menu']); ?> + </div> + + <div class="toolbar-shortcuts clearfix"> + <?php print render($toolbar['toolbar_shortcuts']); ?> + </div> + + <div class="shadow"></div> +</div> |