client/player/development-bundle/demos/autocomplete/remote-jsonp.html
changeset 57 3a3c15c462f8
parent 48 44d58d2e90b5
parent 56 da0957782d03
child 58 ec1d0e7dcb53
equal deleted inserted replaced
48:44d58d2e90b5 57:3a3c15c462f8
     1 <!DOCTYPE html>
       
     2 <html lang="en">
       
     3 <head>
       
     4 	<meta charset="UTF-8" />
       
     5 	<title>jQuery UI Autocomplete Remote JSONP datasource demo</title>
       
     6 	<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
       
     7 	<script type="text/javascript" src="../../jquery-1.4.2.js"></script>
       
     8 	<script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
       
     9 	<script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
       
    10 	<script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
       
    11 	<script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
       
    12 	<link type="text/css" href="../demos.css" rel="stylesheet" />
       
    13 	<script type="text/javascript">
       
    14 	$(function() {
       
    15 		function log(message) {
       
    16 			$("<div/>").text(message).prependTo("#log");
       
    17 			$("#log").attr("scrollTop", 0);
       
    18 		}
       
    19 		
       
    20 		$("#city").autocomplete({
       
    21 			source: function(request, response) {
       
    22 				$.ajax({
       
    23 					url: "http://ws.geonames.org/searchJSON",
       
    24 					dataType: "jsonp",
       
    25 					data: {
       
    26 						featureClass: "P",
       
    27 						style: "full",
       
    28 						maxRows: 12,
       
    29 						name_startsWith: request.term
       
    30 					},
       
    31 					success: function(data) {
       
    32 						response($.map(data.geonames, function(item) {
       
    33 							return {
       
    34 								label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
       
    35 								value: item.name
       
    36 							}
       
    37 						}))
       
    38 					}
       
    39 				})
       
    40 			},
       
    41 			minLength: 2,
       
    42 			select: function(event, ui) {
       
    43 				log(ui.item ? ("Selected: " + ui.item.label) : "Nothing selected, input was " + this.value);
       
    44 			},
       
    45 			open: function() {
       
    46 				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
       
    47 			},
       
    48 			close: function() {
       
    49 				$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
       
    50 			}
       
    51 		});
       
    52 	});
       
    53 	</script>
       
    54 	<style>
       
    55 		.ui-autocomplete-loading { background: url(indicator.gif) no-repeat right; }
       
    56 		#city { width: 25em; }
       
    57 	</style>
       
    58 </head>
       
    59 <body>
       
    60 
       
    61 <div class="demo">
       
    62 
       
    63 <div class="ui-widget">
       
    64 	<label for="city">Your city: </label>
       
    65 	<input id="city" />
       
    66 	Powered by <a href="http://geonames.org">geonames.org</a>
       
    67 </div>
       
    68 
       
    69 <div class="ui-widget" style="margin-top:2em; font-family:Arial">
       
    70 	Result:
       
    71 	<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
       
    72 </div>
       
    73 
       
    74 </div><!-- End demo -->
       
    75 
       
    76 <div class="demo-description">
       
    77 <p>
       
    78 The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are cities, displayed when at least two characters are entered into the field.
       
    79 </p>
       
    80 <p>
       
    81 In this case, the datasource is the <a href="http://geonames.org">geonames.org webservice</a>. While only the city name itself ends up in the input after selecting an element, more info is displayed in the suggestions to help find the right entry. That data is also available in callbacks, as illustrated by the Result area below the input. 
       
    82 </p>
       
    83 </div><!-- End demo-description -->
       
    84 
       
    85 </body>
       
    86 </html>