From fb0b321380278eb6ea75ca419eaf5f149a99374e Mon Sep 17 00:00:00 2001 From: Pepijn Over Date: Fri, 1 Aug 2014 15:30:01 +0200 Subject: [PATCH] adding bootstrap multiselect for users/servers --- docs/credits.rst | 1 + src/lang/bg_BG.lang.php | 2 - src/lang/da_DK.lang.php | 2 - src/lang/de_DE.lang.php | 2 - src/lang/en_US.lang.php | 2 - src/lang/es_ES.lang.php | 2 - src/lang/fr_FR.lang.php | 2 - src/lang/it_IT.lang.php | 2 - src/lang/ko_KR.lang.php | 2 - src/lang/nl_NL.lang.php | 2 - src/lang/pt_BR.lang.php | 2 - src/lang/ru_RU.lang.php | 2 - src/lang/zh_CN.lang.php | 2 - .../Controller/ServerController.class.php | 4 +- .../User/Controller/UserController.class.php | 4 +- src/templates/main.tpl.html | 2 + src/templates/server/server.tpl.html | 192 +++++++++--------- src/templates/user/user.tpl.html | 154 +++++++------- static/js/scripts.js | 5 + .../bootstrap-multiselect.min.css | 1 + .../bootstrap-multiselect.min.js | 1 + 21 files changed, 177 insertions(+), 211 deletions(-) create mode 100644 static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.css create mode 100644 static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.js diff --git a/docs/credits.rst b/docs/credits.rst index f60734c8..672fee5d 100644 --- a/docs/credits.rst +++ b/docs/credits.rst @@ -116,5 +116,6 @@ The following libraries are being used by PHP Server Monitor: * jqPlot - http://www.jqplot.com * Twitter Bootstrap - http://getbootstrap.com +* Bootstrap Multiselect - https://github.com/davidstutz/bootstrap-multiselect * PHP Mailer - https://github.com/PHPMailer/PHPMailer * php-pushover - https://github.com/kryap/php-pushover \ No newline at end of file diff --git a/src/lang/bg_BG.lang.php b/src/lang/bg_BG.lang.php index 048003ed..ca5ba0d3 100644 --- a/src/lang/bg_BG.lang.php +++ b/src/lang/bg_BG.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'преди минута', 'seconds_ago' => 'преди %d секунди', 'a_second_ago' => 'преди секунда', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Настройки', diff --git a/src/lang/da_DK.lang.php b/src/lang/da_DK.lang.php index bca9c62d..b7fc3357 100644 --- a/src/lang/da_DK.lang.php +++ b/src/lang/da_DK.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'omkring et minut siden', 'seconds_ago' => '%d sekunder siden', 'a_second_ago' => 'et sekund siden', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Indstillinger', diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php index f7353e81..d1d0f54b 100644 --- a/src/lang/de_DE.lang.php +++ b/src/lang/de_DE.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'about a minute ago', 'seconds_ago' => '%d seconds ago', 'a_second_ago' => 'a second ago', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Einstellungen', diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 999da3ad..1019013a 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'about a minute ago', 'seconds_ago' => '%d seconds ago', 'a_second_ago' => 'a second ago', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Config', diff --git a/src/lang/es_ES.lang.php b/src/lang/es_ES.lang.php index 243f59d7..45833263 100644 --- a/src/lang/es_ES.lang.php +++ b/src/lang/es_ES.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'about a minute ago', 'seconds_ago' => '%d seconds ago', 'a_second_ago' => 'a second ago', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Configurar', diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php index b326cf1f..fbf0cdf4 100644 --- a/src/lang/fr_FR.lang.php +++ b/src/lang/fr_FR.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'Il y a une minute', 'seconds_ago' => 'Il y a %d secondes', 'a_second_ago' => 'Il y a une seconde', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Configuration', diff --git a/src/lang/it_IT.lang.php b/src/lang/it_IT.lang.php index 1b831df8..0d311573 100644 --- a/src/lang/it_IT.lang.php +++ b/src/lang/it_IT.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'about a minute ago', 'seconds_ago' => '%d seconds ago', 'a_second_ago' => 'a second ago', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Configurazione', diff --git a/src/lang/ko_KR.lang.php b/src/lang/ko_KR.lang.php index d9316189..1fb127db 100644 --- a/src/lang/ko_KR.lang.php +++ b/src/lang/ko_KR.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'about a minute ago', 'seconds_ago' => '%d seconds ago', 'a_second_ago' => 'a second ago', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => '설정', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index 5864d8f6..ba0035ba 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'een minuut geleden', 'seconds_ago' => '%d seconden geleden', 'a_second_ago' => 'een seconde geleden', - 'check_all' => 'Selecteer alles', - 'uncheck_all' => 'Deselecteer alles', ), 'menu' => array( 'config' => 'Configuratie', diff --git a/src/lang/pt_BR.lang.php b/src/lang/pt_BR.lang.php index 7921eecc..d4c7a23b 100644 --- a/src/lang/pt_BR.lang.php +++ b/src/lang/pt_BR.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'cerca de um minuto atrás', 'seconds_ago' => '%d segundos atrás', 'a_second_ago' => 'um segundo atrás', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Configuração', diff --git a/src/lang/ru_RU.lang.php b/src/lang/ru_RU.lang.php index c9007b2c..7e1b79ee 100644 --- a/src/lang/ru_RU.lang.php +++ b/src/lang/ru_RU.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => 'минуту назад', 'seconds_ago' => '%d секунд назад', 'a_second_ago' => 'секунду назад', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => 'Параметры', diff --git a/src/lang/zh_CN.lang.php b/src/lang/zh_CN.lang.php index bb9fe4ec..1884fad0 100644 --- a/src/lang/zh_CN.lang.php +++ b/src/lang/zh_CN.lang.php @@ -58,8 +58,6 @@ $sm_lang = array( 'a_minute_ago' => '1分钟前', 'seconds_ago' => '%d 秒前', 'a_second_ago' => '刚刚', - 'check_all' => 'Check all', - 'uncheck_all' => 'Uncheck all', ), 'menu' => array( 'config' => '设置', diff --git a/src/psm/Module/Server/Controller/ServerController.class.php b/src/psm/Module/Server/Controller/ServerController.class.php index 10e59878..0d144537 100644 --- a/src/psm/Module/Server/Controller/ServerController.class.php +++ b/src/psm/Module/Server/Controller/ServerController.class.php @@ -190,7 +190,7 @@ class ServerController extends AbstractServerController { $user_idc_selected = $this->getServerUsers($this->server_id); foreach($users as &$user) { if(in_array($user['user_id'], $user_idc_selected)) { - $user['edit_checked'] = 'checked="checked"'; + $user['edit_selected'] = 'selected="selected"'; } } @@ -443,8 +443,6 @@ class ServerController extends AbstractServerController { 'label_yes' => psm_get_lang('system', 'yes'), 'label_no' => psm_get_lang('system', 'no'), 'label_add_new' => psm_get_lang('system', 'add_new'), - 'label_check_all' => psm_get_lang('system', 'check_all'), - 'label_uncheck_all' => psm_get_lang('system', 'uncheck_all'), ) ); diff --git a/src/psm/Module/User/Controller/UserController.class.php b/src/psm/Module/User/Controller/UserController.class.php index 571ccdf2..0552d6d6 100644 --- a/src/psm/Module/User/Controller/UserController.class.php +++ b/src/psm/Module/User/Controller/UserController.class.php @@ -168,7 +168,7 @@ class UserController extends AbstractController { foreach($this->servers as &$server) { if(in_array($server['server_id'], $user_servers)) { - $server['edit_checked'] = 'checked="checked"'; + $server['edit_selected'] = 'selected="selected"'; $server['class'] = 'active'; } } @@ -329,8 +329,6 @@ class UserController extends AbstractController { 'label_edit' => psm_get_lang('system', 'edit'), 'label_delete' => psm_get_lang('system', 'delete'), 'label_add_new' => psm_get_lang('system', 'add_new'), - 'label_check_all' => psm_get_lang('system', 'check_all'), - 'label_uncheck_all' => psm_get_lang('system', 'uncheck_all'), 'icon_level_10' => 'icon-admin', 'icon_level_20' => 'icon-user', ) diff --git a/src/templates/main.tpl.html b/src/templates/main.tpl.html index a317917a..15924793 100644 --- a/src/templates/main.tpl.html +++ b/src/templates/main.tpl.html @@ -13,6 +13,7 @@ + + diff --git a/src/templates/server/server.tpl.html b/src/templates/server/server.tpl.html index 56f8cf1f..7a1b89cf 100644 --- a/src/templates/server/server.tpl.html +++ b/src/templates/server/server.tpl.html @@ -75,110 +75,102 @@
{titlemode} -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- s -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
- -
- - - - {users} -

-

-
-
+
+ +
+
-
-
- - {label_go_back} +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ s +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + {label_go_back} +
diff --git a/src/templates/user/user.tpl.html b/src/templates/user/user.tpl.html index 2273f2b0..956c933d 100644 --- a/src/templates/user/user.tpl.html +++ b/src/templates/user/user.tpl.html @@ -66,94 +66,86 @@
{titlemode} -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -

{label_level_description}

-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
{label_pushover_description}
-
-
- -
- -
-
-
- -
- -

{label_pushover_device_description}

-
+
+ +
+
-
-
- -
+
+ +
+ +
+
+
+ +
+ +

{label_level_description}

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
{label_pushover_description}
+
+
+ +
+ +
+
+
+ +
+ +

{label_pushover_device_description}

+
+
+
+ +
+ {label} + {servers} -

-

-
+
-
-
-
- - -
-
+
+ + +
\ No newline at end of file diff --git a/static/js/scripts.js b/static/js/scripts.js index 22016f39..40d51e3b 100755 --- a/static/js/scripts.js +++ b/static/js/scripts.js @@ -40,6 +40,11 @@ $().ready(function() { } return false; }); + $('select.multiselect').multiselect({ + includeSelectAllOption: true, + maxHeight: 400, + enableCaseInsensitiveFiltering: true + }); psm_flash_message(); psm_tooltips(); diff --git a/static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.css b/static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.css new file mode 100644 index 00000000..d982bd70 --- /dev/null +++ b/static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.css @@ -0,0 +1 @@ +.multiselect-container{position:absolute;list-style-type:none;margin:0;padding:0}.multiselect-container .input-group{margin:5px}.multiselect-container>li{padding:0}.multiselect-container>li>a.multiselect-all label{font-weight:700}.multiselect-container>li>label.multiselect-group{margin:0;padding:3px 20px;height:100%;font-weight:700}.multiselect-container>li>a{padding:0}.multiselect-container>li>a>label{margin:0;height:100%;cursor:pointer;font-weight:400;padding:3px 20px 3px 40px}.multiselect-container>li>a>label.radio,.multiselect-container>li>a>label.checkbox{margin:0}.multiselect-container>li>a>label>input[type=checkbox]{margin-bottom:5px}.btn-group>.btn-group:nth-child(2)>.multiselect.btn{border-top-left-radius:4px;border-bottom-left-radius:4px}.form-inline .multiselect-container label.checkbox,.form-inline .multiselect-container label.radio{padding:3px 20px 3px 40px}.form-inline .multiselect-container li a label.checkbox input[type=checkbox],.form-inline .multiselect-container li a label.radio input[type=radio]{margin-left:-20px;margin-right:0} \ No newline at end of file diff --git a/static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.js b/static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.js new file mode 100644 index 00000000..a1108d2c --- /dev/null +++ b/static/plugin/bootstrap-multiselect/bootstrap-multiselect.min.js @@ -0,0 +1 @@ +!function($){if(Array.prototype.forEach===null||Array.prototype.forEach===undefined){Array.prototype.forEach=function(func){var index;for(index=0;index0){$(element).multiselect("select",addedArray)}if(deletedArray.length>0){$(element).multiselect("deselect",deletedArray)}},null,"arrayChange")}},update:function(element,valueAccessor,allBindingsAccessor,viewModel,bindingContext){var listOfItems=allBindingsAccessor().options,ms=$(element).data("multiselect"),config=ko.utils.unwrapObservable(valueAccessor());if(isObservableArray(listOfItems)){listOfItems.subscribe(function(theArray){$(element).multiselect("rebuild")})}if(!ms){$(element).multiselect(config)}else{ms.updateOriginalOptions()}}}}function isObservableArray(obj){return ko.isObservable(obj)&&!(obj.destroyAll===undefined)}function Multiselect(select,options){this.options=this.mergeOptions(options);this.$select=$(select);this.originalOptions=this.$select.clone()[0].options;this.query="";this.searchTimeout=null;this.options.multiple=this.$select.attr("multiple")==="multiple";this.options.onChange=$.proxy(this.options.onChange,this);this.options.onDropdownShow=$.proxy(this.options.onDropdownShow,this);this.options.onDropdownHide=$.proxy(this.options.onDropdownHide,this);this.buildContainer();this.buildButton();this.buildDropdown();this.buildSelectAll();this.buildDropdownOptions();this.buildFilter();this.updateButtonText();this.updateSelectAll();this.$select.hide().after(this.$container)}Multiselect.prototype={defaults:{buttonText:function(options,select){if(options.length===0){return this.nonSelectedText+' '}else{if(options.length>this.numberDisplayed){return options.length+" "+this.nSelectedText+' '}else{var selected="";options.each(function(){var label=($(this).attr("label")!==undefined)?$(this).attr("label"):$(this).html();selected+=label+", "});return selected.substr(0,selected.length-2)+' '}}},buttonTitle:function(options,select){if(options.length===0){return this.nonSelectedText}else{var selected="";options.each(function(){selected+=$(this).text()+", "});return selected.substr(0,selected.length-2)}},label:function(element){return $(element).attr("label")||$(element).html()},onChange:function(option,checked){},onDropdownShow:function(event){},onDropdownHide:function(event){},buttonClass:"btn btn-default",dropRight:false,selectedClass:"active",buttonWidth:"auto",buttonContainer:'
',maxHeight:false,checkboxName:"multiselect",includeSelectAllOption:false,includeSelectAllIfMoreThan:0,selectAllText:" Select all",selectAllValue:"multiselect-all",enableFiltering:false,enableCaseInsensitiveFiltering:false,filterPlaceholder:"Search",filterBehavior:"text",preventInputChangeEvent:false,nonSelectedText:"None selected",nSelectedText:"selected",numberDisplayed:3,templates:{button:'',ul:'',filter:'
  • ',li:'
  • ',divider:'
  • ',liGroup:'
  • '}},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)},buildButton:function(){this.$button=$(this.options.templates.button).addClass(this.options.buttonClass);if(this.$select.prop("disabled")){this.disable()}else{this.enable()}if(this.options.buttonWidth&&this.options.buttonWidth!=="auto"){this.$button.css({width:this.options.buttonWidth});this.$container.css({width:this.options.buttonWidth})}var tabindex=this.$select.attr("tabindex");if(tabindex){this.$button.attr("tabindex",tabindex)}this.$container.prepend(this.$button)},buildDropdown:function(){this.$ul=$(this.options.templates.ul);if(this.options.dropRight){this.$ul.addClass("pull-right")}if(this.options.maxHeight){this.$ul.css({"max-height":this.options.maxHeight+"px","overflow-y":"auto","overflow-x":"hidden"})}this.$container.append(this.$ul)},buildDropdownOptions:function(){this.$select.children().each($.proxy(function(index,element){var tag=$(element).prop("tagName").toLowerCase();if($(element).prop("value")==this.options.selectAllValue){return}if(tag==="optgroup"){this.createOptgroup(element)}else{if(tag==="option"){if($(element).data("role")==="divider"){this.createDivider()}else{this.createOptionValue(element)}}}},this));$("li input",this.$ul).on("change",$.proxy(function(event){var $target=$(event.target);var checked=$target.prop("checked")||false;var isSelectAllOption=$target.val()===this.options.selectAllValue;if(this.options.selectedClass){if(checked){$target.parents("li").addClass(this.options.selectedClass)}else{$target.parents("li").removeClass(this.options.selectedClass)}}var value=$target.val();var $option=this.getOptionByValue(value);var $optionsNotThis=$("option",this.$select).not($option);var $checkboxesNotThis=$("input",this.$container).not($target);if(isSelectAllOption){if(checked){this.selectall()}else{this.deselectall()}}if(!isSelectAllOption){if(checked){$option.prop("selected",true);if(this.options.multiple){$option.prop("selected",true)}else{if(this.options.selectedClass){$($checkboxesNotThis).parents("li").removeClass(this.options.selectedClass)}$($checkboxesNotThis).prop("checked",false);$optionsNotThis.prop("selected",false);this.$button.click()}if(this.options.selectedClass==="active"){$optionsNotThis.parents("a").css("outline","")}}else{$option.prop("selected",false)}}this.$select.change();this.updateButtonText();this.updateSelectAll();this.options.onChange($option,checked);if(this.options.preventInputChangeEvent){return false}},this));$("li a",this.$ul).on("touchstart click",function(event){event.stopPropagation();var $target=$(event.target);if(event.shiftKey){var checked=$target.prop("checked")||false;if(checked){var prev=$target.parents("li:last").siblings('li[class="active"]:first');var currentIdx=$target.parents("li").index();var prevIdx=prev.index();if(currentIdx>prevIdx){$target.parents("li:last").prevUntil(prev).each(function(){$(this).find("input:first").prop("checked",true).trigger("change")})}else{$target.parents("li:last").nextUntil(prev).each(function(){$(this).find("input:first").prop("checked",true).trigger("change")})}}}$target.blur()});this.$container.off("keydown.multiselect").on("keydown.multiselect",$.proxy(function(event){if($('input[type="text"]',this.$container).is(":focus")){return}if((event.keyCode===9||event.keyCode===27)&&this.$container.hasClass("open")){this.$button.click()}else{var $items=$(this.$container).find("li:not(.divider):not(.disabled) a").filter(":visible");if(!$items.length){return}var index=$items.index($items.filter(":focus"));if(event.keyCode===38&&index>0){index--}else{if(event.keyCode===40&&index<$items.length-1){index++}else{if(!~index){index=0}}}var $current=$items.eq(index);$current.focus();if(event.keyCode===32||event.keyCode===13){var $checkbox=$current.find("input");$checkbox.prop("checked",!$checkbox.prop("checked"));$checkbox.change()}event.stopPropagation();event.preventDefault()}},this))},createOptionValue:function(element){if($(element).is(":selected")){$(element).prop("selected",true)}var label=this.options.label(element);var value=$(element).val();var inputType=this.options.multiple?"checkbox":"radio";var $li=$(this.options.templates.li);$("label",$li).addClass(inputType);$("label",$li).append('');var selected=$(element).prop("selected")||false;var $checkbox=$("input",$li);$checkbox.val(value);if(value===this.options.selectAllValue){$li.addClass("multiselect-item multiselect-all");$checkbox.parent().parent().addClass("multiselect-all")}$("label",$li).append(" "+label);this.$ul.append($li);if($(element).is(":disabled")){$checkbox.attr("disabled","disabled").prop("disabled",true).parents("a").attr("tabindex","-1").parents("li").addClass("disabled")}$checkbox.prop("checked",selected);if(selected&&this.options.selectedClass){$checkbox.parents("li").addClass(this.options.selectedClass)}},createDivider:function(element){var $divider=$(this.options.templates.divider);this.$ul.append($divider)},createOptgroup:function(group){var groupName=$(group).prop("label");var $li=$(this.options.templates.liGroup);$("label",$li).text(groupName);this.$ul.append($li);if($(group).is(":disabled")){$li.addClass("disabled")}$("option",group).each($.proxy(function(index,element){this.createOptionValue(element)},this))},buildSelectAll:function(){var alreadyHasSelectAll=this.hasSelectAll();if(!alreadyHasSelectAll&&this.options.includeSelectAllOption&&this.options.multiple&&$("option",this.$select).length>this.options.includeSelectAllIfMoreThan){if(this.options.includeSelectAllDivider){this.$ul.prepend($(this.options.templates.divider))}var $li=$(this.options.templates.li);$("label",$li).addClass("checkbox");$("label",$li).append('');var $checkbox=$("input",$li);$checkbox.val(this.options.selectAllValue);$li.addClass("multiselect-item multiselect-all");$checkbox.parent().parent().addClass("multiselect-all");$("label",$li).append(" "+this.options.selectAllText);this.$ul.prepend($li);$checkbox.prop("checked",false)}},buildFilter:function(){if(this.options.enableFiltering||this.options.enableCaseInsensitiveFiltering){var enableFilterLength=Math.max(this.options.enableFiltering,this.options.enableCaseInsensitiveFiltering);if(this.$select.find("option").length>=enableFilterLength){this.$filter=$(this.options.templates.filter);$("input",this.$filter).attr("placeholder",this.options.filterPlaceholder);this.$ul.prepend(this.$filter);this.$filter.val(this.query).on("click",function(event){event.stopPropagation()}).on("input keydown",$.proxy(function(event){clearTimeout(this.searchTimeout);this.searchTimeout=this.asyncFunction($.proxy(function(){if(this.query!==event.target.value){this.query=event.target.value;$.each($("li",this.$ul),$.proxy(function(index,element){var value=$("input",element).val();var text=$("label",element).text();var filterCandidate="";if((this.options.filterBehavior==="text")){filterCandidate=text}else{if((this.options.filterBehavior==="value")){filterCandidate=value}else{if(this.options.filterBehavior==="both"){filterCandidate=text+"\n"+value}}}if(value!==this.options.selectAllValue&&text){var showElement=false;if(this.options.enableCaseInsensitiveFiltering&&filterCandidate.toLowerCase().indexOf(this.query.toLowerCase())>-1){showElement=true}else{if(filterCandidate.indexOf(this.query)>-1){showElement=true}}if(showElement){$(element).show().removeClass("filter-hidden")}else{$(element).hide().addClass("filter-hidden")}}},this))}this.updateSelectAll()},this),300,this)},this))}}},destroy:function(){this.$container.remove();this.$select.show();this.$select.data("multiselect",null)},refresh:function(){$("option",this.$select).each($.proxy(function(index,element){var $input=$("li input",this.$ul).filter(function(){return $(this).val()===$(element).val()});if($(element).is(":selected")){$input.prop("checked",true);if(this.options.selectedClass){$input.parents("li").addClass(this.options.selectedClass)}}else{$input.prop("checked",false);if(this.options.selectedClass){$input.parents("li").removeClass(this.options.selectedClass)}}if($(element).is(":disabled")){$input.attr("disabled","disabled").prop("disabled",true).parents("li").addClass("disabled")}else{$input.prop("disabled",false).parents("li").removeClass("disabled")}},this));this.updateButtonText();this.updateSelectAll()},select:function(selectValues){if(!$.isArray(selectValues)){selectValues=[selectValues]}for(var i=0;i';option.children.forEach(function(subOption){optionDOM+='"});optionDOM+=""}else{optionDOM+='"}});this.$select.html(optionDOM);this.rebuild()},enable:function(){this.$select.prop("disabled",false);this.$button.prop("disabled",false).removeClass("disabled")},disable:function(){this.$select.prop("disabled",true);this.$button.prop("disabled",true).addClass("disabled")},setOptions:function(options){this.options=this.mergeOptions(options)},mergeOptions:function(options){return $.extend(true,{},this.defaults,options)},hasSelectAll:function(){return $("li."+this.options.selectAllValue,this.$ul).length>0},updateSelectAll:function(){if(this.hasSelectAll()){var allBoxes=$("li:not(.multiselect-item):not(.filter-hidden) input:enabled",this.$ul),allBoxesLength=allBoxes.length,checkedBoxesLength=allBoxes.filter(":checked").length,selectAllLi=$("li."+this.options.selectAllValue,this.$ul),selectAllInput=selectAllLi.find("input");if(checkedBoxesLength>0&&checkedBoxesLength===allBoxesLength){selectAllInput.prop("checked",true);selectAllLi.addClass(this.options.selectedClass)}else{selectAllInput.prop("checked",false);selectAllLi.removeClass(this.options.selectedClass)}}},updateButtonText:function(){var options=this.getSelected();$("button",this.$container).html(this.options.buttonText(options,this.$select));$("button",this.$container).attr("title",this.options.buttonTitle(options,this.$select))},getSelected:function(){return $("option",this.$select).filter(":selected")},getOptionByValue:function(value){var options=$("option",this.$select);var valueToCompare=value.toString();for(var i=0;i