@@ -72,11 +72,6 @@ $(document).ready(function() {
72
72
hljs . highlightAll ( ) ;
73
73
} ) ;
74
74
75
- // Show Blog
76
- $ ( ".hide" ) . click ( function ( ) {
77
- $ ( ".new-on-the-blog" ) . hide ( ) ;
78
- } ) ;
79
-
80
75
// Documentation menu dropdown toggle
81
76
$ ( document ) . ready ( function ( ) { // DOM ready
82
77
// If a link has a dropdown, add sub menu toggle.
@@ -435,9 +430,8 @@ $(document).ready(function() {
435
430
* that when the page is refreshed, the same tab will be selected.
436
431
* On page load, selects the tab corresponding to stored value.
437
432
*/
438
- function setupTabs ( tabs , namespace , defaultValue ) {
439
- const PreferenceStorage = Storage ( 'org.scala-lang.docs.preferences' ) ;
440
- const preferredValue = PreferenceStorage . getPreference ( namespace , defaultValue ) ;
433
+ function setupTabs ( tabs , namespace , defaultValue , storage ) {
434
+ const preferredValue = storage . getPreference ( namespace , defaultValue ) ;
441
435
442
436
activateTab ( tabs , preferredValue )
443
437
@@ -448,7 +442,7 @@ $(document).ready(function() {
448
442
const parent = $ ( this ) . parent ( ) ;
449
443
const newValue = $ ( this ) . data ( 'target' ) ;
450
444
451
- PreferenceStorage . setPreference ( namespace , newValue , oldValue => {
445
+ storage . setPreference ( namespace , newValue , _ => {
452
446
// when we set a new scalaVersion, find scalaVersionTabs except current one
453
447
// and activate those tabs.
454
448
activateTab ( tabs . not ( parent ) , newValue ) ;
@@ -459,17 +453,48 @@ $(document).ready(function() {
459
453
} ) ;
460
454
}
461
455
462
- if ( storageAvailable ( 'localStorage' ) ) {
456
+ function setupAlertCancel ( alert , storage ) {
457
+ const messageId = alert . data ( 'message_id' ) ;
458
+ let onHide = ( ) => { } ;
459
+ if ( messageId ) {
460
+ const key = `alert.${ messageId } ` ;
461
+ const isHidden = storage . getPreference ( key , 'show' ) === 'hidden' ;
462
+ if ( isHidden ) {
463
+ alert . hide ( ) ;
464
+ }
465
+ onHide = ( ) => storage . setPreference ( key , 'hidden' , _ => { } ) ;
466
+ }
467
+
468
+
469
+ alert . find ( '.hide' ) . click ( function ( ) {
470
+ alert . hide ( ) , onHide ( ) ;
471
+ } ) ;
472
+ }
473
+
474
+ function setupAllTabs ( storage ) {
463
475
var scalaVersionTabs = $ ( ".tabsection.tabs-scala-version" ) ;
464
476
if ( scalaVersionTabs . length ) {
465
- setupTabs ( scalaVersionTabs , "scalaVersion" , "scala-3" ) ;
477
+ setupTabs ( scalaVersionTabs , "scalaVersion" , "scala-3" , storage ) ;
466
478
}
467
479
var buildToolTabs = $ ( ".tabsection.tabs-build-tool" ) ;
468
480
if ( buildToolTabs . length ) {
469
- setupTabs ( buildToolTabs , "buildTool" , "scala-cli" ) ;
481
+ setupTabs ( buildToolTabs , "buildTool" , "scala-cli" , storage ) ;
482
+ }
483
+ }
484
+
485
+ function setupAllAlertCancels ( storage ) {
486
+ var alertBanners = $ ( ".new-on-the-blog.alert-warning" ) ;
487
+ if ( alertBanners . length ) {
488
+ setupAlertCancel ( alertBanners , storage ) ;
470
489
}
471
490
}
472
491
492
+ if ( storageAvailable ( 'localStorage' ) ) {
493
+ const PreferenceStorage = Storage ( 'org.scala-lang.docs.preferences' ) ;
494
+ setupAllTabs ( PreferenceStorage ) ;
495
+ setupAllAlertCancels ( PreferenceStorage ) ;
496
+ }
497
+
473
498
} ) ;
474
499
475
500
// OS detection
0 commit comments