diff --git a/dist/css/bootstrap-multiselect.css b/dist/css/bootstrap-multiselect.css index f623d090..686b8a9a 100644 --- a/dist/css/bootstrap-multiselect.css +++ b/dist/css/bootstrap-multiselect.css @@ -68,20 +68,66 @@ span.multiselect-native-select select { .multiselect-container .multiselect-reset .input-group { width: 93%; } -.multiselect-container > .multiselect-option.dropdown-item, +.multiselect-container .multiselect-filter > .fa-search { + z-index: 1; + padding-left: 0.75rem; +} +.multiselect-container .multiselect-filter > input.multiselect-search { + border: none; + border-bottom: 1px solid lightgrey; + padding-left: 2rem; + margin-left: -1.625rem; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} +.multiselect-container .multiselect-filter > input.multiselect-search:focus { + border-bottom-right-radius: 0.25rem; + border-bottom-left-radius: 0.25rem; +} +.multiselect-container .multiselect-filter > .multiselect-moz-clear-filter { + margin-left: -1.5rem; + display: none; +} +.multiselect-container .multiselect-option.multiselect-group-option-indented { + padding-left: 1.75rem; +} +.multiselect-container .multiselect-option, +.multiselect-container .multiselect-group, +.multiselect-container .multiselect-all { + padding: 0.25rem 0.25rem 0.25rem 0.75rem; +} +.multiselect-container .multiselect-option.dropdown-item, .multiselect-container .multiselect-group.dropdown-item, -.multiselect-container > .multiselect-option.dropdown-toggle, -.multiselect-container .multiselect-group.dropdown-toggle { +.multiselect-container .multiselect-all.dropdown-item, +.multiselect-container .multiselect-option.dropdown-toggle, +.multiselect-container .multiselect-group.dropdown-toggle, +.multiselect-container .multiselect-all.dropdown-toggle { cursor: pointer; } -.multiselect-container > .multiselect-option > span, -.multiselect-container .multiselect-group > span { - padding: 3px 20px; -} -.multiselect-container > .multiselect-option > span > .form-check-label, -.multiselect-container .multiselect-group > span > .form-check-label { +.multiselect-container .multiselect-option .form-check-label, +.multiselect-container .multiselect-group .form-check-label, +.multiselect-container .multiselect-all .form-check-label { cursor: pointer; } +.multiselect-container .multiselect-option.active:not(.multiselect-active-item-fallback), +.multiselect-container .multiselect-group.active:not(.multiselect-active-item-fallback), +.multiselect-container .multiselect-all.active:not(.multiselect-active-item-fallback), +.multiselect-container .multiselect-option:not(.multiselect-active-item-fallback):active, +.multiselect-container .multiselect-group:not(.multiselect-active-item-fallback):active, +.multiselect-container .multiselect-all:not(.multiselect-active-item-fallback):active { + background-color: lightgrey; + color: black; +} +.multiselect-container .multiselect-option .form-check, +.multiselect-container .multiselect-group .form-check, +.multiselect-container .multiselect-all .form-check { + padding: 0 5px 0 20px; +} +.multiselect-container .multiselect-option:focus, +.multiselect-container .multiselect-group:focus, +.multiselect-container .multiselect-all:focus { + outline: none; +} .form-inline .multiselect-container span.form-check { padding: 3px 20px 3px 40px; } diff --git a/dist/css/bootstrap-multiselect.min.css b/dist/css/bootstrap-multiselect.min.css index beb7bf63..c4d84ebb 100644 --- a/dist/css/bootstrap-multiselect.min.css +++ b/dist/css/bootstrap-multiselect.min.css @@ -1 +1 @@ -span.multiselect-native-select{position:relative}span.multiselect-native-select select{border:0!important;clip:rect(0 0 0 0)!important;height:1px!important;margin:-1px -1px -1px -3px!important;overflow:hidden!important;padding:0!important;position:absolute!important;width:1px!important;left:50%;top:30px}.multiselect.dropdown-toggle:after{display:none}.multiselect-container{position:absolute;list-style-type:none;margin:0;padding:0}.multiselect-container .multiselect-reset .input-group{width:93%}.multiselect-container .multiselect-group.dropdown-item,.multiselect-container .multiselect-group.dropdown-toggle,.multiselect-container>.multiselect-option.dropdown-item,.multiselect-container>.multiselect-option.dropdown-toggle{cursor:pointer}.multiselect-container .multiselect-group>span,.multiselect-container>.multiselect-option>span{padding:3px 20px}.multiselect-container .multiselect-group>span>.form-check-label,.multiselect-container>.multiselect-option>span>.form-check-label{cursor:pointer}.form-inline .multiselect-container span.form-check{padding:3px 20px 3px 40px} \ No newline at end of file +span.multiselect-native-select{position:relative}span.multiselect-native-select select{border:0!important;clip:rect(0 0 0 0)!important;height:1px!important;margin:-1px -1px -1px -3px!important;overflow:hidden!important;padding:0!important;position:absolute!important;width:1px!important;left:50%;top:30px}.multiselect.dropdown-toggle:after{display:none}.multiselect-container{position:absolute;list-style-type:none;margin:0;padding:0}.multiselect-container .multiselect-reset .input-group{width:93%}.multiselect-container .multiselect-filter>.fa-search{z-index:1;padding-left:.75rem}.multiselect-container .multiselect-filter>input.multiselect-search{border:none;border-bottom:1px solid #d3d3d3;padding-left:2rem;margin-left:-1.625rem;border-bottom-right-radius:0;border-bottom-left-radius:0}.multiselect-container .multiselect-filter>input.multiselect-search:focus{border-bottom-right-radius:.25rem;border-bottom-left-radius:.25rem}.multiselect-container .multiselect-filter>.multiselect-moz-clear-filter{margin-left:-1.5rem;display:none}.multiselect-container .multiselect-option.multiselect-group-option-indented{padding-left:1.75rem}.multiselect-container .multiselect-all,.multiselect-container .multiselect-group,.multiselect-container .multiselect-option{padding:.25rem .25rem .25rem .75rem}.multiselect-container .multiselect-all.dropdown-item,.multiselect-container .multiselect-all.dropdown-toggle,.multiselect-container .multiselect-group.dropdown-item,.multiselect-container .multiselect-group.dropdown-toggle,.multiselect-container .multiselect-option.dropdown-item,.multiselect-container .multiselect-option.dropdown-toggle{cursor:pointer}.multiselect-container .multiselect-all .form-check-label,.multiselect-container .multiselect-group .form-check-label,.multiselect-container .multiselect-option .form-check-label{cursor:pointer}.multiselect-container .multiselect-all.active:not(.multiselect-active-item-fallback),.multiselect-container .multiselect-all:not(.multiselect-active-item-fallback):active,.multiselect-container .multiselect-group.active:not(.multiselect-active-item-fallback),.multiselect-container .multiselect-group:not(.multiselect-active-item-fallback):active,.multiselect-container .multiselect-option.active:not(.multiselect-active-item-fallback),.multiselect-container .multiselect-option:not(.multiselect-active-item-fallback):active{background-color:#d3d3d3;color:#000}.multiselect-container .multiselect-all .form-check,.multiselect-container .multiselect-group .form-check,.multiselect-container .multiselect-option .form-check{padding:0 5px 0 20px}.multiselect-container .multiselect-all:focus,.multiselect-container .multiselect-group:focus,.multiselect-container .multiselect-option:focus{outline:0}.form-inline .multiselect-container span.form-check{padding:3px 20px 3px 40px} \ No newline at end of file diff --git a/dist/js/bootstrap-multiselect.js b/dist/js/bootstrap-multiselect.js index 50a6d8fa..705114fa 100644 --- a/dist/js/bootstrap-multiselect.js +++ b/dist/js/bootstrap-multiselect.js @@ -438,11 +438,11 @@ includeResetOption: false, includeResetDivider: false, resetText: 'Reset', + indentGroupOptions: true, templates: { button: '', popupContainer: '', - filter: '
', - filterClearBtn: '
', + filter: '
', option: '', divider: '', optionGroup: '', @@ -559,7 +559,7 @@ this.createDivider(); } else { - this.createOptionValue(element); + this.createOptionValue(element, false); } } @@ -711,17 +711,17 @@ } else if (!$target.is('input')) { var $checkbox = $target.closest('.multiselect-option, .multiselect-all').find('.form-check-input'); - if($checkbox.length > 0) { + if ($checkbox.length > 0) { $checkbox.prop('checked', !$checkbox.prop('checked')); $checkbox.change(); } - else if(this.options.enableClickableOptGroups && this.options.multiple && !$target.hasClass("caret-container")) { + else if (this.options.enableClickableOptGroups && this.options.multiple && !$target.hasClass("caret-container")) { var groupItem = $target; - if(!groupItem.hasClass("multiselect-group")){ + if (!groupItem.hasClass("multiselect-group")) { groupItem = $target.closest('.multiselect-group'); } $checkbox = groupItem.find(".form-check-input"); - if($checkbox.length > 0) { + if ($checkbox.length > 0) { $checkbox.prop('checked', !$checkbox.prop('checked')); $checkbox.change(); } @@ -744,7 +744,7 @@ //Keyboard support. this.$container.off('keydown.multiselect').on('keydown.multiselect', $.proxy(function (event) { - if ($('input[type="text"]', this.$container).is(':focus')) { + if ($('input.multiselect-search', this.$container).is(':focus')) { return; } @@ -774,8 +774,8 @@ } // keyCode 13 = Enter - if(event.keyCode === 13) { - setTimeout(function() { + if (event.keyCode === 13) { + setTimeout(function () { $current.focus(); }, 0); } @@ -906,7 +906,7 @@ * * @param {jQuery} element */ - createOptionValue: function (element) { + createOptionValue: function (element, isGroupOption) { var $element = $(element); if ($element.is(':selected')) { $element.prop('selected', true); @@ -922,6 +922,10 @@ var $option = $(this.options.templates.option); $option.addClass(classes); + if (isGroupOption && this.options.indentGroupOptions) { + $option.addClass("multiselect-group-option-indented") + } + // Hide all children items when collapseOptGroupsByDefault is true if (this.options.collapseOptGroupsByDefault && $(element).parent().prop("tagName").toLowerCase() === "optgroup") { $option.addClass("multiselect-collapsible-hidden"); @@ -1008,7 +1012,7 @@ this.$popupContainer.append($groupOption); $("option", group).each($.proxy(function ($, group) { - this.createOptionValue(group); + this.createOptionValue(group, true); }, this)); }, @@ -1090,10 +1094,20 @@ this.$filter = $(this.options.templates.filter); $('input', this.$filter).attr('placeholder', this.options.filterPlaceholder); - // Adds optional filter clear button - if (this.options.includeFilterClearBtn) { - var clearBtn = $(this.options.templates.filterClearBtn); - clearBtn.on('click', $.proxy(function (event) { + // Handles optional filter clear button + if (!this.options.includeFilterClearBtn) { + this.$filter.find(".multiselect-search").attr("type", "text"); + + // Remove clear button if the old design of the filter with input groups and separated clear button is used + this.$filter.find(".multiselect-clear-filter").remove(); + } + else { + // Firefox does not support a clear button in search inputs right now therefore it must be added manually + if (this.isFirefox() && this.$filter.find(".multiselect-clear-filter").length === 0) { + this.$filter.append(""); + } + + this.$filter.find(".multiselect-clear-filter").on('click', $.proxy(function (event) { clearTimeout(this.searchTimeout); this.query = ''; @@ -1107,7 +1121,6 @@ } }, this)); - this.$filter.find('.input-group').append(clearBtn); } this.$popupContainer.prepend(this.$filter); @@ -1120,6 +1133,15 @@ event.preventDefault(); } + if (this.isFirefox() && this.options.includeFilterClearBtn) { + if (event.target.value) { + this.$filter.find(".multiselect-moz-clear-filter").show(); + } + else { + this.$filter.find(".multiselect-moz-clear-filter").hide(); + } + } + // This is useful to catch "keydown" events after the browser has updated the control. clearTimeout(this.searchTimeout); @@ -1772,6 +1794,17 @@ setAllSelectedText: function (allSelectedText) { this.options.allSelectedText = allSelectedText; this.updateButtonText(); + }, + + isFirefox: function () { + var firefoxIdentifier = 'firefox'; + var valueNotFoundIndex = -1; + + if (navigator && navigator.userAgent) { + return navigator.userAgent.toLocaleLowerCase().indexOf(firefoxIdentifier) > valueNotFoundIndex; + } + + return false; } }; diff --git a/dist/js/bootstrap-multiselect.min.js b/dist/js/bootstrap-multiselect.min.js index 4cb89f27..1532b690 100644 --- a/dist/js/bootstrap-multiselect.min.js +++ b/dist/js/bootstrap-multiselect.min.js @@ -1 +1 @@ -!function(root,factory){"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified("knockout")?define(["jquery","knockout"],factory):factory(root.jQuery,root.ko)}(this,(function($,ko){"use strict";function forEach(array,callback){for(var index=0;index').after(this.$container),this.options.onInitialized(this.$select,this.$container)}void 0!==ko&&ko.bindingHandlers&&!ko.bindingHandlers.multiselect&&(ko.bindingHandlers.multiselect={after:["options","value","selectedOptions","enable","disable"],init:function(element,valueAccessor,allBindings,viewModel,bindingContext){var $element=$(element),config=ko.toJS(valueAccessor());if($element.multiselect(config),allBindings.has("options")){var options=allBindings.get("options");ko.isObservable(options)&&ko.computed({read:function(){options(),setTimeout((function(){var ms=$element.data("multiselect");ms&&ms.updateOriginalOptions(),$element.multiselect("rebuild")}),1)},disposeWhenNodeIsRemoved:element})}if(allBindings.has("value")){var value=allBindings.get("value");ko.isObservable(value)&&ko.computed({read:function(){value(),setTimeout((function(){$element.multiselect("refresh")}),1)},disposeWhenNodeIsRemoved:element}).extend({rateLimit:100,notifyWhenChangesStop:!0})}if(allBindings.has("selectedOptions")){var selectedOptions=allBindings.get("selectedOptions");ko.isObservable(selectedOptions)&&ko.computed({read:function(){selectedOptions(),setTimeout((function(){$element.multiselect("refresh")}),1)},disposeWhenNodeIsRemoved:element}).extend({rateLimit:100,notifyWhenChangesStop:!0})}var setEnabled=function(enable){setTimeout((function(){enable?$element.multiselect("enable"):$element.multiselect("disable")}))};if(allBindings.has("enable")){var enable=allBindings.get("enable");ko.isObservable(enable)?ko.computed({read:function(){setEnabled(enable())},disposeWhenNodeIsRemoved:element}).extend({rateLimit:100,notifyWhenChangesStop:!0}):setEnabled(enable)}if(allBindings.has("disable")){var disable=allBindings.get("disable");ko.isObservable(disable)?ko.computed({read:function(){setEnabled(!disable())},disposeWhenNodeIsRemoved:element}).extend({rateLimit:100,notifyWhenChangesStop:!0}):setEnabled(!disable)}ko.utils.domNodeDisposal.addDisposeCallback(element,(function(){$element.multiselect("destroy")}))},update:function(element,valueAccessor,allBindings,viewModel,bindingContext){var $element=$(element),config=ko.toJS(valueAccessor());$element.multiselect("setOptions",config),$element.multiselect("rebuild")}}),Multiselect.prototype={defaults:{buttonText:function(options,select){if(this.disabledText.length>0&&(select.prop("disabled")||0==options.length&&this.disableIfEmpty))return this.disabledText;if(0===options.length)return this.nonSelectedText;if(this.allSelectedText&&options.length===$("option",$(select)).length&&1!==$("option",$(select)).length&&this.multiple)return this.selectAllNumber?this.allSelectedText+" ("+options.length+")":this.allSelectedText;if(0!=this.numberDisplayed&&options.length>this.numberDisplayed)return options.length+" "+this.nSelectedText;var selected="",delimiter=this.delimiterText;return options.each((function(){var label=void 0!==$(this).attr("label")?$(this).attr("label"):$(this).text();selected+=label+delimiter})),selected.substr(0,selected.length-this.delimiterText.length)},buttonTitle:function(options,select){if(0===options.length)return this.nonSelectedText;var selected="",delimiter=this.delimiterText;return options.each((function(){var label=void 0!==$(this).attr("label")?$(this).attr("label"):$(this).text();selected+=label+delimiter})),selected.substr(0,selected.length-this.delimiterText.length)},checkboxName:function(option){return!1},optionLabel:function(element){return $(element).attr("label")||$(element).text()},optionClass:function(element){return $(element).attr("class")||""},onChange:function(option,checked){},onDropdownShow:function(event){},onDropdownHide:function(event){},onDropdownShown:function(event){},onDropdownHidden:function(event){},onSelectAll:function(){},onDeselectAll:function(){},onInitialized:function($select,$container){},onFiltering:function($filter){},enableHTML:!1,buttonClass:"custom-select",inheritClass:!1,buttonWidth:"auto",buttonContainer:'
',dropRight:!1,dropUp:!1,selectedClass:"active",maxHeight:!1,includeSelectAllOption:!1,includeSelectAllIfMoreThan:0,selectAllText:" Select all",selectAllValue:"multiselect-all",selectAllName:!1,selectAllNumber:!0,selectAllJustVisible:!0,enableFiltering:!1,enableCaseInsensitiveFiltering:!1,enableFullValueFiltering:!1,enableClickableOptGroups:!1,enableCollapsibleOptGroups:!1,collapseOptGroupsByDefault:!1,filterPlaceholder:"Search",filterBehavior:"text",includeFilterClearBtn:!0,preventInputChangeEvent:!1,nonSelectedText:"None selected",nSelectedText:"selected",allSelectedText:"All selected",numberDisplayed:3,disableIfEmpty:!1,disabledText:"",delimiterText:", ",includeResetOption:!1,includeResetDivider:!1,resetText:"Reset",templates:{button:'',popupContainer:'',filter:'
',filterClearBtn:'
',option:'',divider:'',optionGroup:'',resetButton:'
'}},constructor:Multiselect,buildContainer:function(){this.$container=$(this.options.buttonContainer),this.$container.on("show.bs.dropdown",this.options.onDropdownShow),this.$container.on("hide.bs.dropdown",this.options.onDropdownHide),this.$container.on("shown.bs.dropdown",this.options.onDropdownShown),this.$container.on("hidden.bs.dropdown",this.options.onDropdownHidden)},buildButton:function(){this.$button=$(this.options.templates.button).addClass(this.options.buttonClass),this.$select.attr("class")&&this.options.inheritClass&&this.$button.addClass(this.$select.attr("class")),this.$select.prop("disabled")?this.disable():this.enable(),this.options.buttonWidth&&"auto"!==this.options.buttonWidth&&(this.$button.css({width:"100%",overflow:"hidden","text-overflow":"ellipsis"}),this.$container.css({width:this.options.buttonWidth}));var tabindex=this.$select.attr("tabindex");tabindex&&this.$button.attr("tabindex",tabindex),this.$container.prepend(this.$button)},buildDropdown:function(){this.$popupContainer=$(this.options.templates.popupContainer),this.options.dropRight?this.$container.addClass("dropright"):this.options.dropUp&&this.$container.addClass("dropup"),this.options.maxHeight&&this.$popupContainer.css({"max-height":this.options.maxHeight+"px","overflow-y":"auto","overflow-x":"hidden"}),this.$popupContainer.on("touchstart click",(function(e){e.stopPropagation()})),this.$container.append(this.$popupContainer)},buildDropdownOptions:function(){this.$select.children().each($.proxy((function(index,element){var $element=$(element),tag=$element.prop("tagName").toLowerCase();$element.prop("value")!==this.options.selectAllValue&&("optgroup"===tag?this.createOptgroup(element):"option"===tag&&("divider"===$element.data("role")?this.createDivider():this.createOptionValue(element)))}),this)),$(this.$popupContainer).off("change",'> *:not(.multiselect-group) input[type="checkbox"], > *:not(.multiselect-group) input[type="radio"]'),$(this.$popupContainer).on("change",'> *:not(.multiselect-group) input[type="checkbox"], > *:not(.multiselect-group) input[type="radio"]',$.proxy((function(event){var $target=$(event.target),checked=$target.prop("checked")||!1,isSelectAllOption=$target.val()===this.options.selectAllValue;this.options.selectedClass&&(checked?$target.closest(".multiselect-option").addClass(this.options.selectedClass):$target.closest(".multiselect-option").removeClass(this.options.selectedClass));var value=$target.val(),$option=this.getOptionByValue(value),$optionsNotThis=$("option",this.$select).not($option),$checkboxesNotThis=$("input",this.$container).not($target);if(isSelectAllOption?checked?this.selectAll(this.options.selectAllJustVisible,!0):this.deselectAll(this.options.selectAllJustVisible,!0):(checked?($option.prop("selected",!0),this.options.multiple?$option.prop("selected",!0):(this.options.selectedClass&&$($checkboxesNotThis).closest(".dropdown-item").removeClass(this.options.selectedClass),$($checkboxesNotThis).prop("checked",!1),$optionsNotThis.prop("selected",!1),this.$button.click()),"active"===this.options.selectedClass&&$optionsNotThis.closest(".dropdown-item").css("outline","")):$option.prop("selected",!1),this.options.onChange($option,checked),this.updateSelectAll(),this.options.enableClickableOptGroups&&this.options.multiple&&this.updateOptGroups()),this.$select.change(),this.updateButtonText(),this.options.preventInputChangeEvent)return!1}),this)),$(".multiselect-option",this.$popupContainer).off("mousedown"),$(".multiselect-option",this.$popupContainer).on("mousedown",(function(e){if(e.shiftKey)return!1})),$(this.$popupContainer).off("touchstart click",".multiselect-option, .multiselect-all, .multiselect-group"),$(this.$popupContainer).on("touchstart click",".multiselect-option, .multiselect-all, .multiselect-group",$.proxy((function(event){event.stopPropagation();var $target=$(event.target),$input;if(event.shiftKey&&this.options.multiple){$target.is("input")||(event.preventDefault(),($target=$target.closest(".multiselect-option").find("input")).prop("checked",!$target.prop("checked")));var checked=$target.prop("checked")||!1;if(null!==this.lastToggledInput&&this.lastToggledInput!==$target){var from=this.$popupContainer.find(".multiselect-option:visible").index($target.closest(".multiselect-option")),to=this.$popupContainer.find(".multiselect-option:visible").index(this.lastToggledInput.closest(".multiselect-option"));if(from>to){var tmp=to;to=from,from=tmp}++to;var range=this.$popupContainer.find(".multiselect-option:not(.multiselect-filter-hidden)").slice(from,to).find("input");range.prop("checked",checked),this.options.selectedClass&&range.closest(".multiselect-option").toggleClass(this.options.selectedClass,checked);for(var i=0,j=range.length;i0)$checkbox.prop("checked",!$checkbox.prop("checked")),$checkbox.change();else if(this.options.enableClickableOptGroups&&this.options.multiple&&!$target.hasClass("caret-container")){var groupItem=$target;groupItem.hasClass("multiselect-group")||(groupItem=$target.closest(".multiselect-group")),($checkbox=groupItem.find(".form-check-input")).length>0&&($checkbox.prop("checked",!$checkbox.prop("checked")),$checkbox.change())}event.preventDefault()}$target.closest(".multiselect-option").find("input[type='checkbox'], input[type='radio']").length>0?this.lastToggledInput=$target:this.lastToggledInput=null,$target.blur()}),this)),this.$container.off("keydown.multiselect").on("keydown.multiselect",$.proxy((function(event){if(!$('input[type="text"]',this.$container).is(":focus"))if(9===event.keyCode&&this.$container.hasClass("show"))this.$button.click();else{var $items=$(this.$container).find(".multiselect-option:not(.disabled), .multiselect-group:not(.disabled), .multiselect-all").filter(":visible");if(!$items.length)return;var index=$items.index($items.filter(":focus")),$current=$items.eq(index);if(32===event.keyCode){var $checkbox=$current.find("input");$checkbox.prop("checked",!$checkbox.prop("checked")),$checkbox.change(),event.preventDefault()}13===event.keyCode&&setTimeout((function(){$current.focus()}),0)}}),this)),this.options.enableClickableOptGroups&&this.options.multiple&&($(".multiselect-group input",this.$popupContainer).off("change"),$(".multiselect-group input",this.$popupContainer).on("change",$.proxy((function(event){event.stopPropagation();var $target,checked=$(event.target).prop("checked")||!1,$item=$(event.target).closest(".dropdown-item"),$group,$inputs=$item.nextUntil(".multiselect-group").not(".multiselect-filter-hidden").not(".disabled").find("input"),$options=[];this.options.selectedClass&&(checked?$item.addClass(this.options.selectedClass):$item.removeClass(this.options.selectedClass)),$.each($inputs,$.proxy((function(index,input){var $input=$(input),value=$input.val(),$option=this.getOptionByValue(value);checked?($input.prop("checked",!0),$input.closest(".dropdown-item").addClass(this.options.selectedClass),$option.prop("selected",!0)):($input.prop("checked",!1),$input.closest(".dropdown-item").removeClass(this.options.selectedClass),$option.prop("selected",!1)),$options.push(this.getOptionByValue(value))}),this)),this.options.onChange($options,checked),this.$select.change(),this.updateButtonText(),this.updateSelectAll()}),this))),this.options.enableCollapsibleOptGroups&&this.options.multiple&&($(".multiselect-group .caret-container",this.$popupContainer).off("click"),$(".multiselect-group .caret-container",this.$popupContainer).on("click",$.proxy((function(event){var $group,$inputs=$(event.target).closest(".multiselect-group").nextUntil(".multiselect-group").not(".multiselect-filter-hidden"),visible=!0;$inputs.each((function(){visible=visible&&!$(this).hasClass("multiselect-collapsible-hidden")})),visible?$inputs.hide().addClass("multiselect-collapsible-hidden"):$inputs.show().removeClass("multiselect-collapsible-hidden")}),this)))},createCheckbox:function($item,label,name,value,title,inputType){var $wrapper=$("");if($wrapper.addClass("form-check"),this.options.enableHTML&&$(label).length>0)$wrapper.append($(label));else{var $checkboxLabel=$('
+ + + + includeFilterClearBtn + + + +

+ If it is not desired to have a clear button for the search it can also be disabled. +

+
+ + +
+
+
+<script type="text/javascript">
+    $(document).ready(function() {
+        $('#example-includeFilterClearBtn').multiselect({
+            enableFiltering: true,
+            includeFilterClearBtn: false
+        });
+    });
+</script>
+
+
+ + + + enableCaseInsensitiveFiltering @@ -3460,12 +3563,11 @@

Templates

$('#example').multiselect({ templates: { button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span></button>', - ul: '<div class="multiselect-container dropdown-menu"></div>', - filter: '<div class="multiselect-item multiselect-filter"><div class="input-group input-group-sm p-1"><div class="input-group-prepend"><i class="input-group-text fas fa-search"></i></div><input class="form-control multiselect-search" type="text"></div></div>', - filterClearBtn: '<div class="input-group-append"><button class="multiselect-clear-filter input-group-text" type="button"><i class="fas fa-times"></i></button></div>', - li: '<a class="multiselect-option dropdown-item"></a>', + popupContainer: '<div class="multiselect-container dropdown-menu"></div>', + filter: '<div class="multiselect-filter d-flex align-items-center"><i class="fas fa-sm fa-search text-muted"></i><input type="search" class="multiselect-search form-control" /></div>', + option: '<a class="multiselect-option dropdown-item"></a>', divider: '<div class="multiselect-item dropdown-divider"></div>', - liGroup: '<a class="multiselect-item multiselect-group"></a>', + optionGroup: '<a class="multiselect-item multiselect-group"></a>', resetButton: '<div class="multiselect-reset text-center p-2"><a class="btn btn-sm btn-block btn-outline-secondary"></a></div>' } }); @@ -6790,6 +6892,80 @@

Templates

  • The template li was renamed to option
  • The template liGroup was renamed to optionGroup
  • + + Besides the refactoring of upgrading the multiselect to Bootstrap v4 also the filter controls were redesigned. + To keep the old design the following template can be used for filter: + +
    + + +
    +
    +
    +<script type="text/javascript">
    +$(document).ready(function() {
    +   $('#example-legacyFiltering').multiselect({
    +      enableFiltering: true,
    +      templates: {
    +         filter: '<div class="multiselect-filter"><div class="input-group input-group-sm p-1"><div class="input-group-prepend"><i class="input-group-text fas fa-search"></i></div><input class="form-control multiselect-search" type="text" /><div class="input-group-append"><button class="multiselect-clear-filter input-group-text" type="button"><i class="fas fa-times"></i></button></div></div></div>'
    +      }
    +   });
    +});
    +</script>
    +
    +
    + +

    + +

    Colors

    +

    + In Chrome checked checkboxes are highlighted in blue and also in Bootstrap v4 active dropdown items have a blue color. This led to the situation that checked checkboxes were almost not visible anymore. + Therefore the active color for dropdown items was changed a light grey. + If you would like to use the Bootstrap default color you can use the selectedClass option with the value multiselect-active-item-fallback: + +

    + + +
    +
    +
    +<script type="text/javascript">
    +$(document).ready(function() {
    +   $('#example-multiselect-fallback').multiselect({
    +      selectedClass: "active multiselect-active-item-fallback"
    +   });
    +});
    +</script>
    +
    +
    +

    Fonts

    diff --git a/tests/spec/bootstrap-multiselect.js b/tests/spec/bootstrap-multiselect.js index 4832cb75..427951ac 100644 --- a/tests/spec/bootstrap-multiselect.js +++ b/tests/spec/bootstrap-multiselect.js @@ -1448,6 +1448,24 @@ describe('Bootstrap Multiselect "Filter".', function() { }); }); + it('Should create filter.', function() { + expect($('#multiselect-container .multiselect-filter').length).toBe(1); + expect($('#multiselect-container .multiselect-filter input').length).toBe(1); + }); + }); + + describe('Should create legacy filter.', function() { + beforeEach(function() { + $select.multiselect({ + buttonContainer: '
    ', + enableFiltering: true, + templates: { + filter: '
    ' + }, + filterBehavior: 'value' + }); + }); + it('Should create filter.', function() { expect($('#multiselect-container .multiselect-filter').length).toBe(1); expect($('#multiselect-container .multiselect-filter input').length).toBe(1); @@ -1601,11 +1619,14 @@ describe('Bootstrap Multiselect "Filter".', function() { }); }); - describe('Should remove filter on clicking the clear button.', function() { + describe('Should remove filter on clicking the legacy clear button.', function() { beforeEach(function(done) { $select.multiselect({ buttonContainer: '
    ', enableFiltering: true, + templates: { + filter: '
    ' + }, filterBehavior: 'value', onFiltering: function() { done(); diff --git a/tests/spec/bootstrap-multiselect.min.js b/tests/spec/bootstrap-multiselect.min.js new file mode 100644 index 00000000..e38296e7 --- /dev/null +++ b/tests/spec/bootstrap-multiselect.min.js @@ -0,0 +1 @@ +describe('Bootstrap Multiselect "Core".',(function(){var onInitialized=!1;beforeEach((function(){for(var $select=$(''),i=1;i<100;i++){var $option=$('");i<10&&$option.prop("selected",!0),$select.append($option)}$("body").append($select),$select.multiselect({buttonContainer:'
    ',onInitialized:function($select){onInitialized=!0},checkboxName:function($option){return"value-"+$($option).attr("value")}})})),it("Should add the container after the select.",(function(){expect($("#multiselect-container").length).toBe(1)})),it("Should add the multiselect button.",(function(){expect($("#multiselect-container .multiselect").length).toBe(1)})),it("Should add the dropdown menu.",(function(){expect($("#multiselect-container .dropdown-menu").length).toBe(1)})),it("Should add an li element with checkbox and label for each option.",(function(){expect($("#multiselect-container .multiselect-option").length).toBe(99),expect($("#multiselect-container .form-check-label").length).toBe(99),expect($('#multiselect-container input[type="checkbox"]').length).toBe(99)})),it("Should preserve selected options.",(function(){expect($('#multiselect-container input[type="checkbox"]:checked').length).toBe(9),expect($("#multiselect option:selected").length).toBe(9)})),it("Should be able to select options by value.",(function(){$("#multiselect").multiselect("select","10"),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!0)})),it('Select method should handle "null" and "undefined" correctly.',(function(){expect($("#multiselect option:selected").length).toBe(9),$("#multiselect").multiselect("select",null),expect($("#multiselect option:selected").length).toBe(9),$("#multiselect").multiselect("select",void 0),expect($("#multiselect option:selected").length).toBe(9)})),it("Should be able to deselect options by value.",(function(){$("#multiselect").multiselect("select","10"),$("#multiselect").multiselect("deselect","10"),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!1)})),it('Deselect method should handle "null" and "undefined" correctly.',(function(){expect($("#multiselect option:selected").length).toBe(9),$("#multiselect").multiselect("deselect",null),expect($("#multiselect option:selected").length).toBe(9),$("#multiselect").multiselect("deselect",void 0),expect($("#multiselect option:selected").length).toBe(9)})),it("Should be able to select options using an array of values.",(function(){$("#multiselect").multiselect("select",["10","11"]),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="11"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="11"]').prop("checked")).toBe(!0)})),it("Should be able to deselect options using an array of values.",(function(){$("#multiselect").multiselect("select",["10","11"]),$("#multiselect").multiselect("deselect",["10","11"]),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="11"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="11"]').prop("checked")).toBe(!1)})),it("Should be able to disable the multiselect",(function(){$("#multiselect").multiselect("disable"),expect($("#multiselect").prop("disabled")).toBe(!0)})),it("Should be able to enable the multiselect",(function(){$("#multiselect").multiselect("disable"),$("#multiselect").multiselect("enable"),expect($("#multiselect").prop("disabled")).toBe(!1)})),it("Should be able to select all options.",(function(){$("#multiselect").multiselect("selectAll");for(var i=1;i<100;i++)expect($('#multiselect option[value="'+i.toString()+'"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="'+i.toString()+'"]').prop("checked")).toBe(!0)})),it("Should be able to deselect all options.",(function(){$("#multiselect").multiselect("selectAll");for(var i=1;i<100;i++)expect($('#multiselect option[value="'+i.toString()+'"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="'+i.toString()+'"]').prop("checked")).toBe(!0);$("#multiselect").multiselect("deselectAll");for(var i=1;i<100;i++)expect($('#multiselect option[value="'+i.toString()+'"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="'+i.toString()+'"]').prop("checked")).toBe(!1)})),it("Should update the checkboxes according to the selected options after using refresh.",(function(){for(var i=10;i<20;i++)$('#multiselect option[value="'+i+'"]').prop("selected",!0);expect($("#multiselect option:selected").length).toBe(19),expect($('#multiselect-container input[type="checkbox"]:checked').length).toBe(9),$("#multiselect").multiselect("refresh"),expect($('#multiselect-container input[type="checkbox"]:checked').length).toBe(19);for(var i=10;i<20;i++)expect($('#multiselect option[value="'+i+'"]').prop("selected")).toBe(!0)})),it("Should remove container, button and ul after destroy.",(function(){$("#multiselect").multiselect("destroy"),expect($("#multiselect-container.multiselect-container").length).toBe(0),expect($("#multiselect-container .multiselect").length).toBe(0),expect($("#multiselect-container .dropdown-menu").length).toBe(0)})),it("Should select an option when checkbox is changed (change event).",(function(){$('#multiselect-container .multiselect-option input[value="10"]').prop("checked",!0),$('#multiselect-container .multiselect-option input[value="10"]').trigger("change"),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!0)})),it("Should deselect an option when checkbox is changed (change event).",(function(){$('#multiselect-container .multiselect-option input[value="10"]').prop("checked",!0),$('#multiselect-container .multiselect-option input[value="10"]').trigger("change"),$('#multiselect-container .multiselect-option input[value="10"]').prop("checked",!1),$('#multiselect-container .multiselect-option input[value="10"]').trigger("change"),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!1)})),it("Should select an option when checkbox is clicked.",(function(){$('#multiselect-container .multiselect-option input[value="10"]').click(),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!0)})),it("Should deselect an option when checkbox is clicked.",(function(){$('#multiselect-container .multiselect-option input[value="10"]').click(),$('#multiselect-container .multiselect-option input[value="10"]').click(),expect($('#multiselect-container input[value="10"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="10"]').prop("selected")).toBe(!1)})),it("Should trigger onInitialized.",(function(){expect(onInitialized).toBe(!0)})),it("Should correctly apply checkboxName.",(function(){$("#multiselect-container input").each((function(){expect($(this).attr("name")).toBe("value-"+$(this).attr("value"))}))})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Multiple Multiselects".',(function(){var multiselects=["one","two","three"],onSelectAllTriggered=0,onDeselectAllTriggered=0,onChangeFired=0;beforeEach((function(){onSelectAllTriggered=0,onDeselectAllTriggered=0,onChangeFired=0;for(var m=0;m<3;m++){for(var $select=$(''),i=1;i<10;i++)$select.append('");$("body").append($select),$select.multiselect({buttonContainer:'
    ',includeSelectAllOption:!0,selectAllValue:"multiselect-all",onSelectAll:function(){onSelectAllTriggered++},onDeselectAll:function(){onDeselectAllTriggered++},onChange:function(option,checked){onChangeFired++}})}})),it("Should initialize all multiselects.",(function(){expect($(".multiselect").length).toBe(3);for(var m=0;m<3;m++)expect($("#multiselect-"+multiselects[m]).length).toBe(1),expect($("#multiselect-container-"+multiselects[m]).length).toBe(1),expect($("#multiselect-container-"+multiselects[m]+" .multiselect").length).toBe(1),expect($("#multiselect-container-"+multiselects[m]+" .dropdown-menu").length).toBe(1),expect($("#multiselect-container-"+multiselects[m]+" .multiselect-option").length).toBe(9),expect($("#multiselect-container-"+multiselects[m]+" .multiselect-all").length).toBe(1),expect($("#multiselect-container-"+multiselects[m]+" .form-check-label").length).toBe(10),expect($("#multiselect-container-"+multiselects[m]+' input[type="checkbox"]').length).toBe(10)})),it("Should not select/deselect options in other multiselects.",(function(){for(var m=0;m<3;m++){for(var i=1;i<10;i++){$("#multiselect-container-"+multiselects[m]+' input[value="'+i+'"]').click(),expect($("#multiselect-container-"+multiselects[m]+' input[value!="multiselect-all"]:checked').length).toBe(i);for(var n=0;n<3;n++)m!=n&&expect($("#multiselect-container-"+multiselects[n]+' input[value!="multiselect-all"]:checked').length).toBe(0)}for(var i=9;i>=1;i--){$("#multiselect-container-"+multiselects[m]+' input[value="'+i+'"]').click(),expect($("#multiselect-container-"+multiselects[m]+' input[value!="multiselect-all"]:checked').length).toBe(i-1);for(var n=0;n<3;n++)m!=n&&expect($("#multiselect-container-"+multiselects[n]+' input[value!="multiselect-all"]:checked').length).toBe(0)}}})),it("Should not trigger onChange in other multiselects.",(function(){for(var m=0;m<3;m++)for(var i=1;i<10;i++)$("#multiselect-container-"+multiselects[m]+' input[value="'+i+'"]').click(),expect(onChangeFired).toBe(1),onChangeFired=0})),it("Should not select all/deselect all options in other multiselects.",(function(){for(var m=0;m<3;m++){$("#multiselect-container-"+multiselects[m]+' input[value="multiselect-all"]').click(),expect($("#multiselect-container-"+multiselects[m]+' input[value!="multiselect-all"]:checked').length).toBe(9);for(var n=0;n<3;n++)n!=m&&(expect($("#multiselect-container-"+multiselects[n]+' input[value!="multiselect-all"]:checked').length).toBe(0),expect($("#multiselect-container-"+multiselects[n]+' input[value="multiselect-all"]:checked').length).toBe(0));$("#multiselect-container-"+multiselects[m]+' input[value="multiselect-all"]').click(),expect($("#multiselect-container-"+multiselects[m]+' input[value!="multiselect-all"]:checked').length).toBe(0)}})),it("Should not trigger onSelectAll in other multiselects.",(function(){for(var m=0;m<3;m++)$("#multiselect-container-"+multiselects[m]+' input[value="multiselect-all"]').click(),expect(onSelectAllTriggered).toBe(1),expect(onChangeFired).toBe(0),$("#multiselect-container-"+multiselects[m]+' input[value="multiselect-all"]').click(),onSelectAllTriggered=0})),it("Should not trigger onDeselectAll in other multiselects",(function(){for(var m=0;m<3;m++)$("#multiselect-container-"+multiselects[m]+' input[value="multiselect-all"]').click(),$("#multiselect-container-"+multiselects[m]+' input[value="multiselect-all"]').click(),expect(onSelectAllTriggered).toBe(1),expect(onDeselectAllTriggered).toBe(1),expect(onChangeFired).toBe(0),onSelectAllTriggered=0,onDeselectAllTriggered=0})),afterEach((function(){for(var m=0;m<3;m++)$("#multiselect-"+multiselects[m]).multiselect("destroy"),$("#multiselect-"+multiselects[m]).remove()}))})),describe('Bootstrap Multiselect "Single Selection".',(function(){beforeEach((function(){for(var $select=$(''),i=1;i<100;i++)$select.append('");$("body").append($select),$select.multiselect({buttonContainer:'
    '})})),it("Should create radio buttons instead of checkboxes.",(function(){expect($('#multiselect-container input[type="radio"]').length).toBe(99),expect($('#multiselect-container input[type="checkbox"]').length).toBe(0),expect($("#multiselect option:selected").length).toBe(1)})),it("Only one option at a time can be selected.",(function(){expect($("#multiselect option:selected").length).toBe(1);var i=0;$("#multiselect-container input").each((function(){0===i?(expect($(this).prop("checked")).toBe(!0),i++):(expect($(this).prop("checked")).toBe(!1),$(this).click(),expect($("#multiselect option:selected").length).toBe(1),expect($(this).prop("checked")).toBe(!0),i++)}))})),it("Deselect all should work.",(function(){expect($("#multiselect option:selected").length).toBe(1)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Individual Configuration Options".',(function(){describe("disableIfEmpty.",(function(){var $select=null;beforeEach((function(){$select=$(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',disableIfEmpty:!0})})),it("Should disable button if emppty.",(function(){expect($("#multiselect-container button").prop("disabled")).toBe(!0)})),it("Should still be disabled after invoking rebuild.",(function(){$select.multiselect("rebuild"),expect($("#multiselect-container button").prop("disabled")).toBe(!0)})),it("Should not be disabled after invoking rebuild after adding options.",(function(){$select.append(''),$select.multiselect("rebuild"),expect($("#multiselect-container button").prop("disabled")).toBe(!1)})),it("Should not be disabled after rebuilding with more options after invoking destroy.",(function(){$select.append(''),$select.multiselect("destroy"),$select.multiselect({buttonContainer:'
    ',disableIfEmpty:!0}),expect($("#multiselect-container button").prop("disabled")).toBe(!1)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))}))})),describe('Bootstrap Multiselect "individual Methods".',(function(){describe('Method "clearSelection" should clear selection in multiple mode.',(function(){beforeEach((function(){var $select=$('');$select.append(''),$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    '})})),it('Method "clearSelection" should clear selection.',(function(){$('#multiselect-container input[value="value-1"]').click(),$('#multiselect-container input[value="value-2"]').click(),expect($("#multiselect-container input:checked").length).toBe(2),expect($("#multiselect option:selected").length).toBe(2),$("#multiselect").multiselect("clearSelection"),expect($("#multiselect-container input:checked").length).toBe(0),expect($("#multiselect option:selected").length).toBe(0)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Method "clearSelection" should correctly update select all.',(function(){beforeEach((function(){var $select=$('');$select.append(''),$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',includeSelectAllOption:!0,selectAllValue:"multiselect-all"})})),it('Method "clearSelection" should clear selection.',(function(){$('#multiselect-container input[value="multiselect-all"]').click(),expect($("#multiselect-container input:checked").length).toBe(4),expect($("#multiselect option:selected").length).toBe(3),$("#multiselect").multiselect("clearSelection"),expect($("#multiselect-container input:checked").length).toBe(0),expect($("#multiselect option:selected").length).toBe(0)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Method "clearSelection" should clear selection in single mode.',(function(){beforeEach((function(){var $select=$('');$select.append(''),$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    '})})),it('Method "clearSelection" is NOT able to clear selection.',(function(){$('#multiselect-container input[value="value-2"]').click(),expect($("#multiselect-container input:checked").length).toBe(1),expect($("#multiselect option:selected").length).toBe(1),$("#multiselect").multiselect("clearSelection"),expect($("#multiselect-container input:checked").length).toBe(1),expect($("#multiselect option:selected").length).toBe(1)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))}))})),describe('Bootstrap Multiselect "Clickable Optgroups"',(function(){var fired=0;beforeEach((function(){for(var $select=$(''),i=1;i<11;i++){for(var $optgroup=$(''),j=1;j<11;j++)1==i?$optgroup.append('"):$optgroup.append('");$select.append($optgroup)}$("body").append($select),fired=0,$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0,numberDisplayed:10,onChange:function(option,checked){fired++}})})),it("Should correctly create inputs for optgroups.",(function(){expect($("#multiselect-container .multiselect-group").length).toBe(10),expect($("#multiselect-container .multiselect-group input").length).toBe(10),$("#multiselect-container .multiselect-group").each((function(){expect($("input",$(this).nextUntil(".multiselect-group")).length).toBe(10)}))})),it("Groups should be clickable and correctly initialized.",(function(){expect($("#multiselect option:selected").length).toBe(10),expect(fired).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){0==i?($(".form-check-label",$(this)).click(),expect($("option:selected",$("#multiselect optgroup")[i]).length).toBe(0),expect($("#multiselect option:selected").length).toBe(0),$(".form-check-label",$(this)).click(),expect($("option:selected",$("#multiselect optgroup")[i]).length).toBe(10),expect($("#multiselect option:selected").length).toBe(10)):($(".form-check-label",$(this)).click(),expect($("option:selected",$("#multiselect optgroup")[i]).length).toBe(10),expect($("#multiselect option:selected").length).toBe(20),$(".form-check-label",$(this)).click()),i++}))})),it("Clickable groups should fire onChange only once.",(function(){expect($("#multiselect option:selected").length).toBe(10),expect(fired).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect(fired).toBe(1),fired=0,$(".form-check-label",$(this)).click(),expect(fired).toBe(1),fired=0,i++}))})),it("Clickable groups should fire change only once",(function(){expect($("#multiselect option:selected").length).toBe(10);var changed=0;$("#multiselect").on("change",(function(){changed++})),$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect(changed).toBe(1),changed=0,$(".form-check-label",$(this)).click(),expect(changed).toBe(1),changed=0})),fired=0})),it("Should update button text.",(function(){expect($("#multiselect option:selected").length).toBe(10),expect(fired).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){if(0==i){var text="";$("option:selected",$("#multiselect optgroup")[i]).each((function(){text+=$(this).text()+", "})),text=text.substr(0,text.length-2),expect($("#multiselect-container .multiselect-selected-text").text()).toBe(text),$(".form-check-label",$(this)).click()}else{$(".form-check-label",$(this)).click();var text="";$("option:selected",$("#multiselect optgroup")[i]).each((function(){text+=$(this).text()+", "})),text=text.substr(0,text.length-2),expect($("#multiselect-container .multiselect-selected-text").text()).toBe(text),$(".form-check-label",$(this)).click()}i++}))})),it("Should be updated by clicking corresponding options.",(function(){for(var i=1;i<10;i++){expect($("option:selected",$("#multiselect optgroup")[0]).length).toBe(10),expect($("#multiselect option:selected").length).toBe(10);var $group=$($("#multiselect-container .multiselect-group")[i]),$optGroup=$($("#multiselect optgroup")[i]);$group.nextUntil(".multiselect-group").each((function(){var $input=$("input",this);$input.click(),expect($input.prop("checked")).toBe(!0)})),expect($("option:selected",$optGroup).length).toBe(10),expect($("#multiselect option:selected").length).toBe(20),expect($("input",$group).prop("checked")).toBe(!0),$group.nextUntil(".multiselect-group").each((function(){var $input=$("input",this);$input.click(),expect($input.prop("checked")).toBe(!1)})),expect($("#multiselect option:selected").length).toBe(10),expect($("input",$group).prop("checked")).toBe(!1)}})),it("Should be updated through select/deselect.",(function(){for(var values=[],i=1;i<11;i++)values.push("1-"+i);var $group=$("#multiselect-container .multiselect-group")[0];$("#multiselect").multiselect("deselect",values),expect($("input",$group).prop("checked")).toBe(!1),$("#multiselect").multiselect("select",values),expect($("input",$group).prop("checked")).toBe(!0)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Collapsible Optgroups"',(function(){var fired=0;beforeEach((function(){for(var $select=$(''),i=1;i<11;i++){for(var $optgroup=$(''),j=1;j<11;j++)$optgroup.append('");$select.append($optgroup)}$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableCollapsibleOptGroups:!0,onChange:function(option,checked){fired++}})})),it("Should correctly create headers for optgroups.",(function(){expect($("#multiselect-container .multiselect-group").length).toBe(10),$("#multiselect-container .multiselect-group").each((function(){expect($("input",$(this).nextUntil(".multiselect-group")).length).toBe(10)}))})),it("Groups should not be clickable.",(function(){expect($("#multiselect option:selected").length).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect($("option:selected",$("#multiselect optgroup")[i]).length).toBe(0),expect($("#multiselect option:selected").length).toBe(0),$(".form-check-label",$(this)).click(),i++}))})),it("Should be collapsible.",(function(){var $group=$("#multiselect-container .multiselect-group:first"),$options,$options;$(".caret-container",$group).click(),($options=$group.nextUntil(".multiselect-group")).each((function(){expect($(this).hasClass("multiselect-collapsible-hidden")).toBe(!0),expect($(this).hasClass("multiselect-collapsible-hidden")).toBe($(this).is(":hidden"))})),$(".caret-container",$group).click(),($options=$group.nextUntil("li.multiselect-group")).each((function(){expect($(this).hasClass("multiselect-collapsible-hidden")).toBe(!1),expect($(this).hasClass("multiselect-collapsible-hidden")).toBe($(this).is(":hidden"))}))})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Clickable+Collapsible Optgroups"',(function(){var fired=0;beforeEach((function(){for(var $select=$(''),i=1;i<11;i++){for(var $optgroup=$(''),j=1;j<11;j++)$optgroup.append('");$select.append($optgroup)}$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0,enableCollapsibleOptGroups:!0,onChange:function(option,checked){fired++}})})),it("Should correctly create inputs for optgroups.",(function(){expect($("#multiselect-container .multiselect-group").length).toBe(10),expect($("#multiselect-container .multiselect-group input").length).toBe(10),$("#multiselect-container .multiselect-group").each((function(){expect($("input",$(this).nextUntil(".multiselect-group")).length).toBe(10)}))})),it("Groups should be clickable.",(function(){expect($("#multiselect option:selected").length).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect($("option:selected",$("#multiselect optgroup")[i]).length).toBe(10),expect($("#multiselect option:selected").length).toBe(10),$(".form-check-label",$(this)).click(),i++}))})),it("Clickable groups should fire onChange only once.",(function(){expect($("#multiselect option:selected").length).toBe(0),fired=0,expect(fired).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect(fired).toBe(1),fired=0,$(".form-check-label",$(this)).click(),expect(fired).toBe(1),fired=0,i++}))})),it("Should be collapsible.",(function(){var $group=$("#multiselect-container .multiselect-group:first"),$lis,$lis;$(".caret-container",$group).click(),($lis=$group.nextUntil(".multiselect-group")).each((function(){expect($(this).hasClass("multiselect-collapsible-hidden")).toBe(!0),expect($(this).hasClass("multiselect-collapsible-hidden")).toBe($(this).is(":hidden"))})),$(".caret-container",$group).click(),($lis=$group.nextUntil(".multiselect-group")).each((function(){expect($(this).hasClass("multiselect-collapsible-hidden")).toBe(!1),expect($(this).hasClass("multiselect-collapsible-hidden")).toBe($(this).is(":hidden"))}))})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"',(function(){var fired=0;beforeEach((function(){for(var $select=$(''),i=1;i<11;i++){for(var $optgroup=$(''),j=1;j<11;j++)$optgroup.append('");$select.append($optgroup)}$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0,enableCollapsibleOptGroups:!0,includeSelectAllOption:!0,selectAllValue:"multiselect-all"})})),it("Should NOT handle option groups differently, i.e. not set class to active.",(function(){var $groups,$lis;$('#multiselect-container input[value="multiselect-all"]').click(),$("#multiselect-container .multiselect-group").each((function(){expect($(this).hasClass("active")).toBe(!0)})),$("#multiselect-container .multiselect-option:not(.multiselect-group)").each((function(){expect($(this).hasClass("active")).toBe(!0)}))})),it("Should select all options (including option groups).",(function(){var $options;$('#multiselect-container input[value="multiselect-all"]').click(),$("#multiselect-container .multiselect-option").each((function(){expect($("input",this).prop("checked")).toBe(!0)}))})),it("Should automatically update select all.",(function(){var i=0;$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect($("option:selected",$("#multiselect optgroup")[i]).length).toBe(10),expect($("#multiselect option:selected").length).toBe(10*(i+1)),i++})),expect($('#multiselect-container .multiselect-all input[value="multiselect-all"]').prop("checked")).toBe(!0)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Dataprovider"',(function(){beforeEach((function(){var $select=$('');$("body").append($select),$select.multiselect({buttonContainer:'
    '})}));var options=[{label:"Option 1",value:"1",selected:!0,title:"Option 1 Title"},{label:"Option 2",value:"2",title:"Option 2 Title"},{label:"Option 3",value:"3",selected:!0,title:"Option 3 Title"},{label:"Option 4",value:"4",title:"Option 4 Title"},{label:"Option 5",value:"5",title:"Option 5 Title"},{label:"Option 6",value:"6",title:"Option 6 Title"}],options_attributes=[{label:"Option 1",value:"1",attributes:{"some-attribute":"test"}}];it("Should be able to add options.",(function(){$("#multiselect").multiselect("dataprovider",options),expect($("#multiselect option").length).toBe(6),expect($("#multiselect-container input").length).toBe(6),expect($('#multiselect option[value="1"]').length).toBe(1),expect($('#multiselect option[value="1"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="1"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="2"]').length).toBe(1),expect($('#multiselect option[value="2"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="2"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="3"]').length).toBe(1),expect($('#multiselect option[value="3"]').prop("selected")).toBe(!0),expect($('#multiselect-container input[value="3"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="4"]').length).toBe(1),expect($('#multiselect option[value="4"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="4"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="5"]').length).toBe(1),expect($('#multiselect option[value="5"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="5"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="6"]').length).toBe(1),expect($('#multiselect option[value="6"]').prop("selected")).toBe(!1),expect($('#multiselect-container input[value="6"]').prop("checked")).toBe(!1)})),it("Should be able to define title.",(function(){$("#multiselect").multiselect("dataprovider",options),expect($('#multiselect option[value="1"]').attr("title")).toBe("Option 1 Title"),expect($('#multiselect option[value="2"]').attr("title")).toBe("Option 2 Title"),expect($('#multiselect option[value="3"]').attr("title")).toBe("Option 3 Title"),expect($('#multiselect option[value="4"]').attr("title")).toBe("Option 4 Title"),expect($('#multiselect option[value="5"]').attr("title")).toBe("Option 5 Title"),expect($('#multiselect option[value="6"]').attr("title")).toBe("Option 6 Title"),expect($('#multiselect-container input[value="1"]').closest(".multiselect-option").attr("title")).toBe("Option 1 Title"),expect($('#multiselect-container input[value="2"]').closest(".multiselect-option").attr("title")).toBe("Option 2 Title"),expect($('#multiselect-container input[value="3"]').closest(".multiselect-option").attr("title")).toBe("Option 3 Title"),expect($('#multiselect-container input[value="4"]').closest(".multiselect-option").attr("title")).toBe("Option 4 Title"),expect($('#multiselect-container input[value="5"]').closest(".multiselect-option").attr("title")).toBe("Option 5 Title"),expect($('#multiselect-container input[value="6"]').closest(".multiselect-option").attr("title")).toBe("Option 6 Title")})),it("Should be able to define data attributes.",(function(){$("#multiselect").multiselect("dataprovider",options_attributes),expect($('#multiselect option[value="1"]').attr("value")).toBe("1"),expect($('#multiselect option[value="1"]').attr("data-some-attribute")).toBe("test")}));var optgroups=[{label:"Group 1",children:[{label:"Option 1.1",value:"1-1"},{label:"Option 1.2",value:"1-2"},{label:"Option 1.3",value:"1-3"}]},{label:"Group 2",children:[{label:"Option 2.1",value:"1"},{label:"Option 2.2",value:"2"},{label:"Option 2.3",value:"3"}]}];it("Should be able to handle optgroups.",(function(){$("#multiselect").multiselect("dataprovider",optgroups),expect($("#multiselect optgroup").length).toBe(2),expect($("#multiselect option").length).toBe(6),expect($("#multiselect-container input").length).toBe(6),expect($('#multiselect optgroup[label="Group 1"] option').length).toBe(3),expect($('#multiselect optgroup[label="Group 2"] option').length).toBe(3)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Select All".',(function(){var onSelectAllTriggered=!1,onDeselectAllTriggered=!1,fired=0;beforeEach((function(){onSelectAllTriggered=!1,onDeselectAllTriggered=!1,fired=0;for(var $select=$(''),i=1;i<100;i++)$select.append('');$("body").append($select),$select.multiselect({buttonContainer:'
    ',includeSelectAllOption:!0,selectAllValue:"multiselect-all",onSelectAll:function(){onSelectAllTriggered=!0},onDeselectAll:function(){onDeselectAllTriggered=!0},onChange:function(option,checked){fired++}})})),it("Should not add an additional option to the select.",(function(){expect($('#multiselect option[value="multiselect-all"]').length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').length).toBe(1),expect($("#multiselect option").length).toBe(99),expect($("#multiselect-container input").length).toBe(100)})),it('Should update the select all when all options are selected by the "select" method.',(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1);for(var i=1;i<100;i++)$("#multiselect").multiselect("select",i.toString()),expect($('#multiselect option[value="'+i.toString()+'"]').prop("selected")).toBe(!0);expect($("#multiselect option:selected").length).toBe(99),expect($("#multiselect-container input").length).toBe(100),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0)})),it('Should update the select all when all options are deselected by the "deselect" method (first all options are selected as before).',(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1);for(var i=1;i<100;i++)$("#multiselect").multiselect("select",i.toString());expect($("#multiselect option:selected").length).toBe(99),expect($("#multiselect-container input:checked").length).toBe(100),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0);for(var i=1;i<100;i++)$("#multiselect").multiselect("deselect",i.toString());expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1)})),it("Should update the select all option when all options are selected by the change event.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').prop("checked",!0),$('#multiselect-container input[value!="multiselect-all"]').trigger("change"),expect($('#multiselect option:selected[value!="multiselect-all"]').length).toBe(99),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0)})),it("Should update the select all option when all options are deselected by the change event.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').prop("checked",!0),$('#multiselect-container input[value!="multiselect-all"]').trigger("change"),expect($('#multiselect option:selected[value!="multiselect-all"]').length).toBe(99),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0),$('#multiselect-container input[value!="multiselect-all"]').prop("checked",!1),$('#multiselect-container input[value!="multiselect-all"]').trigger("change"),expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1)})),it("Should update the select all option when all options are selected by the click event.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').click(),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0)})),it("Should update the select all option when all options are deselected by the click event.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').click(),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0),$('#multiselect-container input[value!="multiselect-all"]').click(),expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1)})),it("Should trigger onSelectAll/onDeselectAll when changing the select all option.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value="multiselect-all"]').prop("checked",!0),$('#multiselect-container input[value="multiselect-all"]').trigger("change"),expect($("#multiselect option:selected").length).toBe(99),expect($("#multiselect-container input:checked").length).toBe(100),expect(onSelectAllTriggered).toBe(!0),$('#multiselect-container input[value="multiselect-all"]').prop("checked",!1),$('#multiselect-container input[value="multiselect-all"]').trigger("change"),expect($('#multiselect option:selected[value!="multiselect-all"]').length).toBe(0),expect($("#multiselect option:selected").length).toBe(0),expect(onDeselectAllTriggered).toBe(!0)})),it("Should trigger the onSelectAll/onDeselectAll when clicking the select all option.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value="multiselect-all"]').click(),expect($("#multiselect option:selected").length).toBe(99),expect($("#multiselect-container input:checked").length).toBe(100),expect(onSelectAllTriggered).toBe(!0),$('#multiselect-container input[value="multiselect-all"]').click(),expect($('#multiselect option:selected[value!="multiselect-all"]').length).toBe(0),expect($("#multiselect option:selected").length).toBe(0),expect(onDeselectAllTriggered).toBe(!0)})),it("Should NOT trigger onSelectAll/onDeselectAll based on the change event.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').prop("checked",!0),$('#multiselect-container input[value!="multiselect-all"]').trigger("change"),expect($('#multiselect option:selected[value!="multiselect-all"]').length).toBe(99),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0),expect(onSelectAllTriggered).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').prop("checked",!1),$('#multiselect-container input[value!="multiselect-all"]').trigger("change"),expect($('#multiselect option:selected[value!="multiselect-all"]').length).toBe(0),expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),expect(onDeselectAllTriggered).toBe(!1)})),it("Should NOT trigger onSelectAll/onDeselectAll based on the click event.",(function(){expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').click(),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!0),expect(onSelectAllTriggered).toBe(!1),$('#multiselect-container input[value!="multiselect-all"]').click(),expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="multiselect-all"]').prop("checked")).toBe(!1),expect(onDeselectAllTriggered).toBe(!1)})),it("Should trigger onSelectAll/onDeselectAll on function call.",(function(){$("#multiselect").multiselect("selectAll",!0,!0),expect(onSelectAllTriggered).toBe(!0),$("#multiselect").multiselect("deselectAll",!0,!0),expect(onDeselectAllTriggered).toBe(!0)})),it("Should NOT trigger onSelectAll on initialization but initialize the select all option correctly.",(function(){for(var $select=$(''),i=1;i<10;i++)$select.append('');$("body").append($select),onSelectAllTriggered=!1,$select.multiselect({buttonContainer:'
    ',includeSelectAllOption:!0,selectAllValue:"multiselect-all",onSelectAll:function(){onSelectAllTriggered=!0}}),expect($('#multiselect-onSelectAll-container input[value="multiselect-all"]').prop("checked")).toBe(!0),expect(onSelectAllTriggered).toBe(!1),$("#multiselect-onSelectAll").multiselect("destroy"),$("#multiselect-onSelectAll").remove()})),it("Should NOT trigger onDeselectAll on initialization but initialize the select all option correctly.",(function(){for(var $select=$(''),i=1;i<10;i++)$select.append('');$("body").append($select),onDeselectAllTriggered=!1,$select.multiselect({buttonContainer:'
    ',includeSelectAllOption:!0,selectAllValue:"multiselect-all",onDeselectAll:function(){onDeselectAllTriggered=!0}}),expect($('#multiselect-onDeselectAll-container input[value="multiselect-all"]').prop("checked")).toBe(!1),expect(onDeselectAllTriggered).toBe(!1),$("#multiselect-onDeselectAll").multiselect("destroy"),$("#multiselect-onDeselectAll").remove()})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Filter".',(function(){var $select=null;beforeEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove(),$select=$('');for(var i=1;i<10;i++)$select.append('");$("body").append($select)})),describe("Should create filter.",(function(){beforeEach((function(){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value"})})),it("Should create filter.",(function(){expect($("#multiselect-container .multiselect-filter").length).toBe(1),expect($("#multiselect-container .multiselect-filter input").length).toBe(1)}))})),describe("Should create legacy filter.",(function(){beforeEach((function(){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,templates:{filter:'
    '},filterBehavior:"value"})})),it("Should create filter.",(function(){expect($("#multiselect-container .multiselect-filter").length).toBe(1),expect($("#multiselect-container .multiselect-filter input").length).toBe(1),expect($("#multiselect-container .multiselect-filter .multiselect-clear-filter").length).toBe(1)}))})),describe("Should filter elements by value.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should filter elements.",(function(){for(var i=1;i<10;i++)9!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!1,i)}))})),describe("Should filter elements by value only.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("Option").trigger("keydown")})),it("Should filter elements.",(function(){for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i)}))})),describe("Should filter elements by text.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"text",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("Option 9").trigger("keydown")})),it("Should filter elements.",(function(){for(var i=1;i<10;i++)9!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!1,i)}))})),describe("Should filter elements by text only.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"text",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("value").trigger("keydown")})),it("Should filter elements.",(function(){for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i)}))})),describe("Should filter elements by text and value - text.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"both",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("Option 9").trigger("keydown")})),it("Should filter elements.",(function(){for(var i=1;i<10;i++)9!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!1,i)}))})),describe("Should filter elements by text and value - value.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"both",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should filter elements.",(function(){for(var i=1;i<10;i++)9!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!1,i)}))})),describe("Should remove filter on clicking the legacy clear button.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,templates:{filter:'
    '},filterBehavior:"value",onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should remove filter.",(function(){for(var i=1;i<10;i++)9!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!0,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!1,i);$("#multiselect-container .multiselect-filter .multiselect-clear-filter").click();for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').closest(".multiselect-option").hasClass("multiselect-filter-hidden")).toBe(!1,i)}))})),describe("Filtering and removing the filter should not alter selection.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",onFiltering:function(){done()}}),$('#multiselect-container .multiselect-option input[value="value-1"]').click(),$('#multiselect-container .multiselect-option input[value="value-9"]').click();for(var i=1;i<10;i++)9!=i&&1!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should not alter selection.",(function(){for(var i=1;i<10;i++)9!=i&&1!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i);$("#multiselect-container .multiselect-filter .multiselect-clear-filter").click();for(var i=1;i<10;i++)9!=i&&1!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i)}))})),describe("Select method should select both hidden and visible options.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",onFiltering:function(){done()}});for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should not alter selection.",(function(){$("#multiselect").multiselect("select","value-1"),expect($('#multiselect-container .multiselect-option input[value="value-1"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="value-1"]').prop("selected")).toBe(!0),$("#multiselect").multiselect("select","value-9"),expect($('#multiselect-container .multiselect-option input[value="value-9"]').prop("checked")).toBe(!0),expect($('#multiselect option[value="value-9"]').prop("selected")).toBe(!0)}))})),describe("Deselect method should select both hidden and visible options.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",onFiltering:function(){done()}}),$('#multiselect-container .multiselect-option input[value="value-9"]').click(),$('#multiselect-container .multiselect-option input[value="value-1"]').click();for(var i=1;i<10;i++)9!=i&&1!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should not alter selection.",(function(){$("#multiselect").multiselect("deselect","value-1"),expect($('#multiselect-container .multiselect-option input[value="value-1"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="value-1"]').prop("selected")).toBe(!1),$("#multiselect").multiselect("deselect","value-9"),expect($('#multiselect-container .multiselect-option input[value="value-9"]').prop("checked")).toBe(!1),expect($('#multiselect option[value="value-9"]').prop("selected")).toBe(!1)}))})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Select All+Filter+selectAllJustVisible".',(function(){var $select=null;beforeEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove(),$select=$('');for(var i=1;i<10;i++)$select.append('");$("body").append($select)})),describe("Should select only visible options if selectAllJustVisible is true.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",includeSelectAllOption:!0,selectAllJustVisible:!0,selectAllValue:"multiselect-all",onFiltering:function(){done()}});for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should select one option.",(function(){$('#multiselect-container .multiselect-all input[value="multiselect-all"]').click();for(var i=1;i<10;i++)9!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i)}))})),describe("Should deselect only visible options if selectAllJustVisible is true.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",includeSelectAllOption:!0,selectAllJustVisible:!0,selectAllValue:"multiselect-all",onFiltering:function(){done()}}),$('#multiselect-container .multiselect-option input[value="value-1"]').click(),$('#multiselect-container .multiselect-option input[value="value-9"]').click();for(var i=1;i<10;i++)9!=i&&1!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should deselect one option.",(function(){$("#multiselect-container .multiselect-all input").click();for(var i=1;i<10;i++)1!=i?expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i):expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i)}))})),describe("Should select all options if selectAllJustVisible is false.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",includeSelectAllOption:!0,selectAllJustVisible:!1,selectAllValue:"multiselect-all",onFiltering:function(){done()}});for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should select all options.",(function(){$('#multiselect-container .multiselect-all input[value="multiselect-all"]').click();for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i)}))})),describe("Should deselect all options if selectAllJustVisible is false.",(function(){beforeEach((function(done){$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,filterBehavior:"value",includeSelectAllOption:!0,selectAllJustVisible:!1,selectAllValue:"multiselect-all",onFiltering:function(){done()}});for(var i=1;i<10;i++)$('#multiselect-container .multiselect-option input[value="value-'+i+'"]').click(),expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!0,i);$("#multiselect-container .multiselect-filter input").val("value-9").trigger("keydown")})),it("Should select all options.",(function(){$('#multiselect-container .multiselect-all input[value="multiselect-all"]').click();for(var i=1;i<10;i++)expect($('#multiselect-container .multiselect-option input[value="value-'+i+'"]').prop("checked")).toBe(!1,i)}))})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe('Bootstrap Multiselect "Specific Issues".',(function(){it("#393.",(function(){for(var $select=$(''),i=1;i<100;i++)$select.append('');$("body").append($select),$select.multiselect({buttonContainer:'
    ',includeSelectAllOption:!0,selectAllValue:0}),expect($('#multiselect-container input[value="0"]').length).toBe(1),expect($('#multiselect-container input[value="0"]').prop("checked")).toBe(!1),$("#multiselect").multiselect("selectAll"),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="0"]').prop("checked")).toBe(!0),$("#multiselect").multiselect("deselectAll"),expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="0"]').prop("checked")).toBe(!1),$('#multiselect-container input[value="0"]').click(),expect($("#multiselect option:selected").length).toBe(99),expect($('#multiselect-container input[value="0"]').prop("checked")).toBe(!0),$('#multiselect-container input[value="0"]').click(),expect($("#multiselect option:selected").length).toBe(0),expect($('#multiselect-container input[value="0"]').prop("checked")).toBe(!1),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()})),it("#405.",(function(){for(var selection=document.getSelection(),range=document.createRange(),$selection=$("Some text to select"),$select=$(''),i=1;i<5;i++)$select.append('');$("body").append($selection).append($select),$select.multiselect({buttonContainer:'
    '}),range.selectNodeContents($selection.get(0)),selection.removeAllRanges(),selection.addRange(range),"Range"===document.getSelection().type&&($("#multiselect-container").find(".multiselect-option:first .form-check-label").trigger("click"),expect($("#multiselect-container").find("input:first").prop("checked")).toBe(!0)),$("#multiselect").multiselect("destroy"),$("#multiselect").remove(),$selection.remove()})),it("#679.",(function(){for(var $select=$(''),i=1;i<11;i++){for(var $optgroup=$(''),j=1;j<11;j++)$optgroup.append('");$select.append($optgroup)}$("body").append($select);var fired=0;$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0,enableCollapsibleOptGroups:!0,onChange:function(option,checked){fired++}}),expect($("#multiselect option:selected").length).toBe(0),expect(fired).toBe(0);var i=0;$("#multiselect-container .multiselect-group").each((function(){$(".form-check-label",$(this)).click(),expect(fired).toBe(1),fired=0,$(".form-check-label",$(this)).click(),expect(fired).toBe(1),fired=0,i++})),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()})),it("#655/1 when clicking the options.",(function(){var $select=$('');$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0}),$('#multiselect-container input[value="2-1"]').click(),$('#multiselect-container input[value="2-2"]').click(),$('#multiselect-container input[value="2-3"]').click(),expect($($("#multiselect-container .multiselect-group input")[0]).prop("checked")).toBe(!1),expect($('#multiselect-container input[value="1-1"]').prop("checked")).toBe(!1),expect($('#multiselect-container input[value="1-2"]').prop("checked")).toBe(!1),expect($('#multiselect-container input[value="1-3"]').prop("checked")).toBe(!1),expect($($("#multiselect-container .multiselect-group input")[1]).prop("checked")).toBe(!0),expect($('#multiselect-container input[value="2-1"]').prop("checked")).toBe(!0),expect($('#multiselect-container input[value="2-2"]').prop("checked")).toBe(!0),expect($('#multiselect-container input[value="2-3"]').prop("checked")).toBe(!0),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()})),it("#655/1 when clicking the optgroup.",(function(){var $select=$('');$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0}),$($("#multiselect-container .multiselect-group input")[1]).click(),expect($($("#multiselect-container .multiselect-group input")[0]).prop("checked")).toBe(!1),expect($('#multiselect-container input[value="1-1"]').prop("checked")).toBe(!1),expect($('#multiselect-container input[value="1-2"]').prop("checked")).toBe(!1),expect($('#multiselect-container input[value="1-3"]').prop("checked")).toBe(!1),expect($($("#multiselect-container .multiselect-group input")[1]).prop("checked")).toBe(!0),expect($('#multiselect-container input[value="2-1"]').prop("checked")).toBe(!0),expect($('#multiselect-container input[value="2-2"]').prop("checked")).toBe(!0),expect($('#multiselect-container input[value="2-3"]').prop("checked")).toBe(!0),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()})),it("#655/2 when clicking the options.",(function(){var $select=$('');$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0,selectedClass:"multiselect-custom-selected"}),$('#multiselect-container input[value="2-1"]').click(),$('#multiselect-container input[value="2-2"]').click(),$('#multiselect-container input[value="2-3"]').click(),expect($($("#multiselect-container .multiselect-group")[0]).prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="1-1"])').prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="1-2"])').prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="1-3"])').prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($($("#multiselect-container .multiselect-group")[1]).prop("class").split(" ")).toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="2-1"])').prop("class").split(" ")).toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="2-2"])').prop("class").split(" ")).toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="2-3"])').prop("class").split(" ")).toContain("multiselect-custom-selected"),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()})),it("#655/2 when clicking the optgroup.",(function(){var $select=$('');$select.append(''),$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableClickableOptGroups:!0,selectedClass:"multiselect-custom-selected"}),$($("#multiselect-container .multiselect-group input")[1]).click(),expect($($("#multiselect-container .multiselect-group")[0]).prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="1-1"])').prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="1-2"])').prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="1-3"])').prop("class").split(" ")).not.toContain("multiselect-custom-selected"),expect($($("#multiselect-container .multiselect-group")[1]).prop("class").split(" ")).toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="2-1"])').prop("class").split(" ")).toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="2-2"])').prop("class").split(" ")).toContain("multiselect-custom-selected"),expect($('#multiselect-container .multiselect-option:has(input[value="2-3"])').prop("class").split(" ")).toContain("multiselect-custom-selected"),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()})),describe("#732.",(function(){var triggeredOnSelectAll=!1,triggeredOnDeselectAll=!1;beforeEach((function(done){triggeredOnSelectAll=!1,triggeredOnDeselectAll=!1;var $select=$('');$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    ',enableFiltering:!0,includeSelectAllOption:!0,onSelectAll:function(){triggeredOnSelectAll=!0},onDeselectAll:function(){triggeredOnDeselectAll=!0},onFiltering:function(){done()}}),$("#multiselect-container .multiselect-filter input").val("2").trigger("keydown")})),it("Should not fire onSelectAll or onDeselectAll when filtering or clearing filter.",(function(){expect(triggeredOnSelectAll).toBe(!1),expect(triggeredOnDeselectAll).toBe(!1),$("#multiselect-container .multiselect-filter .multiselect-clear-filter").click(),expect(triggeredOnSelectAll).toBe(!1),expect(triggeredOnDeselectAll).toBe(!1)})),afterEach((function(){$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),it("#759.",(function(){var $select=$('');$select.append(''),$("body").append($select),$select.multiselect({buttonContainer:'
    '}),expect($("#multiselect-container .multiselect-selected-text").text()).toBe("Test"),$("#multiselect").multiselect("destroy"),$("#multiselect").remove()}))})),describe("Knockout Binding.",(function(){var $testArea;afterEach((function(){$testArea&&$testArea.multiselect("destroy").remove()})),it("Should update values and options with an observable array.",(function(){jasmine.clock().install(),$testArea=$('').appendTo(document.body);var viewModel={myValues:ko.observableArray(),myOptions:ko.observableArray([])};expect(void 0!==ko.bindingHandlers.multiselect.init).toEqual(!0);var optionSpy=spyOn(ko.bindingHandlers.selectedOptions,"init").and.callThrough(),multiSpy=spyOn(ko.bindingHandlers.multiselect,"init").and.callThrough();ko.applyBindings(viewModel,$testArea[0]),expect(optionSpy.calls.count()).toEqual(1),expect(multiSpy.calls.count()).toEqual(1),expect($testArea.find("option").length).toEqual(0),expect($testArea.val()).toEqual(null),expect($testArea.next().find("button.multiselect").text().trim()).toEqual("None selected"),expect($testArea.next().find(".multiselect-option").length).toEqual(0),viewModel.myOptions(["option1","option2"]),jasmine.clock().tick(1e3),expect($testArea.next().find(".multiselect-option").length).toEqual(2),expect($testArea.find("option").length).toEqual(2),expect($testArea.find("option:checked").length).toEqual(0),viewModel.myValues(["option2"]),jasmine.clock().tick(1e3),expect($testArea.find("option:checked").length).toEqual(1),expect($testArea.find("option:checked").text().trim()).toEqual("option2"),viewModel.myValues(["option1","option2"]),jasmine.clock().tick(1e3),expect($testArea.find("option:checked").length).toEqual(2),expect($testArea.find("option:checked").map((function(){return $(this).text().trim()})).toArray()).toEqual(["option1","option2"]),expect($testArea.next().find("button.multiselect").text().trim()).toEqual("All selected (2)"),viewModel.myOptions.push("wacky option"),jasmine.clock().tick(1e3),expect($testArea.find("option:checked").length).toEqual(2),expect($testArea.find("option:checked").map((function(){return $(this).text().trim()})).toArray()).toEqual(["option1","option2"]),expect($testArea.find("option").map((function(){return $(this).text().trim()})).toArray()).toEqual(["option1","option2","wacky option"]),expect($testArea.next().find("button.multiselect").text().trim()).toEqual("2 selected")}))})),describe('Bootstrap Multiselect "Reset".',(function(){var $select;beforeEach((function(){$select=$('');for(var i=1;i<100;i++)$select.append('');$("body").append($select),$select.multiselect({buttonContainer:'
    ',includeResetOption:!0})})),it("Should not add an additional option to the select.",(function(){expect($select.find("option").length).toBe(99)})),it("Should add reset button.",(function(){expect($("#multiselect-container").find(".multiselect-reset button").text()).toBe("Reset")})),it("Should reset if button clicked.",(function(){$select.multiselect("selectAll",!0,!1),expect($select.find("option:selected").length).toBe(99),$("#multiselect-container").find(".multiselect-reset button").click(),expect($select.find("option:selected").length).toBe(0)})),afterEach((function(){$select.multiselect("destroy"),$select.remove()}))})); \ No newline at end of file