mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-04 22:28:21 +00:00
Begin moving to NPM/Gulp based build system
There are too many options.
This commit is contained in:
@@ -1,100 +1 @@
|
||||
jQuery(function($) {
|
||||
$
|
||||
.widget(
|
||||
"custom.combobox",
|
||||
{
|
||||
_create : function() {
|
||||
this.wrapper = $("<span>").addClass(
|
||||
"custom-combobox")
|
||||
.insertAfter(this.element);
|
||||
|
||||
this.element.hide();
|
||||
this._createAutocomplete();
|
||||
},
|
||||
|
||||
_createAutocomplete : function() {
|
||||
var selected = this.element.children(":selected"), value = selected
|
||||
.val() ? selected.text() : "";
|
||||
|
||||
this.input = $("<input>").appendTo(this.wrapper)
|
||||
.val(value).attr("title", "").addClass(
|
||||
"form-control").autocomplete({
|
||||
delay : 0,
|
||||
minLength : 3,
|
||||
source : $.proxy(this, "_source")
|
||||
}).tooltip({
|
||||
tooltipClass : "ui-state-highlight"
|
||||
});
|
||||
|
||||
this._on(this.input, {
|
||||
autocompleteselect : function(event, ui) {
|
||||
ui.item.option.selected = true;
|
||||
this._trigger("select", event, {
|
||||
item : ui.item.option
|
||||
});
|
||||
},
|
||||
|
||||
autocompletechange : "_removeIfInvalid"
|
||||
});
|
||||
},
|
||||
|
||||
_source : function(request, response) {
|
||||
var matcher = new RegExp($.ui.autocomplete
|
||||
.escapeRegex(request.term), "i");
|
||||
response(this.element.children("option").map(
|
||||
function() {
|
||||
var text = $(this).text();
|
||||
if (this.value
|
||||
&& (!request.term || matcher
|
||||
.test(text)))
|
||||
return {
|
||||
label : text,
|
||||
value : text,
|
||||
option : this
|
||||
};
|
||||
}));
|
||||
},
|
||||
|
||||
_removeIfInvalid : function(event, ui) {
|
||||
|
||||
// Selected an item, nothing to do
|
||||
if (ui.item) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Search for a match (case-insensitive)
|
||||
var value = this.input.val(), valueLowerCase = value
|
||||
.toLowerCase(), valid = false;
|
||||
this.element
|
||||
.children("option")
|
||||
.each(
|
||||
function() {
|
||||
if ($(this).text()
|
||||
.toLowerCase() === valueLowerCase) {
|
||||
this.selected = valid = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Found a match, nothing to do
|
||||
if (valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove invalid value
|
||||
this.input.val("").attr("title",
|
||||
value + " didn't match any item").tooltip(
|
||||
"open");
|
||||
this.element.val("");
|
||||
this._delay(function() {
|
||||
this.input.tooltip("close").attr("title", "");
|
||||
}, 25000);
|
||||
this.input.data("ui-autocomplete").term = "";
|
||||
},
|
||||
|
||||
_destroy : function() {
|
||||
this.wrapper.remove();
|
||||
this.element.show();
|
||||
}
|
||||
});
|
||||
});
|
||||
jQuery(function(s){s.widget("custom.combobox",{_create:function(){this.wrapper=s("<span>").addClass("custom-combobox").insertAfter(this.element),this.element.hide(),this._createAutocomplete()},_createAutocomplete:function(){var t=this.element.children(":selected"),e=t.val()?t.text():"";this.input=s("<input>").appendTo(this.wrapper).val(e).attr("title","").addClass("form-control").autocomplete({delay:0,minLength:3,source:s.proxy(this,"_source")}).tooltip({tooltipClass:"ui-state-highlight"}),this._on(this.input,{autocompleteselect:function(t,e){e.item.option.selected=!0,this._trigger("select",t,{item:e.item.option})},autocompletechange:"_removeIfInvalid"})},_source:function(e,t){var i=new RegExp(s.ui.autocomplete.escapeRegex(e.term),"i");t(this.element.children("option").map(function(){var t=s(this).text();if(this.value&&(!e.term||i.test(t)))return{label:t,value:t,option:this}}))},_removeIfInvalid:function(t,e){if(!e.item){var i=this.input.val(),o=i.toLowerCase(),n=!1;this.element.children("option").each(function(){if(s(this).text().toLowerCase()===o)return this.selected=n=!0,!1}),n||(this.input.val("").attr("title",i+" didn't match any item").tooltip("open"),this.element.val(""),this._delay(function(){this.input.tooltip("close").attr("title","")},25e3),this.input.data("ui-autocomplete").term="")}},_destroy:function(){this.wrapper.remove(),this.element.show()}})});
|
||||
Reference in New Issue
Block a user