@@ -413,6 +413,20 @@ $.widget("ui.tabs", {
413
413
414
414
} ,
415
415
416
+ _getIndex : function ( index ) {
417
+ // meta-function to give users option to provide a href string instead of a numerical index.
418
+ // also sanitizes numerical indexes to valid values.
419
+ if ( typeof ( index ) == 'string' ) {
420
+ index = this . anchors . index ( this . anchors . filter ( '[href$=' + index + ']' ) ) ;
421
+ index = ( index == - 1 ?NaN :index ) ;
422
+ } else if ( typeof ( index ) != 'number' ) {
423
+ index = NaN ;
424
+ } else if ( index > this . anchors . length ) {
425
+ index = this . anchors . length ;
426
+ }
427
+ return index ;
428
+ } ,
429
+
416
430
destroy : function ( ) {
417
431
var o = this . options ;
418
432
@@ -512,6 +526,7 @@ $.widget("ui.tabs", {
512
526
} ,
513
527
514
528
remove : function ( index ) {
529
+ index = this . _getIndex ( index ) ;
515
530
var o = this . options , $li = this . lis . eq ( index ) . remove ( ) ,
516
531
$panel = this . panels . eq ( index ) . remove ( ) ;
517
532
@@ -532,6 +547,7 @@ $.widget("ui.tabs", {
532
547
} ,
533
548
534
549
enable : function ( index ) {
550
+ index = this . _getIndex ( index ) ;
535
551
var o = this . options ;
536
552
if ( $ . inArray ( index , o . disabled ) == - 1 ) {
537
553
return ;
@@ -546,6 +562,7 @@ $.widget("ui.tabs", {
546
562
} ,
547
563
548
564
disable : function ( index ) {
565
+ index = this . _getIndex ( index ) ;
549
566
var self = this , o = this . options ;
550
567
if ( index != o . selected ) { // cannot disable already selected tab
551
568
this . lis . eq ( index ) . addClass ( 'ui-state-disabled' ) ;
@@ -561,9 +578,7 @@ $.widget("ui.tabs", {
561
578
} ,
562
579
563
580
select : function ( index ) {
564
- if ( typeof index == 'string' ) {
565
- index = this . anchors . index ( this . anchors . filter ( '[href$=' + index + ']' ) ) ;
566
- }
581
+ index = this . _getIndex ( index ) ;
567
582
else if ( index === null ) { // usage of null is deprecated, TODO remove in next release
568
583
index = - 1 ;
569
584
}
@@ -576,6 +591,7 @@ $.widget("ui.tabs", {
576
591
} ,
577
592
578
593
load : function ( index ) {
594
+ index = this . _getIndex ( index ) ;
579
595
var self = this , o = this . options , a = this . anchors . eq ( index ) [ 0 ] , url = $ . data ( a , 'load.tabs' ) ;
580
596
581
597
this . abort ( ) ;
0 commit comments