!function($){"use strict";$.expr[":"].icontains=function(obj,index,meta){return $(obj).text().toUpperCase().indexOf(meta[3].toUpperCase())>=0;};var Selectpicker=function(element,options,e){if(e){e.stopPropagation();e.preventDefault();} this.$element=$(element);this.$newElement=null;this.$button=null;this.$menu=null;this.options=$.extend({},$.fn.selectpicker.defaults,this.$element.data(),typeof options=='object'&&options);if(this.options.title==null){this.options.title=this.$element.attr('title');} this.val=Selectpicker.prototype.val;this.render=Selectpicker.prototype.render;this.refresh=Selectpicker.prototype.refresh;this.setStyle=Selectpicker.prototype.setStyle;this.selectAll=Selectpicker.prototype.selectAll;this.deselectAll=Selectpicker.prototype.deselectAll;this.init();};Selectpicker.prototype={constructor:Selectpicker,init:function(){this.$element.hide();this.multiple=this.$element.prop('multiple');var id=this.$element.attr('id');this.$newElement=this.createView();this.$element.after(this.$newElement);this.$menu=this.$newElement.find('> .dropdown-menu');this.$button=this.$newElement.find('> button');this.$searchbox=this.$newElement.find('input');if(id!==undefined){var that=this;this.$button.attr('data-id',id);$('label[for="'+id+'"]').click(function(e){e.preventDefault();that.$button.focus();});} this.checkDisabled();this.clickListener();if(this.options.liveSearch){this.liveSearchListener();} this.render();this.liHeight();this.setStyle();this.setWidth();if(this.options.container){this.selectPosition();} this.$menu.data('this',this);this.$newElement.data('this',this);},createDropdown:function(){var multiple=this.multiple?' show-tick':'';var header=this.options.header?'
'+this.options.header+'
':'';var searchbox=this.options.liveSearch?'':'';var drop="
"+""+""+"
";return $(drop);},createView:function(){var $drop=this.createDropdown();var $li=this.createLi();$drop.find('ul').append($li);return $drop;},reloadLi:function(){this.destroyLi();var $li=this.createLi();this.$menu.find('ul').append($li);},destroyLi:function(){this.$menu.find('li').remove();},createLi:function(){var that=this,_liA=[],_liHtml='';this.$element.find('option').each(function(){var $this=$(this);var optionClass=$this.attr("class")||'';var inline=$this.attr("style")||'';var text=$this.data('content')?$this.data('content'):$this.html();var subtext=$this.data('subtext')!==undefined?''+$this.data('subtext')+'':'';var icon=$this.data('icon')!==undefined?' ':'';if(icon!==''&&($this.is(':disabled')||$this.parent().is(':disabled'))){icon=''+icon+'';} if(!$this.data('content')){text=icon+''+text+subtext+'';} if(that.options.hideDisabled&&($this.is(':disabled')||$this.parent().is(':disabled'))){_liA.push('');}else if($this.parent().is('optgroup')&&$this.data('divider')!==true){if($this.index()==0){var label=$this.parent().attr('label');var labelSubtext=$this.parent().data('subtext')!==undefined?''+$this.parent().data('subtext')+'':'';var labelIcon=$this.parent().data('icon')?' ':'';label=labelIcon+''+label+labelSubtext+'';if($this[0].index!=0){_liA.push('
'+'
'+label+'
'+ that.createA(text,"opt "+optionClass,inline));}else{_liA.push('
'+label+'
'+ that.createA(text,"opt "+optionClass,inline));}}else{_liA.push(that.createA(text,"opt "+optionClass,inline));}}else if($this.data('divider')===true){_liA.push('
');}else if($(this).data('hidden')===true){_liA.push('');}else{_liA.push(that.createA(text,optionClass,inline));}});$.each(_liA,function(i,item){_liHtml+="
  • "+item+"
  • ";});if(!this.multiple&&this.$element.find('option:selected').length==0&&!this.options.title){this.$element.find('option').eq(0).prop('selected',true).attr('selected','selected');} return $(_liHtml);},createA:function(text,classes,inline){return''+ text+''+'';},render:function(){var that=this;this.$element.find('option').each(function(index){that.setDisabled(index,$(this).is(':disabled')||$(this).parent().is(':disabled'));that.setSelected(index,$(this).is(':selected'));});this.tabIndex();var selectedItems=this.$element.find('option:selected').map(function(){var $this=$(this);var icon=$this.data('icon')&&that.options.showIcon?' ':'';var subtext;if(that.options.showSubtext&&$this.attr('data-subtext')&&!that.multiple){subtext=' '+$this.data('subtext')+'';}else{subtext='';} if($this.data('content')&&that.options.showContent){return $this.data('content');}else if($this.attr('title')!=undefined){return $this.attr('title');}else{return icon+$this.html()+subtext;}}).toArray();var title=!this.multiple?selectedItems[0]:selectedItems.join(", ");if(this.multiple&&this.options.selectedTextFormat.indexOf('count')>-1){var max=this.options.selectedTextFormat.split(">");var notDisabled=this.options.hideDisabled?':not([disabled])':'';if((max.length>1&&selectedItems.length>max[1])||(max.length==1&&selectedItems.length>=2)){title=this.options.countSelectedText.replace('{0}',selectedItems.length).replace('{1}',this.$element.find('option:not([data-divider="true"]):not([data-hidden="true"])'+notDisabled).length);}} if(!title){title=this.options.title!=undefined?this.options.title:this.options.noneSelectedText;} this.$newElement.find('.filter-option').html(title);},setStyle:function(style,status){if(this.$element.attr('class')){this.$newElement.addClass(this.$element.attr('class').replace(/selectpicker|mobile-device/gi,''));} var buttonClass=style?style:this.options.style;if(status=='add'){this.$button.addClass(buttonClass);}else if(status=='remove'){this.$button.removeClass(buttonClass);}else{this.$button.removeClass(this.options.style);this.$button.addClass(buttonClass);}},liHeight:function(){var $selectClone=this.$menu.parent().clone().appendTo('body'),$menuClone=$selectClone.addClass('open').find('> .dropdown-menu'),liHeight=$menuClone.find('li > a').outerHeight(),headerHeight=this.options.header?$menuClone.find('.popover-title').outerHeight():0,searchHeight=this.options.liveSearch?$menuClone.find('.bootstrap-select-searchbox').outerHeight():0;$selectClone.remove();this.$newElement.data('liHeight',liHeight).data('headerHeight',headerHeight).data('searchHeight',searchHeight);},setSize:function(){var that=this,menu=this.$menu,menuInner=menu.find('.inner'),selectHeight=this.$newElement.outerHeight(),liHeight=this.$newElement.data('liHeight'),headerHeight=this.$newElement.data('headerHeight'),searchHeight=this.$newElement.data('searchHeight'),divHeight=menu.find('li .divider').outerHeight(true),menuPadding=parseInt(menu.css('padding-top'))+ parseInt(menu.css('padding-bottom'))+ parseInt(menu.css('border-top-width'))+ parseInt(menu.css('border-bottom-width')),notDisabled=this.options.hideDisabled?':not(.disabled)':'',$window=$(window),menuExtras=menuPadding+parseInt(menu.css('margin-top'))+parseInt(menu.css('margin-bottom'))+2,menuHeight,selectOffsetTop,selectOffsetBot,posVert=function(){selectOffsetTop=that.$newElement.offset().top-$window.scrollTop();selectOffsetBot=$window.height()-selectOffsetTop-selectHeight;};posVert();if(this.options.header)menu.css('padding-top',0);if(this.options.size=='auto'){var getSize=function(){var minHeight;posVert();menuHeight=selectOffsetBot-menuExtras;if(that.options.dropupAuto){that.$newElement.toggleClass('dropup',(selectOffsetTop>selectOffsetBot)&&((menuHeight-menuExtras)3){minHeight=liHeight*3+menuExtras-2;}else{minHeight=0;} menu.css({'max-height':menuHeight+'px','overflow':'hidden','min-height':minHeight+'px'});menuInner.css({'max-height':menuHeight-headerHeight-searchHeight-menuPadding+'px','overflow-y':'auto','min-height':minHeight-menuPadding+'px'});};getSize();$(window).resize(getSize);$(window).scroll(getSize);}else if(this.options.size&&this.options.size!='auto'&&menu.find('li'+notDisabled).length>this.options.size){var optIndex=menu.find("li"+notDisabled+" > *").filter(':not(.div-contain)').slice(0,this.options.size).last().parent().index();var divLength=menu.find("li").slice(0,optIndex+1).find('.div-contain').length;menuHeight=liHeight*this.options.size+divLength*divHeight+menuPadding;if(that.options.dropupAuto){this.$newElement.toggleClass('dropup',(selectOffsetTop>selectOffsetBot)&&(menuHeight .dropdown-menu').css('width');selectClone.remove();this.$newElement.css('width',ulWidth);}else if(this.options.width=='fit'){this.$menu.css('min-width','');this.$newElement.css('width','').addClass('fit-width');}else if(this.options.width){this.$menu.css('min-width','');this.$newElement.css('width',this.options.width);}else{this.$menu.css('min-width','');this.$newElement.css('width','');} if(this.$newElement.hasClass('fit-width')&&this.options.width!=='fit'){this.$newElement.removeClass('fit-width');}},selectPosition:function(){var that=this,drop="
    ",$drop=$(drop),pos,actualHeight,getPlacement=function($element){$drop.addClass($element.attr('class')).toggleClass('dropup',$element.hasClass('dropup'));pos=$element.offset();actualHeight=$element.hasClass('dropup')?0:$element[0].offsetHeight;$drop.css({'top':pos.top+actualHeight,'left':pos.left,'width':$element[0].offsetWidth,'position':'absolute'});};this.$newElement.on('click',function(){getPlacement($(this));$drop.appendTo(that.options.container);$drop.toggleClass('open',!$(this).hasClass('open'));$drop.append(that.$menu);});$(window).resize(function(){getPlacement(that.$newElement);});$(window).on('scroll',function(){getPlacement(that.$newElement);});$('html').on('click',function(e){if($(e.target).closest(that.$newElement).length<1){$drop.removeClass('open');}});},mobile:function(){this.$element.addClass('mobile-device').appendTo(this.$newElement);if(this.options.container)this.$menu.hide();},refresh:function(){this.reloadLi();this.render();this.setWidth();this.setStyle();this.checkDisabled();this.liHeight();},update:function(){this.reloadLi();this.setWidth();this.setStyle();this.checkDisabled();this.liHeight();},setSelected:function(index,selected){this.$menu.find('li').eq(index).toggleClass('selected',selected);},setDisabled:function(index,disabled){if(disabled){this.$menu.find('li').eq(index).addClass('disabled').find('a').attr('href','#').attr('tabindex',-1);}else{this.$menu.find('li').eq(index).removeClass('disabled').find('a').removeAttr('href').attr('tabindex',0);}},isDisabled:function(){return this.$element.is(':disabled');},checkDisabled:function(){var that=this;if(this.isDisabled()){this.$button.addClass('disabled').attr('tabindex',-1);}else{if(this.$button.hasClass('disabled')){this.$button.removeClass('disabled');} if(this.$button.attr('tabindex')==-1){if(!this.$element.data('tabindex'))this.$button.removeAttr('tabindex');}} this.$button.click(function(){return!that.isDisabled();});},tabIndex:function(){if(this.$element.is('[tabindex]')){this.$element.data('tabindex',this.$element.attr("tabindex"));this.$button.attr('tabindex',this.$element.data('tabindex'));}},clickListener:function(){var that=this;$('body').on('touchstart.dropdown','.dropdown-menu',function(e){e.stopPropagation();});this.$newElement.on('click',function(){that.setSize();if(!that.options.liveSearch&&!that.multiple){setTimeout(function(){that.$menu.find('.selected a').focus();},10);}});this.$menu.on('click','li a',function(e){var clickedIndex=$(this).parent().index(),prevValue=that.$element.val(),prevIndex=that.$element.prop('selectedIndex');if(that.multiple){e.stopPropagation();} e.preventDefault();if(!that.isDisabled()&&!$(this).parent().hasClass('disabled')){var $options=that.$element.find('option');var $option=$options.eq(clickedIndex);if(!that.multiple){$options.prop('selected',false);$option.prop('selected',true);} else{var state=$option.prop('selected');$option.prop('selected',!state);} if(!that.multiple){that.$button.focus();}else if(that.options.liveSearch){that.$searchbox.focus();} if((prevValue!=that.$element.val()&&that.multiple)||(prevIndex!=that.$element.prop('selectedIndex')&&!that.multiple)){that.$element.change();}}});this.$menu.on('click','li.disabled a, li dt, li .div-contain, .popover-title, .popover-title :not(.close)',function(e){if(e.target==this){e.preventDefault();e.stopPropagation();if(!that.options.liveSearch){that.$button.focus();}else{that.$searchbox.focus();}}});this.$menu.on('click','.popover-title .close',function(){that.$button.focus();});this.$searchbox.on('click',function(e){e.stopPropagation();});this.$element.change(function(){that.render();});},liveSearchListener:function(){var that=this,no_results=$('
  • ');this.$newElement.on('click.dropdown.data-api',function(){that.$menu.find('.active').removeClass('active');if(!!that.$searchbox.val()){that.$searchbox.val('');that.$menu.find('li').show();no_results.remove();} if(!that.multiple)that.$menu.find('.selected').addClass('active');setTimeout(function(){that.$searchbox.focus();},10);});this.$searchbox.on('input propertychange',function(){if(that.$searchbox.val()){that.$menu.find('li').show().not(':icontains('+that.$searchbox.val()+')').hide();if(!that.$menu.find('li').filter(':visible:not(.no-results)').length){no_results.remove();no_results.html('No results match "'+that.$searchbox.val()+'"').show();that.$menu.find('li').last().after(no_results);}else{no_results.remove();}}else{that.$menu.find('li').show();} that.$menu.find('li.active').removeClass('active');that.$menu.find('li').filter(':visible:not(.divider)').eq(0).addClass('active').find('a').focus();$(this).focus();});this.$menu.on('mouseenter','a',function(e){that.$menu.find('.active').removeClass('active');$(e.currentTarget).parent().not('.disabled').addClass('active');});this.$menu.on('mouseleave','a',function(){that.$menu.find('.active').removeClass('active');});},val:function(value){if(value!=undefined){this.$element.val(value);this.$element.change();return this.$element;}else{return this.$element.val();}},selectAll:function(){this.$element.find('option').prop('selected',true).attr('selected','selected');this.render();},deselectAll:function(){this.$element.find('option').prop('selected',false).removeAttr('selected');this.render();},keydown:function(e){var $this,$items,$parent,index,next,first,last,prev,nextPrev,that,prevIndex,isActive,keyCodeMap={32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9"};$this=$(this);$parent=$this.parent();if($this.is('input'))$parent=$this.parent().parent();that=$parent.data('this');if(that.options.liveSearch)$parent=$this.parent().parent();if(that.options.container)$parent=that.$menu;$items=$('[role=menu] li:not(.divider) a',$parent);isActive=that.$menu.parent().hasClass('open');if(that.options.liveSearch){if(/(^9$|27)/.test(e.keyCode)&&isActive&&that.$menu.find('.active').length==0){e.preventDefault();that.$menu.parent().removeClass('open');that.$button.focus();} $items=$('[role=menu] li:not(.divider):visible',$parent);if(!$this.val()&&!/(38|40)/.test(e.keyCode)){if($items.filter('.active').length==0){$items=that.$newElement.find('li').filter(':icontains('+keyCodeMap[e.keyCode]+')');}}} if(!$items.length)return;if(/(38|40)/.test(e.keyCode)){if(!isActive){that.$menu.parent().addClass('open');} index=$items.index($items.filter(':focus'));first=$items.parent(':not(.disabled):visible').first().index();last=$items.parent(':not(.disabled):visible').last().index();next=$items.eq(index).parent().nextAll(':not(.disabled):visible').eq(0).index();prev=$items.eq(index).parent().prevAll(':not(.disabled):visible').eq(0).index();nextPrev=$items.eq(next).parent().prevAll(':not(.disabled):visible').eq(0).index();if(that.options.liveSearch){$items.each(function(i){if($(this).is(':not(.disabled)')){$(this).data('index',i);}});index=$items.index($items.filter('.active'));first=$items.filter(':not(.disabled):visible').first().data('index');last=$items.filter(':not(.disabled):visible').last().data('index');next=$items.eq(index).nextAll(':not(.disabled):visible').eq(0).data('index');prev=$items.eq(index).prevAll(':not(.disabled):visible').eq(0).data('index');nextPrev=$items.eq(next).prevAll(':not(.disabled):visible').eq(0).data('index');} prevIndex=$this.data('prevIndex');if(e.keyCode==38){if(that.options.liveSearch)index-=1;if(index!=nextPrev&&index>prev)index=prev;if(indexlast)index=last;if(index==prevIndex)index=first;} $this.data('prevIndex',index);if(!that.options.liveSearch){$items.eq(index).focus();}else{e.preventDefault();if(!$this.is('.dropdown-toggle')){$items.removeClass('active');$items.eq(index).addClass('active').find('a').focus();$this.focus();}}}else if(!$this.is('input')){var keyIndex=[];$items.each(function(){if($(this).parent().is(':not(.disabled)')){if($.trim($(this).text().toLowerCase()).substring(0,1)==keyCodeMap[e.keyCode]){keyIndex.push($(this).parent().index());}}});var count=$(document).data('keycount');count++;$(document).data('keycount',count);var prevKey=$.trim($(':focus').text().toLowerCase()).substring(0,1);if(prevKey!=keyCodeMap[e.keyCode]){count=1;$(document).data('keycount',count);}else if(count>=keyIndex.length){$(document).data('keycount',0);} $items.eq(keyIndex[count-1]).focus();} if(/(13|32|^9$)/.test(e.keyCode)&&isActive){if(!/(32)/.test(e.keyCode))e.preventDefault();if(!that.options.liveSearch){$(':focus').click();}else if(!/(32)/.test(e.keyCode)){that.$menu.find('.active a').click();$this.focus();} $(document).data('keycount',0);} if((/(^9$|27)/.test(e.keyCode)&&isActive&&(that.multiple||that.options.liveSearch))||(/(27)/.test(e.keyCode)&&!isActive)){that.$menu.parent().removeClass('open');that.$button.focus();}},hide:function(){this.$newElement.hide();},show:function(){this.$newElement.show();},destroy:function(){this.$newElement.remove();this.$element.remove();}};$.fn.selectpicker=function(option,event){var args=arguments;var value;var chain=this.each(function(){if($(this).is('select')){var $this=$(this),data=$this.data('selectpicker'),options=typeof option=='object'&&option;if(!data){$this.data('selectpicker',(data=new Selectpicker(this,options,event)));}else if(options){for(var i in options){data.options[i]=options[i];}} if(typeof option=='string'){var property=option;if(data[property]instanceof Function){[].shift.apply(args);value=data[property].apply(data,args);}else{value=data.options[property];}}}});if(value!=undefined){return value;}else{return chain;}};$.fn.selectpicker.defaults={style:'btn-default',size:'auto',title:null,selectedTextFormat:'values',noneSelectedText:'Nothing selected',countSelectedText:'{0} of {1} selected',width:false,container:false,hideDisabled:false,showSubtext:false,showIcon:true,showContent:true,dropupAuto:true,header:false,liveSearch:false};$(document).data('keycount',0).on('keydown','.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bootstrap-select-searchbox input',Selectpicker.prototype.keydown);}(window.jQuery);