Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/jquery.multiselect.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,18 @@
},

updateCache: function() {

// each list item
this.rows = this.instance.menu.find(".ui-multiselect-checkboxes li:not(.ui-multiselect-optgroup-label)");

// cache
this.cache = this.element.children().map(function() {
// Skip display-none rows
this.cache = this.element.children(":not(:css(display=none))").map(function() {
var elem = $(this);

// account for optgroups
if(this.tagName.toLowerCase() === "optgroup") {
elem = elem.children();
elem = elem.children(":not(:css(display=none))");
}

return elem.map(function() {
Expand Down
14 changes: 11 additions & 3 deletions src/jquery.multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
*
*/
(function($, undefined) {
// http://stackoverflow.com/a/3640212/401636
// custom css filter ex: :css(display=none)
$.expr[':'].css = function(obj, index, meta, stack) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fond of modifying anything in jQuery for this widget. This is a side effect that could impact other defined expressions in other widgets or by the user.

You should declare a method in the widget instead and use that as a parameter to filter.

var args = meta[3].split(/\s*=\s*/);
return $(obj).css(args[0]) == args[1];
}

var multiselectID = 0;
var $doc = $(document);
Expand Down Expand Up @@ -199,15 +205,17 @@
}
}

//Turn all the options and optiongroups into list items
el.children().each(function(i) {
// Turn all the options and optiongroups into list items
// hide display=none options and optiongroups
el.children(":not(:css(display=none))").each(function(i) {
var $this = $(this);

if(this.tagName === 'OPTGROUP') {
var $groupLabel = $("<li/>").addClass('ui-multiselect-optgroup-label ' + this.className).appendTo($dropdown);
var $link = $("<a/>").attr("href", "#").text(this.getAttribute('label')).appendTo($groupLabel);

$this.children().each(function() {
// hide display=none options
$this.children(":not(:css(display=none))").each(function() {
var $listItem = makeItem(this, true).appendTo($dropdown);
});
} else {
Expand Down