| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('cr.ui', function() { | 5 cr.define('cr.ui', function() { |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Returns the TabBox for a Tab or a TabPanel. | 8 * Returns the TabBox for a Tab or a TabPanel. |
| 9 * @param {Tab|TabPanel} el The tab or tabpanel element. | 9 * @param {Tab|TabPanel} el The tab or tabpanel element. |
| 10 * @return {TabBox} The tab box if found. | 10 * @return {TabBox} The tab box if found. |
| 11 */ | 11 */ |
| 12 function getTabBox(el) { | 12 function getTabBox(el) { |
| 13 return findAncestor(el, function(node) { | 13 return findAncestor( |
| 14 return node.tagName == 'TABBOX'; | 14 el, function(node) { return node.tagName == 'TABBOX'; }); |
| 15 }); | |
| 16 } | 15 } |
| 17 | 16 |
| 18 /** | 17 /** |
| 19 * Returns whether an element is a tab related object. | 18 * Returns whether an element is a tab related object. |
| 20 * @param {HTMLElement} el The element whose tag is being checked | 19 * @param {HTMLElement} el The element whose tag is being checked |
| 21 * @return {boolean} Whether the element is a tab related element. | 20 * @return {boolean} Whether the element is a tab related element. |
| 22 */ | 21 */ |
| 23 function isTabElement(el) { | 22 function isTabElement(el) { |
| 24 return el.tagName == 'TAB' || el.tagName == 'TABPANEL'; | 23 return el.tagName == 'TAB' || el.tagName == 'TABPANEL'; |
| 25 } | 24 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 }, | 97 }, |
| 99 | 98 |
| 100 /** | 99 /** |
| 101 * Callback for when a Tab or TabPanel changes its selected property. | 100 * Callback for when a Tab or TabPanel changes its selected property. |
| 102 * @param {Event} e The property change event. | 101 * @param {Event} e The property change event. |
| 103 * @private | 102 * @private |
| 104 */ | 103 */ |
| 105 handleSelectedChange_: function(e) { | 104 handleSelectedChange_: function(e) { |
| 106 var target = e.target; | 105 var target = e.target; |
| 107 if (e.newValue && isTabElement(target) && getTabBox(target) == this) { | 106 if (e.newValue && isTabElement(target) && getTabBox(target) == this) { |
| 108 var index = Array.prototype.indexOf.call(target.parentElement.children, | 107 var index = |
| 109 target); | 108 Array.prototype.indexOf.call(target.parentElement.children, target); |
| 110 this.selectedIndex = index; | 109 this.selectedIndex = index; |
| 111 } | 110 } |
| 112 }, | 111 }, |
| 113 | 112 |
| 114 selectedIndex_: -1 | 113 selectedIndex_: -1 |
| 115 }; | 114 }; |
| 116 | 115 |
| 117 /** | 116 /** |
| 118 * The index of the selected tab or -1 if no tab is selected. | 117 * The index of the selected tab or -1 if no tab is selected. |
| 119 * @type {number} | 118 * @type {number} |
| 120 */ | 119 */ |
| 121 cr.defineProperty(TabBox, 'selectedIndex', cr.PropertyKind.JS_PROP, | 120 cr.defineProperty( |
| 122 selectedIndexSetHook); | 121 TabBox, 'selectedIndex', cr.PropertyKind.JS_PROP, selectedIndexSetHook); |
| 123 | 122 |
| 124 /** | 123 /** |
| 125 * Creates a new tabs element. | 124 * Creates a new tabs element. |
| 126 * @param {string} opt_label The text label for the item. | 125 * @param {string} opt_label The text label for the item. |
| 127 * @constructor | 126 * @constructor |
| 128 * @extends {HTMLElement} | 127 * @extends {HTMLElement} |
| 129 */ | 128 */ |
| 130 var Tabs = cr.ui.define('tabs'); | 129 var Tabs = cr.ui.define('tabs'); |
| 131 Tabs.prototype = { | 130 Tabs.prototype = { |
| 132 __proto__: HTMLElement.prototype, | 131 __proto__: HTMLElement.prototype, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 cr.defineProperty(TabPanel, 'selected', cr.PropertyKind.BOOL_ATTR); | 231 cr.defineProperty(TabPanel, 'selected', cr.PropertyKind.BOOL_ATTR); |
| 233 | 232 |
| 234 return { | 233 return { |
| 235 TabBox: TabBox, | 234 TabBox: TabBox, |
| 236 Tabs: Tabs, | 235 Tabs: Tabs, |
| 237 Tab: Tab, | 236 Tab: Tab, |
| 238 TabPanels: TabPanels, | 237 TabPanels: TabPanels, |
| 239 TabPanel: TabPanel | 238 TabPanel: TabPanel |
| 240 }; | 239 }; |
| 241 }); | 240 }); |
| OLD | NEW |