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:
(function ($) {
// Initial values:
$('#edit-lang-dropdown-select_msdd').addClass('closed').removeClass('open');
// Events
var oHandler = $('select#edit-lang-dropdown-select').data("dd");
oHandler.addMyEvent('onOpen', function(){
$('#edit-lang-dropdown-select_msdd').addClass('open').removeClass('closed');
});
oHandler.addMyEvent('onClose', function(){
$('#edit-lang-dropdown-select_msdd').addClass('closed').removeClass('open');
});
})(jQuery);
More about the plugin and download:
http://www.marghoobsuleman.com/jquery-image-dropdown
https://github.com/marghoobsuleman/ms-Dropdown