~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/docs/tabview/tabview-fromjs.html

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Example: Dynamic TabView from JavaScript</title>
6
 
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
 
    <link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
 
    <link rel="stylesheet" href="../assets/css/main.css">
9
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
 
    <script src="../../build/yui/yui-min.js"></script>
11
 
</head>
12
 
<body>
13
 
 
14
 
<div id="doc">
15
 
    <h1>Example: Dynamic TabView from JavaScript</h1>
16
 
 
17
 
    
18
 
 
19
 
    <div class="yui3-g">
20
 
        <div class="yui3-u-3-4">
21
 
            <div id="main">
22
 
                <div class="content"><div class="intro">
23
 
    <p>This example shows how to create a <code>TabView</code> widget dynamically and insert it into the page.</p>
24
 
</div>
25
 
 
26
 
<div class="example yui3-skin-sam">
27
 
<div id="demo">
28
 
</div>
29
 
 
30
 
<script type="text/javascript">
31
 
YUI().use('tabview', function(Y) {
32
 
    var tabview = new Y.TabView({
33
 
        children: [{
34
 
            label: 'foo',
35
 
            content: '<p>foo content</p>'
36
 
        }, {
37
 
            label: 'bar',
38
 
            content: '<p>bar content</p>'
39
 
        }, {
40
 
            label: 'baz',
41
 
            content: '<p>baz content</p>'
42
 
        }]
43
 
    });
44
 
 
45
 
    tabview.render('#demo');
46
 
    tabview.selectChild(2);
47
 
});
48
 
</script>
49
 
 
50
 
</div>
51
 
 
52
 
<h2>Creating a TabView From JavaScript</h2>
53
 
 
54
 
<p>A <code>TabView</code> can be created dynamically using a small amount of JavaScript.</p>
55
 
 
56
 
<h3>The Markup</h3>
57
 
 
58
 
<p>There are no markup requirements in this case, although you may want to have a placeholder to render the tabview into, which is what this example does.</p>
59
 
 
60
 
<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
61
 
&lt;&#x2F;div&gt;</pre>
62
 
 
63
 
 
64
 
<h3>The JavaScript</h3>
65
 
 
66
 
<p>The minimal requirement for creating a <code>TabView</code> from scratch are the labels and content for each tab.
67
 
These are added as the <code>children</code> attribute when creating the <code>TabView</code>.</p>
68
 
 
69
 
<pre class="code prettyprint">var tabview = new Y.TabView({
70
 
    children: [{
71
 
        label: &#x27;foo&#x27;,
72
 
        content: &#x27;&lt;p&gt;foo content&lt;&#x2F;p&gt;&#x27;
73
 
    }, {
74
 
        label: &#x27;bar&#x27;,
75
 
        content: &#x27;&lt;p&gt;bar content&lt;&#x2F;p&gt;&#x27;
76
 
    }, {
77
 
        label: &#x27;baz&#x27;,
78
 
        content: &#x27;&lt;p&gt;baz content&lt;&#x2F;p&gt;&#x27;
79
 
    }]
80
 
});</pre>
81
 
 
82
 
 
83
 
<h3>Rendering</h3>
84
 
 
85
 
<p>Calling render creates the <code>TabView</code>, inserting into the node
86
 
passed to render.
87
 
</p>
88
 
 
89
 
<pre class="code prettyprint">tabview.render(&#x27;#demo&#x27;);</pre>
90
 
 
91
 
 
92
 
<h3>Changing the Selected Tab</h3>
93
 
 
94
 
<p>By default, clicking a tab makes it selected and shows its content.  You can also do this programmatically
95
 
by calling the <code>selectChild</code> method on the <code>TabView</code>, passing it the index of the
96
 
tab to be selected.
97
 
</p>
98
 
 
99
 
<pre class="code prettyprint">tabview.selectChild(2);</pre>
100
 
 
101
 
 
102
 
<h2>Complete Example Source</h2>
103
 
<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
104
 
&lt;&#x2F;div&gt;
105
 
 
106
 
&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
107
 
YUI().use(&#x27;tabview&#x27;, function(Y) {
108
 
    var tabview = new Y.TabView({
109
 
        children: [{
110
 
            label: &#x27;foo&#x27;,
111
 
            content: &#x27;&lt;p&gt;foo content&lt;&#x2F;p&gt;&#x27;
112
 
        }, {
113
 
            label: &#x27;bar&#x27;,
114
 
            content: &#x27;&lt;p&gt;bar content&lt;&#x2F;p&gt;&#x27;
115
 
        }, {
116
 
            label: &#x27;baz&#x27;,
117
 
            content: &#x27;&lt;p&gt;baz content&lt;&#x2F;p&gt;&#x27;
118
 
        }]
119
 
    });
120
 
 
121
 
    tabview.render(&#x27;#demo&#x27;);
122
 
    tabview.selectChild(2);
123
 
});
124
 
&lt;&#x2F;script&gt;</pre>
125
 
 
126
 
</div>
127
 
            </div>
128
 
        </div>
129
 
 
130
 
        <div class="yui3-u-1-4">
131
 
            <div class="sidebar">
132
 
                
133
 
 
134
 
                
135
 
                    <div class="sidebox">
136
 
                        <div class="hd">
137
 
                            <h2 class="no-toc">Examples</h2>
138
 
                        </div>
139
 
 
140
 
                        <div class="bd">
141
 
                            <ul class="examples">
142
 
                                
143
 
                                    
144
 
                                        <li data-description="This example shows how to create a TabView wigdet from existing HTML.">
145
 
                                            <a href="tabview-basic.html">TabView from Existing Markup</a>
146
 
                                        </li>
147
 
                                    
148
 
                                
149
 
                                    
150
 
                                        <li data-description="This example shows how to create a TabView wigdet from JavaScript.">
151
 
                                            <a href="tabview-fromjs.html">Dynamic TabView from JavaScript</a>
152
 
                                        </li>
153
 
                                    
154
 
                                
155
 
                                    
156
 
                                        <li data-description="This example shows how to add and remove Tabs.">
157
 
                                            <a href="tabview-add-remove.html">Adding and Removing Tabs</a>
158
 
                                        </li>
159
 
                                    
160
 
                                
161
 
                                    
162
 
                                        <li data-description="This example shows how to load tab content remotely using a YQL plugin.">
163
 
                                            <a href="tabview-yql.html">Loading Tab Content</a>
164
 
                                        </li>
165
 
                                    
166
 
                                
167
 
                                    
168
 
                                
169
 
                            </ul>
170
 
                        </div>
171
 
                    </div>
172
 
                
173
 
 
174
 
                
175
 
                    <div class="sidebox">
176
 
                        <div class="hd">
177
 
                            <h2 class="no-toc">Examples That Use This Component</h2>
178
 
                        </div>
179
 
 
180
 
                        <div class="bd">
181
 
                            <ul class="examples">
182
 
                                
183
 
                                    
184
 
                                
185
 
                                    
186
 
                                
187
 
                                    
188
 
                                
189
 
                                    
190
 
                                
191
 
                                    
192
 
                                        <li data-description="Demonstrates how to add browser history support to a TabView widget using the History Utility.">
193
 
                                            <a href="../history/history-tabview.html">History + TabView</a>
194
 
                                        </li>
195
 
                                    
196
 
                                
197
 
                            </ul>
198
 
                        </div>
199
 
                    </div>
200
 
                
201
 
            </div>
202
 
        </div>
203
 
    </div>
204
 
</div>
205
 
 
206
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
207
 
<script>prettyPrint();</script>
208
 
 
209
 
</body>
210
 
</html>