annotate rhodecode/public/js/yui/tabview/tabview.js @ 677:469108c210f6 beta

Upgrade of Yui2, added selector rollup.
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 11 Nov 2010 01:40:59 +0000
parents 1e757ac98988
children 289ff43cc190
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 /*
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 Code licensed under the BSD License:
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 http://developer.yahoo.net/yui/license.txt
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
5 version: 2.8.0r4
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 (function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
9 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
10 * The tabview module provides a widget for managing content bound to tabs.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11 * @module tabview
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
12 * @requires yahoo, dom, event, element
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13 *
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16 var Y = YAHOO.util,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17 Dom = Y.Dom,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
18 Event = Y.Event,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 document = window.document,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 // STRING CONSTANTS
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
22 ACTIVE = 'active',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
23 ACTIVE_INDEX = 'activeIndex',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
24 ACTIVE_TAB = 'activeTab',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
25 CONTENT_EL = 'contentEl',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26 ELEMENT = 'element',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
27
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
28 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
29 * A widget to control tabbed views.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30 * @namespace YAHOO.widget
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
31 * @class TabView
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
32 * @extends YAHOO.util.Element
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 * @constructor
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
34 * @param {HTMLElement | String | Object} el(optional) The html
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
35 * element that represents the TabView, or the attribute object to use.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 * An element will be created if none provided.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
37 * @param {Object} attr (optional) A key map of the tabView's
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38 * initial attributes. Ignored if first arg is attributes object.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
39 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
40 TabView = function(el, attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
41 attr = attr || {};
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
42 if (arguments.length == 1 && !YAHOO.lang.isString(el) && !el.nodeName) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
43 attr = el; // treat first arg as attr object
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
44 el = attr.element || null;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
45 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
46
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
47 if (!el && !attr.element) { // create if we dont have one
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
48 el = this._createTabViewElement(attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
50 TabView.superclass.constructor.call(this, el, attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
51 };
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
52
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
53 YAHOO.extend(TabView, Y.Element, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
54 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
55 * The className to add when building from scratch.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
56 * @property CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
57 * @default "navset"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
58 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
59 CLASSNAME: 'yui-navset',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
60
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
61 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
62 * The className of the HTMLElement containing the TabView's tab elements
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
63 * to look for when building from existing markup, or to add when building
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
64 * from scratch.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
65 * All childNodes of the tab container are treated as Tabs when building
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
66 * from existing markup.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
67 * @property TAB_PARENT_CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
68 * @default "nav"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
69 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
70 TAB_PARENT_CLASSNAME: 'yui-nav',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
71
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
72 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
73 * The className of the HTMLElement containing the TabView's label elements
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
74 * to look for when building from existing markup, or to add when building
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
75 * from scratch.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
76 * All childNodes of the content container are treated as content elements when
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
77 * building from existing markup.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
78 * @property CONTENT_PARENT_CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
79 * @default "nav-content"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
80 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
81 CONTENT_PARENT_CLASSNAME: 'yui-content',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
82
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
83 _tabParent: null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
84 _contentParent: null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
85
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
86 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
87 * Adds a Tab to the TabView instance.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
88 * If no index is specified, the tab is added to the end of the tab list.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
89 * @method addTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
90 * @param {YAHOO.widget.Tab} tab A Tab instance to add.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
91 * @param {Integer} index The position to add the tab.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
92 * @return void
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
93 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
94 addTab: function(tab, index) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
95 var tabs = this.get('tabs'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
96 before = this.getTab(index),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
97 tabParent = this._tabParent,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
98 contentParent = this._contentParent,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
99 tabElement = tab.get(ELEMENT),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
100 contentEl = tab.get(CONTENT_EL);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
101
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
102 if (!tabs) { // not ready yet
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
103 this._queue[this._queue.length] = ['addTab', arguments];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
104 return false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
105 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
106
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
107 index = (index === undefined) ? tabs.length : index;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
108
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
109 tabs.splice(index, 0, tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
110
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
111 if ( before ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
112 tabParent.insertBefore(tabElement, before.get(ELEMENT));
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
113 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
114 tabParent.appendChild(tabElement);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
115 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
116
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
117 if ( contentEl && !Dom.isAncestor(contentParent, contentEl) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
118 contentParent.appendChild(contentEl);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
119 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
120
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
121 if ( !tab.get(ACTIVE) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
122 tab.set('contentVisible', false, true); /* hide if not active */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
123 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
124 this.set(ACTIVE_TAB, tab, true);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
125 this.set('activeIndex', index, true);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
126 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
127
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
128 this._initTabEvents(tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
129 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
130
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
131 _initTabEvents: function(tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
132 tab.addListener( tab.get('activationEvent'), tab._onActivate, this, tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
133 tab.addListener( tab.get('activationEventChange'), tab._onActivationEventChange, this, tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
134 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
135
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
136 _removeTabEvents: function(tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
137 tab.removeListener(tab.get('activationEvent'), tab._onActivate, this, tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
138 tab.removeListener('activationEventChange', tab._onActivationEventChange, this, tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
139 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
140
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
141 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
142 * Routes childNode events.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
143 * @method DOMEventHandler
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
144 * @param {event} e The Dom event that is being handled.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
145 * @return void
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
146 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
147 DOMEventHandler: function(e) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
148 var target = Event.getTarget(e),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
149 tabParent = this._tabParent,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
150 tabs = this.get('tabs'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
151 tab,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
152 tabEl,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
153 contentEl;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
154
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
155
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
156 if (Dom.isAncestor(tabParent, target) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
157 for (var i = 0, len = tabs.length; i < len; i++) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
158 tabEl = tabs[i].get(ELEMENT);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
159 contentEl = tabs[i].get(CONTENT_EL);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
160
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
161 if ( target == tabEl || Dom.isAncestor(tabEl, target) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
162 tab = tabs[i];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
163 break; // note break
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
164 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
165 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
166
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
167 if (tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
168 tab.fireEvent(e.type, e);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
169 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
170 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
171 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
172
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
173 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
174 * Returns the Tab instance at the specified index.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
175 * @method getTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
176 * @param {Integer} index The position of the Tab.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
177 * @return YAHOO.widget.Tab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
178 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
179 getTab: function(index) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
180 return this.get('tabs')[index];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
181 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
182
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
183 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
184 * Returns the index of given tab.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
185 * @method getTabIndex
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
186 * @param {YAHOO.widget.Tab} tab The tab whose index will be returned.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
187 * @return int
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
188 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
189 getTabIndex: function(tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
190 var index = null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
191 tabs = this.get('tabs');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
192 for (var i = 0, len = tabs.length; i < len; ++i) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
193 if (tab == tabs[i]) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
194 index = i;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
195 break;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
196 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
197 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
198
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
199 return index;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
200 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
201
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
202 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
203 * Removes the specified Tab from the TabView.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
204 * @method removeTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
205 * @param {YAHOO.widget.Tab} item The Tab instance to be removed.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
206 * @return void
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
207 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
208 removeTab: function(tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
209 var tabCount = this.get('tabs').length,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
210 index = this.getTabIndex(tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
211
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
212 if ( tab === this.get(ACTIVE_TAB) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
213 if (tabCount > 1) { // select another tab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
214 if (index + 1 === tabCount) { // if last, activate previous
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
215 this.set(ACTIVE_INDEX, index - 1);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
216 } else { // activate next tab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
217 this.set(ACTIVE_INDEX, index + 1);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
218 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
219 } else { // no more tabs
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
220 this.set(ACTIVE_TAB, null);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
221 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
222 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
223
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
224 this._removeTabEvents(tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
225 this._tabParent.removeChild( tab.get(ELEMENT) );
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
226 this._contentParent.removeChild( tab.get(CONTENT_EL) );
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
227 this._configs.tabs.value.splice(index, 1);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
228
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
229 tab.fireEvent('remove', { type: 'remove', tabview: this });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
230 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
231
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
232 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
233 * Provides a readable name for the TabView instance.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
234 * @method toString
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
235 * @return String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
236 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
237 toString: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
238 var name = this.get('id') || this.get('tagName');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
239 return "TabView " + name;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
240 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
241
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
242 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
243 * The transiton to use when switching between tabs.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
244 * @method contentTransition
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
245 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
246 contentTransition: function(newTab, oldTab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
247 if (newTab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
248 newTab.set('contentVisible', true);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
249 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
250 if (oldTab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
251 oldTab.set('contentVisible', false);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
252 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
253 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
254
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
255 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
256 * setAttributeConfigs TabView specific properties.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
257 * @method initAttributes
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
258 * @param {Object} attr Hash of initial attributes
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
259 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
260 initAttributes: function(attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
261 TabView.superclass.initAttributes.call(this, attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
262
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
263 if (!attr.orientation) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
264 attr.orientation = 'top';
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
265 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
266
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
267 var el = this.get(ELEMENT);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
268
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
269 if (!Dom.hasClass(el, this.CLASSNAME)) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
270 Dom.addClass(el, this.CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
271 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
272
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
273 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
274 * The Tabs belonging to the TabView instance.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
275 * @attribute tabs
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
276 * @type Array
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
277 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
278 this.setAttributeConfig('tabs', {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
279 value: [],
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
280 readOnly: true
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
281 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
282
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
283 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
284 * The container of the tabView's label elements.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
285 * @property _tabParent
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
286 * @private
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
287 * @type HTMLElement
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
288 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
289 this._tabParent =
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
290 this.getElementsByClassName(this.TAB_PARENT_CLASSNAME,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
291 'ul' )[0] || this._createTabParent();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
292
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
293 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
294 * The container of the tabView's content elements.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
295 * @property _contentParent
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
296 * @type HTMLElement
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
297 * @private
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
298 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
299 this._contentParent =
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
300 this.getElementsByClassName(this.CONTENT_PARENT_CLASSNAME,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
301 'div')[0] || this._createContentParent();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
302
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
303 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
304 * How the Tabs should be oriented relative to the TabView.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
305 * @attribute orientation
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
306 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
307 * @default "top"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
308 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
309 this.setAttributeConfig('orientation', {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
310 value: attr.orientation,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
311 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
312 var current = this.get('orientation');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
313 this.addClass('yui-navset-' + value);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
314
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
315 if (current != value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
316 this.removeClass('yui-navset-' + current);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
317 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
318
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
319 if (value === 'bottom') {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
320 this.appendChild(this._tabParent);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
321 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
322 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
323 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
324
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
325 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
326 * The index of the tab currently active.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
327 * @attribute activeIndex
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
328 * @type Int
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
329 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
330 this.setAttributeConfig(ACTIVE_INDEX, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
331 value: attr.activeIndex,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
332 validator: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
333 var ret = true;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
334 if (value && this.getTab(value).get('disabled')) { // cannot activate if disabled
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
335 ret = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
336 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
337 return ret;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
338 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
339 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
340
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
341 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
342 * The tab currently active.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
343 * @attribute activeTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
344 * @type YAHOO.widget.Tab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
345 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
346 this.setAttributeConfig(ACTIVE_TAB, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
347 value: attr.activeTab,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
348 method: function(tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
349 var activeTab = this.get(ACTIVE_TAB);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
350
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
351 if (tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
352 tab.set(ACTIVE, true);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
353 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
354
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
355 if (activeTab && activeTab !== tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
356 activeTab.set(ACTIVE, false);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
357 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
358
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
359 if (activeTab && tab !== activeTab) { // no transition if only 1
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
360 this.contentTransition(tab, activeTab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
361 } else if (tab) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
362 tab.set('contentVisible', true);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
363 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
364 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
365 validator: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
366 var ret = true;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
367 if (value && value.get('disabled')) { // cannot activate if disabled
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
368 ret = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
369 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
370 return ret;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
371 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
372 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
373
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
374 this.on('activeTabChange', this._onActiveTabChange);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
375 this.on('activeIndexChange', this._onActiveIndexChange);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
376
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
377 if ( this._tabParent ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
378 this._initTabs();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
379 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
380
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
381 // Due to delegation we add all DOM_EVENTS to the TabView container
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
382 // but IE will leak when unsupported events are added, so remove these
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
383 this.DOM_EVENTS.submit = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
384 this.DOM_EVENTS.focus = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
385 this.DOM_EVENTS.blur = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
386
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
387 for (var type in this.DOM_EVENTS) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
388 if ( YAHOO.lang.hasOwnProperty(this.DOM_EVENTS, type) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
389 this.addListener.call(this, type, this.DOMEventHandler);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
390 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
391 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
392 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
393
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
394 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
395 * Removes selected state from the given tab if it is the activeTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
396 * @method deselectTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
397 * @param {Int} index The tab index to deselect
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
398 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
399 deselectTab: function(index) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
400 if (this.getTab(index) === this.get('activeTab')) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
401 this.set('activeTab', null);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
402 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
403 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
404
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
405 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
406 * Makes the tab at the given index the active tab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
407 * @method selectTab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
408 * @param {Int} index The tab index to be made active
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
409 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
410 selectTab: function(index) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
411 this.set('activeTab', this.getTab(index));
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
412 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
413
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
414 _onActiveTabChange: function(e) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
415 var activeIndex = this.get(ACTIVE_INDEX),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
416 newIndex = this.getTabIndex(e.newValue);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
417
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
418 if (activeIndex !== newIndex) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
419 if (!(this.set(ACTIVE_INDEX, newIndex)) ) { // NOTE: setting
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
420 // revert if activeIndex update fails (cancelled via beforeChange)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
421 this.set(ACTIVE_TAB, e.prevValue);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
422 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
423 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
424 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
425
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
426 _onActiveIndexChange: function(e) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
427 // no set if called from ActiveTabChange event
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
428 if (e.newValue !== this.getTabIndex(this.get(ACTIVE_TAB))) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
429 if (!(this.set(ACTIVE_TAB, this.getTab(e.newValue))) ) { // NOTE: setting
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
430 // revert if activeTab update fails (cancelled via beforeChange)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
431 this.set(ACTIVE_INDEX, e.prevValue);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
432 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
433 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
434 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
435
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
436 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
437 * Creates Tab instances from a collection of HTMLElements.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
438 * @method _initTabs
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
439 * @private
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
440 * @return void
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
441 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
442 _initTabs: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
443 var tabs = Dom.getChildren(this._tabParent),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
444 contentElements = Dom.getChildren(this._contentParent),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
445 activeIndex = this.get(ACTIVE_INDEX),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
446 tab,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
447 attr,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
448 active;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
449
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
450 for (var i = 0, len = tabs.length; i < len; ++i) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
451 attr = {};
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
452
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
453 if (contentElements[i]) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
454 attr.contentEl = contentElements[i];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
455 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
456
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
457 tab = new YAHOO.widget.Tab(tabs[i], attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
458 this.addTab(tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
459
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
460 if (tab.hasClass(tab.ACTIVE_CLASSNAME) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
461 active = tab;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
462 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
463 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
464 if (activeIndex) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
465 this.set(ACTIVE_TAB, this.getTab(activeIndex));
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
466 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
467 this._configs.activeTab.value = active; // dont invoke method
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
468 this._configs.activeIndex.value = this.getTabIndex(active);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
469 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
470 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
471
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
472 _createTabViewElement: function(attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
473 var el = document.createElement('div');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
474
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
475 if ( this.CLASSNAME ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
476 el.className = this.CLASSNAME;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
477 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
478
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
479 return el;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
480 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
481
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
482 _createTabParent: function(attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
483 var el = document.createElement('ul');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
484
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
485 if ( this.TAB_PARENT_CLASSNAME ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
486 el.className = this.TAB_PARENT_CLASSNAME;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
487 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
488
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
489 this.get(ELEMENT).appendChild(el);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
490
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
491 return el;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
492 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
493
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
494 _createContentParent: function(attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
495 var el = document.createElement('div');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
496
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
497 if ( this.CONTENT_PARENT_CLASSNAME ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
498 el.className = this.CONTENT_PARENT_CLASSNAME;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
499 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
500
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
501 this.get(ELEMENT).appendChild(el);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
502
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
503 return el;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
504 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
505 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
506
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
507
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
508 YAHOO.widget.TabView = TabView;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
509 })();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
510
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
511 (function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
512 var Y = YAHOO.util,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
513 Dom = Y.Dom,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
514 Lang = YAHOO.lang,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
515
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
516
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
517 // STRING CONSTANTS
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
518 ACTIVE_TAB = 'activeTab',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
519 LABEL = 'label',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
520 LABEL_EL = 'labelEl',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
521 CONTENT = 'content',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
522 CONTENT_EL = 'contentEl',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
523 ELEMENT = 'element',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
524 CACHE_DATA = 'cacheData',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
525 DATA_SRC = 'dataSrc',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
526 DATA_LOADED = 'dataLoaded',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
527 DATA_TIMEOUT = 'dataTimeout',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
528 LOAD_METHOD = 'loadMethod',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
529 POST_DATA = 'postData',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
530 DISABLED = 'disabled',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
531
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
532 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
533 * A representation of a Tab's label and content.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
534 * @namespace YAHOO.widget
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
535 * @class Tab
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
536 * @extends YAHOO.util.Element
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
537 * @constructor
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
538 * @param element {HTMLElement | String} (optional) The html element that
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
539 * represents the Tab. An element will be created if none provided.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
540 * @param {Object} properties A key map of initial properties
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
541 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
542 Tab = function(el, attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
543 attr = attr || {};
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
544 if (arguments.length == 1 && !Lang.isString(el) && !el.nodeName) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
545 attr = el;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
546 el = attr.element;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
547 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
548
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
549 if (!el && !attr.element) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
550 el = this._createTabElement(attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
551 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
552
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
553 this.loadHandler = {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
554 success: function(o) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
555 this.set(CONTENT, o.responseText);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
556 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
557 failure: function(o) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
558 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
559 };
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
560
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
561 Tab.superclass.constructor.call(this, el, attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
562
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
563 this.DOM_EVENTS = {}; // delegating to tabView
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
564 };
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
565
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
566 YAHOO.extend(Tab, YAHOO.util.Element, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
567 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
568 * The default tag name for a Tab's inner element.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
569 * @property LABEL_INNER_TAGNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
570 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
571 * @default "em"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
572 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
573 LABEL_TAGNAME: 'em',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
574
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
575 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
576 * The class name applied to active tabs.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
577 * @property ACTIVE_CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
578 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
579 * @default "selected"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
580 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
581 ACTIVE_CLASSNAME: 'selected',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
582
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
583 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
584 * The class name applied to active tabs.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
585 * @property HIDDEN_CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
586 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
587 * @default "yui-hidden"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
588 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
589 HIDDEN_CLASSNAME: 'yui-hidden',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
590
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
591 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
592 * The title applied to active tabs.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
593 * @property ACTIVE_TITLE
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
594 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
595 * @default "active"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
596 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
597 ACTIVE_TITLE: 'active',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
598
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
599 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
600 * The class name applied to disabled tabs.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
601 * @property DISABLED_CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
602 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
603 * @default "disabled"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
604 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
605 DISABLED_CLASSNAME: DISABLED,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
606
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
607 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
608 * The class name applied to dynamic tabs while loading.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
609 * @property LOADING_CLASSNAME
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
610 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
611 * @default "disabled"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
612 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
613 LOADING_CLASSNAME: 'loading',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
614
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
615 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
616 * Provides a reference to the connection request object when data is
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
617 * loaded dynamically.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
618 * @property dataConnection
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
619 * @type Object
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
620 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
621 dataConnection: null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
622
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
623 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
624 * Object containing success and failure callbacks for loading data.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
625 * @property loadHandler
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
626 * @type object
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
627 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
628 loadHandler: null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
629
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
630 _loading: false,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
631
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
632 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
633 * Provides a readable name for the tab.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
634 * @method toString
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
635 * @return String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
636 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
637 toString: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
638 var el = this.get(ELEMENT),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
639 id = el.id || el.tagName;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
640 return "Tab " + id;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
641 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
642
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
643 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
644 * setAttributeConfigs Tab specific properties.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
645 * @method initAttributes
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
646 * @param {Object} attr Hash of initial attributes
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
647 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
648 initAttributes: function(attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
649 attr = attr || {};
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
650 Tab.superclass.initAttributes.call(this, attr);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
651
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
652 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
653 * The event that triggers the tab's activation.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
654 * @attribute activationEvent
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
655 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
656 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
657 this.setAttributeConfig('activationEvent', {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
658 value: attr.activationEvent || 'click'
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
659 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
660
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
661 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
662 * The element that contains the tab's label.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
663 * @attribute labelEl
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
664 * @type HTMLElement
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
665 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
666 this.setAttributeConfig(LABEL_EL, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
667 value: attr[LABEL_EL] || this._getLabelEl(),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
668 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
669 value = Dom.get(value);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
670 var current = this.get(LABEL_EL);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
671
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
672 if (current) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
673 if (current == value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
674 return false; // already set
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
675 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
676
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
677 current.parentNode.replaceChild(value, current);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
678 this.set(LABEL, value.innerHTML);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
679 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
680 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
681 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
682
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
683 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
684 * The tab's label text (or innerHTML).
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
685 * @attribute label
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
686 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
687 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
688 this.setAttributeConfig(LABEL, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
689 value: attr.label || this._getLabel(),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
690 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
691 var labelEl = this.get(LABEL_EL);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
692 if (!labelEl) { // create if needed
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
693 this.set(LABEL_EL, this._createLabelEl());
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
694 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
695
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
696 labelEl.innerHTML = value;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
697 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
698 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
699
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
700 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
701 * The HTMLElement that contains the tab's content.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
702 * @attribute contentEl
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
703 * @type HTMLElement
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
704 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
705 this.setAttributeConfig(CONTENT_EL, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
706 value: attr[CONTENT_EL] || document.createElement('div'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
707 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
708 value = Dom.get(value);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
709 var current = this.get(CONTENT_EL);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
710
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
711 if (current) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
712 if (current === value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
713 return false; // already set
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
714 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
715 if (!this.get('selected')) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
716 Dom.addClass(value, this.HIDDEN_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
717 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
718 current.parentNode.replaceChild(value, current);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
719 this.set(CONTENT, value.innerHTML);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
720 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
721 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
722 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
723
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
724 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
725 * The tab's content.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
726 * @attribute content
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
727 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
728 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
729 this.setAttributeConfig(CONTENT, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
730 value: attr[CONTENT],
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
731 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
732 this.get(CONTENT_EL).innerHTML = value;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
733 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
734 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
735
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
736 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
737 * The tab's data source, used for loading content dynamically.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
738 * @attribute dataSrc
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
739 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
740 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
741 this.setAttributeConfig(DATA_SRC, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
742 value: attr.dataSrc
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
743 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
744
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
745 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
746 * Whether or not content should be reloaded for every view.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
747 * @attribute cacheData
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
748 * @type Boolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
749 * @default false
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
750 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
751 this.setAttributeConfig(CACHE_DATA, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
752 value: attr.cacheData || false,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
753 validator: Lang.isBoolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
754 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
755
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
756 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
757 * The method to use for the data request.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
758 * @attribute loadMethod
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
759 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
760 * @default "GET"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
761 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
762 this.setAttributeConfig(LOAD_METHOD, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
763 value: attr.loadMethod || 'GET',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
764 validator: Lang.isString
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
765 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
766
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
767 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
768 * Whether or not any data has been loaded from the server.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
769 * @attribute dataLoaded
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
770 * @type Boolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
771 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
772 this.setAttributeConfig(DATA_LOADED, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
773 value: false,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
774 validator: Lang.isBoolean,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
775 writeOnce: true
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
776 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
777
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
778 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
779 * Number if milliseconds before aborting and calling failure handler.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
780 * @attribute dataTimeout
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
781 * @type Number
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
782 * @default null
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
783 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
784 this.setAttributeConfig(DATA_TIMEOUT, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
785 value: attr.dataTimeout || null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
786 validator: Lang.isNumber
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
787 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
788
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
789 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
790 * Arguments to pass when POST method is used
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
791 * @attribute postData
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
792 * @default null
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
793 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
794 this.setAttributeConfig(POST_DATA, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
795 value: attr.postData || null
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
796 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
797
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
798 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
799 * Whether or not the tab is currently active.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
800 * If a dataSrc is set for the tab, the content will be loaded from
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
801 * the given source.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
802 * @attribute active
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
803 * @type Boolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
804 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
805 this.setAttributeConfig('active', {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
806 value: attr.active || this.hasClass(this.ACTIVE_CLASSNAME),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
807 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
808 if (value === true) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
809 this.addClass(this.ACTIVE_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
810 this.set('title', this.ACTIVE_TITLE);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
811 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
812 this.removeClass(this.ACTIVE_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
813 this.set('title', '');
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
814 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
815 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
816 validator: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
817 return Lang.isBoolean(value) && !this.get(DISABLED) ;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
818 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
819 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
820
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
821 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
822 * Whether or not the tab is disabled.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
823 * @attribute disabled
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
824 * @type Boolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
825 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
826 this.setAttributeConfig(DISABLED, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
827 value: attr.disabled || this.hasClass(this.DISABLED_CLASSNAME),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
828 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
829 if (value === true) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
830 Dom.addClass(this.get(ELEMENT), this.DISABLED_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
831 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
832 Dom.removeClass(this.get(ELEMENT), this.DISABLED_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
833 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
834 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
835 validator: Lang.isBoolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
836 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
837
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
838 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
839 * The href of the tab's anchor element.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
840 * @attribute href
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
841 * @type String
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
842 * @default '#'
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
843 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
844 this.setAttributeConfig('href', {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
845 value: attr.href ||
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
846 this.getElementsByTagName('a')[0].getAttribute('href', 2) || '#',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
847 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
848 this.getElementsByTagName('a')[0].href = value;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
849 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
850 validator: Lang.isString
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
851 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
852
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
853 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
854 * The Whether or not the tab's content is visible.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
855 * @attribute contentVisible
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
856 * @type Boolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
857 * @default false
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
858 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
859 this.setAttributeConfig('contentVisible', {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
860 value: attr.contentVisible,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
861 method: function(value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
862 if (value) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
863 Dom.removeClass(this.get(CONTENT_EL), this.HIDDEN_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
864
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
865 if ( this.get(DATA_SRC) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
866 // load dynamic content unless already loading or loaded and caching
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
867 if ( !this._loading && !(this.get(DATA_LOADED) && this.get(CACHE_DATA)) ) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
868 this._dataConnect();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
869 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
870 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
871 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
872 Dom.addClass(this.get(CONTENT_EL), this.HIDDEN_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
873 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
874 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
875 validator: Lang.isBoolean
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
876 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
877 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
878
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
879 _dataConnect: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
880 if (!Y.Connect) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
881 return false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
882 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
883
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
884 Dom.addClass(this.get(CONTENT_EL).parentNode, this.LOADING_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
885 this._loading = true;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
886 this.dataConnection = Y.Connect.asyncRequest(
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
887 this.get(LOAD_METHOD),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
888 this.get(DATA_SRC),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
889 {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
890 success: function(o) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
891 this.loadHandler.success.call(this, o);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
892 this.set(DATA_LOADED, true);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
893 this.dataConnection = null;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
894 Dom.removeClass(this.get(CONTENT_EL).parentNode,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
895 this.LOADING_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
896 this._loading = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
897 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
898 failure: function(o) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
899 this.loadHandler.failure.call(this, o);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
900 this.dataConnection = null;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
901 Dom.removeClass(this.get(CONTENT_EL).parentNode,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
902 this.LOADING_CLASSNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
903 this._loading = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
904 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
905 scope: this,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
906 timeout: this.get(DATA_TIMEOUT)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
907 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
908
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
909 this.get(POST_DATA)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
910 );
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
911 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
912 _createTabElement: function(attr) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
913 var el = document.createElement('li'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
914 a = document.createElement('a'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
915 label = attr.label || null,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
916 labelEl = attr.labelEl || null;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
917
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
918 a.href = attr.href || '#'; // TODO: Use Dom.setAttribute?
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
919 el.appendChild(a);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
920
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
921 if (labelEl) { // user supplied labelEl
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
922 if (!label) { // user supplied label
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
923 label = this._getLabel();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
924 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
925 } else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
926 labelEl = this._createLabelEl();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
927 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
928
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
929 a.appendChild(labelEl);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
930
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
931 return el;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
932 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
933
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
934 _getLabelEl: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
935 return this.getElementsByTagName(this.LABEL_TAGNAME)[0];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
936 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
937
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
938 _createLabelEl: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
939 var el = document.createElement(this.LABEL_TAGNAME);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
940 return el;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
941 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
942
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
943
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
944 _getLabel: function() {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
945 var el = this.get(LABEL_EL);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
946
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
947 if (!el) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
948 return undefined;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
949 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
950
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
951 return el.innerHTML;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
952 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
953
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
954 _onActivate: function(e, tabview) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
955 var tab = this,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
956 silent = false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
957
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
958 Y.Event.preventDefault(e);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
959 if (tab === tabview.get(ACTIVE_TAB)) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
960 silent = true; // dont fire activeTabChange if already active
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
961 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
962 tabview.set(ACTIVE_TAB, tab, silent);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
963 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
964
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
965 _onActivationEventChange: function(e) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
966 var tab = this;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
967
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
968 if (e.prevValue != e.newValue) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
969 tab.removeListener(e.prevValue, tab._onActivate);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
970 tab.addListener(e.newValue, tab._onActivate, this, tab);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
971 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
972 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
973 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
974
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
975
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
976 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
977 * Fires when a tab is removed from the tabview
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
978 * @event remove
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
979 * @type CustomEvent
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
980 * @param {Event} An event object with fields for "type" ("remove")
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
981 * and "tabview" (the tabview instance it was removed from)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
982 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
983
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
984 YAHOO.widget.Tab = Tab;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
985 })();
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
986
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
987 YAHOO.register("tabview", YAHOO.widget.TabView, {version: "2.8.0r4", build: "2449"});