highlightAccessKey() public static method

Highlights an access key in a label.
public static highlightAccessKey ( string $label, string $accessKey ) : string
$label string The label to highlight the access key in.
$accessKey string The access key to highlight.
return string The HTML version of the label with the access key highlighted.
Esempio n. 1
0
 /**
  * Renders the tabs.
  *
  * @param string $active_tab  If specified, the name of the active tab. If
  *                            not, the active tab is determined
  *                            automatically.
  * @param string $class       The CSS class of the tabset.
  */
 public function render($active_tab = null, $class = 'tabset')
 {
     $html = "<div class=\"{$class}\"><ul>\n";
     $active = $_SERVER['PHP_SELF'] . $this->_vars->get($this->_name);
     foreach ($this->_tabs as $tab) {
         $link = $this->_addPreserved($tab['link']);
         if (!is_null($this->_name) && !is_null($tab['tabname'])) {
             $link->add($this->_name, $tab['tabname']);
         }
         $classes = array();
         if (isset($tab['class'])) {
             $classes[] = $tab['class'];
         }
         if (!is_null($active_tab) && (string) $active_tab == (string) $tab['tabname'] || $active == $tab['link'] . $tab['tabname']) {
             $classes[] = 'horde-active';
         }
         $class = $classes ? ' class="' . implode(' ', $classes) . '"' : '';
         $id = '';
         if (!empty($tab['id'])) {
             $id = ' id="' . htmlspecialchars($tab['id']) . '"';
         }
         if (!isset($tab['target'])) {
             $tab['target'] = '';
         }
         if (!isset($tab['onclick'])) {
             $tab['onclick'] = '';
         }
         $accesskey = Horde::getAccessKey($tab['title']);
         if (!empty($tab['img'])) {
             $img = Horde_Themes_Image::tag($tab['img']);
         } else {
             $img = '';
         }
         $html .= '<li' . $class . $id . '>' . $link->link(array('target' => $tab['target'], 'onclick' => $tab['onclick'], 'accesskey' => $accesskey)) . $img . Horde::highlightAccessKey(str_replace(' ', '&nbsp;', $tab['title']), $accesskey) . "</a> </li>\n";
     }
     return $html . "</ul></div><br class=\"clear\" />\n";
 }
Esempio n. 2
0
 /**
  * Adds a row to the sidebar.
  *
  * If containers/sections are not added explicitly to the view
  * through the "containers" property, these rows will be used
  * instead.
  *
  * @param array $row         A hash with the row information. Possible
  *                           values:
  *   - label: (string) The row text.
  *   - selected: (boolean) Whether to mark the row as active.
  *   - style: (string) Additional CSS styles to apply to the row.
  *   - url (string) URL to link the row to.
  *   - type (string, optional) The row type, defaults to "tree". Further
  *     $row properties depending on the type:
  *     - tree:
  *       - cssClass: (string) CSS class for the icon.
  *       - id: (string) DOM ID for the row link.
  *     - checkbox:
  *     - radiobox:
  *       - color: (string, optional) Background color.
  *       - edit: (string, optional) URL for extra edit icon.
  * @param string $container  If using multiple sidebar sections, the ID of
  *                           the section to add the row to. Sections will
  *                           be rendered in the order of their first usage.
  */
 public function addRow(array $row, $container = '')
 {
     if (!isset($this->containers[$container])) {
         $this->containers[$container] = array('rows' => array());
         if ($container) {
             $this->containers[$container]['id'] = $container;
         }
     }
     $boxrow = isset($row['type']) && ($row['type'] == 'checkbox' || $row['type'] == 'radiobox');
     $label = htmlspecialchars($row['label']);
     if (isset($row['url'])) {
         $url = empty($row['url']) ? new Horde_Url() : $row['url'];
         if ($boxrow) {
             $attributes = array();
         } else {
             $ak = Horde::getAccessKey($label);
             $attributes = $ak ? array('accesskey' => $ak) : array();
         }
         foreach (array('onclick', 'target', 'class') as $attribute) {
             if (!empty($row[$attribute])) {
                 $attributes[$attribute] = $row[$attribute];
             }
         }
         if ($boxrow) {
             $class = 'horde-resource-' . (empty($row['selected']) ? 'off' : 'on');
             if ($row['type'] == 'radiobox') {
                 $class .= ' horde-radiobox';
             }
             if (empty($attributes['class'])) {
                 $attributes['class'] = $class;
             } else {
                 $attributes['class'] .= ' ' . $class;
             }
             $row['link'] = $url->link($attributes) . $label . '</a>';
         } else {
             $row['link'] = $url->link($attributes) . Horde::highlightAccessKey($label, $ak) . '</a>';
         }
     } else {
         $row['link'] = '<span class="horde-resource-none">' . $label . '</span>';
     }
     if ($boxrow) {
         $this->containers[$container]['type'] = $row['type'];
         if (!isset($row['style'])) {
             $row['style'] = '';
         }
         if (!isset($row['color'])) {
             $row['color'] = '#dddddd';
         }
         $foreground = '000';
         if (Horde_Image::brightness($row['color']) < 128) {
             $foreground = 'fff';
         }
         if (strlen($row['style'])) {
             $row['style'] .= ';';
         }
         $row['style'] .= 'background-color:' . $row['color'] . ';color:#' . $foreground;
         if (isset($row['edit'])) {
             $row['editLink'] = $row['edit']->link(array('title' => _("Edit"), 'class' => 'horde-resource-edit-' . $foreground)) . '&#9658;' . '</a>';
         }
     }
     $this->containers[$container]['rows'][] = $row;
 }
Esempio n. 3
0
 /**
  * Returns a label element including an access key for usage in conjuction
  * with a form field. User preferences regarding access keys are respected.
  *
  * @param string $for    The form field's id attribute.
  * @param string $label  The label text.
  * @param string $ak     The access key to use. If null a new access key
  *                       will be generated.
  *
  * @return string  The html code for the label element.
  */
 function label($for, $label, $ak = null)
 {
     if ($ak === null) {
         $ak = Horde::getAccessKey($label, 1);
     }
     $label = Horde::highlightAccessKey($label, $ak);
     return sprintf('<label for="%s"%s>%s</label>', $for, !empty($ak) ? ' accesskey="' . $ak . '"' : '', $label);
 }