source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/demos/autocomplete/remote-with-cache.html@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1<!doctype html>
2<html>
3<head>
4 <title>jQuery UI Autocomplete Remote with caching demo</title>
5 <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
6 <script type="text/javascript" src="../../jquery-1.4.1.js"></script>
7 <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
8 <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
9 <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
10 <script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
11 <link type="text/css" href="../demos.css" rel="stylesheet" />
12 <script type="text/javascript">
13 $(function() {
14 function log(message) {
15 $("<div/>").text(message).prependTo("#log");
16 $("#log").attr("scrollTop", 0);
17 }
18
19 var cache = {};
20 $("#birds").autocomplete({
21 source: function(request, response) {
22 if (cache.term == request.term && cache.content) {
23 response(cache.content);
24 }
25 if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
26 var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
27 response($.grep(cache.content, function(value) {
28 return matcher.test(value.value)
29 }));
30 }
31 $.ajax({
32 url: "search.php",
33 dataType: "json",
34 data: request,
35 success: function(data) {
36 cache.term = request.term;
37 cache.content = data;
38 response(data);
39 }
40 });
41 },
42 minLength: 2,
43 select: function(event, ui) {
44 log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
45 }
46 });
47 });
48 </script>
49</head>
50<body>
51
52<div class="demo">
53
54<div class="ui-widget">
55 <label for="birds">Birds: </label>
56 <input id="birds" />
57</div>
58
59<div class="ui-widget" style="margin-top:2em; font-family:Arial">
60 Result:
61 <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
62</div>
63
64</div><!-- End demo -->
65
66<div class="demo-description">
67<p>
68The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.
69</p>
70<p>
71Similar to the remote datasource demo, though this adds some local caching to improve performance. The cache here saves just one query, and could be extended to cache multiple values, one for each term.
72</p>
73</div><!-- End demo-description -->
74
75</body>
76</html>
Note: See TracBrowser for help on using the repository browser.