Alternative javascript/jQuery snippet

markus_petrux - October 21, 2007 - 09:03
Project:Administration Menu Dropdown
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,

I have created an alternative version of the javascript used by this awesome module that I thought it would be nice to share.

It uses jQuery to collapse/expand the admin menu on mouse over/out. When the menu is "collapsed", only the icon on the left is visible, mouseovering the icon expands de whole menu using jQuery animation. The display state of the icon itself can still be toggled with the keyboard, though this version needs to press ctrl+alt+shift at a time, so it doesn't conflict (or it is at least a bit more difficult to) with other "hotkeys" that one can have installed on the browser.

By default, only the icon is displayed. And that's it. I hope that some out there might find it useful. It's been a good excuse for me to learn how jQuery works.

Cheers

AttachmentSize
admin_menu_dropdown.js_.txt1.93 KB

#1

Shawn Conn - November 20, 2007 - 15:43
Status:active» closed

That's pretty slick. When I initially played around with doing this module my first attempt was something similar like this. I decided on keeping the entire menu hidden to keep things a minimal as possible. This will help for those that would prefer to just use a mouse. Thanks for contrib!

#2

markus_petrux - June 12, 2008 - 11:22

Hi,

Here's another version which is compatible with recent version of admin_menu D6.

if (Drupal.jsEnabled) {
  Drupal.admin_menu_fix = {
    init: function() {
      $("div#admin-menu").children("ul:first").children("li:gt(0)").hide();
      $("div#admin-menu").width("24px").height("24px").css("overflow","hidden");
      Drupal.admin_menu_fix.is_ready = true;
      Drupal.admin_menu_fix.is_collapsed = true;
      $("div#admin-menu ul:first li.admin-menu-icon:first a:first").css("padding","4px").attr({
        href: "#",
        title: "Click here to toggle administration menu visibility!"
      }).click(function() {
        this.blur();
        if (!Drupal.admin_menu_fix.is_ready) return;
        Drupal.admin_menu_fix.is_ready = false;
        if (Drupal.admin_menu_fix.is_collapsed) {
          $("div#admin-menu").width("100%").css("overflow","visible").children("ul:first").children("li:gt(0)").show();
          Drupal.admin_menu_fix.is_collapsed = false;
        }
        else {
          $("div#admin-menu").width("24px").css("overflow","hidden").children("ul:first").children("li:gt(0)").hide();
          Drupal.admin_menu_fix.is_collapsed = true;
        }
        Drupal.admin_menu_fix.is_ready = true;
        return false;
      });
    }
  };
  $(document).ready(Drupal.admin_menu_fix.init);
}

I hope that helps someone.

#3

Deciphered - June 15, 2008 - 23:23
 
 

Drupal is a registered trademark of Dries Buytaert.