dropdown.theme.inc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @file
  4. * Provide a javascript based dropdown menu.
  5. *
  6. * An example are the dropdown settings in the panels ui, like for adding
  7. * new panes.
  8. *
  9. * The dropdown menu will show up as a clickable link; when clicked,
  10. * a small menu will slide down beneath it, showing the list of links.
  11. *
  12. * The dropdown will stay open until either the user has moved the mouse
  13. * away from the box for > .5 seconds, or can be immediately closed by
  14. * clicking the link again. The code is smart enough that if the mouse
  15. * moves away and then back within the .5 second window, it will not
  16. * re-close.
  17. *
  18. * Multiple dropdowns can be placed per page.
  19. *
  20. * If the user does not have javascript enabled, the link will not appear,
  21. * and instead by default the list of links will appear as a normal inline
  22. * list.
  23. *
  24. * The menu is heavily styled by default, and to make it look different
  25. * will require a little bit of CSS. You can apply your own class to the
  26. * dropdown to help ensure that your CSS can override the dropdown's CSS.
  27. *
  28. * In particular, the text, link, background and border colors may need to
  29. * be changed. Please see dropdown.css for information about the existing
  30. * styling.
  31. */
  32. /**
  33. * Delegated implementation of hook_theme()
  34. */
  35. function ctools_dropdown_theme(&$items) {
  36. $items['ctools_dropdown'] = array(
  37. 'variables' => array('title' => NULL, 'links' => NULL, 'image' => FALSE, 'class' => ''),
  38. 'file' => 'includes/dropdown.theme.inc',
  39. );
  40. }
  41. /**
  42. * Create a dropdown menu.
  43. *
  44. * @param array $variables
  45. * An associative array containing:
  46. * - title: The text to place in the clickable area to activate the dropdown.
  47. * - links: A list of links to provide within the dropdown, suitable for use
  48. * in via Drupal's theme('links').
  49. * - image: If true, the dropdown link is an image and will not get extra
  50. * decorations that a text dropdown link will.
  51. * - class: An optional class to add to the dropdown's container div to allow
  52. * you to style a single dropdown however you like without interfering with
  53. * other dropdowns.
  54. *
  55. * @return string
  56. * Returns HTML for a language configuration form.
  57. */
  58. function theme_ctools_dropdown($vars) {
  59. // Provide a unique identifier for every dropdown on the page.
  60. static $id = 0;
  61. $id++;
  62. $class = 'ctools-dropdown-no-js ctools-dropdown' . ($vars['class'] ? (' ' . $vars['class']) : '');
  63. ctools_add_js('dropdown');
  64. ctools_add_css('dropdown');
  65. $output = '<div class="' . $class . '" id="ctools-dropdown-' . $id . '">';
  66. $output .= '<div class="ctools-dropdown-link-wrapper">';
  67. if ($vars['image']) {
  68. $output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-image-link">' . $vars['title'] . '</a>';
  69. }
  70. else {
  71. $output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-text-link">' . check_plain($vars['title']) . '</a>';
  72. }
  73. $output .= '</div>';
  74. $output .= '<div class="ctools-dropdown-container-wrapper">';
  75. $output .= '<div class="ctools-dropdown-container">';
  76. $output .= theme_links(array('links' => $vars['links'], 'attributes' => array(), 'heading' => ''));
  77. $output .= '</div>';
  78. $output .= '</div>';
  79. $output .= '</div>';
  80. return $output;
  81. }