Commit 4f22e998 authored by Tyf0x's avatar Tyf0x

** Removed the mirroring on the "Select All" option. **

Signed-off-by: 's avatarTyf0x <Tyf0x@users.noreply.github.com>
parent 7f31ccbc
......@@ -106,8 +106,8 @@
// Build select all if enabled.
this.buildContainer();
this.buildButton();
this.buildSelectAll();
this.buildDropdown();
this.buildSelectAll();
this.buildDropdownOptions();
this.buildFilter();
......@@ -362,33 +362,35 @@
}
}
if (checked) {
$option.prop('selected', true);
if (this.options.multiple) {
// Simply select additional option.
if(!isSelectAllOption){
if (checked) {
$option.prop('selected', true);
}
else {
// Unselect all other options and corresponding checkboxes.
if (this.options.selectedClass) {
$($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass);
if (this.options.multiple) {
// Simply select additional option.
$option.prop('selected', true);
}
else {
// Unselect all other options and corresponding checkboxes.
if (this.options.selectedClass) {
$($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass);
}
$($checkboxesNotThis).prop('checked', false);
$optionsNotThis.prop('selected', false);
$($checkboxesNotThis).prop('checked', false);
$optionsNotThis.prop('selected', false);
// It's a single selection, so close.
this.$button.click();
}
// It's a single selection, so close.
this.$button.click();
}
if (this.options.selectedClass === "active") {
$optionsNotThis.parents("a").css("outline", "");
if (this.options.selectedClass === "active") {
$optionsNotThis.parents("a").css("outline", "");
}
}
else {
// Unselect option.
$option.prop('selected', false);
}
}
else {
// Unselect option.
$option.prop('selected', false);
}
this.$select.change();
......@@ -573,20 +575,35 @@
/**
* Build the selct all.
* Checks if a select all ahs already been created.
* Checks if a select all has already been created.
*/
buildSelectAll: function() {
var alreadyHasSelectAll = this.hasSelectAll();
if (!alreadyHasSelectAll && this.options.includeSelectAllOption && this.options.multiple
&& $('option[data-role!="divider"]', this.$select).length > this.options.includeSelectAllIfMoreThan) {
&& $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) {
// Check whether to add a divider after the select all.
if (this.options.includeSelectAllDivider) {
this.$select.prepend('<option value="" disabled="disabled" data-role="divider">');
this.$ul.prepend($(this.options.templates.divider));
}
this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>');
var $li = $(this.options.templates.li);
$('label', $li).addClass("checkbox");
$('label', $li).append('<input type="checkbox" name="' + this.options.checkboxName + '" />');
var $checkbox = $('input', $li);
$checkbox.val(this.options.selectAllValue);
$li.addClass("multiselect-item multiselect-all");
$checkbox.parent().parent()
.addClass('multiselect-all');
$('label', $li).append(" " + this.options.selectAllText);
this.$ul.prepend($li);
$checkbox.prop('checked', false);
}
},
......@@ -644,10 +661,10 @@
}
if (showElement) {
$(element).show();
$(element).show().removeClass("filter-hidden");
}
else {
$(element).hide();
$(element).hide().addClass("filter-hidden");
}
}
}, this));
......@@ -793,11 +810,11 @@
$("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").addClass(this.options.selectedClass);
if (allCheckboxesCount === visibleCheckboxesCount) {
$("option:enabled:not([data-role='divider'])", this.$select).prop('selected', true);
$("option:enabled", this.$select).prop('selected', true);
}
else {
var values = visibleCheckboxes.map(function() { return $(this).val() }).get();
$("option:enabled:not([data-role='divider'])", this.$select).filter(function(index){ return $.inArray($(this).val(), values) !== -1; }).prop('selected', true);
$("option:enabled", this.$select).filter(function(index){ return $.inArray($(this).val(), values) !== -1; }).prop('selected', true);
}
},
......@@ -819,13 +836,13 @@
values = visibleCheckboxes.map(function() { return $(this).val() }).get();
$("option:enabled:not([data-role='divider'])", this.$select).filter(function(index){ return $.inArray($(this).val(), values) !== -1; }).prop('selected', false);
$("option:enabled", this.$select).filter(function(index){ return $.inArray($(this).val(), values) !== -1; }).prop('selected', false);
$("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").removeClass(this.options.selectedClass);
}else {
allCheckboxes.prop('checked', false);
$("option:enabled:not([data-role='divider'])", this.$select).prop('selected', false);
$("option:enabled", this.$select).prop('selected', false);
$("li:not(.divider):not(.disabled)", this.$ul).removeClass(this.options.selectedClass);
}
},
......@@ -837,10 +854,6 @@
rebuild: function() {
this.$ul.html('');
// Remove select all option in select.
$('option[value="' + this.options.selectAllValue + '"]', this.$select).remove();
$('option[data-role="divider"]', this.$select).remove();
// Important to distinguish between radios and checkboxes.
this.options.multiple = this.$select.attr('multiple') === "multiple";
......@@ -905,28 +918,32 @@
},
/**
* Checks whether a select all option is present.
* Checks whether a select all checkbox is present.
*
* @returns {Boolean}
*/
hasSelectAll: function() {
return $('option[value="' + this.options.selectAllValue + '"]', this.$select).length > 0;
return $('li.' + this.options.selectAllValue, this.$ul).length > 0;
},
/**
* Updates the select all option based on the currently displayed and selected checkboxes.
* Updates the select all checkbox based on the currently displayed and selected checkboxes.
*/
updateSelectAll: function() {
if (this.hasSelectAll()) {
var allBoxes = $("li:not(.multiselect-item) input:enabled", this.$ul).filter(":visible"),
var allBoxes = $("li:not(.multiselect-item):not(.filter-hidden) input:enabled", this.$ul),
allBoxesLength = allBoxes.length,
checkedBoxesLength = allBoxes.filter(":checked").length;
checkedBoxesLength = allBoxes.filter(":checked").length,
selectAllLi = $("li." + this.options.selectAllValue, this.$ul),
selectAllInput = selectAllLi.find("input");
if (checkedBoxesLength > 0 && checkedBoxesLength === allBoxesLength) {
this.select(this.options.selectAllValue);
selectAllInput.prop("checked", true);
selectAllLi.addClass(this.options.selectedClass);
}
else {
this.deselect(this.options.selectAllValue);
selectAllInput.prop("checked", false);
selectAllLi.removeClass(this.options.selectedClass);
}
}
},
......@@ -951,7 +968,7 @@
* @returns {jQUery}
*/
getSelected: function() {
return $('option:not([value="' + this.options.selectAllValue + '"])', this.$select).filter(":selected");
return $('option', this.$select).filter(":selected");
},
/**
......
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