Commit 7be7b939 authored by Luís Rudge's avatar Luís Rudge

adding the search textbox outisde of the same ul container

parent 55434cce
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<script>
$('.dropdown input, .dropdown label').click(function (e) {
e.stopPropagation();
});
</script>
<div class="hero-unit"> <div class="hero-unit">
<h1>Bootstrap Multiselect</h1> <h1>Bootstrap Multiselect</h1>
<p> <p>
...@@ -110,7 +115,7 @@ ...@@ -110,7 +115,7 @@
$('#example27').multiselect({ includeSelectAllOption: true }); $('#example27').multiselect({ includeSelectAllOption: true });
$('#example28').multiselect({ includeSelectAllOption: true, enableFiltering: true, maxHeight:100 }); $('#example28').multiselect({ includeSelectAllOption: true, enableFiltering: true, maxHeight: 150 });
}); });
</script> </script>
<p> <p>
......
...@@ -53,10 +53,10 @@ ...@@ -53,10 +53,10 @@
this.$container = $(this.options.buttonContainer) this.$container = $(this.options.buttonContainer)
.append('<button type="button" class="multiselect dropdown-toggle ' + this.options.buttonClass + '" data-toggle="dropdown">' + this.options.buttonText(this.getSelected(), this.$select) + '</button>') .append('<button type="button" class="multiselect dropdown-toggle ' + this.options.buttonClass + '" data-toggle="dropdown">' + this.options.buttonText(this.getSelected(), this.$select) + '</button>')
.append('<ul class="dropdown-menu' + (this.options.dropRight ? ' pull-right' : '') + '"></ul>'); .append('<div id="dropdown-container" class="dropdown-menu" style="position:absolute;"><ul style="list-style-type: none;margin:0;padding:0;"></ul></div>');
if (this.options.enableFiltering) { if (this.options.enableFiltering) {
$('ul', this.$container).prepend('<div class="input-prepend" style="padding:3px;"><span class="add-on"><i class="icon-search"></i></span><input id="multiselect-default-search" type="text" placeholder="' + this.options.filterPlaceholder + '"></div>'); $('#dropdown-container', this.$container).prepend('<div class="input-prepend" style="padding:3px;"><span class="add-on"><i class="icon-search"></i></span><input id="multiselect-default-search" type="text" placeholder="' + this.options.filterPlaceholder + '"></div>');
$('#multiselect-default-search', this.$container).val(this.query).click(function (event) { $('#multiselect-default-search', this.$container).val(this.query).click(function (event) {
event.stopPropagation(); event.stopPropagation();
}).keydown($.proxy(function (event) { }).keydown($.proxy(function (event) {
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
// Set max height of dropdown menu to activate auto scrollbar. // Set max height of dropdown menu to activate auto scrollbar.
if (this.options.maxHeight) { if (this.options.maxHeight) {
$('ul', this.$container).css({ $('#dropdown-container ul', this.$container).css({
'max-height': this.options.maxHeight + 'px', 'max-height': this.options.maxHeight + 'px',
'overflow-y': 'auto', 'overflow-y': 'auto',
'overflow-x': 'hidden' 'overflow-x': 'hidden'
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
if (value == 'select-all-option') $checkbox.parent().parent().addClass('select-all-option'); if (value == 'select-all-option') $checkbox.parent().parent().addClass('select-all-option');
$('label', $li).append(" " + label); $('label', $li).append(" " + label);
$('ul', this.$container).append($li); $('#dropdown-container ul', this.$container).append($li);
if ($(element).is(':disabled')) { if ($(element).is(':disabled')) {
$checkbox.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled'); $checkbox.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled');
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
// Add a header for the group. // Add a header for the group.
var $li = $('<li><label style="margin:0;padding:3px 20px 3px 20px;height:100%;" class="multiselect-group"></label></li>'); var $li = $('<li><label style="margin:0;padding:3px 20px 3px 20px;height:100%;" class="multiselect-group"></label></li>');
$('label', $li).text(groupName); $('label', $li).text(groupName);
$('ul', this.$container).append($li); $('#dropdown-container ul', this.$container).append($li);
// Add the options of the group. // Add the options of the group.
$('option', group).each($.proxy(function (index, element) { $('option', group).each($.proxy(function (index, element) {
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
}, this)); }, this));
// Bind the change event on the dropdown elements. // Bind the change event on the dropdown elements.
$('ul li input', this.$container).on('change', $.proxy(function(event) { $('#dropdown-container ul li input', this.$container).on('change', $.proxy(function (event) {
var checked = $(event.target).prop('checked') || false; var checked = $(event.target).prop('checked') || false;
var isSelectAllOption = $(event.target).val() == 'select-all-option'; var isSelectAllOption = $(event.target).val() == 'select-all-option';
...@@ -263,7 +263,7 @@ ...@@ -263,7 +263,7 @@
this.$select.change(); this.$select.change();
}, this)); }, this));
$('ul li a', this.$container).on('touchstart click', function(event) { $('#dropdown-container ul li a', this.$container).on('touchstart click', function (event) {
event.stopPropagation(); event.stopPropagation();
}); });
...@@ -327,7 +327,7 @@ ...@@ -327,7 +327,7 @@
// Refreshs the checked options based on the current state of the select. // Refreshs the checked options based on the current state of the select.
refresh: function() { refresh: function() {
$('option', this.$select).each($.proxy(function(index, element) { $('option', this.$select).each($.proxy(function(index, element) {
var $input = $('ul li input', this.$container).filter(function () { var $input = $('#dropdown-container ul li input', this.$container).filter(function () {
return $(this).val() == $(element).val(); return $(this).val() == $(element).val();
}); });
...@@ -353,7 +353,7 @@ ...@@ -353,7 +353,7 @@
// Select an option by its value. // Select an option by its value.
select: function(value) { select: function(value) {
var $option = $('option', this.$select).filter(function () { return $(this).val() == value; }); var $option = $('option', this.$select).filter(function () { return $(this).val() == value; });
var $checkbox = $('ul li input', this.$container).filter(function () { return $(this).val() == value; }); var $checkbox = $('#dropdown-container ul li input', this.$container).filter(function () { return $(this).val() == value; });
if (this.options.selectedClass) { if (this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass); $checkbox.parents('li').addClass(this.options.selectedClass);
...@@ -369,7 +369,7 @@ ...@@ -369,7 +369,7 @@
// Deselect an option by its value. // Deselect an option by its value.
deselect: function(value) { deselect: function(value) {
var $option = $('option', this.$select).filter(function () { return $(this).val() == value; }); var $option = $('option', this.$select).filter(function () { return $(this).val() == value; });
var $checkbox = $('ul li input', this.$container).filter(function () { return $(this).val() == value; }); var $checkbox = $('#dropdown-container ul li input', this.$container).filter(function () { return $(this).val() == value; });
if (this.options.selectedClass) { if (this.options.selectedClass) {
$checkbox.parents('li').removeClass(this.options.selectedClass); $checkbox.parents('li').removeClass(this.options.selectedClass);
...@@ -384,7 +384,7 @@ ...@@ -384,7 +384,7 @@
// Rebuild the whole dropdown menu. // Rebuild the whole dropdown menu.
rebuild: function() { rebuild: function() {
$('ul', this.$container).html(''); $('#dropdown-container ul', this.$container).html('');
this.buildDropdown(this.$select, this.options); this.buildDropdown(this.$select, this.options);
this.updateButtonText(); this.updateButtonText();
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment