Commit e5587e3b authored by David Stutz's avatar David Stutz

#143. #183, #89, #78. But not perfect. Select all option needs to be updated...

#143. #183, #89, #78. But not perfect. Select all option needs to be updated depending on the filter.
parent 2a1be40e
...@@ -178,11 +178,16 @@ ...@@ -178,11 +178,16 @@
$('#example28').multiselect({ $('#example28').multiselect({
includeSelectAllOption: true, includeSelectAllOption: true,
enableFiltering: 1, enableFiltering: true,
maxHeight: 150 maxHeight: 150
}); });
$('#example32').multiselect(); $('#example32').multiselect();
$('#example39').multiselect({
includeSelectAllOption: true,
enableCaseInsensitiveFiltering: true
});
}); });
</script> </script>
<p> <p>
...@@ -493,6 +498,30 @@ ...@@ -493,6 +498,30 @@
The button will keep the <code>tabindex</code> of the select. The button will keep the <code>tabindex</code> of the select.
</td> </td>
</tr> </tr>
<tr>
<td>
<select id="example39" multiple="multiple">
<option value="lab">Lab Course</option>
<option value="proseminar">Proseminar</option>
<optgroup label="Mathematics">
<option value="analysis">Analysis</option>
<option value="algebra">Linear Algebra</option>
<option value="discrete">Discrete Mathematics</option>
<option value="numerical">Numerical Analysis</option>
<option value="probability">Probability Theory</option>
</optgroup>
<optgroup label="Computer Science">
<option value="programming">Introduction to Programming</option>
<option value="automata">Automata Theory</option>
<option value="complexity">Complexity Theory</option>
<option value="software">Software Engineering</option>
</optgroup>
</select>
</td>
<td>
Using <code>optgroups</code>s with filtering and the select all option.
</td>
</tr>
</table> </table>
<div class="page-header"> <div class="page-header">
...@@ -939,7 +968,7 @@ ...@@ -939,7 +968,7 @@
<table class="table table-striped"> <table class="table table-striped">
<tbody> <tbody>
<tr> <tr>
<td> <td width="50%">
<p><code>.multiselect('destroy')</code></p> <p><code>.multiselect('destroy')</code></p>
<p> <p>
This method is used to destroy the plugin on the given element - meaning unbinding the plugin. This method is used to destroy the plugin on the given element - meaning unbinding the plugin.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"use strict";// jshint ;_; "use strict";// jshint ;_;
if (typeof ko != 'undefined' && ko.bindingHandlers && !ko.bindingHandlers.multiselect) { if (typeof ko !== 'undefined' && ko.bindingHandlers && !ko.bindingHandlers.multiselect) {
ko.bindingHandlers.multiselect = { ko.bindingHandlers.multiselect = {
init : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {}, init : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {},
update : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { update : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
this.query = ''; this.query = '';
this.searchTimeout = null; this.searchTimeout = null;
this.options.multiple = this.$select.attr('multiple') == "multiple"; this.options.multiple = this.$select.attr('multiple') === "multiple";
this.options.onChange = $.proxy(this.options.onChange, this); this.options.onChange = $.proxy(this.options.onChange, this);
this.options.onDropdownShow = $.proxy(this.options.onDropdownShow, this); this.options.onDropdownShow = $.proxy(this.options.onDropdownShow, this);
this.options.onDropdownHide = $.proxy(this.options.onDropdownHide, this); this.options.onDropdownHide = $.proxy(this.options.onDropdownHide, this);
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
// option is selected, or a list of the selected options up to a length of 3 selected options by default. // option is selected, or a list of the selected options up to a length of 3 selected options by default.
// If more than 3 options are selected, the number of selected options is printed. // If more than 3 options are selected, the number of selected options is printed.
buttonText: function(options, select) { buttonText: function(options, select) {
if (options.length == 0) { if (options.length === 0) {
return this.nonSelectedText + ' <b class="caret"></b>'; return this.nonSelectedText + ' <b class="caret"></b>';
} }
else { else {
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
}, },
// Like the buttonText option to update the title of the button. // Like the buttonText option to update the title of the button.
buttonTitle: function(options, select) { buttonTitle: function(options, select) {
if (options.length == 0) { if (options.length === 0) {
return this.nonSelectedText; return this.nonSelectedText;
} }
else { else {
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
this.$button.attr('tabindex', tabindex); this.$button.attr('tabindex', tabindex);
} }
this.$container.prepend(this.$button) this.$container.prepend(this.$button);
}, },
// Build dropdown container ul. // Build dropdown container ul.
...@@ -196,7 +196,7 @@ ...@@ -196,7 +196,7 @@
}); });
} }
this.$container.append(this.$ul) this.$container.append(this.$ul);
}, },
// Build the dropdown and bind event handling. // Build the dropdown and bind event handling.
...@@ -204,11 +204,13 @@ ...@@ -204,11 +204,13 @@
this.$select.children().each($.proxy(function(index, element) { this.$select.children().each($.proxy(function(index, element) {
// Support optgroups and options without a group simultaneously. // Support optgroups and options without a group simultaneously.
var tag = $(element).prop('tagName').toLowerCase(); var tag = $(element).prop('tagName')
if (tag == 'optgroup') { .toLowerCase();
if (tag === 'optgroup') {
this.createOptgroup(element); this.createOptgroup(element);
} }
else if (tag == 'option') { else if (tag === 'option') {
this.createOptionValue(element); this.createOptionValue(element);
} }
// Other illegal tags will be ignored. // Other illegal tags will be ignored.
...@@ -217,15 +219,17 @@ ...@@ -217,15 +219,17 @@
// Bind the change event on the dropdown elements. // Bind the change event on the dropdown elements.
$('li input', this.$ul).on('change', $.proxy(function(event) { $('li input', this.$ul).on('change', $.proxy(function(event) {
var checked = $(event.target).prop('checked') || false; var checked = $(event.target).prop('checked') || false;
var isSelectAllOption = $(event.target).val() == this.options.selectAllValue; var isSelectAllOption = $(event.target).val() === this.options.selectAllValue;
// Apply or unapply the configured selected class. // Apply or unapply the configured selected class.
if (this.options.selectedClass) { if (this.options.selectedClass) {
if (checked) { if (checked) {
$(event.target).parents('li').addClass(this.options.selectedClass); $(event.target).parents('li')
.addClass(this.options.selectedClass);
} }
else { else {
$(event.target).parents('li').removeClass(this.options.selectedClass); $(event.target).parents('li')
.removeClass(this.options.selectedClass);
} }
} }
...@@ -236,17 +240,23 @@ ...@@ -236,17 +240,23 @@
var $optionsNotThis = $('option', this.$select).not($option); var $optionsNotThis = $('option', this.$select).not($option);
var $checkboxesNotThis = $('input', this.$container).not($(event.target)); var $checkboxesNotThis = $('input', this.$container).not($(event.target));
// Toggle all options if the select all option was changed.
if (isSelectAllOption) { if (isSelectAllOption) {
if (this.$select[0][0].value == this.options.selectAllValue) { if (this.$select[0][0].value === this.options.selectAllValue) {
var values = []; var values = [];
var options = this.$select.children(); var options = $('option[value!="' + this.options.selectAllValue + '"]', this.$select);
for(var i = 0; i < $checkboxesNotThis.length; i++) { for (var i = 0; i < options.length; i++) {
if (options[i].value !== this.options.selectAllValue) { // Additionally check whether the option is visible within the dropcown.
if (options[i].value !== this.options.selectAllValue && this.getInputByValue(options[i].value).is(':visible')) {
values.push(options[i].value); values.push(options[i].value);
} }
} }
checked ? this.select(values) : this.deselect(values)
if (checked) {
this.select(values);
}
else {
this.deselect(values);
}
} }
} }
...@@ -270,7 +280,7 @@ ...@@ -270,7 +280,7 @@
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", "");
} }
} }
...@@ -291,33 +301,36 @@ ...@@ -291,33 +301,36 @@
$('li a', this.$ul).on('touchstart click', function(event) { $('li a', this.$ul).on('touchstart click', function(event) {
event.stopPropagation(); event.stopPropagation();
if ( event.shiftKey) { if (event.shiftKey) {
var checked = $(event.target).prop('checked') || false; var checked = $(event.target).prop('checked') || false;
if ( checked ) {
if (checked) {
var prev = $(event.target).parents('li:last') var prev = $(event.target).parents('li:last')
.siblings('li[class="active"]:first'); .siblings('li[class="active"]:first');
var currentIdx = $(event.target).parents('li').index(), var currentIdx = $(event.target).parents('li')
prevIdx = prev.index(); .index();
var prevIdx = prev.index();
if ( currentIdx > prevIdx ) { if (currentIdx > prevIdx) {
$(event.target).parents("li:last").prevUntil(prev).each( $(event.target).parents("li:last").prevUntil(prev).each(
function() { function() {
$(this).find("input:first").prop("checked", true).trigger("change"); $(this).find("input:first").prop("checked", true)
.trigger("change");
} }
); );
} else { }
else {
$(event.target).parents("li:last").nextUntil(prev).each( $(event.target).parents("li:last").nextUntil(prev).each(
function() { function() {
$(this).find("input:first").prop("checked", true).trigger("change"); $(this).find("input:first").prop("checked", true)
.trigger("change");
} }
); );
} }
} }
} }
$(event.target).blur(); $(event.target).blur();
}); });
...@@ -326,7 +339,7 @@ ...@@ -326,7 +339,7 @@
if ($('input[type="text"]', this.$container).is(':focus')) { if ($('input[type="text"]', this.$container).is(':focus')) {
return; return;
} }
if ((event.keyCode == 9 || event.keyCode == 27) && this.$container.hasClass('open')) { if ((event.keyCode === 9 || event.keyCode === 27) && this.$container.hasClass('open')) {
// Close on tab or escape. // Close on tab or escape.
this.$button.click(); this.$button.click();
} }
...@@ -340,11 +353,11 @@ ...@@ -340,11 +353,11 @@
var index = $items.index($items.filter(':focus')); var index = $items.index($items.filter(':focus'));
// Navigation up. // Navigation up.
if (event.keyCode == 38 && index > 0) { if (event.keyCode === 38 && index > 0) {
index--; index--;
} }
// Navigate down. // Navigate down.
else if (event.keyCode == 40 && index < $items.length - 1) { else if (event.keyCode === 40 && index < $items.length - 1) {
index++; index++;
} }
else if (!~index) { else if (!~index) {
...@@ -354,7 +367,7 @@ ...@@ -354,7 +367,7 @@
var $current = $items.eq(index); var $current = $items.eq(index);
$current.focus(); $current.focus();
if (event.keyCode == 32 || event.keyCode == 13) { if (event.keyCode === 32 || event.keyCode === 13) {
var $checkbox = $current.find('input'); var $checkbox = $current.find('input');
$checkbox.prop("checked", !$checkbox.prop("checked")); $checkbox.prop("checked", !$checkbox.prop("checked"));
...@@ -386,8 +399,9 @@ ...@@ -386,8 +399,9 @@
var $checkbox = $('input', $li); var $checkbox = $('input', $li);
$checkbox.val(value); $checkbox.val(value);
if (value == this.options.selectAllValue) { if (value === this.options.selectAllValue) {
$checkbox.parent().parent().addClass('multiselect-all'); $checkbox.parent().parent()
.addClass('multiselect-all');
} }
$('label', $li).append(" " + label); $('label', $li).append(" " + label);
...@@ -395,13 +409,17 @@ ...@@ -395,13 +409,17 @@
this.$ul.append($li); this.$ul.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');
} }
$checkbox.prop('checked', selected); $checkbox.prop('checked', selected);
if (selected && this.options.selectedClass) { if (selected && this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass); $checkbox.parents('li')
.addClass(this.options.selectedClass);
} }
}, },
...@@ -423,7 +441,8 @@ ...@@ -423,7 +441,8 @@
// Add the select all option to the select. // Add the select all option to the select.
buildSelectAll: function() { buildSelectAll: function() {
var alreadyHasSelectAll = this.$select[0][0] ? this.$select[0][0].value == this.options.selectAllValue : false; var alreadyHasSelectAll = this.$select[0][0] ? this.$select[0][0].value === this.options.selectAllValue : false;
// If options.includeSelectAllOption === true, add the include all checkbox. // If options.includeSelectAllOption === true, add the include all checkbox.
if (this.options.includeSelectAllOption && this.options.multiple && !alreadyHasSelectAll) { if (this.options.includeSelectAllOption && this.options.multiple && !alreadyHasSelectAll) {
this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>'); this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>');
...@@ -436,6 +455,7 @@ ...@@ -436,6 +455,7 @@
// Build filter if filtering OR case insensitive filtering is enabled and the number of options exceeds (or equals) enableFilterLength. // Build filter if filtering OR case insensitive filtering is enabled and the number of options exceeds (or equals) enableFilterLength.
if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) { if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) {
var enableFilterLength = Math.max(this.options.enableFiltering, this.options.enableCaseInsensitiveFiltering); var enableFilterLength = Math.max(this.options.enableFiltering, this.options.enableCaseInsensitiveFiltering);
if (this.$select.find('option').length >= enableFilterLength) { if (this.$select.find('option').length >= enableFilterLength) {
this.$filter = $(this.templates.filter); this.$filter = $(this.templates.filter);
...@@ -450,24 +470,23 @@ ...@@ -450,24 +470,23 @@
this.searchTimeout = this.asyncFunction($.proxy(function() { this.searchTimeout = this.asyncFunction($.proxy(function() {
if (this.query != event.target.value) { if (this.query !== event.target.value) {
this.query = event.target.value; this.query = event.target.value;
$.each($('li', this.$ul), $.proxy(function(index, element) { $.each($('li', this.$ul), $.proxy(function(index, element) {
var value = $('input', element).val(); var value = $('input', element).val();
if (value != this.options.selectAllValue) {
var text = $('label', element).text(); var text = $('label', element).text();
var value = $('input', element).val();
if (value && text && value != this.options.selectAllValue) { if (value !== this.options.selectAllValue && text) {
// by default lets assume that element is not // by default lets assume that element is not
// interesting for this search // interesting for this search
var showElement = false; var showElement = false;
var filterCandidate = ''; var filterCandidate = '';
if ((this.options.filterBehavior == 'text' || this.options.filterBehavior == 'both')) { if ((this.options.filterBehavior === 'text' || this.options.filterBehavior === 'both')) {
filterCandidate = text; filterCandidate = text;
} }
if ((this.options.filterBehavior == 'value' || this.options.filterBehavior == 'both')) { if ((this.options.filterBehavior === 'value' || this.options.filterBehavior === 'both')) {
filterCandidate = value; filterCandidate = value;
} }
...@@ -485,9 +504,10 @@ ...@@ -485,9 +504,10 @@
$(element).hide(); $(element).hide();
} }
} }
}
}, this)); }, this));
} }
// TODO: check whether select all option needs to be updated.
}, this), 300, this); }, this), 300, this);
}, this)); }, this));
} }
...@@ -504,29 +524,36 @@ ...@@ -504,29 +524,36 @@
refresh: function() { refresh: function() {
$('option', this.$select).each($.proxy(function(index, element) { $('option', this.$select).each($.proxy(function(index, element) {
var $input = $('li input', this.$ul).filter(function() { var $input = $('li input', this.$ul).filter(function() {
return $(this).val() == $(element).val(); return $(this).val() === $(element).val();
}); });
if ($(element).is(':selected')) { if ($(element).is(':selected')) {
$input.prop('checked', true); $input.prop('checked', true);
if (this.options.selectedClass) { if (this.options.selectedClass) {
$input.parents('li').addClass(this.options.selectedClass); $input.parents('li')
.addClass(this.options.selectedClass);
} }
} }
else { else {
$input.prop('checked', false); $input.prop('checked', false);
if (this.options.selectedClass) { if (this.options.selectedClass) {
$input.parents('li').removeClass(this.options.selectedClass); $input.parents('li')
.removeClass(this.options.selectedClass);
} }
} }
if ($(element).is(":disabled")) { if ($(element).is(":disabled")) {
$input.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled'); $input.attr('disabled', 'disabled')
.prop('disabled', true)
.parents('li')
.addClass('disabled');
} }
else { else {
$input.prop('disabled', false).parents('li').removeClass('disabled'); $input.prop('disabled', false)
.parents('li')
.removeClass('disabled');
} }
}, this)); }, this));
...@@ -540,14 +567,14 @@ ...@@ -540,14 +567,14 @@
} }
for (var i = 0; i < selectValues.length; i++) { for (var i = 0; i < selectValues.length; i++) {
var value = selectValues[i]; var value = selectValues[i];
var $option = this.getOptionByValue(value); var $option = this.getOptionByValue(value);
var $checkbox = this.getInputByValue(value); var $checkbox = this.getInputByValue(value);
if (this.options.selectedClass) { if (this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass); $checkbox.parents('li')
.addClass(this.options.selectedClass);
} }
$checkbox.prop('checked', true); $checkbox.prop('checked', true);
...@@ -572,7 +599,8 @@ ...@@ -572,7 +599,8 @@
var $checkbox = this.getInputByValue(value); var $checkbox = this.getInputByValue(value);
if (this.options.selectedClass) { if (this.options.selectedClass) {
$checkbox.parents('li').removeClass(this.options.selectedClass); $checkbox.parents('li')
.removeClass(this.options.selectedClass);
} }
$checkbox.prop('checked', false); $checkbox.prop('checked', false);
...@@ -591,7 +619,7 @@ ...@@ -591,7 +619,7 @@
$('option[value="' + this.options.selectAllValue + '"]', this.$select).remove(); $('option[value="' + this.options.selectAllValue + '"]', 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";
this.buildSelectAll(); this.buildSelectAll();
this.buildDropdownOptions(); this.buildDropdownOptions();
...@@ -656,14 +684,14 @@ ...@@ -656,14 +684,14 @@
// Get the corresponding option by ts value. // Get the corresponding option by ts value.
getOptionByValue: function(value) { getOptionByValue: function(value) {
return $('option', this.$select).filter(function() { return $('option', this.$select).filter(function() {
return $(this).val() == value; return $(this).val() === value;
}); });
}, },
// Get an input in the dropdown by its value. // Get an input in the dropdown by its value.
getInputByValue: function(value) { getInputByValue: function(value) {
return $('li input', this.$ul).filter(function() { return $('li input', this.$ul).filter(function() {
return $(this).val() == value; return $(this).val() === value;
}); });
}, },
...@@ -681,7 +709,8 @@ ...@@ -681,7 +709,8 @@
$.fn.multiselect = function(option, parameter) { $.fn.multiselect = function(option, parameter) {
return this.each(function() { return this.each(function() {
var data = $(this).data('multiselect'), options = typeof option == 'object' && option; var data = $(this).data('multiselect');
var options = typeof option === 'object' && option;
// Initialize the multiselect. // Initialize the multiselect.
if (!data) { if (!data) {
...@@ -689,7 +718,7 @@ ...@@ -689,7 +718,7 @@
} }
// Call multiselect method. // Call multiselect method.
if (typeof option == 'string') { if (typeof option === 'string') {
data[option](parameter); data[option](parameter);
} }
}); });
......
...@@ -138,19 +138,6 @@ ...@@ -138,19 +138,6 @@
</td> </td>
<td>Everything fine.</td> <td>Everything fine.</td>
</tr> </tr>
<tr id="test-select-all-tr" class="success">
<th>Test select all</th>
<td>
<select id="test-select-all-select" multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
<td>Everything fine.</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
...@@ -161,31 +148,31 @@ ...@@ -161,31 +148,31 @@
var build = function(select, tr) { var build = function(select, tr) {
select.multiselect(); select.multiselect();
if (select.length == 0) { if (select.length === 0) {
return 'Select not present anymore.'; return 'Select not present anymore.';
} }
if (select.css('display') != 'none') { if (select.css('display') !== 'none') {
return 'Select still visible (expected <code>display: none;</code>).'; return 'Select still visible (expected <code>display: none;</code>).';
} }
if ($('button.multiselect', tr).length == 0) { if ($('button.multiselect', tr).length === 0) {
return 'Multiselect button not present.'; return 'Multiselect button not present.';
} }
if ($('option', select).length != 5) { if ($('option', select).length !== 5) {
return 'Not all options present anymore.'; return 'Not all options present anymore.';
} }
if ($('ul.multiselect-container', tr).length == 0) { if ($('ul.multiselect-container', tr).length === 0) {
return 'Unordered list <code>.multiselect-container</code> not present.'; return 'Unordered list <code>.multiselect-container</code> not present.';
} }
if ($('ul.multiselect-container li', tr).length != 5) { if ($('ul.multiselect-container li', tr).length !== 5) {
return 'No list item for each option present.'; return 'No list item for each option present.';
} }
if ($('ul.multiselect-container li a', tr).length != 5) { if ($('ul.multiselect-container li a', tr).length !== 5) {
return 'Not all list items come with an anchor inside.'; return 'Not all list items come with an anchor inside.';
} }
...@@ -201,23 +188,23 @@ ...@@ -201,23 +188,23 @@
var buildOptgroups = function(select, tr) { var buildOptgroups = function(select, tr) {
select.multiselect(); select.multiselect();
if ($('optgroup', select).length != 2) { if ($('optgroup', select).length !== 2) {
return 'Optgroups not present anymore (2 expected).'; return 'Optgroups not present anymore (2 expected).';
} }
var first = $('optgroup', select).get(0); var first = $('optgroup', select).get(0);
var second = $('optgroup', select).get(1); var second = $('optgroup', select).get(1);
if ($('option', $(first)).length != 2) { if ($('option', $(first)).length !== 2) {
return 'First optgroup does not have 2 options.'; return 'First optgroup does not have 2 options.';
} }
if ($('option', $(second)).length != 3) { if ($('option', $(second)).length !== 3) {
return 'Second optgroup does not have 3 options.'; return 'Second optgroup does not have 3 options.';
} }
// Check the corresponding labels. // Check the corresponding labels.
if ($('label.multiselect-group', tr).length != 2) { if ($('label.multiselect-group', tr).length !== 2) {
return 'Expected 2 labels within the unordered list.'; return 'Expected 2 labels within the unordered list.';
} }
...@@ -225,11 +212,11 @@ ...@@ -225,11 +212,11 @@
var firstLabel = $('label.multiselect-group', tr).get(0); var firstLabel = $('label.multiselect-group', tr).get(0);
var secondLabel = $('label.multiselect-group', tr).get(1); var secondLabel = $('label.multiselect-group', tr).get(1);
if ($(firstLabel).text() != $(first).prop('label')) { if ($(firstLabel).text() !== $(first).prop('label')) {
return 'First group labeled incorrectly.'; return 'First group labeled incorrectly.';
} }
if ($(secondLabel).text() != $(second).prop('label')) { if ($(secondLabel).text() !== $(second).prop('label')) {
return 'Second group labeled incorrectly.'; return 'Second group labeled incorrectly.';
} }
...@@ -244,11 +231,11 @@ ...@@ -244,11 +231,11 @@
var buildSelected = function(select, tr ) { var buildSelected = function(select, tr ) {
select.multiselect(); select.multiselect();
if ($('option:selected', select).length != 1) { if ($('option:selected', select).length !== 1) {
return 'Multiselect did not adopt selected options (1 selected option).'; return 'Multiselect did not adopt selected options (1 selected option).';
} }
if ($('ul.multiselect-container li.active', tr).length != 1) { if ($('ul.multiselect-container li.active', tr).length !== 1) {
return 'Corresponding list item not set to <code>.active</code>.'; return 'Corresponding list item not set to <code>.active</code>.';
} }
...@@ -267,7 +254,7 @@ ...@@ -267,7 +254,7 @@
selectAllValue: value selectAllValue: value
}); });
if ($('.multiselect-container input[value="' + value + '"]', tr).length != 1) { if ($('.multiselect-container input[value="' + value + '"]', tr).length !== 1) {
return 'Expected exactly one input with value ' + value + ' as select all option.'; return 'Expected exactly one input with value ' + value + ' as select all option.';
} }
...@@ -284,7 +271,7 @@ ...@@ -284,7 +271,7 @@
enableFiltering: true enableFiltering: true
}); });
if ($('.multiselect-search', tr).length != 1) { if ($('.multiselect-search', tr).length !== 1) {
return 'No search input present.'; return 'No search input present.';
} }
...@@ -296,11 +283,11 @@ ...@@ -296,11 +283,11 @@
} }
// Test select. // Test select.
var select = function(select, tr) { var select = function(selectElement, tr) {
select.multiselect(); selectElement.multiselect();
// Check for no selected options and no active li's. // Check for no selected options and no active li's.
if ($('option:selected', select).length > 0) { if ($('option:selected', selectElement).length > 0) {
return 'There are already selected options (0 expected).'; return 'There are already selected options (0 expected).';
} }
...@@ -308,42 +295,42 @@ ...@@ -308,42 +295,42 @@
return 'There are already active list items (0 expected).'; return 'There are already active list items (0 expected).';
} }
select.multiselect('select', 1); selectElement.multiselect('select', '1');
if ($('option:selected', select).length != 1) { if ($('option:selected', selectElement).length !== 1) {
return 'Just selected an option - option not marked selected.'; return 'Just selected an option - option not marked selected.';
} }
if ($('ul.multiselect-container li.active', tr).length != 1) { if ($('ul.multiselect-container li.active', tr).length !== 1) {
return 'Just selected an option - list item not set active.'; return 'Just selected an option - list item not set active.';
} }
if ($('option:selected', select).first().val() != 1) { if ($('option:selected', selectElement).first().val() !== '1') {
return 'Wrong option selected.'; return 'Wrong option selected.';
} }
select.multiselect('select', [2, 3]); selectElement.multiselect('select', ['2', '3']);
if ($('option:selected', select).length != 3) { if ($('option:selected', selectElement).length !== 3) {
return 'Just selected two additional options - options not marked selected.'; return 'Just selected two additional options - options not marked selected.';
} }
if ($('ul.multiselect-container li.active', tr).length != 3) { if ($('ul.multiselect-container li.active', tr).length !== 3) {
return 'Just selected two additional options - list items not set active.'; return 'Just selected two additional options - list items not set active.';
} }
var second = $('option:selected', select).get(1), var second = $('option:selected', selectElement).get(1),
third = $('option:selected', select).get(2); third = $('option:selected', selectElement).get(2);
if (second == undefined || second.length == 0) { if (second === undefined || second.length === 0) {
return 'Could not get second option.'; return 'Could not get second option.';
} }
if (third == undefined || third.length == 0) { if (third === undefined || third.length === 0) {
return 'Could not get third option.'; return 'Could not get third option.';
} }
if ($(second).val() != 2 || $(third).val() != 3) { if ($(second).val() !== '2' || $(third).val() !== '3') {
return 'Wrong options selected.'; return 'Wrong options selected.';
} }
...@@ -360,29 +347,29 @@ ...@@ -360,29 +347,29 @@
select.multiselect(); select.multiselect();
// Check for no selected options and no active li's. // Check for no selected options and no active li's.
if ($('option:selected', select).length != 3) { if ($('option:selected', select).length !== 3) {
return 'There should be 3 options selected.'; return 'There should be 3 options selected.';
} }
if ($('ul.multiselect-container li.active', tr).length != 3) { if ($('ul.multiselect-container li.active', tr).length !== 3) {
return 'There should be 3 list items set to active.'; return 'There should be 3 list items set to active.';
} }
select.multiselect('deselect', 1); select.multiselect('deselect', '1');
if ($('option:selected', select).length != 2) { if ($('option:selected', select).length !== 2) {
return 'Just deselected an option - option not marked deselected.'; return 'Just deselected an option - option not marked deselected.';
} }
if ($('ul.multiselect-container li.active', tr).length != 2) { if ($('ul.multiselect-container li.active', tr).length !== 2) {
return 'Just deselected an option - list item not set inactive.'; return 'Just deselected an option - list item not set inactive.';
} }
if ($('option:selected', select).first().val() != 2) { if ($('option:selected', select).first().val() !== '2') {
return 'Wrong option deselected.'; return 'Wrong option deselected.';
} }
select.multiselect('deselect', [2, 3]); select.multiselect('deselect', ['2', '3']);
if ($('option:selected', select).length > 0) { if ($('option:selected', select).length > 0) {
return 'Just deselected two additional options - options not marked deselected.'; return 'Just deselected two additional options - options not marked deselected.';
...@@ -403,11 +390,11 @@ ...@@ -403,11 +390,11 @@
var maxHeight = function(select, tr) { var maxHeight = function(select, tr) {
select.multiselect({ select.multiselect({
maxHeight: 100, maxHeight: 100
}); });
var height = $('.multiselect-container', tr).css('max-height'); var height = $('.multiselect-container', tr).css('max-height');
if (height != '100px') { if (height !== '100px') {
return 'Max height not set correctly (set: ' + height + ').'; return 'Max height not set correctly (set: ' + height + ').';
} }
...@@ -418,38 +405,6 @@ ...@@ -418,38 +405,6 @@
$('#test-max-height-tr').removeClass('success').addClass('danger'); $('#test-max-height-tr').removeClass('success').addClass('danger');
$('#test-max-height-tr td').last().html(maxHeight); $('#test-max-height-tr td').last().html(maxHeight);
} }
var selectAll = function(select, tr) {
var value = 'multiselect-select-all';
select.multiselect({
includeSelectAllOption: true,
selectAllValue: value
});
if ($('option:selected', select).length > 0) {
return 'Test expected 0 selected options as initial state (found ' + $('option:selected', select).length + ').';
}
// Trigger select all.
$('.multiselect-container input[value="' + value + '"]', tr).click();
if ($('option:selected', select).length != $('option', select).length) {
return 'Not all options selected.';
}
$('.multiselect-container input[value="' + value + '"]', tr).click();
if ($('option:selected', select).length > 0) {
return 'There is some option selected (0 expected).';
}
return false;
}($('#test-select-all-select'), $('#test-select-all-tr'));
if (selectAll) {
$('#test-select-all-tr').removeClass('success').addClass('danger');
$('#test-select-all-tr td').last().html(selectAll);
}
}); });
</script> </script>
</body> </body>
......
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