Bug Tracker

Changeset 3952

Show
Ignore:
Timestamp:
11/27/07 22:08:49 (9 months ago)
Author:
klaus.hartl
Message:

make use of hasClass and eq for less and better readable code, cleaned up tabs tests page

Location:
trunk/ui/current
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/current/tests/tabs.html

    r3930 r3952  
    7777            }); 
    7878        </script> 
    79  
    80         <style type="text/css" media="screen, projection"> 
    81             /* Not required for Tabs, just to make this demo look better... */ 
    82             h1 { 
    83                 margin: 1em 0 1.5em; 
    84                 font-size: 18px; 
    85             } 
    86             h2 { 
    87                 margin: 2em 0 1.5em; 
    88                 font-size: 16px; 
    89             } 
    90             p { 
    91                 margin: 0; 
    92             } 
    93             pre, pre+p, p+p { 
    94                 margin: 1em 0 0; 
    95             } 
    96             code { 
    97                 font-family: "Courier New", Courier, monospace; 
    98             } 
    99         </style> 
    10079    </head> 
    10180    <body> 
    102         <h1><a href="http://ui.jquery.com">jQuery UI</a> Tabs</h1> 
     81        <h1><a href="http://ui.jquery.com">jQuery UI</a> Tabs tests</h1> 
    10382 
    10483        <h2>Simple Tabs</h2> 
     
    391370        </div> 
    392371 
    393         <h2>Tested with</h2> 
    394  
    395         <ul> 
    396             <li>Firefox 2.0</li> 
    397             <li>Firefox 1.5</li> 
    398             <li>Opera 9.20</li> 
    399             <li>Safari 2.0.4</li> 
    400             <li><abbr title="Internet Explorer">IE</abbr> 7</li> 
    401             <li><abbr title="Internet Explorer">IE</abbr> 6</li> 
    402         </ul> 
    403  
    404372    </body> 
    405373</html> 
  • trunk/ui/current/ui.tabs.js

    r3935 r3952  
    157157 
    158158                // attach necessary classes for styling if not present 
    159                 $(this.source).is('.' + o.navClass) || $(this.source).addClass(o.navClass); 
     159                $(this.source).hasClass(o.navClass) || $(this.source).addClass(o.navClass); 
    160160                this.$panels.each(function() { 
    161161                    var $this = $(this); 
    162                     $this.is('.' + o.panelClass) || $this.addClass(o.panelClass); 
     162                    $this.hasClass(o.panelClass) || $this.addClass(o.panelClass); 
    163163                }); 
    164164                 
     
    193193                        o.initial = parseInt($.cookie(self.uuid)) || 0; 
    194194                        return false; // break 
    195                     } else if ( $(a).parent('li').is('.' + o.selectedClass) ) { 
     195                    } else if ( $(a).parent('li').hasClass(o.selectedClass) ) { 
    196196                        o.initial = i; 
    197197                        return false; // break 
     
    199199                }); 
    200200                var n = this.$tabs.length; 
    201                 while ( this.$tabs.eq(o.initial).parent('li').is('.' + o.disabledClass) && n) { 
     201                while ( this.$tabs.eq(o.initial).parent('li').hasClass(o.disabledClass) && n) { 
    202202                    o.initial = ++o.initial < this.$tabs.length ? o.initial : 0; 
    203203                    n--; 
     
    307307                // If tab is already selected and not unselectable or tab disabled or click callback returns false stop here. 
    308308                // Check if click handler returns false last so that it is not executed for a disabled tab! 
    309                 if (($li.is('.' + o.selectedClass) && !o.unselect) || $li.is('.' + o.disabledClass) 
     309                if (($li.hasClass(o.selectedClass) && !o.unselect) || $li.hasClass(o.disabledClass) 
    310310                    || o.click(this, $show[0], $hide[0]) === false) { 
    311311                    this.blur(); 
     
    319319                // if tab may be closed 
    320320                if (o.unselect) { 
    321                     if ($li.is('.' + o.selectedClass)) { 
     321                    if ($li.hasClass(o.selectedClass)) { 
    322322                        $li.removeClass(o.selectedClass); 
    323323                        self.$panels.stop(); 
     
    387387        add: function(url, text, position) { 
    388388            if (url && text) { 
    389                 var o = this.options; 
    390                 position = position || this.$tabs.length; // append by default                 
    391                  
    392                 var $li = $(o.tabTemplate.replace(/#\{href\}/, url).replace(/#\{text\}/, text)); 
     389                position = position || this.$tabs.length; // append by default   
     390                 
     391                var o = this.options, 
     392                    $li = $(o.tabTemplate.replace(/#\{href\}/, url).replace(/#\{text\}/, text)); 
    393393                 
    394394                if (url.indexOf('#') == 0) { 
     
    400400                // try to find an existing element before creating a new one 
    401401                var $panel = $('#' + id); 
    402                 $panel = $panel.length && $panel || $(o.panelTemplate).attr('id', id).addClass(o.panelClass).addClass(o.hideClass); 
     402                $panel = $panel.length && $panel 
     403                    || $(o.panelTemplate).attr('id', id).addClass(o.panelClass).addClass(o.hideClass); 
    403404                if (position >= this.$tabs.length) { 
    404405                    $li.appendTo(this.source); 
    405406                    $panel.appendTo(this.source.parentNode); 
    406407                } else { 
    407                     $li.insertBefore(this.$tabs.slice(position - 1, position).parent('li')); 
     408                    $li.insertBefore(this.$tabs.eq(position - 1).parent('li')); 
    408409                    $panel.insertBefore(this.$panels[position - 1]); 
    409410                } 
     
    426427        remove: function(position) { 
    427428            if (position && position.constructor == Number) {                 
    428                 var $li = this.$tabs.slice(position - 1, position).parent('li').remove(), 
    429                     $panel = this.$panels.slice(position - 1, position).remove(), 
    430                     o = this.options; 
     429                var o = this.options, $li = this.$tabs.eq(position - 1).parent('li').remove(), 
     430                    $panel = this.$panels.eq(position - 1).remove(); 
    431431                     
    432432                // If selected tab was removed focus tab to the right or 
    433433                // tab to the left if last tab was removed. 
    434                 if ($li.is('.' + o.selectedClass) && this.$tabs.length > 1) { 
     434                if ($li.hasClass(o.selectedClass) && this.$tabs.length > 1) { 
    435435                    this.click(position + (position < this.$tabs.length ? 1 : -1)); 
    436436                } 
     
    440440        }, 
    441441        enable: function(position) { 
    442             var $li = this.$tabs.slice(position - 1, position).parent('li'), o = this.options; 
     442            var o = this.options, $li = this.$tabs.eq(position - 1).parent('li'); 
    443443            $li.removeClass(o.disabledClass); 
    444444            if ($.browser.safari) { // fix disappearing tab (that used opacity indicating disabling) after enabling in Safari 2... 
     
    452452        disable: function(position) { 
    453453            var o = this.options;       
    454             this.$tabs.slice(position - 1, position).parent('li').addClass(o.disabledClass); 
     454            this.$tabs.eq(position - 1).parent('li').addClass(o.disabledClass); 
    455455            o.disable(this.$tabs[position - 1], this.$panels[position - 1]); // callback 
    456456        }, 
    457457        click: function(position) { 
    458             this.$tabs.slice(position - 1, position).trigger(this.options.event); 
     458            this.$tabs.eq(position - 1).trigger(this.options.event); 
    459459        }, 
    460460        load: function(position, url, callback) { 
    461461            var self = this, o = this.options, 
    462                 $a = this.$tabs.slice(position - 1, position), a = $a[0], $span = $('span', a); 
     462                $a = this.$tabs.eq(position - 1), a = $a[0], $span = $('span', a); 
    463463             
    464464            // shift arguments 
     
    517517        }, 
    518518        href: function(position, href) { 
    519             $.data(this.$tabs.slice(position - 1, position)[0], 'href', href); 
     519            $.data(this.$tabs.eq(position - 1)[0], 'href', href); 
    520520        } 
    521521    });