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