1
0
Fork 0
wmdeit_kaform/addons/combobox/kube.combobox.min.js

1 line
1.8 KiB
JavaScript

!function(e){e.add("module","combobox",{init:function(e,t){this.app=e,this.$win=e.$win;var s={placeholder:""};this.context=t,this.params=t.getParams(s),this.$element=t.getElement()},start:function(){this._buildSource(),this._buildCaret(),this._buildEvent()},stop:function(){this.$sourceBox.after(this.$element),this.$sourceBox.remove(),this.$element.off(".kube.combobox"),this.$win.off(".kube.combobox")},_buildSource:function(){this.$sourceBox=e.dom("<div>"),this.$sourceBox.addClass("combobox"),this.$source=e.dom("<input>"),this.$source.attr("type","text"),this.$source.attr("placeholder",this.params.placeholder),this.$sourceBox.width(this.$element.width()),this.$sourceBox.append(this.$source),this.$element.after(this.$sourceBox),this.$element.attr("class",""),this.$element.attr("style",""),this.$sourceBox.append(this.$element),this.$win.on("resize.kube.combobox",this._resize.bind(this))},_buildCaret:function(){this.$sourceCaret=e.dom("<span>"),this.$sourceCaret.addClass("combobox-caret"),this.$sourceBox.append(this.$sourceCaret)},_buildEvent:function(){this.$element.on("change.kube.combobox",this._select.bind(this)),this.$source.on("keyup.kube.combobox",this._type.bind(this))},_resize:function(){this.$sourceBox.width(this.$element.width())},_type:function(t){var s=this.$source.val();this.app.broadcast("combobox.set",this,s),this.$sourceValue&&this.$sourceValue.remove(),""!==s.trim()&&(this.$sourceValue=e.dom("<option>"),this.$sourceValue.attr("value",s),this.$sourceValue.attr("selected",!0),this.$sourceValue.text(s),this.$sourceValue.addClass("is-hidden"),this.$element.append(this.$sourceValue))},_select:function(e){var t=e.target,s=t.options[t.selectedIndex].text;this.$sourceValue&&this.$sourceValue.remove(),this.$source.val(s),this.app.broadcast("combobox.set",this,s)}})}(Kube);