Bug Tracker

Changeset 5545

Show
Ignore:
Timestamp:
05/09/08 21:39:51 (7 months ago)
Author:
klaus.hartl
Message:

UI Tabs: explicitly setting selected tab has to overide other options, selected tab cannot be disabled

Files:
1 modified

Legend:

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

    r5484 r5545  
    8585                }); 
    8686 
    87                 // Try to retrieve selected tab: 
    88                 // 1. from fragment identifier in url if present 
     87                // Selected tab 
     88                // use "selected" option or try to retrieve: 
     89                // 1. from fragment identifier in url 
    8990                // 2. from cookie 
    9091                // 3. from selected class attribute on <li> 
    91                 // 4. otherwise use given "selected" option 
    92                 // 5. check if tab is disabled 
    93                 this.$tabs.each(function(i, a) { 
     92                if (o.selected === undefined) { 
    9493                    if (location.hash) { 
    95                         if (a.hash == location.hash) { 
    96                             o.selected = i; 
    97                             // prevent page scroll to fragment 
    98                             //if (($.browser.msie || $.browser.opera) && !o.remote) { 
    99                             if ($.browser.msie || $.browser.opera) { 
    100                                 var $toShow = $(location.hash), toShowId = $toShow.attr('id'); 
    101                                 $toShow.attr('id', ''); 
    102                                 setTimeout(function() { 
    103                                     $toShow.attr('id', toShowId); // restore id 
    104                                 }, 500); 
     94                        this.$tabs.each(function(i, a) { 
     95                            if (a.hash == location.hash) { 
     96                                o.selected = i; 
     97                                // prevent page scroll to fragment 
     98                                if ($.browser.msie || $.browser.opera) { // && !o.remote 
     99                                    var $toShow = $(location.hash), toShowId = $toShow.attr('id'); 
     100                                    $toShow.attr('id', ''); 
     101                                    setTimeout(function() { 
     102                                        $toShow.attr('id', toShowId); // restore id 
     103                                    }, 500); 
     104                                } 
     105                                scrollTo(0, 0); 
     106                                return false; // break 
    105107                            } 
    106                             scrollTo(0, 0); 
    107                             return false; // break 
    108                         } 
    109                     } else if (o.cookie) { 
     108                        }); 
     109                    } 
     110                    else if (o.cookie) { 
    110111                        var index = parseInt($.cookie('ui-tabs' + $.data(self.element)),10); 
    111                         if (index && self.$tabs[index]) { 
     112                        if (index && self.$tabs[index]) 
    112113                            o.selected = index; 
    113                             return false; // break 
    114                         } 
    115                     } else if ( self.$lis.eq(i).hasClass(o.selectedClass) ) { 
    116                         o.selected = i; 
    117                         return false; // break 
    118114                    } 
    119                 }); 
    120  
     115                    else if (self.$lis.filter('.' + o.selectedClass).length) 
     116                        o.selected = self.$lis.index( self.$lis.filter('.' + o.selectedClass)[0] ); 
     117                } 
     118                o.selected = o.selected === null || o.selected !== undefined ? o.selected : 0; // first tab selected by default 
     119 
     120                // Take disabling tabs via class attribute from HTML 
     121                // into account and update option properly. 
     122                // A selected tab cannot become disabled. 
     123                o.disabled = $.unique(o.disabled.concat( 
     124                    $.map(this.$lis.filter('.' + o.disabledClass), 
     125                        function(n, i) { return self.$lis.index(n); } ) 
     126                )).sort(); 
     127                if ($.inArray(o.selected, o.disabled) != -1) 
     128                    o.disabled.splice($.inArray(o.selected, o.disabled), 1); 
     129                 
    121130                // highlight selected tab 
    122131                this.$panels.addClass(o.hideClass); 
     
    128137                    // seems to be expected behavior that the show callback is fired 
    129138                    var onShow = function() { 
    130                         $(self.element).triggerHandler('tabsshow', 
    131                             [self.ui(self.$tabs[o.selected], self.$panels[o.selected])], o.show); 
     139                        $(self.element).triggerHandler('tabsshow', 
     140                            [self.ui(self.$tabs[o.selected], self.$panels[o.selected])], o.show); 
    132141                    };  
    133142 
    134                     // load if remote tab 
    135                     if ($.data(this.$tabs[o.selected], 'load.tabs')) 
    136                         this.load(o.selected, onShow); 
    137                     // just trigger show event 
    138                     else 
    139                         onShow(); 
    140                          
    141                 } 
    142  
    143                 // Take disabling tabs via class attribute from HTML 
    144                 // into account and update option properly... 
    145                 o.disabled = $.unique(o.disabled.concat( 
    146                     $.map(this.$lis.filter('.' + o.disabledClass), 
    147                         function(n, i) { return self.$lis.index(n); } ) 
    148                 )).sort(); 
     143                    // load if remote tab 
     144                    if ($.data(this.$tabs[o.selected], 'load.tabs')) 
     145                        this.load(o.selected, onShow); 
     146                    // just trigger show event 
     147                    else 
     148                        onShow(); 
     149                     
     150                } 
    149151                 
    150152                // clean up to avoid memory leaks in certain versions of IE 6 
     
    200202                    // callback 
    201203                    $(self.element).triggerHandler('tabsshow', 
    202                         [self.ui(clicked, $show[0])], o.show); 
     204                        [self.ui(clicked, $show[0])], o.show); 
    203205 
    204206                }); 
     
    505507    $.ui.tabs.defaults = { 
    506508        // basic setup 
    507         selected: 0, 
    508509        unselect: false, 
    509510        event: 'click', 
     
    556557                    t = ++t < self.$tabs.length ? t : 0; 
    557558                    self.select(t); 
    558                 }, ms);  
     559                }, ms);  
    559560            } 
    560561