Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Allow dropdowns for select box.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed May 30, 2017
1 parent 943dc79 commit 0de1219
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
53 changes: 53 additions & 0 deletions app/assets/javascripts/bootstrap_select_dropdown.js
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();
}
})
});
});
1 change: 1 addition & 0 deletions app/assets/javascripts/plum_boot.es6
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class Initializer {
}

initialize_bootstrap_select() {
$("optgroup").addClass("closed")
$("select[multiple='multiple']").selectpicker({})
$(".datatable").DataTable()
}
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
@import 'components/tabs';
@import 'components/welcome_page';
@import 'components/catalog';
@import 'components/select_box';
3 changes: 3 additions & 0 deletions app/assets/stylesheets/components/select_box.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.bootstrap-select .dropdown-header {
cursor: pointer;
}

0 comments on commit 0de1219

Please sign in to comment.