Yahoo! Developer Network Home - Help

YUI Library Examples: TabView Control: Getting Content from an External Source

TabView Control: Getting Content from an External Source

This demonstrates how to load Tab content from an external data source.

Loading TabView from an External Data Source

The YUI TabView provides a built-in way to load external data.

Because our content depends on JavaScript, in this case we will build our TabView entirely from script. First create a container to insert our new TabView into. This can be any existing element on the page, including the <body>, but for this example, we will create a <div> called container:

1<div id="container"><h2>Browser News</h2></div
view plain | print | ?

Next we will create a TabView instance, omitting the element argument, which signals the constructor to create the TabView container:

1var tabView = new YAHOO.widget.TabView(); 
view plain | print | ?

Next we add tabs to our TabView, including the label and a dataSrcpointing to the content, setting the default selected tab to "active". To minimize the number of requests, we will set each cacheData for each Tab.

1tabView.addTab( new YAHOO.widget.Tab({ 
2    label: 'Opera'
3    dataSrc: 'assets//news.php?&query=opera+browser'
4    cacheData: true
5    active: true 
6})); 
7 
8tabView.addTab( new YAHOO.widget.Tab({ 
9    label: 'Firefox'
10    dataSrc: 'assets//news.php?&query=firefox+browser'
11    cacheData: true 
12})); 
13 
14tabView.addTab( new YAHOO.widget.Tab({ 
15    label: 'Explorer'
16    dataSrc: 'assets//news.php?&query=microsoft+explorer+browser'
17    cacheData: true 
18})); 
19 
20tabView.addTab( new YAHOO.widget.Tab({ 
21    label: 'Safari'
22    dataSrc: 'assets//news.php?&query=apple+safari+browser'
23    cacheData: true 
24})); 
view plain | print | ?

All that is left is to append our new TabView to our container:

1tabView.appendTo('container'); 
view plain | print | ?

This is a basic example of how to load content from an external source into a TabView widget.

YUI Logger Output:

Logger Console

INFO39ms (+0) 4:12:39 PM:

example

The example has finished loading; as you interact with it, you'll see log messages appearing here.

INFO39ms (+0) 4:12:39 PM:

Tab

attributes initialized

INFO39ms (+0) 4:12:39 PM:

Tab

creating Tab Dom

INFO39ms (+0) 4:12:39 PM:

Tab

attributes initialized

INFO39ms (+0) 4:12:39 PM:

Tab

creating Tab Dom

INFO39ms (+0) 4:12:39 PM:

Tab

attributes initialized

INFO39ms (+1) 4:12:39 PM:

Tab

creating Tab Dom

INFO38ms (+0) 4:12:39 PM:

Connection

Transaction 0 sent.

INFO38ms (+0) 4:12:39 PM:

Connection

Default HTTP header X-Requested-With set with value of XMLHttpRequest

INFO38ms (+0) 4:12:39 PM:

Connection

Initialize transaction header X-Request-Header to XMLHttpRequest.

INFO38ms (+2) 4:12:39 PM:

Connection

XHR object created for transaction 0

INFO36ms (+0) 4:12:39 PM:

Tab

attributes initialized

INFO36ms (+1) 4:12:39 PM:

Tab

creating Tab Dom

INFO35ms (+1) 4:12:39 PM:

TabView

attributes initialized

INFO34ms (+34) 4:12:39 PM:

TabView

TabView Dom created

INFO0ms (+0) 4:12:39 PM:

global

Logger initialized

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

More TabView Control Resources:

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings