Bug Tracker

Changeset 4128

Show
Ignore:
Timestamp:
12/12/07 23:33:05 (1 year ago)
Author:
klaus.hartl
Message:

Allow nesting elements inside of tab list items, fixes #2039

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/current/ui.tabs.js

    r3983 r4128  
    127127        tabify: function(init) { 
    128128 
    129             this.$tabs = $('a:first-child', this.source); 
     129            this.$lis = $('li:has(a[href])', this.source); 
     130            this.$tabs = $('a[href]', this.source); 
    130131            this.$panels = $([]); 
    131132             
     
    192193                        o.initial = parseInt($.cookie( $.ui.tabs.INSTANCE_KEY + $.data(self.source) )) || 0; 
    193194                        return false; // break 
    194                     } else if ( $(a).parent('li').hasClass(o.selectedClass) ) { 
     195                    } else if ( self.$lis.eq(i).hasClass(o.selectedClass) ) { 
    195196                        o.initial = i; 
    196197                        return false; // break 
    197198                    } 
    198199                }); 
    199                 var n = this.$tabs.length; 
    200                 while ( this.$tabs.eq(o.initial).parent('li').hasClass(o.disabledClass) && n) { 
    201                     o.initial = ++o.initial < this.$tabs.length ? o.initial : 0; 
     200                var n = this.$lis.length; 
     201                while (this.$lis.eq(o.initial).hasClass(o.disabledClass) && n) { 
     202                    o.initial = ++o.initial < this.$lis.length ? o.initial : 0; 
    202203                    n--; 
    203204                } 
     
    207208 
    208209                // highlight selected tab 
    209                 var $lis = this.$tabs.parent('li'); 
    210210                this.$panels.addClass(o.hideClass); 
    211                 $lis.removeClass(o.selectedClass); 
     211                this.$lis.removeClass(o.selectedClass); 
    212212                if (!o.unselected) { 
    213213                    this.$panels.eq(o.initial).show().removeClass(o.hideClass); // use show and remove class to show in any case no matter how it has been hidden before 
    214                     $lis.eq(o.initial).addClass(o.selectedClass); 
     214                    this.$lis.eq(o.initial).addClass(o.selectedClass); 
    215215                } 
    216216 
     
    287287 
    288288            // switch a tab 
    289             function switchTab(clicked, $hide, $show) { 
     289            function switchTab(clicked, $li, $hide, $show) { 
    290290                /*if (o.bookmarkable && trueClick) { // add to history only if true click occured, not a triggered click 
    291291                    $.ajaxHistory.update(clicked.hash); 
    292292                }*/ 
    293                 $(clicked).parents('li:eq(0)').addClass(o.selectedClass) 
     293                $li.addClass(o.selectedClass) 
    294294                    .siblings().removeClass(o.selectedClass); 
    295295                hideTab(clicked, $hide, $show); 
     
    300300 
    301301                //var trueClick = e.clientX; // add to history only if true click occured, not a triggered click 
    302                 var $li = $(this).parent('li'), 
     302                var $li = $(this).parents('li:eq(0)'), 
    303303                    $hide = self.$panels.filter(':visible'), 
    304304                    $show = $(this.hash); 
     
    359359                        var a = this; 
    360360                        self.load(self.$tabs.index(this) + 1, $.data(this, 'href'), function() { 
    361                             switchTab(a, $hide, $show); 
     361                            switchTab(a, $li, $hide, $show); 
    362362                        }); 
    363363                    } else { 
    364                         switchTab(this, $hide, $show); 
     364                        switchTab(this, $li, $hide, $show); 
    365365                    } 
    366366 
     
    397397                $panel = $panel.length && $panel 
    398398                    || $(o.panelTemplate).attr('id', id).addClass(o.panelClass).addClass(o.hideClass); 
    399                 if (position >= this.$tabs.length) { 
     399                if (position >= this.$lis.length) { 
    400400                    $li.appendTo(this.source); 
    401401                    $panel.appendTo(this.source.parentNode); 
    402402                } else { 
    403                     $li.insertBefore(this.$tabs.eq(position - 1).parent('li')); 
     403                    $li.insertBefore(this.$lis[position - 1]); 
    404404                    $panel.insertBefore(this.$panels[position - 1]); 
    405405                } 
     
    422422        remove: function(position) { 
    423423            if (position && position.constructor == Number) {                 
    424                 var o = this.options, $li = this.$tabs.eq(position - 1).parent('li').remove(), 
     424                var o = this.options, $li = this.$lis.eq(position - 1).remove(), 
    425425                    $panel = this.$panels.eq(position - 1).remove(); 
    426426                     
     
    435435        }, 
    436436        enable: function(position) { 
    437             var o = this.options, $li = this.$tabs.eq(position - 1).parent('li'); 
     437            var o = this.options, $li = this.$lis.eq(position - 1); 
    438438            $li.removeClass(o.disabledClass); 
    439439            if ($.browser.safari) { // fix disappearing tab (that used opacity indicating disabling) after enabling in Safari 2... 
     
    447447        disable: function(position) { 
    448448            var o = this.options;       
    449             this.$tabs.eq(position - 1).parent('li').addClass(o.disabledClass); 
     449            this.$lis.eq(position - 1).addClass(o.disabledClass); 
    450450            o.disable(this.$tabs[position - 1], this.$panels[position - 1]); // callback 
    451451        },