@@ -91,6 +91,27 @@ $(document)
9191 // });
9292 } ) ;
9393
94+ function overflowShadows ( el ) {
95+ function handleScroll ( ) {
96+ const canScrollUp = el . scrollTop > 0
97+ const canScrollDown = el . offsetHeight + el . scrollTop < el . scrollHeight
98+ el . classList . toggle ( "overflow-shadows--both" , canScrollUp && canScrollDown )
99+ el . classList . toggle ( "overflow-shadows--top-only" , canScrollUp && ! canScrollDown )
100+ el . classList . toggle ( "overflow-shadows--bottom-only" , ! canScrollUp && canScrollDown )
101+ }
102+
103+ el . addEventListener ( "scroll" , handleScroll , { passive : true } )
104+ handleScroll ( )
105+
106+ const observer = new IntersectionObserver ( handleScroll )
107+ observer . observe ( el ) // el won't have scrollTop etc when hidden, so we need to recalculate when it's revealed
108+
109+ return ( ) => {
110+ el . removeEventListener ( "scroll" , handleScroll )
111+ observer . unobserve ( el )
112+ }
113+ }
114+
94115$ ( document )
95116 . ready ( function ( ) {
96117 // load data for the menu
@@ -108,7 +129,7 @@ $(document)
108129 }
109130 attachTo . find ( ".dropdown-menu" )
110131 . remove ( ) ;
111- var menu = [ '<ul class="dropdown-menu ms-n1 mt-n1">' ] ;
132+ var menu = [ '<ul class="dropdown-menu ms-n1 mt-n1 overflow-shadows ">' ] ;
112133 var groups = data [ parentId ] ;
113134 var gtype = "" ;
114135 for ( var i = 0 ; i < groups . length ; ++ i ) {
@@ -127,6 +148,8 @@ $(document)
127148 attachTo . closest ( ".dropdown-menu" ) ;
128149 }
129150 attachTo . append ( menu . join ( "" ) ) ;
151+
152+ attachTo . find ( ".overflow-shadows" ) . each ( function ( ) { overflowShadows ( this ) } )
130153 }
131154 }
132155 } ) ;
0 commit comments