Skip to content

Commit 10182e2

Browse files
author
Tom Doan
committed
Add 'multiVerbosity' option
1 parent 92fbcd3 commit 10182e2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ Name | Type | Default | Description
6060
`customClass` | string | arrow | The class name to customize the drop-down menu style. The default `arrow` class displays a chevron-type arrow icon. Two additional helper classes are built in (add either or both to `arrow`): `triangle` converts the chevron into a solid triangle; `small` renders the arrow icon at half size.
6161
`height` | number | 50 | The drop-down menu item height. The minimum value is 8. Note that the maximum number of items displayed when the menu is opened is determined by the `size` attribute of the `<select>` element.
6262
`hoverIntent` | number | 200 | The wait period (in milliseconds) before collapsing the drop-down menu after you hover off of it. If you hover back onto the menu within the wait period, it will remain open. The minimum value is 0.
63-
`multiDelimiter` | string | ; | The separator character to use for the list of selected values in a multi-select menu.
63+
`multiDelimiter` | string | ; | The separator character to use for the list of selected items in a multi-select menu.
64+
`multiVerbosity` | number | 99 | The maximum number of selected items to display in a multi-select menu before replacing it with a summary (e.g., "2/3 selected"). To display "0/3 selected" instead of "None selected", set this option to -1.
6465
`selectedMarker` | string | **&#10003;** | The icon or symbol to mark that an item is selected. HTML is accepted (e.g., `<i class="fa fa-check"></i>`).
6566
`afterLoad` | function | | Callback function to execute after the drop-down menu widget is loaded.
6667

dist/js/jquery.prettydropdowns.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
height: 50,
1717
hoverIntent: 200,
1818
multiDelimiter: '; ',
19+
multiVerbosity: 99,
1920
selectedMarker: '&#10003;',
2021
afterLoad: function(){}
2122
}, oOptions);
@@ -24,6 +25,12 @@
2425
// Validate options
2526
if (isNaN(oOptions.height) || oOptions.height<8) oOptions.height = 8;
2627
if (isNaN(oOptions.hoverIntent) || oOptions.hoverIntent<0) oOptions.hoverIntent = 200;
28+
if (isNaN(oOptions.multiVerbosity)) oOptions.multiVerbosity = 99;
29+
30+
// Translable strings
31+
var MULTI_NONE = 'None selected',
32+
MULTI_PREFIX = 'Selected: ',
33+
MULTI_POSTFIX = ' selected';
2734

2835
// Globals
2936
var $current,
@@ -441,11 +448,14 @@
441448
// Update selected values for multi-select menu
442449
updateSelected = function($dropdown) {
443450
var $select = $dropdown.parent().children('select'),
444-
sSelected = $('option', $select).map(function() {
451+
aSelected = $('option', $select).map(function() {
445452
if (this.selected) return this.text;
446-
}).get().join(oOptions.multiDelimiter);
453+
}).get(),
454+
sSelected;
455+
if (oOptions.multiVerbosity>=aSelected.length) sSelected = aSelected.join(oOptions.multiDelimiter) || MULTI_NONE;
456+
else sSelected = aSelected.length + '/' + $('option', $select).length + MULTI_POSTFIX;
447457
if (sSelected) {
448-
var sTitle = ($select.attr('title') ? $select.attr('title') + '\n' : '') + 'Selected: ' + sSelected;
458+
var sTitle = ($select.attr('title') ? $select.attr('title') : '') + (aSelected.length ? '\n' + MULTI_PREFIX + aSelected.join(oOptions.multiDelimiter) : '');
449459
$dropdown.children('.selected').text(sSelected);
450460
$dropdown.attr({
451461
'title': sTitle,

0 commit comments

Comments
 (0)