fix a bug in TabPanel that would make it return a SplitPanel

This commit is contained in:
rolux 2012-04-07 01:45:14 +02:00
parent 37030b5d27
commit 67a0f82266

View file

@ -1,11 +1,14 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript // vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict'; 'use strict';
Ox.TabPanel = function(options, self) { Ox.TabPanel = function(options, self) {
self = self || {}; self = self || {};
var that = Ox.Element({}, self) var that = Ox.Element({}, self)
.defaults({ .defaults({
content: null, content: null,
size: 24,
tabs: [] tabs: []
}) })
.options(options || {}); .options(options || {});
@ -20,6 +23,7 @@ Ox.TabPanel = function(options, self) {
selectable: true, selectable: true,
value: self.selected value: self.selected
}) })
.css({top: (self.options.size - 16) / 2 + 'px'})
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
self.selected = data.value; self.selected = data.value;
@ -29,11 +33,12 @@ Ox.TabPanel = function(options, self) {
}) })
.appendTo(self.$bar); .appendTo(self.$bar);
that.$element = Ox.SplitPanel({ that.setElement(
Ox.SplitPanel({
elements: [ elements: [
{ {
element: self.$bar, element: self.$bar,
size: 24 size: self.options.size
}, },
{ {
element: getContent() element: getContent()
@ -41,7 +46,8 @@ Ox.TabPanel = function(options, self) {
], ],
orientation: 'vertical' orientation: 'vertical'
}) })
.addClass('OxTabPanel'); .addClass('OxTabPanel')
);
function getContent() { function getContent() {
return Ox.isObject(self.options.content) return Ox.isObject(self.options.content)
@ -50,15 +56,18 @@ Ox.TabPanel = function(options, self) {
} }
function getSelected() { function getSelected() {
return self.options.tabs.filter(function(tab) { var selected = self.options.tabs.filter(function(tab) {
return tab.selected; return tab.selected;
})[0].id; });
return (selected.length ? selected : self.options.tabs)[0].id;
} }
// fixme: does this collide with a jquery fn?
that.select = function(id) { that.select = function(id) {
if (Ox.getIndexById(self.options.tabs, id) > -1) { if (Ox.getIndexById(self.options.tabs, id) > -1) {
self.$tabs.options({value: id}); self.$tabs.options({value: id});
} }
return that;
}; };
that.selected = function() { that.selected = function() {