1
1
$ ( document ) . ready ( function ( ) {
2
2
3
+ var BATCH_LANGUAGES = [ "java" , "xml" , "both" ] ;
3
4
var $xmlButton = $ ( "#xmlButton" ) ;
4
5
var $javaButton = $ ( "#javaButton" ) ;
5
6
var $bothButton = $ ( "#bothButton" ) ;
@@ -10,20 +11,24 @@ $(document).ready(function(){
10
11
var $javaContent = $ ( "*.javaContent" ) ;
11
12
var $javaContentAll = $ ( "*.javaContent > *" ) ;
12
13
13
- setJava ( ) ;
14
-
15
- // Initial cookie handler. This part remembers the reader's choice and sets the toggle
16
- // accordingly.
17
- var docToggleCookieString = Cookies . get ( "docToggle" ) ;
18
- if ( docToggleCookieString != null ) {
19
- if ( docToggleCookieString === "xml" ) {
14
+ // Initial cookie handler. This part remembers the
15
+ // reader's choice and sets the toggle accordingly.
16
+ var lang = window . localStorage . getItem ( "docToggle" ) ;
17
+ if ( BATCH_LANGUAGES . indexOf ( lang ) === - 1 ) {
18
+ lang = "java" ;
19
+ $javaButton . prop ( "checked" , true ) ;
20
+ setJava ( ) ;
21
+ } else {
22
+ if ( lang === "xml" ) {
20
23
$xmlButton . prop ( "checked" , true ) ;
21
24
setXml ( ) ;
22
- } else if ( docToggleCookieString === "java" ) {
25
+ }
26
+ if ( lang === "java" ) {
23
27
$javaButton . prop ( "checked" , true ) ;
24
28
setJava ( ) ;
25
- } else if ( docToggleCookieString === "both" ) {
26
- $bothButton . prop ( "checked" , true ) ;
29
+ }
30
+ if ( lang === "both" ) {
31
+ $javaButton . prop ( "checked" , true ) ;
27
32
setBoth ( ) ;
28
33
}
29
34
}
@@ -48,7 +53,7 @@ $(document).ready(function(){
48
53
$xmlContentAll . removeClass ( "js-toc-ignore" ) ;
49
54
window . dispatchEvent ( new Event ( "tocRefresh" ) ) ;
50
55
tocbot . refresh ( ) ;
51
- Cookies . set ( 'docToggle' , 'xml' , { expires : 3652 } ) ;
56
+ window . localStorage . setItem ( 'docToggle' , 'xml' ) ;
52
57
}
53
58
54
59
function setJava ( ) {
@@ -58,7 +63,7 @@ $(document).ready(function(){
58
63
$javaContentAll . removeClass ( "js-toc-ignore" ) ;
59
64
window . dispatchEvent ( new Event ( "tocRefresh" ) ) ;
60
65
tocbot . refresh ( ) ;
61
- Cookies . set ( 'docToggle' , 'java' , { expires : 3652 } ) ;
66
+ window . localStorage . setItem ( 'docToggle' , 'java' ) ;
62
67
}
63
68
64
69
function setBoth ( ) {
@@ -68,7 +73,7 @@ $(document).ready(function(){
68
73
$xmlContentAll . removeClass ( "js-toc-ignore" ) ;
69
74
window . dispatchEvent ( new Event ( "tocRefresh" ) ) ;
70
75
tocbot . refresh ( ) ;
71
- Cookies . set ( 'docToggle' , 'both' , { expires : 3652 } ) ;
76
+ window . localStorage . setItem ( 'docToggle' , 'both' ) ;
72
77
}
73
78
74
79
} ) ;
0 commit comments