Subversion Repositories Sites.obs-saisons.fr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
40 aurelien 1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
	<meta charset="utf-8">
5
	<title>jQuery UI Autocomplete - Remote JSONP datasource</title>
6
	<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7
	<script src="../../jquery-1.4.2.js"></script>
8
	<script src="../../ui/jquery.ui.core.js"></script>
9
	<script src="../../ui/jquery.ui.widget.js"></script>
10
	<script src="../../ui/jquery.ui.position.js"></script>
11
	<script src="../../ui/jquery.ui.autocomplete.js"></script>
12
	<link rel="stylesheet" href="../demos.css">
13
	<style>
14
	.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
15
	#city { width: 25em; }
16
	</style>
17
	<script>
18
	$(function() {
19
		function log( message ) {
20
			$( "<div/>" ).text( message ).prependTo( "#log" );
21
			$( "#log" ).attr( "scrollTop", 0 );
22
		}
23
 
24
		$( "#city" ).autocomplete({
25
			source: function( request, response ) {
26
				$.ajax({
27
					url: "http://ws.geonames.org/searchJSON",
28
					dataType: "jsonp",
29
					data: {
30
						featureClass: "P",
31
						style: "full",
32
						maxRows: 12,
33
						name_startsWith: request.term
34
					},
35
					success: function( data ) {
36
						response( $.map( data.geonames, function( item ) {
37
							return {
38
								label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
39
								value: item.name
40
							}
41
						}));
42
					}
43
				});
44
			},
45
			minLength: 2,
46
			select: function( event, ui ) {
47
				log( ui.item ?
48
					"Selected: " + ui.item.label :
49
					"Nothing selected, input was " + this.value);
50
			},
51
			open: function() {
52
				$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
53
			},
54
			close: function() {
55
				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
56
			}
57
		});
58
	});
59
	</script>
60
</head>
61
<body>
62
 
63
<div class="demo">
64
 
65
<div class="ui-widget">
66
	<label for="city">Your city: </label>
67
	<input id="city" />
68
	Powered by <a href="http://geonames.org">geonames.org</a>
69
</div>
70
 
71
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
72
	Result:
73
	<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
74
</div>
75
 
76
</div><!-- End demo -->
77
 
78
 
79
 
80
<div class="demo-description">
81
<p>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.</p>
82
<p>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.</p>
83
</div><!-- End demo-description -->
84
 
85
</body>
86
</html>