Created
July 16, 2013 08:37
-
-
Save stborchert/6006938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
/** | |
* Change multi-value dropdown to single-value dropdown and back (visually). | |
*/ | |
Drupal.behaviors.collapsibleFilterRewriteMultipleSelect = { | |
attach: function(context, settings) { | |
$.each(Drupal.settings.collapsibleFilter.multiple_selects, function(name, settings) { | |
$('select#edit-' + name) | |
.once('collapsible-filter-multiple-rewrite') | |
.each(function() { | |
var selectionCount = $('option:selected', $(this)).length; | |
if (selectionCount <= 1) { | |
// Set size of select to 1 if there is not more than 1 selected. | |
$(this).attr('size', 1); | |
// Remove attribute "multiple". | |
$(this).removeAttr('multiple'); | |
// Set default option. | |
if (selectionCount === 0 || $(this).val() === 'All') { | |
$(this).val('All'); | |
} | |
// Add link to expand the dropdown. | |
$expand = $('<a>') | |
.addClass('select-expander') | |
.attr('href', '#') | |
.attr('title', Drupal.t('Expand selection')) | |
.html('[+]') | |
.click(function() { | |
// Get corresponding select element. | |
$select = $(this) | |
.parent('.form-type-select') | |
.find('.collapsible-filter-multiple-rewrite-processed'); | |
// Expand element. | |
$select.attr('size', settings.size) | |
.attr('multiple', 'multiple'); | |
$(this).remove(); | |
}) | |
.appendTo($(this).parent()); | |
} | |
}); | |
}); | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment