49083bdeea021deba27d384020e207589622ce21
[myslice.git] / third-party / jquery-ui-1.10.2 / demos / autocomplete / remote-jsonp.html
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.9.1.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.menu.js"></script>
12         <script src="../../ui/jquery.ui.autocomplete.js"></script>
13         <link rel="stylesheet" href="../demos.css">
14         <style>
15         .ui-autocomplete-loading {
16                 background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
17         }
18         #city { width: 25em; }
19         </style>
20         <script>
21         $(function() {
22                 function log( message ) {
23                         $( "<div>" ).text( message ).prependTo( "#log" );
24                         $( "#log" ).scrollTop( 0 );
25                 }
26
27                 $( "#city" ).autocomplete({
28                         source: function( request, response ) {
29                                 $.ajax({
30                                         url: "http://ws.geonames.org/searchJSON",
31                                         dataType: "jsonp",
32                                         data: {
33                                                 featureClass: "P",
34                                                 style: "full",
35                                                 maxRows: 12,
36                                                 name_startsWith: request.term
37                                         },
38                                         success: function( data ) {
39                                                 response( $.map( data.geonames, function( item ) {
40                                                         return {
41                                                                 label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
42                                                                 value: item.name
43                                                         }
44                                                 }));
45                                         }
46                                 });
47                         },
48                         minLength: 2,
49                         select: function( event, ui ) {
50                                 log( ui.item ?
51                                         "Selected: " + ui.item.label :
52                                         "Nothing selected, input was " + this.value);
53                         },
54                         open: function() {
55                                 $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
56                         },
57                         close: function() {
58                                 $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
59                         }
60                 });
61         });
62         </script>
63 </head>
64 <body>
65
66 <div class="ui-widget">
67         <label for="city">Your city: </label>
68         <input id="city">
69         Powered by <a href="http://geonames.org">geonames.org</a>
70 </div>
71
72 <div class="ui-widget" style="margin-top:2em; font-family:Arial">
73         Result:
74         <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
75 </div>
76
77 <div class="demo-description">
78 <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>
79 <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>
80 </div>
81 </body>
82 </html>