| 1 |
<!doctype html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 |
<title>jQuery UI Autocomplete - Custom data and display</title> |
| 7 |
<link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 |
<link rel="stylesheet" href="../demos.css"> |
| 9 |
<style> |
| 10 |
#project-label { |
| 11 |
display: block; |
| 12 |
font-weight: bold; |
| 13 |
margin-bottom: 1em; |
| 14 |
} |
| 15 |
#project-icon { |
| 16 |
float: left; |
| 17 |
height: 32px; |
| 18 |
width: 32px; |
| 19 |
} |
| 20 |
#project-description { |
| 21 |
margin: 0; |
| 22 |
padding: 0; |
| 23 |
} |
| 24 |
</style> |
| 25 |
<script src="../../external/requirejs/require.js"></script> |
| 26 |
<script src="../bootstrap.js"> |
| 27 |
var projects = [ |
| 28 |
{ |
| 29 |
value: "jquery", |
| 30 |
label: "jQuery", |
| 31 |
desc: "the write less, do more, JavaScript library", |
| 32 |
icon: "jquery_32x32.png" |
| 33 |
}, |
| 34 |
{ |
| 35 |
value: "jquery-ui", |
| 36 |
label: "jQuery UI", |
| 37 |
desc: "the official user interface library for jQuery", |
| 38 |
icon: "jqueryui_32x32.png" |
| 39 |
}, |
| 40 |
{ |
| 41 |
value: "sizzlejs", |
| 42 |
label: "Sizzle JS", |
| 43 |
desc: "a pure-JavaScript CSS selector engine", |
| 44 |
icon: "sizzlejs_32x32.png" |
| 45 |
} |
| 46 |
]; |
| 47 |
|
| 48 |
$( "#project" ).autocomplete({ |
| 49 |
minLength: 0, |
| 50 |
source: projects, |
| 51 |
focus: function( event, ui ) { |
| 52 |
$( "#project" ).val( ui.item.label ); |
| 53 |
return false; |
| 54 |
}, |
| 55 |
select: function( event, ui ) { |
| 56 |
$( "#project" ).val( ui.item.label ); |
| 57 |
$( "#project-id" ).val( ui.item.value ); |
| 58 |
$( "#project-description" ).html( ui.item.desc ); |
| 59 |
$( "#project-icon" ).attr( "src", "images/" + ui.item.icon ); |
| 60 |
|
| 61 |
return false; |
| 62 |
} |
| 63 |
}) |
| 64 |
.autocomplete( "instance" )._renderItem = function( ul, item ) { |
| 65 |
return $( "<li>" ) |
| 66 |
.append( "<div>" + item.label + "<br>" + item.desc + "</div>" ) |
| 67 |
.appendTo( ul ); |
| 68 |
}; |
| 69 |
</script> |
| 70 |
</head> |
| 71 |
<body> |
| 72 |
|
| 73 |
<div id="project-label">Select a project (type "j" for a start):</div> |
| 74 |
<img id="project-icon" src="images/transparent_1x1.png" class="ui-state-default" alt=""> |
| 75 |
<input id="project"> |
| 76 |
<input type="hidden" id="project-id"> |
| 77 |
<p id="project-description"></p> |
| 78 |
|
| 79 |
<div class="demo-description"> |
| 80 |
<p>You can use your own custom data formats and displays by simply overriding the default focus and select actions.</p> |
| 81 |
<p>Try typing "j" to get a list of projects or just press the down arrow.</p> |
| 82 |
</div> |
| 83 |
</body> |
| 84 |
</html> |