PageSourceSearch

https://nevgen.org/js/nevgen/nevgen.combobox.js

js nevgen.org collected 2026-10-02 10:30:55 UTC 6,292 bytes, 139 lines download raw bytes

1(function( $ ) {
2        $.widget( "ui.combobox", {
3            select : function(event, ui){ alert (ui.item.value);},
4            _create: function() {
5                var input,
6                    that = this,
7                    select = this.element.hide(),
8                    selected = select.children( ":selected" ),
9                    value = selected.val() ? selected.text() : "",
10                    wrapper = this.wrapper = $( "<span>" )
11                        .addClass( "ui-combobox" )
12                        .insertAfter( select );
13
14                function removeIfInvalid(element) {
15                    var value = $( element ).val(),
16                        matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ),
17                        valid = false;
18                    select.children( "option" ).each(function() {
19                        if ( $( this ).text().match( matcher ) ) {
20                            this.selected = valid = true;
21                            return false;
22                        }
23                    });
24                    if ( !valid ) {
25                        // remove invalid value, as it didn't match anything
26                        $( element )
27                            .val( "" )
28                            .attr( "title", value + " didn't match any item" )
29                            .tooltip( "open" );
30                        select.val( "" );
31                        setTimeout(function() {
32                            input.tooltip( "close" ).attr( "title", "" );
33                        }, 2500 );
34                        input.data( "autocomplete" ).term = "";
35                        return false;
36                    }
37                }
38
39                input = $( "<input>" )
40                    .appendTo( wrapper )
41                    .val( value )
42                    .attr( "title", "" )
43                    .addClass( "ui-state-default ui-combobox-input" )
44                    .autocomplete({
45                        delay: 0,
46                        minLength: 0,
47                        source: function( request, response ) {
48                            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
49                            response( select.children( "option" ).map(function() {
50                                var text = $( this ).text();
51                                if ( this.value && ( !request.term || matcher.test(text) ) )
52                                    return {
53                                        label: text.replace(
54                                            new RegExp(
55                                                "(?![^&;]+;)(?!<[^<>]*)(" +
56                                                $.ui.autocomplete.escapeRegex(request.term) +
57                                                ")(?![^<>]*>)(?![^&;]+;)", "gi"
58                                            ), "<strong>$1</strong>" ),
59                                        value: text,
60                                        option: this
61                                    };
62                            }) );
63                        },
64                        select: function( event, ui ) {
65                        if(that.options.select != null){
66                            that.options.select(event, ui);
67                            }
68                            ui.item.option.selected = true;
69                            that._trigger( "selected", event, {
70                                item: ui.item.option
71                            });
72                        },
73                        change: function( event, ui ) {                         
74                            if ( !ui.item )
75                                return removeIfInvalid( this );
76
77                        }
78                    })
79                    .addClass( "ui-widget ui-widget-content ui-corner-left" );
80
81                input.data( "autocomplete" )._renderItem = function( ul, item ) {
82                    return $( "<li>" )
83                        .data( "item.autocomplete", item )
84                        .append( "<a>" + item.label + "</a>" )
85                        .appendTo( ul );
86                };
87
88                $( "<a>" )
89                    .attr( "tabIndex", -1 )
90                    .attr( "title", "Show All Items" )
91                    .tooltip()
92                    .appendTo( wrapper )
93                    .button({
94                        icons: {
95                            primary: "ui-icon-triangle-1-s"
96                        },
97                        text: false
98                    })
99                    .removeClass( "ui-corner-all" )
100                    .addClass( "ui-corner-right ui-combobox-toggle" )
101                    .click(function() {
102                        // close if already visible
103                        if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
104                            input.autocomplete( "close" );
105                            removeIfInvalid( input );
106                            return;
107                        }
108
109                        // work around a bug (likely same cause as #5265)
110                        $( this ).blur();
111
112                        // pass empty string as value to search for, displaying all results
113                        input.autocomplete( "search", "" );
114                        input.focus();
115                    });
116
117                    input
118                        .tooltip({
119                            position: {
120                                of: this.button
121                            },
122                            tooltipClass: "ui-state-highlight"
123                        });
124            },
125
126            destroy: function() {
127                this.wrapper.remove();
128                this.element.show();
129                $.Widget.prototype.destroy.call( this );
130            }
131        });
132    })( jQuery );
133
134    $(function() {
135        $( "#combobox" ).combobox({select : function(event, ui){ alert(ui.item.value); }});
136        $( "#toggle" ).click(function() {
137            $( "#combobox" ).toggle();
138        });
139    });

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.