Add open/closed classes on events in JavaScript image combobox / msdropdown / msdd / Drupal lang_dropdown

Add open/closed classes on events in JavaScript image combobox / msdropdown / msdd / Drupal lang_dropdown

Today I'd like to present you a little snippet to add open/closed classes within MSDropdown jQuery Plugin!
Explicitly this plugin is used within Drupals Language switcher dropdown / lang_dropdown Module.

Therefore we needed open/closed classes to determine the current state of selection for CSS purposes.

Fortunately the plugin developer (thank you so much, really great development!) was so gracious to provide "onOpen" and "onClose" events to hook into.
So the last challenge was to pick the MsDropdown object within DOM to add the events. And it worked!

Here are the results as snippet, feel free to use and modify:

  1. (function ($) {
  2.     // Initial values:
  3.     $('#edit-lang-dropdown-select_msdd').addClass('closed').removeClass('open');
  4.    
  5.     // Events
  6.     var oHandler = $('select#edit-lang-dropdown-select').data("dd");
  7.     oHandler.addMyEvent('onOpen', function(){
  8.       $('#edit-lang-dropdown-select_msdd').addClass('open').removeClass('closed');
  9.     });
  10.     oHandler.addMyEvent('onClose', function(){
  11.       $('#edit-lang-dropdown-select_msdd').addClass('closed').removeClass('open');
  12.     });
  13.   })(jQuery);

More about the plugin and download:
http://www.marghoobsuleman.com/jquery-image-dropdown
https://github.com/marghoobsuleman/ms-Dropdown

Today I'd like to present you a little snippet to add open/closed classes within MSDropdown jQuery Plugin!Explicitly this plugin is used within Drupals Language switcher dropdown / lang_dropdown Module.Therefore we needed open/closed classes to determine the current state of selection for CSS purposes.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.

More information about formatting options

Refresh Type the characters you see in this picture.
Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.