diff --git a/toolbar_prototype.info b/toolbar_prototype.info index abd3de5..3f0a9c6 100644 --- a/toolbar_prototype.info +++ b/toolbar_prototype.info @@ -1,4 +1,3 @@ -name = Drupal Gardens toolbar prototype -description = Reorganizes the toolbar and adds collapsible menus +name = Toolbar prototype +description = Reorganizes the toolbar and adds collapsible menus. core = 7.x -files[] = toolbar_prototype.module diff --git a/toolbar_prototype.js b/toolbar_prototype.js index 39eb3e4..c730c33 100644 --- a/toolbar_prototype.js +++ b/toolbar_prototype.js @@ -1,4 +1,3 @@ - (function ($) { Drupal.toolbar_prototype = Drupal.toolbar_prototype || {}; @@ -7,39 +6,39 @@ Drupal.toolbar_prototype = Drupal.toolbar_prototype || {}; * Attach toggling behavior and notify the overlay of the toolbar. */ Drupal.behaviors.toolbar_prototype = { - attach: function(context) { + attach: function (context) { var $drawer_links = $('#toolbar .drawer-links a:not(#toolbar-link-admin-appearance)', context) $('#toolbar .toolbar-menu li').bind('mouseenter', Drupal.toolbar_prototype.drawer_toggle); - + Drupal.toolbar_prototype.path = $('#toolbar .active'); Drupal.toolbar_prototype.original = Drupal.settings.toolbar.tooltips.default; $(window).bind('hashchange.drupal-overlay', Drupal.toolbar_prototype.activeTrail); $(document).bind('drupalOverlayLoad', Drupal.toolbar_prototype.activeTrail); $(document).bind('drupalOverlayClose', Drupal.toolbar_prototype.drawer_close); - + $('#toolbar li').bind('mouseenter', Drupal.toolbar_prototype.tooltipShow); $('#toolbar').bind('mouseleave', Drupal.toolbar_prototype.tooltipHide); $('#toolbar').bind('mouseleave', Drupal.toolbar_prototype.drawer_close); $('#tooltip .toolbar-menu li').bind('mouseleave', Drupal.toolbar_prototype.tooltipHide); - + } }; Drupal.toolbar_prototype.drawer_toggle = function (event) { event.preventDefault(); event.stopPropagation(); - + var $this = $(this).children('a:first'); var $drawer = $('#' + $this.attr('drawer')); - + if (!$drawer.length) { // Let normal interaction proceed Drupal.toolbar_prototype.drawer_close(); $(this).addClass('active').blur(); return; } - + if ($drawer.hasClass('active-path') && $this.hasClass('active-path')) { Drupal.toolbar_prototype.drawer_close(); Drupal.toolbar_prototype.path.addClass('active'); @@ -53,7 +52,7 @@ Drupal.toolbar_prototype.drawer_toggle = function (event) { $drawer.parentsUntil('#toolbar').addClass('active-path'); $('body').css('paddingTop', Drupal.toolbar.height()); } - + Drupal.overlay.eventhandlerAlterDisplacedElements(); }; @@ -87,11 +86,11 @@ Drupal.toolbar_prototype.tooltipShow = function (event) { if (event.type == 'mouseenter' && Drupal.settings.toolbar.tooltips[index] != '') { text = Drupal.settings.toolbar.tooltips[index] } - + if (!$('.toolbar-drawer').hasClass('active') && event.type == 'mouseleave') { Drupal.toolbar_prototype.tooltipHide(); } - + $('.toolbar-tooltips').html(text); $('.toolbar-tooltips').show(500); }; diff --git a/toolbar_prototype.module b/toolbar_prototype.module index ee54039..ae90d60 100644 --- a/toolbar_prototype.module +++ b/toolbar_prototype.module @@ -1,5 +1,13 @@ 'element', @@ -7,6 +15,9 @@ function toolbar_prototype_theme($existing, $type, $theme, $path) { return $items; } +/** + * Implements hook_theme_registry_alter(). + */ function toolbar_prototype_theme_registry_alter(&$theme_registry) { if (isset($theme_registry['toolbar'])) { $theme_registry['toolbar']['template'] = 'toolbar_prototype'; @@ -14,6 +25,9 @@ function toolbar_prototype_theme_registry_alter(&$theme_registry) { } } +/** + * Implements hook_module_implements_alter(). + */ function toolbar_prototype_module_implements_alter(&$implementations, $hook) { if ($hook == 'page_alter') { $group = $implementations['toolbar_prototype']; @@ -22,10 +36,16 @@ function toolbar_prototype_module_implements_alter(&$implementations, $hook) { } } +/** + * Implements hook_page_alter(). + */ function toolbar_prototype_page_alter(&$page) { $page['page_top']['toolbar']['#pre_render'] = array('toolbar_prototype_pre_render'); } +/** + * #pre_render callback: @todo. + */ function toolbar_prototype_pre_render($toolbar) { $toolbar = array_merge($toolbar, toolbar_prototype_view()); $toolbar['toolbar_drawer'] = array_merge($toolbar['toolbar_drawer'], toolbar_prototype_fill_drawer()); @@ -34,11 +54,17 @@ function toolbar_prototype_pre_render($toolbar) { return $toolbar; } +/** + * @todo. + * + * @return array + * @todo. + */ function toolbar_prototype_view() { global $user; $trails = array(); - foreach(menu_get_active_trail() as $trail) { + foreach (menu_get_active_trail() as $trail) { $trails[] = $trail['href']; } @@ -223,10 +249,16 @@ function toolbar_prototype_view() { return $build; } +/** + * @todo. + * + * @return array + * @todo. + */ function toolbar_prototype_fill_drawer() { $drawer = array(); - // Created the content drawer + // Created the content drawer. $item = menu_get_item('node/add'); $content = system_admin_menu_block($item); $drawer['content-drawer'] = array( @@ -237,10 +269,10 @@ function toolbar_prototype_fill_drawer() { 'node/add', ), ); - $drawer['content-drawer']['add'] = array( + $drawer['content-drawer']['add'] = array( '#theme' => 'links', '#links' => $content, - '#attributes' => array('class' => 'toolbar-add'), + '#attributes' => array('class' => array('toolbar-add')), ); $drawer['content-drawer']['list'] = array( @@ -250,7 +282,7 @@ function toolbar_prototype_fill_drawer() { 'comments' => menu_get_item('admin/content/comment'), 'media' => menu_get_item('admin/content/media'), ), - '#attributes' => array('class' => 'toolbar-list'), + '#attributes' => array('class' => array('toolbar-list')), ); // Create the people drawer @@ -269,7 +301,7 @@ function toolbar_prototype_fill_drawer() { '#links' => array( 'people' => menu_get_item($add_user_path), ), - '#attributes' => array('class' => 'toolbar-add'), + '#attributes' => array('class' => array('toolbar-add')), ); $drawer['people-drawer']['permissions'] = array( '#theme' => 'links', @@ -277,14 +309,14 @@ function toolbar_prototype_fill_drawer() { 'permissions' => menu_get_item('admin/people/permissions'), 'roles' => menu_get_item('admin/people/permissions/roles'), ), - '#attributes' => array('class' => 'toolbar-gear'), + '#attributes' => array('class' => array('toolbar-gear')), ); $drawer['people-drawer']['list'] = array( '#theme' => 'links', '#links' => array( 'people' => menu_get_item('admin/people'), ), - '#attributes' => array('class' => 'toolbar-list'), + '#attributes' => array('class' => array('toolbar-list')), ); // Create the site drawer @@ -295,7 +327,7 @@ function toolbar_prototype_fill_drawer() { 'structure' => array( '#theme' => 'links', '#links' => $content, - '#attributes' => array('class' => 'toolbar-gear'), + '#attributes' => array('class' => array('toolbar-gear')), ), 'modules' => array( '#theme' => 'links', @@ -317,7 +349,7 @@ function toolbar_prototype_fill_drawer() { '#links' => array( 'reports' => menu_get_item('admin/reports'), ), - '#attributes' => array('class' => 'toolbar-graph'), + '#attributes' => array('class' => array('toolbar-graph')), ), '#theme' => 'toolbar_prototype_drawer_section', '#attributes' => array('id' => 'site-drawer'), @@ -330,7 +362,7 @@ function toolbar_prototype_fill_drawer() { ); $trails = array(); - foreach(menu_get_active_trail() as $trail) { + foreach (menu_get_active_trail() as $trail) { $trails[] = $trail['href']; } @@ -340,8 +372,8 @@ function toolbar_prototype_fill_drawer() { 'clearfix', ); - foreach($drawer as $key => $drawer_section) { - foreach($drawer_section['#paths'] as $path) { + foreach ($drawer as $key => $drawer_section) { + foreach ($drawer_section['#paths'] as $path) { if (in_array($path, $trails)) { $drawer[$key]['#attributes']['class'][] = 'active'; $toolbar_drawer_classes[] = 'active'; @@ -354,15 +386,33 @@ function toolbar_prototype_fill_drawer() { return $drawer; } -function theme_toolbar_prototype_drawer_section($vars) { - $element = $vars['element']; - $classes = isset($element['#attributes']['class']) ? 'drawer ' . implode(' ', $element['#attributes']['class']) : 'drawer'; - $output = '
'; +/** + * Returns HTML for the section of a toolbar drawer. + * + * @param array $variables + * An associative array containing: + * - element: The render element. + * + * @ingroup themeable + */ +function theme_toolbar_prototype_drawer_section($variables) { + $element = $variables['element']; + $element['#attributes']['class'][] = 'drawer'; + $output = ''; $output .= drupal_render_children($element); $output .= '
'; return $output; } +/** + * @todo. + * + * @param array $toolbar + * @todo. + * + * @return bool + * @todo. + */ function toolbar_prototype_tooltips($toolbar) { $tooltips = array('default' => t('This is your administrative toolbar')); toolbar_prototype_gather_tooltips($toolbar, $tooltips); @@ -372,11 +422,19 @@ function toolbar_prototype_tooltips($toolbar) { return TRUE; } +/** + * @todo. + * + * @param array $parent + * @todo. + * @param array $settings + * @todo. + */ function toolbar_prototype_gather_tooltips($parent, &$settings) { $tooltips = array(); - foreach(element_children($parent) as $child_key) { + foreach (element_children($parent) as $child_key) { if (isset($parent[$child_key]['#links'])) { - foreach($parent[$child_key]['#links'] as $key => $link) { + foreach ($parent[$child_key]['#links'] as $key => $link) { $path = isset($link['path']) ? url($link['path']) : 'href' . url($link['href']); $settings[$path] = $link['description']; } diff --git a/toolbar_prototype.tpl.php b/toolbar_prototype.tpl.php index 9aeb66a..50577ab 100644 --- a/toolbar_prototype.tpl.php +++ b/toolbar_prototype.tpl.php @@ -1,5 +1,4 @@ - +
- +
- +