This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1317 from pulibrary/multiselect_box_dropdown
Allow dropdowns for select box.
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
$(function (){ | ||
// for some strange reason selectpicker prevents the click-event. so just use mouseup | ||
// when clicking on an optgroup "label", toggle it's "children" | ||
$(document).on("mouseup", ".bootstrap-select .dropdown-header", function (){ | ||
var $optgroup = $(this), | ||
$ul = $optgroup.closest("ul"), | ||
optgroup = $optgroup.data("optgroup"), | ||
|
||
// options that belong to this optgroup | ||
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup); | ||
|
||
// show/hide options | ||
if($optgroup.hasClass("closed")) { | ||
$options.show(); | ||
} else { | ||
$options.hide(); | ||
} | ||
|
||
$optgroup.toggleClass("closed"); | ||
}); | ||
|
||
// initially close all optgroups that have the class "closed" | ||
$(document).on("loaded.bs.select", function (){ | ||
$(this).find(".dropdown-header.closed").each(function (){ | ||
var $optgroup = $(this), | ||
$ul = $optgroup.closest("ul"), | ||
optgroup = $optgroup.data("optgroup"), | ||
|
||
// options that belong to this optgroup | ||
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup); | ||
|
||
// show/hide options | ||
$options.hide(); | ||
}); | ||
}); | ||
$(document).on("changed.bs.select", function(){ | ||
$(this).find(".dropdown-header.closed").each(function(){ | ||
var $optgroup = $(this), | ||
$ul = $optgroup.closest("ul"), | ||
optgroup = $optgroup.data("optgroup"), | ||
|
||
// options that belong to this optgroup | ||
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup); | ||
|
||
// show/hide options | ||
if($optgroup.hasClass("closed")) { | ||
$options.hide(); | ||
} else { | ||
$options.show(); | ||
} | ||
}) | ||
}); | ||
}); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.bootstrap-select .dropdown-header { | ||
cursor: pointer; | ||
} |