Created
November 27, 2012 13:57
-
-
Save mbajur/4154343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Custom jquery.ui.autocomplete widget | |
* for main search input | |
*/ | |
$.widget( "custom.catcomplete", $.ui.autocomplete, { | |
_renderMenu: function( ul, items ) { | |
var that = this, | |
currentCategory = ""; | |
$.each( items, function( index, item ) { | |
if ( item.category != currentCategory ) { | |
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" ); | |
currentCategory = item.category; | |
} | |
that._renderItemData( ul, item ); | |
}); | |
} | |
}); | |
$(document).ready(function(){ | |
/** | |
* Main search input autocomplete data | |
* and init | |
*/ | |
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" } | |
]; | |
$( "#search" ).catcomplete({ | |
delay: 0, | |
source: data | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link href="/assets/jquery.ui.core.css?body=1" media="all" rel="stylesheet" type="text/css" /> | |
<link href="/assets/jquery.ui.theme.css?body=1" media="all" rel="stylesheet" type="text/css" /> | |
<link href="/assets/jquery.ui.autocomplete.css?body=1" media="all" rel="stylesheet" type="text/css" /> | |
<script src="/assets/jquery.js?body=1" type="text/javascript"></script> | |
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> | |
<script src="/assets/jquery.ui.core.js?body=1" type="text/javascript"></script> | |
<script src="/assets/jquery.ui.widget.js?body=1" type="text/javascript"></script> | |
<script src="/assets/jquery.ui.position.js?body=1" type="text/javascript"></script> | |
<script src="/assets/jquery.ui.autocomplete.js?body=1" type="text/javascript"></script> | |
<script src="/assets/application.js?body=1" type="text/javascript"></script> | |
<meta content="authenticity_token" name="csrf-param" /> | |
<meta content="sco9E+wtF+66jeoV01yruD4i8BtdrdwjfUOYnVegdu4=" name="csrf-token" /> | |
</head> | |
<body> | |
<form class='navbar-form pull-left'> | |
<input class='span5' id='search' placeholder='Search...' type='text'> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment