--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/datasource/datasource-function.html Tue Jul 16 14:29:46 2013 +0200
@@ -0,0 +1,404 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Example: DataSource.Function</title>
+ <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
+ <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
+ <link rel="stylesheet" href="../assets/css/main.css">
+ <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
+ <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
+ <script src="../../build/yui/yui-min.js"></script>
+
+</head>
+<body>
+<!--
+<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>
+-->
+<div id="doc">
+ <div id="hd">
+ <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
+ </div>
+
+
+ <h1>Example: DataSource.Function</h1>
+ <div class="yui3-g">
+ <div class="yui3-u-3-4">
+ <div id="main">
+ <div class="content"><style scoped>
+/* custom styles for this example */
+#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
+</style>
+
+<div class="intro">
+ <p>DataSource.Function allows the implementer to define a JavaScript function that returns data values, for maximum customizeability. A <a href="../dataschema/">DataSchema</a> plugin is used to normalize incoming data into a known format for consistency of usage by other components.</p>
+</div>
+
+<div class="example yui3-skin-sam">
+ <form id="demo">
+ <h4>Array</h4>
+ <h6>Data</h6>
+ <pre>
+[
+ {name:"abc",id:123},
+ {name:"def",id:456},
+ {name:"ghi",id:789}
+]
+ </pre>
+
+ <h6>Schema</h6>
+ <pre>
+{
+ resultFields: ["name","id"]
+}
+ </pre>
+
+ <h6>Normalized data</h6>
+ <input type="button" id="demo_array" value="Retrieve data">
+ <div id="demo_output_array" class="output"></div>
+
+ <h4>JSON</h4>
+ <h6>Data</h6>
+ <pre>
+{
+ "profile":{
+ "current":160,
+ "target":150
+ },
+ "reference": [
+ {
+ "category":"exercise",
+ "type":"expenditure",
+ "activities":[
+ {"name":"biking", "calories":550},
+ {"name":"golf", "calories":1000},
+ {"name":"running", "calories":650},
+ {"name":"swimming", "calories":650},
+ {"name":"walking", "calories":225}
+ ]
+ },
+ {
+ "category":"nutrition",
+ "type":"intake",
+ "fruit":[
+ {"name":"apple", "calories":70},
+ {"name":"banana", "calories":70},
+ {"name":"orange", "calories":90},
+ ],
+ "vegetables":[
+ {"name":"baked potato", "calories":150},
+ {"name":"broccoli", "calories":50},
+ {"name":"green beans", "calories":30}
+ ]
+ }
+ ],
+ "program": [
+ {
+ "category":"exercise",
+ "schedule":[
+ {"day":"sunday", "activity":"swimming"},
+ {"day":"monday", "activity":"running"},
+ {"day":"tuesday", "activity":"biking"},
+ {"day":"wednesday", "activity":"running"},
+ {"day":"thursday", "activity":"swimming"},
+ {"day":"friday", "activity":"running"},
+ {"day":"saturday", "activity":"golf"}
+ ]
+ },
+ {
+ "category":"diet",
+ "schedule":[
+ ]
+ }
+ ]
+}
+ </pre>
+
+ <h6>Schema</h6>
+ <pre>
+{
+ resultListLocator: "reference[1].fruit",
+ resultFields: ["name","calories"]
+}
+ </pre>
+
+ <h6>Normalized data</h6>
+ <input type="button" id="demo_json" value="Retrieve data">
+ <div id="demo_output_json" class="output"></div>
+</form>
+
+<script type="text/javascript">
+YUI().use("dump", "node", "datasource-function", "datasource-arrayschema", "datasource-jsonschema", function (Y) {
+ var myFunctionArray = function(request) {
+ return [
+ {name:"abc",id:123},
+ {name:"def",id:456},
+ {name:"ghi",id:789}
+ ];
+ },
+ myDataSourceArray = new Y.DataSource.Function({source:myFunctionArray}),
+ myCallbackArray = {
+ success: function(e){
+ Y.one("#demo_output_array").setHTML(Y.dump(e.response));
+ },
+ failure: function(e){
+ Y.one("#demo_output_array").setHTML("Could not retrieve data: " + e.error.message);
+ }
+ };
+
+ myDataSourceArray.plug(Y.Plugin.DataSourceArraySchema, {
+ schema: {
+ resultFields: ["name","id"]
+ }
+ });
+
+ Y.on("click", function(e){
+ myDataSourceArray.sendRequest({callback: myCallbackArray});
+ }, "#demo_array");
+
+ var myFunctionJSON = function(request) {
+ return {"profile":{"current":160,"target":150},"reference": [{"category":"exercise","type":"expenditure","activities":[{"name":"biking", "calories":550},{"name":"golf", "calories":1000},{"name":"running", "calories":650},{"name":"swimming", "calories":650},{"name":"walking", "calories":225}]},{"category":"nutrition","type":"intake","fruit":[{"name":"apple", "calories":70},{"name":"banana", "calories":70},{"name":"orange", "calories":90},],"vegetables":[{"name":"baked potato", "calories":150},{"name":"broccoli", "calories":50},{"name":"green beans", "calories":30}]}],"program": [{"category":"exercise","schedule":[{"day":"sunday", "activity":"swimming"},{"day":"monday", "activity":"running"},{"day":"tuesday", "activity":"biking"},{"day":"wednesday", "activity":"running"},{"day":"thursday", "activity":"swimming"},{"day":"friday", "activity":"running"},{"day":"saturday", "activity":"golf"}]},{"category":"diet","schedule":[]}]};
+ },
+ myDataSourceJSON = new Y.DataSource.Function({source:myFunctionJSON}),
+ myCallbackJSON = {
+ success: function(e){
+ Y.one("#demo_output_json").setHTML(Y.dump(e.response));
+ },
+ failure: function(e){
+ Y.one("#demo_output_json").setHTML("Could not retrieve data: " + e.error.message);
+ }
+ };
+
+ myDataSourceJSON.plug(Y.Plugin.DataSourceJSONSchema, {
+ schema: {
+ resultListLocator: "reference[1].fruit",
+ resultFields: ["name","calories"]
+ }
+ });
+
+ Y.on("click", function(e){
+ myDataSourceJSON.sendRequest({callback:myCallbackJSON});
+ }, "#demo_json");
+});
+
+</script>
+
+</div>
+
+<p>Your custom function can return arbitrary data, so use the appropriate schema plugin to normalize the data into a consistent format. Array data would use a DataSourceArraySchema plugin:</p>
+
+<pre class="code prettyprint">YUI().use("datasource-function", "datasource-arrayschema", function(Y) {
+ var myFunction = function(request) {
+ return [
+ {name:"abc",id:123},
+ {name:"def",id:456},
+ {name:"ghi",id:789}
+ ];
+ },
+ myDataSource = new Y.DataSource.Function({source:myFunction}),
+ myCallback = {
+ success: function(e){
+ alert(e.response);
+ },
+ failure: function(e){
+ alert("Could not retrieve data: " + e.error.message);
+ }
+ };
+
+ myDataSource.plug(Y.Plugin.DataSourceArraySchema, {
+ schema: {
+ resultFields: ["name","id"]
+ }
+ });
+
+ myDataSource.sendRequest({callback:myCallback});
+});</pre>
+
+
+<p>Whereas JSON data would use a DataSourceJSONSchema plugin:</p>
+
+<pre class="code prettyprint">YUI().use("datasource-function", "datasource-jsonschema", function(Y) {
+ var myFunction = function(request) {
+ return {
+ "profile":{
+ "current":160,
+ "target":150
+ },
+ "reference": [
+ {
+ ...
+ },
+ {
+ "category":"nutrition",
+ "type":"intake",
+ "fruit":[
+ {"name":"apple", "calories":70},
+ {"name":"banana", "calories":70},
+ {"name":"orange", "calories":90},
+ ],
+ "vegetables":[
+ {"name":"baked potato", "calories":150},
+ {"name":"broccoli", "calories":50},
+ {"name":"green beans", "calories":30}
+ ]
+ }
+ ],
+ "program": [
+ ...
+ ]
+ };
+ },
+ myDataSource = new Y.DataSource.Function({source:myFunction}),
+ myCallback = {
+ success: function(e){
+ alert(e.response);
+ },
+ failure: function(e){
+ alert("Could not retrieve data: " + e.error.message);
+ }
+ };
+
+ myDataSource.plug(Y.Plugin.DataSourceJSONSchema, {
+ schema: {
+ resultListLocator: "reference[1].fruit",
+ resultFields: ["name","calories"]
+ }
+ });
+
+ myDataSource.sendRequest({callback:myCallback});
+});</pre>
+
+
+</div>
+ </div>
+ </div>
+
+ <div class="yui3-u-1-4">
+ <div class="sidebar">
+
+
+
+ <div class="sidebox">
+ <div class="hd">
+ <h2 class="no-toc">Examples</h2>
+ </div>
+
+ <div class="bd">
+ <ul class="examples">
+
+
+ <li data-description="The Local DataSource manages retrieval of in-page data, from JavaScript arrays and objects to DOM elements.">
+ <a href="datasource-local.html">DataSource.Local</a>
+ </li>
+
+
+
+ <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.">
+ <a href="datasource-get.html">DataSource.Get</a>
+ </li>
+
+
+
+ <li data-description="The IO DataSource manages retrieval of data from remote sources, via the IO Utility.">
+ <a href="datasource-io.html">DataSource.IO</a>
+ </li>
+
+
+
+ <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">
+ <a href="datasource-function.html">DataSource.Function</a>
+ </li>
+
+
+
+ <li data-description="Use the DataSourceCache plugin to enable caching and reduce server calls to remote sources.">
+ <a href="datasource-caching.html">DataSource with Caching</a>
+ </li>
+
+
+
+ <li data-description="The DataSourceCache plugin supports offline caching so that cached data persists across browser sessions.">
+ <a href="datasource-offlinecache.html">DataSource with Offline Cache</a>
+ </li>
+
+
+
+ <li data-description="Use the Pollable extension to enable polling in your DataSource.">
+ <a href="datasource-polling.html">DataSource with Polling</a>
+ </li>
+
+
+
+
+ </ul>
+ </div>
+ </div>
+
+
+
+ <div class="sidebox">
+ <div class="hd">
+ <h2 class="no-toc">Examples That Use This Component</h2>
+ </div>
+
+ <div class="bd">
+ <ul class="examples">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <li data-description="How to provide autocomplete suggestions using a DataSource instance.">
+ <a href="../autocomplete/ac-datasource.html">Remote Data via DataSource</a>
+ </li>
+
+
+ </ul>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ </div>
+</div>
+
+<script src="../assets/vendor/prettify/prettify-min.js"></script>
+<script>prettyPrint();</script>
+
+<script>
+YUI.Env.Tests = {
+ examples: [],
+ project: '../assets',
+ assets: '../assets/datasource',
+ name: 'datasource-function',
+ title: 'DataSource.Function',
+ newWindow: '',
+ auto: false
+};
+YUI.Env.Tests.examples.push('datasource-local');
+YUI.Env.Tests.examples.push('datasource-get');
+YUI.Env.Tests.examples.push('datasource-io');
+YUI.Env.Tests.examples.push('datasource-function');
+YUI.Env.Tests.examples.push('datasource-caching');
+YUI.Env.Tests.examples.push('datasource-offlinecache');
+YUI.Env.Tests.examples.push('datasource-polling');
+YUI.Env.Tests.examples.push('ac-datasource');
+
+</script>
+<script src="../assets/yui/test-runner.js"></script>
+
+
+
+</body>
+</html>