2016-07-20 23:12:46 +02:00
|
|
|
!function(t){"use strict";var e=function(e,s){this.options=t.extend({},t.fn.combobox.defaults,s),this.template=this.options.template||this.template,this.$source=t(e),this.$container=this.setup(),this.$element=this.$container.find("input[type=text]"),this.$target=this.$container.find("input[type=hidden]"),this.$button=this.$container.find(".dropdown-toggle"),this.$menu=t(this.options.menu).appendTo("body"),this.matcher=this.options.matcher||this.matcher,this.sorter=this.options.sorter||this.sorter,this.highlighter=this.options.highlighter||this.highlighter,this.shown=!1,this.selected=!1,this.refresh(),this.transferAttributes(),this.listen()};e.prototype={constructor:e,setup:function(){var e=t(this.template());return this.$source.before(e),this.$source.hide(),e},disable:function(){this.$element.prop("disabled",!0),this.$button.attr("disabled",!0),this.disabled=!0,this.$container.addClass("combobox-disabled")},enable:function(){this.$element.prop("disabled",!1),this.$button.attr("disabled",!1),this.disabled=!1,this.$container.removeClass("combobox-disabled")},parse:function(){var e=this,s={},i=[],o=!1,n="";return this.$source.find("option").each(function(){var r=t(this);return""===r.val()?void(e.options.placeholder=r.text()):(s[r.text()]=r.val(),i.push(r.text()),void(r.prop("selected")&&(o=r.text(),n=r.val())))}),this.map=s,o&&(this.$element.val(o),this.$target.val(n),this.$container.addClass("combobox-selected"),this.selected=!0),i},transferAttributes:function(){this.options.placeholder=this.$source.attr("data-placeholder")||this.options.placeholder,"undefined"!==this.options.appendId&&this.$element.attr("id",this.$source.attr("id")+this.options.appendId),this.$element.attr("placeholder",this.options.placeholder),this.$target.prop("name",this.$source.prop("name")),this.$target.val(this.$source.val()),this.$source.removeAttr("name"),this.$element.attr("required",this.$source.attr("required")),this.$element.attr("rel",this.$source.attr("rel")),this.$element.attr("title",this.$source.attr("title")),this.$element.attr("class",this.$source.attr("class")),this.$element.attr("tabindex",this.$source.attr("tabindex")),this.$source.removeAttr("tabindex"),void 0!==this.$source.attr("disabled")&&this.disable()},select:function(){var t=this.$menu.find(".active").attr("data-value");return this.$element.val(this.updater(t)).trigger("change"),this.$target.val(this.map[t]).trigger("change"),this.$source.val(this.map[t]).trigger("change"),this.$container.addClass("combobox-selected"),this.selected=!0,this.hide()},updater:function(t){return t},show:function(){var e=t.extend({},this.$element.position(),{height:this.$element[0].offsetHeight});return this.$menu.insertAfter(this.$element).css({top:e.top+e.height,left:e.left}).show(),t(".dropdown-menu").on("mousedown",t.proxy(this.scrollSafety,this)),this.shown=!0,this},hide:function(){return this.$menu.hide(),t(".dropdown-menu").off("mousedown",t.proxy(this.scrollSafety,this)),this.$element.on("blur",t.proxy(this.blur,this)),this.shown=!1,this},lookup:function(t){return this.query=this.$element.val(),this.process(this.source)},process:function(e){var s=this;return e=t.grep(e,function(t){return s.matcher(t)}),e=this.sorter(e),e.length?this.render(e.slice(0,this.options.items)).show():this.shown?this.hide():this},template:function(){return"2"==this.options.bsVersion?'<div class="combobox-container"><input type="hidden" /> <div class="input-append"> <input type="text" autocomplete="false" /> <span class="add-on dropdown-toggle" data-dropdown="dropdown"> <span class="caret"/> <i class="icon-remove"/> </span> </div> </div>':'<div class="combobox-container"> <input type="hidden" /> <div class="input-group"> <input type="text" autocomplete="false" /> <span class="input-group-addon dropdown-toggle" data-dropdown="dropdown"> <span class="caret" /> <span class="glyphicon glyphicon-remove" /> </span> </div> </div>'},matcher:function(t){return~t.toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(t){for(var e,s=[],i=[],o=[];e=t.shift();)e.toLowerCase().indexOf(this.query.toLowerCase())?~e.inde
|