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