|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: DataSource with Polling</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: DataSource with Polling</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style scoped> |
|
|
29 |
/* custom styles for this example */ |
|
|
30 |
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;} |
|
|
31 |
</style> |
|
|
32 |
|
|
|
33 |
<div class="intro"> |
|
|
34 |
<p>DataSource's Pollable extension enables polling functionality on all your DataSource instances.</p> |
|
|
35 |
</div> |
|
|
36 |
|
|
|
37 |
<div class="example yui3-skin-sam"> |
|
|
38 |
<form id="demo"> |
|
|
39 |
<h6>Poll every second for current time:</h6> |
|
|
40 |
<input type="button" id="demo_enable" value="Start polling"> |
|
|
41 |
<input type="button" id="demo_disable" value="End polling"> |
|
|
42 |
<div id="demo_output_polling" class="output"></div> |
|
|
43 |
</form> |
|
|
44 |
|
|
|
45 |
<script type="text/javascript"> |
|
|
46 |
YUI().use("dump", "node", "datasource-function", "datasource-polling", function (Y) { |
|
|
47 |
var id, |
|
|
48 |
myFunction = function() { |
|
|
49 |
return new Date(); |
|
|
50 |
}, |
|
|
51 |
myDataSource = new Y.DataSource.Function({source:myFunction}), |
|
|
52 |
request = { |
|
|
53 |
callback: { |
|
|
54 |
success: function(e){ |
|
|
55 |
Y.one("#demo_output_polling") |
|
|
56 |
.setHTML("At the tone the time will be: " + |
|
|
57 |
Y.dump(e.response.results[0].toString())); |
|
|
58 |
}, |
|
|
59 |
failure: function(e){ |
|
|
60 |
Y.one("#demo_output_polling") |
|
|
61 |
.setHTML("Could not retrieve data: " + e.error.message); |
|
|
62 |
} |
|
|
63 |
} |
|
|
64 |
}; |
|
|
65 |
|
|
|
66 |
Y.on("click", function(e){ |
|
|
67 |
if(id) { |
|
|
68 |
myDataSource.clearInterval(id); |
|
|
69 |
} |
|
|
70 |
id = myDataSource.setInterval(1000, request); |
|
|
71 |
}, "#demo_enable"); |
|
|
72 |
|
|
|
73 |
Y.on("click", function(e){ |
|
|
74 |
myDataSource.clearInterval(id); |
|
|
75 |
}, "#demo_disable"); |
|
|
76 |
}); |
|
|
77 |
</script> |
|
|
78 |
|
|
|
79 |
</div> |
|
|
80 |
|
|
|
81 |
<p>Include the <code>datasource-pollable</code> extension in your <code>Y.use()</code> statement to add the <code>setInterval()</code>, <code>clearInterval()</code>, and <code>clearAllInterval()</code> methods to all your DataSource instances.</p> |
|
|
82 |
|
|
|
83 |
<pre class="code prettyprint">YUI().use("datasource-function", "datasource-polling", function(Y) { |
|
|
84 |
var myFunction = function() { |
|
|
85 |
return new Date(); |
|
|
86 |
}, |
|
|
87 |
myDataSource = new Y.DataSource.Function({source:myFunction}), |
|
|
88 |
request = { |
|
|
89 |
callback: { |
|
|
90 |
success: function(e){ |
|
|
91 |
Y.one("#demo_output_polling") |
|
|
92 |
.setHTML("At the tone the time will be: " + |
|
|
93 |
Y.dump(e.response.results[0].toString())); |
|
|
94 |
}, |
|
|
95 |
failure: function(e){ |
|
|
96 |
Y.one("#demo_output_polling") |
|
|
97 |
.setHTML("Could not retrieve data: " + e.error.message); |
|
|
98 |
} |
|
|
99 |
} |
|
|
100 |
}, |
|
|
101 |
id = myDataSource.setInterval(1000, request); // Starts polling |
|
|
102 |
|
|
|
103 |
myDataSource.clearInterval(id); // Ends polling |
|
|
104 |
});</pre> |
|
|
105 |
|
|
|
106 |
</div> |
|
|
107 |
</div> |
|
|
108 |
</div> |
|
|
109 |
|
|
|
110 |
<div class="yui3-u-1-4"> |
|
|
111 |
<div class="sidebar"> |
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
<div class="sidebox"> |
|
|
116 |
<div class="hd"> |
|
|
117 |
<h2 class="no-toc">Examples</h2> |
|
|
118 |
</div> |
|
|
119 |
|
|
|
120 |
<div class="bd"> |
|
|
121 |
<ul class="examples"> |
|
|
122 |
|
|
|
123 |
|
|
|
124 |
<li data-description="The Local DataSource manages retrieval of in-page data, from JavaScript arrays and objects to DOM elements."> |
|
|
125 |
<a href="datasource-local.html">DataSource.Local</a> |
|
|
126 |
</li> |
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
<li data-description="The Get DataSource, which manages retrieval of data from remote sources via the Get Utility, can be useful for accessing data from cross-domain servers without the need for a proxy."> |
|
|
131 |
<a href="datasource-get.html">DataSource.Get</a> |
|
|
132 |
</li> |
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
<li data-description="The IO DataSource manages retrieval of data from remote sources, via the IO Utility."> |
|
|
137 |
<a href="datasource-io.html">DataSource.IO</a> |
|
|
138 |
</li> |
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
<li data-description="The Function DataSource, which manages retrieval of data from a JavaScript function, provides a highly customizeable mechanism for implementer-defined data retrieval algorithms"> |
|
|
143 |
<a href="datasource-function.html">DataSource.Function</a> |
|
|
144 |
</li> |
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
<li data-description="Use the DataSourceCache plugin to enable caching and reduce server calls to remote sources."> |
|
|
149 |
<a href="datasource-caching.html">DataSource with Caching</a> |
|
|
150 |
</li> |
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
<li data-description="The DataSourceCache plugin supports offline caching so that cached data persists across browser sessions."> |
|
|
155 |
<a href="datasource-offlinecache.html">DataSource with Offline Cache</a> |
|
|
156 |
</li> |
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
<li data-description="Use the Pollable extension to enable polling in your DataSource."> |
|
|
161 |
<a href="datasource-polling.html">DataSource with Polling</a> |
|
|
162 |
</li> |
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
</ul> |
|
|
168 |
</div> |
|
|
169 |
</div> |
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
<div class="sidebox"> |
|
|
174 |
<div class="hd"> |
|
|
175 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
176 |
</div> |
|
|
177 |
|
|
|
178 |
<div class="bd"> |
|
|
179 |
<ul class="examples"> |
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
<li data-description="How to provide autocomplete suggestions using a DataSource instance."> |
|
|
197 |
<a href="../autocomplete/ac-datasource.html">Remote Data via DataSource</a> |
|
|
198 |
</li> |
|
|
199 |
|
|
|
200 |
|
|
|
201 |
</ul> |
|
|
202 |
</div> |
|
|
203 |
</div> |
|
|
204 |
|
|
|
205 |
</div> |
|
|
206 |
</div> |
|
|
207 |
</div> |
|
|
208 |
</div> |
|
|
209 |
|
|
|
210 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
211 |
<script>prettyPrint();</script> |
|
|
212 |
|
|
|
213 |
<script> |
|
|
214 |
YUI.Env.Tests = { |
|
|
215 |
examples: [], |
|
|
216 |
project: '../assets', |
|
|
217 |
assets: '../assets/datasource', |
|
|
218 |
name: 'datasource-polling', |
|
|
219 |
title: 'DataSource with Polling', |
|
|
220 |
newWindow: '', |
|
|
221 |
auto: false |
|
|
222 |
}; |
|
|
223 |
YUI.Env.Tests.examples.push('datasource-local'); |
|
|
224 |
YUI.Env.Tests.examples.push('datasource-get'); |
|
|
225 |
YUI.Env.Tests.examples.push('datasource-io'); |
|
|
226 |
YUI.Env.Tests.examples.push('datasource-function'); |
|
|
227 |
YUI.Env.Tests.examples.push('datasource-caching'); |
|
|
228 |
YUI.Env.Tests.examples.push('datasource-offlinecache'); |
|
|
229 |
YUI.Env.Tests.examples.push('datasource-polling'); |
|
|
230 |
YUI.Env.Tests.examples.push('ac-datasource'); |
|
|
231 |
|
|
|
232 |
</script> |
|
|
233 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
</body> |
|
|
238 |
</html> |