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>
|
2013-12-02 18:36:12 +00:00
|
|
|
<link rel="stylesheet" href="../../themes/base/all.css">
|
2014-06-10 11:55:45 +00:00
|
|
|
<script src="../../external/jquery/jquery.js"></script>
|
2013-12-02 18:36:12 +00:00
|
|
|
<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, {
|
2013-11-13 17:51:48 +00:00
|
|
|
_create: function() {
|
|
|
|
this._super();
|
2013-11-13 18:17:51 +00:00
|
|
|
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
|
2013-11-13 17:51:48 +00:00
|
|
|
},
|
2010-03-17 23:42:32 +00:00
|
|
|
_renderMenu: function( ul, items ) {
|
2012-02-12 14:14:36 +00:00
|
|
|
var that = this,
|
2010-03-17 23:42:32 +00:00
|
|
|
currentCategory = "";
|
|
|
|
$.each( items, function( index, item ) {
|
2013-12-22 16:36:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-12-22 16:36:43 +00:00
|
|
|
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>
|