aboutsummaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2010-01-26 20:52:21 +0000
committerJörn Zaefferer <joern.zaefferer@gmail.com>2010-01-26 20:52:21 +0000
commit1382af8af0196a0bce10d8c58f449d2320cdf8a9 (patch)
tree13a1e5cadc625f90de40c187d05a1eddc0de3da8 /demos
parentc3dd4ac373660b1d36eb527a7ad1387d5d39ef9d (diff)
downloadjquery-ui-1382af8af0196a0bce10d8c58f449d2320cdf8a9.tar.gz
jquery-ui-1382af8af0196a0bce10d8c58f449d2320cdf8a9.zip
autocomplete: added xml-parsing demo
Diffstat (limited to 'demos')
-rw-r--r--demos/autocomplete/index.html1
-rw-r--r--demos/autocomplete/london.xml114
-rw-r--r--demos/autocomplete/xml.html68
3 files changed, 183 insertions, 0 deletions
diff --git a/demos/autocomplete/index.html b/demos/autocomplete/index.html
index ffca515e0..3063d8db8 100644
--- a/demos/autocomplete/index.html
+++ b/demos/autocomplete/index.html
@@ -14,6 +14,7 @@
<li><a href="remote-jsonp.html">Remote JSONP datasource</a></li>
<li><a href="combobox.html">Combobox</a></li>
<li><a href="custom-data.html">Custom data and display</a></li>
+ <li><a href="xml.html">XML data parsed once</a></li>
</ul>
</div>
</body>
diff --git a/demos/autocomplete/london.xml b/demos/autocomplete/london.xml
new file mode 100644
index 000000000..262854998
--- /dev/null
+++ b/demos/autocomplete/london.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<geonames style="MEDIUM">
+<totalResultsCount>6987</totalResultsCount>
+<geoname>
+<name>London</name>
+<lat>51.5084152563931</lat>
+<lng>-0.125532746315002</lng>
+<geonameId>2643743</geonameId>
+<countryCode>GB</countryCode>
+<countryName>United Kingdom</countryName>
+
+<fcl>P</fcl>
+<fcode>PPLC</fcode>
+</geoname>
+<geoname>
+<name>London</name>
+<lat>42.983389283</lat>
+<lng>-81.233042387</lng>
+<geonameId>6058560</geonameId>
+<countryCode>CA</countryCode>
+<countryName>Canada</countryName>
+
+<fcl>P</fcl>
+<fcode>PPL</fcode>
+</geoname>
+<geoname>
+<name>East London</name>
+<lat>-33.0152850934643</lat>
+<lng>27.9116249084473</lng>
+<geonameId>1006984</geonameId>
+<countryCode>ZA</countryCode>
+<countryName>South Africa</countryName>
+
+<fcl>P</fcl>
+<fcode>PPL</fcode>
+</geoname>
+<geoname>
+<name>City</name>
+<lat>51.5133363996235</lat>
+<lng>-0.0890064239501953</lng>
+<geonameId>2643744</geonameId>
+<countryCode>GB</countryCode>
+<countryName>United Kingdom</countryName>
+
+<fcl>A</fcl>
+<fcode>ADM2</fcode>
+</geoname>
+<geoname>
+<name>London</name>
+<lat>37.1289771</lat>
+<lng>-84.0832646</lng>
+<geonameId>4298960</geonameId>
+<countryCode>US</countryCode>
+<countryName>United States</countryName>
+
+<fcl>P</fcl>
+<fcode>PPL</fcode>
+</geoname>
+<geoname>
+<name>The Tower of London</name>
+<lat>51.5082349601834</lat>
+<lng>-0.0763034820556641</lng>
+<geonameId>6286786</geonameId>
+<countryCode>GB</countryCode>
+<countryName>United Kingdom</countryName>
+
+<fcl>S</fcl>
+<fcode>CSTL</fcode>
+</geoname>
+<geoname>
+<name>London Reefs</name>
+<lat>8.85</lat>
+<lng>112.5333333</lng>
+<geonameId>1879967</geonameId>
+<countryCode> </countryCode>
+<countryName> </countryName>
+
+<fcl>U</fcl>
+<fcode>RFSU</fcode>
+</geoname>
+<geoname>
+<name>Greater London</name>
+<lat>51.5</lat>
+<lng>-0.1666667</lng>
+<geonameId>2648110</geonameId>
+<countryCode>GB</countryCode>
+<countryName>United Kingdom</countryName>
+
+<fcl>A</fcl>
+<fcode>ADM2</fcode>
+</geoname>
+<geoname>
+<name>London</name>
+<lat>46.1666667</lat>
+<lng>6.0166667</lng>
+<geonameId>2661811</geonameId>
+<countryCode>CH</countryCode>
+<countryName>Switzerland</countryName>
+
+<fcl>H</fcl>
+<fcode>STM</fcode>
+</geoname>
+<geoname>
+<name>London Borough of Islington</name>
+<lat>51.5333333</lat>
+<lng>-0.1333333</lng>
+<geonameId>3333156</geonameId>
+<countryCode>GB</countryCode>
+<countryName>United Kingdom</countryName>
+
+<fcl>A</fcl>
+<fcode>ADM2</fcode>
+</geoname>
+</geonames>
diff --git a/demos/autocomplete/xml.html b/demos/autocomplete/xml.html
new file mode 100644
index 000000000..92a089b56
--- /dev/null
+++ b/demos/autocomplete/xml.html
@@ -0,0 +1,68 @@
+<!doctype html>
+<html>
+<head>
+ <title>jQuery UI Autocomplete Remote datasource demo</title>
+ <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
+ <script type="text/javascript" src="../../jquery-1.4.js"></script>
+ <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
+ <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
+ <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
+ <script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
+ <link type="text/css" href="../demos.css" rel="stylesheet" />
+ <script type="text/javascript">
+ $(function() {
+ function log(message) {
+ $("<div/>").text(message).prependTo("#log");
+ $("#log").attr("scrollTop", 0);
+ }
+
+ $.ajax({
+ url: "london.xml",
+ dataType: "xml",
+ success: function(xmlResponse) {
+ var data = $("geoname", xmlResponse).map(function() {
+ return {
+ value: $("name", this).text() + ", " + ($.trim($("countryName", this).text()) || "(unknown country)"),
+ id: $("geonameId", this).text()
+ };
+ }).get();
+ $("#birds").autocomplete({
+ source: data,
+ minLength: 0,
+ select: function(event, ui) {
+ log(ui.item ? ("Selected: " + ui.item.value + ", geonameId: " + ui.item.id) : "Nothing selected, input was " + this.value);
+ }
+ });
+ }
+ })
+
+ });
+ </script>
+</head>
+<body>
+
+<div class="demo">
+
+<div class="ui-widget">
+ <label for="birds">London matches: </label>
+ <input id="birds" />
+</div>
+
+<div class="ui-widget" style="margin-top:2em; font-family:Arial">
+ Result:
+ <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
+</div>
+
+</div><!-- End demo -->
+
+<div class="demo-description">
+<p>
+This demo shows how to retrieve some XML data, parse it using jQuery's methods, then provide it to the autocomplete as the datasource.
+</p>
+<p>
+This should also serve as a reference on how to parse a remote XML datasource - the parsing would just happen for each request within the source-callback.
+</p>
+</div><!-- End demo-description -->
+
+</body>
+</html>