2

Is it possible to use a javascript function for a link in Drupal? I would like to make an option to show/hide the administration menu when clicked on the Drupal icon. Something simple like this:

  $links['icon'] = array(
    '#title' => theme('admin_menu_icon'),
    '#attributes' => array('class' => array('admin-menu-icon')),
    '#href' => 'javascript: alert("ok")', 
    '#options' => array(
      'html' => TRUE,
    ),
2

Very simple... Just found it myself :)

'#attributes' => array('onmousedown' => array('alert("ok")')),
0

I quickly made a small module to show/hide the administration module when clicking on the Drupal icon. Sometimes the menu bar is just anoying me ;)

function mymodule_init() {
    drupal_add_css(drupal_get_path('module', 'mymodule') . '/css/adminmenu.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));
}

function mymodule_theme_registry_alter(&$theme_registry) {
    if (!empty($theme_registry['admin_menu_icon'])) {
        $theme_registry['admin_menu_icon']['function'] = 'mymodule_admin_menu_icon';
    }
}

function mymodule_admin_menu_icon($variables) {
  return '<img onmousedown="jQuery(\'#admin-menu\').toggleClass(\'collapsed\')" class="admin-menu-icon" src="' . $variables['src'] . '" width="16" height="16" title="Show / Hide" alt="Show / Hide" />';
}

And the CSS part:

#admin-menu.collapsed {
    position: fixed;
    width: 20px;
    height: 20px;
    overflow: hidden;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.