jquery-ui/demos/autocomplete/categories.html

68 lines
1.9 KiB
HTML
Raw Normal View History

2012-09-10 15:33:46 +00:00
<!doctype html>
2010-03-17 23:42:32 +00:00
<html lang="en">
<head>
2010-09-10 02:24:52 +00:00
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
2010-09-10 02:33:09 +00:00
<title>jQuery UI Autocomplete - Categories</title>
<link rel="stylesheet" href="../../themes/base/all.css">
2010-09-10 02:24:52 +00:00
<link rel="stylesheet" href="../demos.css">
<style>
2010-03-17 23:42:32 +00:00
.ui-autocomplete-category {
2010-09-10 02:24:52 +00:00
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
2010-03-17 23:42:32 +00:00
}
</style>
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
},
_renderMenu: function( ul, items ) {
var that = this,
currentCategory = "";
$.each( items, function( index, item ) {
var li;
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
li = that._renderItemData( ul, item );
if ( item.category ) {
li.attr( "aria-label", item.category + " : " + item.label );
}
});
}
});
2010-03-17 23:42:32 +00:00
var data = [
{ label: "anders", category: "" },
{ label: "andreas", category: "" },
{ label: "antal", category: "" },
{ label: "annhhx10", category: "Products" },
{ label: "annk K12", category: "Products" },
{ label: "annttop C13", category: "Products" },
{ label: "anders andersson", category: "People" },
{ label: "andreas andersson", category: "People" },
{ label: "andreas johnson", category: "People" }
];
2011-05-27 12:32:48 +00:00
2010-09-10 02:24:52 +00:00
$( "#search" ).catcomplete({
2010-03-17 23:42:32 +00:00
delay: 0,
source: data
});
</script>
</head>
<body>
2012-09-10 15:33:46 +00:00
<label for="search">Search: </label>
<input id="search">
2010-09-10 02:24:52 +00:00
2010-03-17 23:42:32 +00:00
<div class="demo-description">
2010-09-10 02:24:52 +00:00
<p>A categorized search result. Try typing "a" or "n".</p>
2012-09-10 15:33:46 +00:00
</div>
2010-03-17 23:42:32 +00:00
</body>
</html>