From 67a0f82266df5d810028b9b1a1e33da2ea723936 Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 7 Apr 2012 01:45:14 +0200 Subject: [PATCH] fix a bug in TabPanel that would make it return a SplitPanel --- source/Ox.UI/js/Panel/Ox.TabPanel.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/Panel/Ox.TabPanel.js b/source/Ox.UI/js/Panel/Ox.TabPanel.js index 94f85c01..96aa8e08 100644 --- a/source/Ox.UI/js/Panel/Ox.TabPanel.js +++ b/source/Ox.UI/js/Panel/Ox.TabPanel.js @@ -1,11 +1,14 @@ // vim: et:ts=4:sw=4:sts=4:ft=javascript + 'use strict'; + Ox.TabPanel = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ content: null, + size: 24, tabs: [] }) .options(options || {}); @@ -20,6 +23,7 @@ Ox.TabPanel = function(options, self) { selectable: true, value: self.selected }) + .css({top: (self.options.size - 16) / 2 + 'px'}) .bindEvent({ change: function(data) { self.selected = data.value; @@ -29,11 +33,12 @@ Ox.TabPanel = function(options, self) { }) .appendTo(self.$bar); - that.$element = Ox.SplitPanel({ + that.setElement( + Ox.SplitPanel({ elements: [ { element: self.$bar, - size: 24 + size: self.options.size }, { element: getContent() @@ -41,7 +46,8 @@ Ox.TabPanel = function(options, self) { ], orientation: 'vertical' }) - .addClass('OxTabPanel'); + .addClass('OxTabPanel') + ); function getContent() { return Ox.isObject(self.options.content) @@ -50,15 +56,18 @@ Ox.TabPanel = function(options, self) { } function getSelected() { - return self.options.tabs.filter(function(tab) { + var selected = self.options.tabs.filter(function(tab) { 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) { if (Ox.getIndexById(self.options.tabs, id) > -1) { self.$tabs.options({value: id}); - } + } + return that; }; that.selected = function() {