jquery-ui/demos/autocomplete/categories.html

76 lines
2.0 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">
2010-09-10 02:33:09 +00:00
<title>jQuery UI Autocomplete - Categories</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/position.js"></script>
<script src="../../ui/menu.js"></script>
<script src="../../ui/autocomplete.js"></script>
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>
2010-09-10 02:24:52 +00:00
<script>
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
},
2010-03-17 23:42:32 +00:00
_renderMenu: function( ul, items ) {
var that = this,
2010-03-17 23:42:32 +00:00
currentCategory = "";
$.each( items, function( index, item ) {
var li;
2010-03-17 23:42:32 +00:00
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
});
}
});
</script>
2010-09-10 02:24:52 +00:00
<script>
2010-03-17 23:42:32 +00:00
$(function() {
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>