diff -r 322d0feea350 -r 89ef5ed3c48b src/cm/media/js/lib/yui/yui_3.10.3/docs/tabview/tabview-yql.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/tabview/tabview-yql.html Tue Jul 16 14:29:46 2013 +0200 @@ -0,0 +1,316 @@ + + + + + Example: Loading Tab Content + + + + + + + + + + +
+
+

+
+ + +

Example: Loading Tab Content

+
+
+
+
+

This example shows how to create a plugin to load YQL data into a TabView for dynamic content.

+
+ +
+ +

Today's Browser News

+
+ + +
+ +

+Note: be sure to add the yui3-skin-sam classname to the +page's <body> element or to a parent element of the widget in order to apply +the default CSS skin. See Understanding Skinning. +

+
<body class="yui3-skin-sam"> <!-- You need this skin class -->
+ + +

Creating the YQL Plugin

+

Plugin Constructor

+

To create a plugin, we need to create a constructor with a static + NS property. This is the namespace used by the plugin on each + instance.

+ +
// YQL plugin for Y.Tab instances
+var TabYQL = function(config) {
+    this.init(config);
+};
+
+TabYQL.NS = 'yql'; // plugin namespace (e.g. "tab.yql.load(myQuery)");
+ + +Plugin Prototype +

Next we will add the YQL functionality to the prototype. The init method + wires the YQL functionality up using the load method.

+ +
TabYQL.prototype = {
+    init: function(config) {
+        if (this.tab) {
+            this.tab.after('selectedChange', Y.bind(this.afterSelectedChange, this));
+        }
+    },
+
+    afterSelectedChange: function(e) {
+        // only load if not already loaded
+        if (!this.loaded) {
+            this.load(this.query, this.afterLoad);
+        }
+    },
+
+    load: function(query, afterLoad) {
+        Y.YQL(query, Y.bind(afterLoad, this));
+    }
+ + +

Creating the TabView

+

Next we will create a new instance of a TabView:

+ +
/* Create a new TabView instance, with content generated from script */
+var tabview = new Y.TabView();
+ + +

And then use the add method to add the Tab instances, +to add a tab for each of the feeds, then render the tabview into the placeholder +element.

+ + +
var feeds = {
+    Chrome: 'chrome+browser',
+    Firefox: 'firefox+browser',
+    Safari: 'safari+browser',
+    Explorer: 'explorer+browser',
+    Opera: 'opera+browser'
+};
+
+Y.each(feeds, function(feed, label) {
+    var tab = new Y.Tab({
+        label: label,
+        content: 'loading...',
+    });
+
+    tab.plug(TabYQL, {
+        query: 'select title, link from rss where ' +
+            'url="http://search.news.yahoo.com/rss?p=' +
+            feed + '"'
+    });
+
+    tabview.add(tab);
+});
+
+tabview.render('#demo');
+ +
+
+
+ +
+ +
+
+
+ + + + + + + + + + +