@@ -29,7 +29,6 @@ $.widget( "ui.tabs", {
29
29
activate : null ,
30
30
beforeload : null ,
31
31
beforeActivate : null ,
32
- cookie : null , // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
33
32
collapsible : false ,
34
33
disabled : false ,
35
34
event : "click" ,
@@ -50,8 +49,7 @@ $.widget( "ui.tabs", {
50
49
// Selected tab
51
50
// use "selected" option or try to retrieve:
52
51
// 1. from fragment identifier in url
53
- // 2. from cookie
54
- // 3. from selected class attribute on <li>
52
+ // 2. from selected class attribute on <li>
55
53
if ( o . active === undefined ) {
56
54
if ( location . hash ) {
57
55
this . anchors . each ( function ( i , a ) {
@@ -61,9 +59,6 @@ $.widget( "ui.tabs", {
61
59
}
62
60
} ) ;
63
61
}
64
- if ( typeof o . active !== "number" && o . cookie ) {
65
- o . active = parseInt ( self . _cookie ( ) , 10 ) ;
66
- }
67
62
if ( typeof o . active !== "number" && this . lis . filter ( ".ui-tabs-selected" ) . length ) {
68
63
o . active = this . lis . index ( this . lis . filter ( ".ui-tabs-selected" ) ) ;
69
64
}
@@ -139,12 +134,6 @@ $.widget( "ui.tabs", {
139
134
return hash . replace ( / : / g, "\\:" ) ;
140
135
} ,
141
136
142
- _cookie : function ( ) {
143
- var cookie = this . cookie ||
144
- ( this . cookie = this . options . cookie . name || "ui-tabs-" + getNextListId ( ) ) ;
145
- return $ . cookie . apply ( null , [ cookie ] . concat ( $ . makeArray ( arguments ) ) ) ;
146
- } ,
147
-
148
137
_ui : function ( tab , panel ) {
149
138
return {
150
139
tab : tab ,
@@ -189,11 +178,6 @@ $.widget( "ui.tabs", {
189
178
o . disabled = false ;
190
179
}
191
180
192
- // set or update cookie after init and add/remove respectively
193
- if ( o . cookie ) {
194
- this . _cookie ( o . active , o . cookie ) ;
195
- }
196
-
197
181
// disable tabs
198
182
for ( var i = 0 , li ; ( li = this . lis [ i ] ) ; i ++ ) {
199
183
$ ( li ) . toggleClass ( "ui-state-disabled" , $ . inArray ( i , o . disabled ) != - 1 ) ;
@@ -382,21 +366,13 @@ $.widget( "ui.tabs", {
382
366
o . active = - 1 ;
383
367
self . active = null ;
384
368
385
- if ( o . cookie ) {
386
- self . _cookie ( o . active , o . cookie ) ;
387
- }
388
-
389
369
self . element . queue ( "tabs" , function ( ) {
390
370
self . _hideTab ( clicked , $hide ) ;
391
371
} ) . dequeue ( "tabs" ) ;
392
372
393
373
clicked [ 0 ] . blur ( ) ;
394
374
return ;
395
375
} else if ( ! $hide . length ) {
396
- if ( o . cookie ) {
397
- self . _cookie ( o . active , o . cookie ) ;
398
- }
399
-
400
376
self . element . queue ( "tabs" , function ( ) {
401
377
self . _showTab ( clicked , $show , event ) ;
402
378
} ) ;
@@ -409,10 +385,6 @@ $.widget( "ui.tabs", {
409
385
}
410
386
}
411
387
412
- if ( o . cookie ) {
413
- self . _cookie ( o . active , o . cookie ) ;
414
- }
415
-
416
388
// show new tab
417
389
if ( $show . length ) {
418
390
if ( $hide . length ) {
@@ -507,10 +479,6 @@ $.widget( "ui.tabs", {
507
479
}
508
480
} ) ;
509
481
510
- if ( o . cookie ) {
511
- this . _cookie ( null , o . cookie ) ;
512
- }
513
-
514
482
return this ;
515
483
} ,
516
484
@@ -974,6 +942,59 @@ if ( $.uiBackCompat !== false ) {
974
942
this . anchors . eq ( index ) . trigger ( this . options . event + ".tabs" ) ;
975
943
} ;
976
944
} ( jQuery , jQuery . ui . tabs . prototype ) ) ;
945
+
946
+ // cookie option
947
+ ( function ( $ , prototype ) {
948
+ $ . extend ( prototype . options , {
949
+ cookie : null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
950
+ } ) ;
951
+
952
+ var _create = prototype . _create ,
953
+ _refresh = prototype . _refresh ,
954
+ _eventHandler = prototype . _eventHandler ,
955
+ _destroy = prototype . _destroy ;
956
+
957
+ prototype . _create = function ( ) {
958
+ var o = this . options ;
959
+ if ( o . active === undefined ) {
960
+ if ( typeof o . active !== "number" && o . cookie ) {
961
+ o . active = parseInt ( this . _cookie ( ) , 10 ) ;
962
+ }
963
+ }
964
+ _create . call ( this ) ;
965
+ } ;
966
+
967
+ prototype . _cookie = function ( ) {
968
+ var cookie = this . cookie ||
969
+ ( this . cookie = this . options . cookie . name || "ui-tabs-" + getNextListId ( ) ) ;
970
+ return $ . cookie . apply ( null , [ cookie ] . concat ( $ . makeArray ( arguments ) ) ) ;
971
+ } ;
972
+
973
+ prototype . _refresh = function ( ) {
974
+ _refresh . call ( this ) ;
975
+
976
+ // set or update cookie after init and add/remove respectively
977
+ if ( this . options . cookie ) {
978
+ this . _cookie ( this . options . active , this . options . cookie ) ;
979
+ }
980
+ } ;
981
+
982
+ prototype . _eventHandler = function ( event ) {
983
+ _eventHandler . apply ( this , arguments ) ;
984
+
985
+ if ( this . options . cookie ) {
986
+ this . _cookie ( this . options . active , this . options . cookie ) ;
987
+ }
988
+ } ;
989
+
990
+ prototype . _destroy = function ( ) {
991
+ _destroy . call ( this ) ;
992
+
993
+ if ( this . options . cookie ) {
994
+ this . _cookie ( null , this . options . cookie ) ;
995
+ }
996
+ } ;
997
+ } ( jQuery , jQuery . ui . tabs . prototype ) ) ;
977
998
}
978
999
979
1000
} ) ( jQuery ) ;
0 commit comments