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 $title
|
48
|
* The text to place in the clickable area to activate the dropdown.
|
49
|
* @param $links
|
50
|
* A list of links to provide within the dropdown, suitable for use
|
51
|
* in via Drupal's theme('links').
|
52
|
* @param $image
|
53
|
* If true, the dropdown link is an image and will not get extra decorations
|
54
|
* that a text dropdown link will.
|
55
|
* @param $class
|
56
|
* An optional class to add to the dropdown's container div to allow you
|
57
|
* to style a single dropdown however you like without interfering with
|
58
|
* other dropdowns.
|
59
|
*/
|
60
|
function theme_ctools_dropdown($vars) {
|
61
|
// Provide a unique identifier for every dropdown on the page.
|
62
|
static $id = 0;
|
63
|
$id++;
|
64
|
|
65
|
$class = 'ctools-dropdown-no-js ctools-dropdown' . ($vars['class'] ? (' ' . $vars['class']) : '');
|
66
|
|
67
|
ctools_add_js('dropdown');
|
68
|
ctools_add_css('dropdown');
|
69
|
|
70
|
$output = '';
|
71
|
|
72
|
$output .= '<div class="' . $class . '" id="ctools-dropdown-' . $id . '">';
|
73
|
$output .= '<div class="ctools-dropdown-link-wrapper">';
|
74
|
if ($vars['image']) {
|
75
|
$output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-image-link">' . $vars['title'] . '</a>';
|
76
|
}
|
77
|
else {
|
78
|
$output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-text-link">' . check_plain($vars['title']) . '</a>';
|
79
|
}
|
80
|
|
81
|
$output .= '</div>'; // wrapper
|
82
|
$output .= '<div class="ctools-dropdown-container-wrapper">';
|
83
|
$output .= '<div class="ctools-dropdown-container">';
|
84
|
$output .= theme_links(array('links' => $vars['links'], 'attributes' => array(), 'heading' => ''));
|
85
|
$output .= '</div>'; // container
|
86
|
$output .= '</div>'; // container wrapper
|
87
|
$output .= '</div>'; // dropdown
|
88
|
return $output;
|
89
|
}
|
90
|
|