src/cm/media/js/lib/yui/yui_3.10.3/docs/autocomplete/ac-jsonp.html
changeset 525 89ef5ed3c48b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/autocomplete/ac-jsonp.html	Tue Jul 16 14:29:46 2013 +0200
@@ -0,0 +1,269 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Example: Remote Data via JSONP</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: Remote Data via JSONP</h1>
+    <div class="yui3-g">
+        <div class="yui3-u-3-4">
+            <div id="main">
+                <div class="content"><div class="intro">
+<p>
+This example demonstrates how to provide autocomplete suggestions from a remote JSONP API. In this case, we're using the YUI Library website's search API to suggest YUI module names.
+</p>
+
+<p>
+Try typing in a YUI module name. If you cannot think of any, try typing one of these: node, widget, autocomplete.
+</p>
+</div>
+
+<div class="example">
+<div id="demo" class="yui3-skin-sam"> <!-- You need this skin class -->
+  <label for="ac-input">Enter a YUI module name:</label><br>
+  <input id="ac-input" type="text" size="45">
+</div>
+
+<script>
+YUI().use('array-extras', 'autocomplete', 'autocomplete-highlighters', function (Y) {
+  function locateModules(response) {
+    var results = (response && response.data && response.data.results) || [];
+
+    return Y.Array.filter(results, function (result) {
+      return result._type === 'module';
+    });
+  }
+
+  Y.one('#ac-input').plug(Y.Plugin.AutoComplete, {
+    resultHighlighter: 'phraseMatch',
+    resultListLocator: locateModules,
+    resultTextLocator: 'name',
+    source: 'http://yuilibrary.com/api/v1/search/suggest?q={query}&callback={callback}&count=50'
+  });
+});
+</script>
+
+</div>
+
+<h2>HTML</h2>
+<p>
+<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
+page's <code>&lt;body&gt;</code> element or to a parent element of the widget in order to apply
+the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
+</p>
+<pre class="code prettyprint">&lt;div id=&quot;demo&quot; class=&quot;yui3-skin-sam&quot;&gt; &lt;!-- You need this skin class --&gt;
+  &lt;label for=&quot;ac-input&quot;&gt;Enter a YUI module name:&lt;&#x2F;label&gt;&lt;br&gt;
+  &lt;input id=&quot;ac-input&quot; type=&quot;text&quot; size=&quot;45&quot;&gt;
+&lt;&#x2F;div&gt;</pre>
+
+
+<h2>JavaScript</h2>
+
+<h3>YUI Library Search Response Data</h3>
+
+<p>
+The YUI Library website's search API returns a JavaScript object that looks like this:
+</p>
+
+<pre class="code prettyprint">{
+  &quot;status&quot;: &quot;success&quot;,
+  &quot;data&quot;: {
+    &quot;query&quot;: &quot;node&quot;,
+    &quot;total&quot;: 218,
+    &quot;maxScore&quot;: 153.57176,
+    &quot;took&quot;: 3,
+    &quot;results&quot;: [
+      {
+        &quot;_index&quot;: &quot;docs&quot;,
+        &quot;_type&quot;: &quot;component&quot;,
+        &quot;_id&quot;: &quot;component#node&quot;,
+        &quot;_score&quot;: 153.57176,
+        &quot;name&quot;: &quot;node&quot;,
+        &quot;displayName&quot;: &quot;Node&quot;,
+        &quot;description&quot;: &quot;Provides a wrapper for working with DOM nodes.&quot;,
+        &quot;author&quot;: &quot;msweeney&quot;,
+        &quot;url&quot;: &quot;&#x2F;yui&#x2F;docs&#x2F;node&#x2F;&quot;
+      },
+
+      ...
+    ]
+  }
+}</pre>
+
+
+<p>
+If the response were a simple array of strings, AutoComplete would interpret it correctly by default. However, in this case, the response is an object that contains a <code>data.results</code> property, the value of which is an array of result objects rather than an array of strings. Furthermore, we only want results whose <code>_type</code> property is <code>&quot;module&quot;</code>.
+</p>
+
+<p>
+This means we'll need to specify a <a href="http://yuilibrary.com/yui/docs/api/classes/AutoCompleteBase.html#attr_resultListLocator"><code>resultListLocator</code></a> to filter down the JSONP response to just an array of module results. Additionally we'll provide a values for <a href="http://yuilibrary.com/yui/docs/api/classses/AutoCompleteBase.html#attr_resultTextLocator"><code>resultTextLocator</code></a> to indicate the property on <em>each</em> result object that contains the suggestion text, as demonstrated in the implementation code below.
+</p>
+
+<h3>Implementation</h3>
+
+<pre class="code prettyprint">YUI().use(&#x27;array-extras&#x27;, &#x27;autocomplete&#x27;, &#x27;autocomplete-highlighters&#x27;, function (Y) {
+  function locateModules(response) {
+    var results = (response &amp;&amp; response.data &amp;&amp; response.data.results) || [];
+
+    return Y.Array.filter(results, function (result) {
+      return result._type === &#x27;module&#x27;;
+    });
+  }
+
+  Y.one(&#x27;#ac-input&#x27;).plug(Y.Plugin.AutoComplete, {
+    resultHighlighter: &#x27;phraseMatch&#x27;,
+    resultListLocator: locateModules,
+    resultTextLocator: &#x27;name&#x27;,
+    source: &#x27;http:&#x2F;&#x2F;yuilibrary.com&#x2F;api&#x2F;v1&#x2F;search&#x2F;suggest?q={query}&amp;callback={callback}&amp;count=50&#x27;
+  });
+});</pre>
+
+
+<h2>Complete Example Source</h2>
+
+<pre class="code prettyprint">&lt;div id=&quot;demo&quot; class=&quot;yui3-skin-sam&quot;&gt; &lt;!-- You need this skin class --&gt;
+  &lt;label for=&quot;ac-input&quot;&gt;Enter a YUI module name:&lt;&#x2F;label&gt;&lt;br&gt;
+  &lt;input id=&quot;ac-input&quot; type=&quot;text&quot; size=&quot;45&quot;&gt;
+&lt;&#x2F;div&gt;
+
+&lt;script&gt;
+YUI().use(&#x27;array-extras&#x27;, &#x27;autocomplete&#x27;, &#x27;autocomplete-highlighters&#x27;, function (Y) {
+  function locateModules(response) {
+    var results = (response &amp;&amp; response.data &amp;&amp; response.data.results) || [];
+
+    return Y.Array.filter(results, function (result) {
+      return result._type === &#x27;module&#x27;;
+    });
+  }
+
+  Y.one(&#x27;#ac-input&#x27;).plug(Y.Plugin.AutoComplete, {
+    resultHighlighter: &#x27;phraseMatch&#x27;,
+    resultListLocator: locateModules,
+    resultTextLocator: &#x27;name&#x27;,
+    source: &#x27;http:&#x2F;&#x2F;yuilibrary.com&#x2F;api&#x2F;v1&#x2F;search&#x2F;suggest?q={query}&amp;callback={callback}&amp;count=50&#x27;
+  });
+});
+&lt;&#x2F;script&gt;</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="How to provide autocomplete suggestions from a local array.">
+                                            <a href="ac-local.html">Basic Local Data</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to provide autocomplete suggestions using a remote JSONP source.">
+                                            <a href="ac-jsonp.html">Remote Data via JSONP</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to provide autocomplete suggestions using a YQL query source.">
+                                            <a href="ac-yql.html">Remote Data via YQL</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to provide autocomplete suggestions using a DataSource instance.">
+                                            <a href="ac-datasource.html">Remote Data via DataSource</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to implement delimited tag completion.">
+                                            <a href="ac-tagging.html">Tag Completion Using Query Delimiters</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to find and select Flickr photos using a YQL source and a custom autocomplete result formatter.">
+                                            <a href="ac-flickr.html">Find Photos on Flickr (Custom Formatting, YQL Source)</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to use autocomplete-base to filter a set of existing items on a page.">
+                                            <a href="ac-filter.html">Filter a Set of Existing Items on a Page</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="How to find an address using a YQL source calling Google&#x27;s Geocoding Service">
+                                            <a href="ac-geocode.html">Address Completion on Google&#x27;s Geocoding Service</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/autocomplete',
+    name: 'ac-jsonp',
+    title: 'Remote Data via JSONP',
+    newWindow: '',
+    auto:  false 
+};
+YUI.Env.Tests.examples.push('ac-local');
+YUI.Env.Tests.examples.push('ac-jsonp');
+YUI.Env.Tests.examples.push('ac-yql');
+YUI.Env.Tests.examples.push('ac-datasource');
+YUI.Env.Tests.examples.push('ac-tagging');
+YUI.Env.Tests.examples.push('ac-flickr');
+YUI.Env.Tests.examples.push('ac-filter');
+YUI.Env.Tests.examples.push('ac-geocode');
+
+</script>
+<script src="../assets/yui/test-runner.js"></script>
+
+
+
+</body>
+</html>