comparison sites/all/modules/ctools/includes/dropbutton.theme.inc @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ff03f76ab3fe
1 <?php
2
3 /**
4 * @file
5 * Provide a javascript based dropbutton menu.
6 *
7 * An example are the edit/disable/delete links on the views listing page.
8 *
9 * The dropbutton menu will show up as a button with a clickable twisty pointer
10 * to the right. When clicked the button will expand, showing the list of links.
11 *
12 * The dropbutton 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 twisty 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 dropbuttons can be placed per page.
19 *
20 * If only one link is passed to the theme function, the function will render
21 * a ctools-button with no twisty. The twisty is only rendered when 2 or more
22 * links are provided. The wrapping element will be classed with both
23 * ctools-button and ctools-dropbutton when a dropbutton is rendered.
24 *
25 * If the user does not have javascript enabled, the link will not appear,
26 * and instead by default the list of links will appear as a normal inline
27 * list.
28 *
29 * The menu is minimally styled by default, and to make it look different
30 * will require your own CSS. You can apply your own class to the
31 * dropbutton to help style it.
32 *
33 * The twisty is rendered as a border on a widthless and heightless element.
34 * There is no image for the twisty.
35 * The color of the twisty is the color of the link by default. To adjust the
36 * size of the twisty, adjust the border widths on .ctools-twisty. The adjust
37 * the color of the twisty, assign a new color to the .ctools-button class or
38 * assign a color to .ctools-twisty. You shouldn't need to adjust border-color.
39 *
40 * Use the theme() function to render dropbutton e.g.
41 * theme('links__ctools_dropbutton', array()) where array contains a renderable
42 * array of links.
43 */
44
45 /**
46 * Delegated implementation of hook_theme()
47 */
48 function ctools_dropbutton_theme(&$items) {
49 $items['links__ctools_dropbutton'] = array(
50 'variables' => array('title' => NULL, 'links' => NULL, 'image' => FALSE, 'class' => NULL),
51 'file' => 'includes/dropbutton.theme.inc',
52 );
53 }
54
55 /**
56 * Create a dropbutton menu.
57 *
58 * @param $title
59 * The text to place in the clickable area to activate the dropbutton. This
60 * text is indented to -9999px by default.
61 * @param $links
62 * A list of links to provide within the dropbutton, suitable for use
63 * in via Drupal's theme('links').
64 * @param $image
65 * If true, the dropbutton link is an image and will not get extra decorations
66 * that a text dropbutton link will.
67 * @param $class
68 * An optional class to add to the dropbutton's container div to allow you
69 * to style a single dropbutton however you like without interfering with
70 * other dropbuttons.
71 */
72 function theme_links__ctools_dropbutton($vars) {
73 // Check to see if the number of links is greater than 1;
74 // otherwise just treat this like a button.
75 if (!empty($vars['links'])) {
76 $is_drop_button = (count($vars['links']) > 1);
77
78 // Add needed files
79 if ($is_drop_button) {
80 ctools_add_js('dropbutton');
81 ctools_add_css('dropbutton');
82 }
83 ctools_add_css('button');
84
85 // Provide a unique identifier for every button on the page.
86 static $id = 0;
87 $id++;
88
89 // Wrapping div
90 $class = 'ctools-no-js';
91 $class .= ($is_drop_button) ? ' ctools-dropbutton' : '';
92 $class .= ' ctools-button';
93 if (!empty($vars['class'])) {
94 $class .= ($vars['class']) ? (' ' . implode(' ', $vars['class'])) : '';
95 }
96
97 $output = '';
98
99 $output .= '<div class="' . $class . '" id="ctools-button-' . $id . '">';
100
101 // Add a twisty if this is a dropbutton
102 if ($is_drop_button) {
103 $vars['title'] = ($vars['title'] ? check_plain($vars['title']) : t('open'));
104
105 $output .= '<div class="ctools-link">';
106 if ($vars['image']) {
107 $output .= '<a href="#" class="ctools-twisty ctools-image">' . $vars['title'] . '</a>';
108 }
109 else {
110 $output .= '<a href="#" class="ctools-twisty ctools-text">' . $vars['title'] . '</a>';
111 }
112 $output .= '</div>'; // ctools-link
113 }
114
115 // The button content
116 $output .= '<div class="ctools-content">';
117
118 // Check for attributes. theme_links expects an array().
119 $vars['attributes'] = (!empty($vars['attributes'])) ? $vars['attributes'] : array();
120
121 // Remove the inline and links classes from links if they exist.
122 // These classes are added and styled by Drupal core and mess up the default
123 // styling of any link list.
124 if (!empty($vars['attributes']['class'])) {
125 $classes = $vars['attributes']['class'];
126 foreach ($classes as $key => $class) {
127 if ($class === 'inline' || $class === 'links') {
128 unset($vars['attributes']['class'][$key]);
129 }
130 }
131 }
132
133 // Call theme_links to render the list of links.
134 $output .= theme_links(array('links' => $vars['links'], 'attributes' => $vars['attributes'], 'heading' => ''));
135 $output .= '</div>'; // ctools-content
136 $output .= '</div>'; // ctools-dropbutton
137 return $output;
138 }
139 else {
140 return '';
141 }
142 }
143