| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2007 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
--> |
| 9 |
<!-- |
| 10 |
--> |
| 11 |
<head> |
| 12 |
<title>goog.ui.ac.Remote</title> |
| 13 |
<script src="../base.js"></script> |
| 14 |
<script> |
| 15 |
goog.require('goog.ui.ac.AutoComplete'); |
| 16 |
goog.require('goog.ui.ac.InputHandler'); |
| 17 |
goog.require('goog.ui.ac.Renderer'); |
| 18 |
goog.require('goog.ui.ac.RemoteArrayMatcher'); |
| 19 |
goog.require('goog.ui.ac.CachingMatcher'); |
| 20 |
goog.require('goog.ui.ac.Remote'); |
| 21 |
</script> |
| 22 |
<link rel="stylesheet" href="css/demo.css"> |
| 23 |
<link rel="stylesheet" href="../css/autocomplete.css"> |
| 24 |
</head> |
| 25 |
<body> |
| 26 |
<h1>goog.ui.ac.Remote</h1> |
| 27 |
|
| 28 |
Google Buzzwords:<br> |
| 29 |
<input type="text" id="txtInput" style="width:500px"><br> |
| 30 |
<p> |
| 31 |
This data is being pulled from the server at |
| 32 |
<a href="autocompleteremotedata.js">autocompleteremotedata.js</a>. |
| 33 |
</p> |
| 34 |
<p> |
| 35 |
Ideally the server would perform a search on the query and would only |
| 36 |
return relevant results; however, this response is static. |
| 37 |
</p> |
| 38 |
|
| 39 |
<script> |
| 40 |
var input = document.getElementById('txtInput'); |
| 41 |
var ac = new goog.ui.ac.Remote('autocompleteremotedata.js', |
| 42 |
input); |
| 43 |
</script> |
| 44 |
|
| 45 |
<h1>goog.ui.ac.CachingMatcher on top of goog.ui.ac.RemoteArrayMatcher</h1> |
| 46 |
|
| 47 |
Google Buzzwords:<br> |
| 48 |
<input type="text" id="txtInput2" style="width:500px"><br> |
| 49 |
<p> |
| 50 |
This data is being pulled from the server at |
| 51 |
<a href="autocompleteremotedata.js">autocompleteremotedata.js</a>. |
| 52 |
</p> |
| 53 |
<p> |
| 54 |
This sets up a client-side cache of suggestions from the server, and matches |
| 55 |
against the client cache when the user types, while simultaneously making |
| 56 |
requests to the server in the background. The result feels more responsive |
| 57 |
than the goog.ui.ac.Remote, which has no client cache. |
| 58 |
</p> |
| 59 |
|
| 60 |
<script> |
| 61 |
var input = document.getElementById('txtInput2'); |
| 62 |
|
| 63 |
var matcher = new goog.ui.ac.CachingMatcher( |
| 64 |
new goog.ui.ac.RemoteArrayMatcher('autocompleteremotedata.js')); |
| 65 |
// Note - we specify a very low throttle time (10ms) because we are serving |
| 66 |
// these responses directly from the client cache. By default, the |
| 67 |
// CachingMatcher already throttles the requests to its underlying matcher |
| 68 |
// to 1 request every 300ms. |
| 69 |
var inputHandler = new goog.ui.ac.InputHandler(null, null, false, 10); |
| 70 |
var renderer = new goog.ui.ac.Renderer(); |
| 71 |
|
| 72 |
var autoComplete = new goog.ui.ac.AutoComplete( |
| 73 |
matcher, renderer, inputHandler); |
| 74 |
inputHandler.attachAutoComplete(autoComplete); |
| 75 |
inputHandler.attachInputs(input); |
| 76 |
</script> |
| 77 |
</body> |
| 78 |
</html> |