Projet

Général

Profil

Paste
Télécharger (3,13 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / includes / dropdown.theme.inc @ c304a780

1
<?php
2

    
3
/**
4
 * @file
5
 * Provide a javascript based dropdown menu.
6
 *
7
 * An example are the dropdown settings in the panels ui, like for adding
8
 * new panes.
9
 *
10
 * The dropdown menu will show up as a clickable link; when clicked,
11
 * a small menu will slide down beneath it, showing the list of links.
12
 *
13
 * The dropdown will stay open until either the user has moved the mouse
14
 * away from the box for > .5 seconds, or can be immediately closed by
15
 * clicking the link again. The code is smart enough that if the mouse
16
 * moves away and then back within the .5 second window, it will not
17
 * re-close.
18
 *
19
 * Multiple dropdowns can be placed per page.
20
 *
21
 * If the user does not have javascript enabled, the link will not appear,
22
 * and instead by default the list of links will appear as a normal inline
23
 * list.
24
 *
25
 * The menu is heavily styled by default, and to make it look different
26
 * will require a little bit of CSS. You can apply your own class to the
27
 * dropdown to help ensure that your CSS can override the dropdown's CSS.
28
 *
29
 * In particular, the text, link, background and border colors may need to
30
 * be changed. Please see dropdown.css for information about the existing
31
 * styling.
32
 */
33

    
34
/**
35
 * Delegated implementation of hook_theme()
36
 */
37
function ctools_dropdown_theme(&$items) {
38
  $items['ctools_dropdown'] = array(
39
    'variables' => array('title' => NULL, 'links' => NULL, 'image' => FALSE, 'class' => ''),
40
    'file' => 'includes/dropdown.theme.inc',
41
  );
42
}
43

    
44
/**
45
 * Create a dropdown menu.
46
 *
47
 * @param array $variables
48
 *   An associative array containing:
49
 *   - title: The text to place in the clickable area to activate the dropdown.
50
 *   - links: A list of links to provide within the dropdown, suitable for use
51
 *     in via Drupal's theme('links').
52
 *   - image: If true, the dropdown link is an image and will not get extra
53
 *     decorations that a text dropdown link will.
54
 *   - class: An optional class to add to the dropdown's container div to allow
55
 *     you to style a single dropdown however you like without interfering with
56
 *     other dropdowns.
57
 *
58
 * @return string
59
 *   Returns HTML for a language configuration form.
60
 */
61
function theme_ctools_dropdown($vars) {
62
  // Provide a unique identifier for every dropdown on the page.
63
  static $id = 0;
64
  $id++;
65

    
66
  $class = 'ctools-dropdown-no-js ctools-dropdown' . ($vars['class'] ? (' ' . $vars['class']) : '');
67

    
68
  ctools_add_js('dropdown');
69
  ctools_add_css('dropdown');
70

    
71
  $output = '<div class="' . $class . '" id="ctools-dropdown-' . $id . '">';
72
  $output .= '<div class="ctools-dropdown-link-wrapper">';
73
  if ($vars['image']) {
74
    $output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-image-link">' . $vars['title'] . '</a>';
75
  }
76
  else {
77
    $output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-text-link">' . check_plain($vars['title']) . '</a>';
78
  }
79
  $output .= '</div>';
80
  $output .= '<div class="ctools-dropdown-container-wrapper">';
81
  $output .= '<div class="ctools-dropdown-container">';
82
  $output .= theme_links(array('links' => $vars['links'], 'attributes' => array(), 'heading' => ''));
83
  $output .= '</div>';
84
  $output .= '</div>';
85
  $output .= '</div>';
86

    
87
  return $output;
88
}