danielebarchiesi@0: .5 seconds, or can be immediately closed by danielebarchiesi@0: * clicking the twisty again. The code is smart enough that if the mouse danielebarchiesi@0: * moves away and then back within the .5 second window, it will not danielebarchiesi@0: * re-close. danielebarchiesi@0: * danielebarchiesi@0: * Multiple dropbuttons can be placed per page. danielebarchiesi@0: * danielebarchiesi@0: * If only one link is passed to the theme function, the function will render danielebarchiesi@0: * a ctools-button with no twisty. The twisty is only rendered when 2 or more danielebarchiesi@0: * links are provided. The wrapping element will be classed with both danielebarchiesi@0: * ctools-button and ctools-dropbutton when a dropbutton is rendered. danielebarchiesi@0: * danielebarchiesi@0: * If the user does not have javascript enabled, the link will not appear, danielebarchiesi@0: * and instead by default the list of links will appear as a normal inline danielebarchiesi@0: * list. danielebarchiesi@0: * danielebarchiesi@0: * The menu is minimally styled by default, and to make it look different danielebarchiesi@0: * will require your own CSS. You can apply your own class to the danielebarchiesi@0: * dropbutton to help style it. danielebarchiesi@0: * danielebarchiesi@0: * The twisty is rendered as a border on a widthless and heightless element. danielebarchiesi@0: * There is no image for the twisty. danielebarchiesi@0: * The color of the twisty is the color of the link by default. To adjust the danielebarchiesi@0: * size of the twisty, adjust the border widths on .ctools-twisty. The adjust danielebarchiesi@0: * the color of the twisty, assign a new color to the .ctools-button class or danielebarchiesi@0: * assign a color to .ctools-twisty. You shouldn't need to adjust border-color. danielebarchiesi@0: * danielebarchiesi@0: * Use the theme() function to render dropbutton e.g. danielebarchiesi@0: * theme('links__ctools_dropbutton', array()) where array contains a renderable danielebarchiesi@0: * array of links. danielebarchiesi@0: */ danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Delegated implementation of hook_theme() danielebarchiesi@0: */ danielebarchiesi@0: function ctools_dropbutton_theme(&$items) { danielebarchiesi@0: $items['links__ctools_dropbutton'] = array( danielebarchiesi@0: 'variables' => array('title' => NULL, 'links' => NULL, 'image' => FALSE, 'class' => NULL), danielebarchiesi@0: 'file' => 'includes/dropbutton.theme.inc', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Create a dropbutton menu. danielebarchiesi@0: * danielebarchiesi@0: * @param $title danielebarchiesi@0: * The text to place in the clickable area to activate the dropbutton. This danielebarchiesi@0: * text is indented to -9999px by default. danielebarchiesi@0: * @param $links danielebarchiesi@0: * A list of links to provide within the dropbutton, suitable for use danielebarchiesi@0: * in via Drupal's theme('links'). danielebarchiesi@0: * @param $image danielebarchiesi@0: * If true, the dropbutton link is an image and will not get extra decorations danielebarchiesi@0: * that a text dropbutton link will. danielebarchiesi@0: * @param $class danielebarchiesi@0: * An optional class to add to the dropbutton's container div to allow you danielebarchiesi@0: * to style a single dropbutton however you like without interfering with danielebarchiesi@0: * other dropbuttons. danielebarchiesi@0: */ danielebarchiesi@0: function theme_links__ctools_dropbutton($vars) { danielebarchiesi@0: // Check to see if the number of links is greater than 1; danielebarchiesi@0: // otherwise just treat this like a button. danielebarchiesi@0: if (!empty($vars['links'])) { danielebarchiesi@0: $is_drop_button = (count($vars['links']) > 1); danielebarchiesi@0: danielebarchiesi@0: // Add needed files danielebarchiesi@0: if ($is_drop_button) { danielebarchiesi@0: ctools_add_js('dropbutton'); danielebarchiesi@0: ctools_add_css('dropbutton'); danielebarchiesi@0: } danielebarchiesi@0: ctools_add_css('button'); danielebarchiesi@0: danielebarchiesi@0: // Provide a unique identifier for every button on the page. danielebarchiesi@0: static $id = 0; danielebarchiesi@0: $id++; danielebarchiesi@0: danielebarchiesi@0: // Wrapping div danielebarchiesi@0: $class = 'ctools-no-js'; danielebarchiesi@0: $class .= ($is_drop_button) ? ' ctools-dropbutton' : ''; danielebarchiesi@0: $class .= ' ctools-button'; danielebarchiesi@0: if (!empty($vars['class'])) { danielebarchiesi@0: $class .= ($vars['class']) ? (' ' . implode(' ', $vars['class'])) : ''; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $output = ''; danielebarchiesi@0: danielebarchiesi@0: $output .= '
'; danielebarchiesi@0: danielebarchiesi@0: // Add a twisty if this is a dropbutton danielebarchiesi@0: if ($is_drop_button) { danielebarchiesi@0: $vars['title'] = ($vars['title'] ? check_plain($vars['title']) : t('open')); danielebarchiesi@0: danielebarchiesi@0: $output .= ''; // ctools-link danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // The button content danielebarchiesi@0: $output .= '
'; danielebarchiesi@0: danielebarchiesi@0: // Check for attributes. theme_links expects an array(). danielebarchiesi@0: $vars['attributes'] = (!empty($vars['attributes'])) ? $vars['attributes'] : array(); danielebarchiesi@0: danielebarchiesi@0: // Remove the inline and links classes from links if they exist. danielebarchiesi@0: // These classes are added and styled by Drupal core and mess up the default danielebarchiesi@0: // styling of any link list. danielebarchiesi@0: if (!empty($vars['attributes']['class'])) { danielebarchiesi@0: $classes = $vars['attributes']['class']; danielebarchiesi@0: foreach ($classes as $key => $class) { danielebarchiesi@0: if ($class === 'inline' || $class === 'links') { danielebarchiesi@0: unset($vars['attributes']['class'][$key]); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Call theme_links to render the list of links. danielebarchiesi@0: $output .= theme_links(array('links' => $vars['links'], 'attributes' => $vars['attributes'], 'heading' => '')); danielebarchiesi@0: $output .= '
'; // ctools-content danielebarchiesi@0: $output .= '
'; // ctools-dropbutton danielebarchiesi@0: return $output; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: return ''; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: