@@ -72,11 +72,6 @@ $(document).ready(function() {
7272 hljs . highlightAll ( ) ;
7373} ) ;
7474
75- // Show Blog
76- $ ( ".hide" ) . click ( function ( ) {
77- $ ( ".new-on-the-blog" ) . hide ( ) ;
78- } ) ;
79-
8075// Documentation menu dropdown toggle
8176$ ( document ) . ready ( function ( ) { // DOM ready
8277 // If a link has a dropdown, add sub menu toggle.
@@ -435,9 +430,8 @@ $(document).ready(function() {
435430 * that when the page is refreshed, the same tab will be selected.
436431 * On page load, selects the tab corresponding to stored value.
437432 */
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 ) ;
441435
442436 activateTab ( tabs , preferredValue )
443437
@@ -448,7 +442,7 @@ $(document).ready(function() {
448442 const parent = $ ( this ) . parent ( ) ;
449443 const newValue = $ ( this ) . data ( 'target' ) ;
450444
451- PreferenceStorage . setPreference ( namespace , newValue , oldValue => {
445+ storage . setPreference ( namespace , newValue , _ => {
452446 // when we set a new scalaVersion, find scalaVersionTabs except current one
453447 // and activate those tabs.
454448 activateTab ( tabs . not ( parent ) , newValue ) ;
@@ -459,17 +453,48 @@ $(document).ready(function() {
459453 } ) ;
460454 }
461455
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 ) {
463475 var scalaVersionTabs = $ ( ".tabsection.tabs-scala-version" ) ;
464476 if ( scalaVersionTabs . length ) {
465- setupTabs ( scalaVersionTabs , "scalaVersion" , "scala-3" ) ;
477+ setupTabs ( scalaVersionTabs , "scalaVersion" , "scala-3" , storage ) ;
466478 }
467479 var buildToolTabs = $ ( ".tabsection.tabs-build-tool" ) ;
468480 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 ) ;
470489 }
471490 }
472491
492+ if ( storageAvailable ( 'localStorage' ) ) {
493+ const PreferenceStorage = Storage ( 'org.scala-lang.docs.preferences' ) ;
494+ setupAllTabs ( PreferenceStorage ) ;
495+ setupAllAlertCancels ( PreferenceStorage ) ;
496+ }
497+
473498} ) ;
474499
475500// OS detection
0 commit comments