11import $ from 'jquery' ;
22import { generateAriaId } from './base.ts' ;
33import type { FomanticInitFunction } from '../../types.ts' ;
4+ import { hideElem } from '../../utils/dom.ts' ;
45
56const ariaPatchKey = '_giteaAriaPatchDropdown' ;
67const fomanticDropdownFn = $ . fn . dropdown ;
@@ -59,6 +60,30 @@ function updateSelectionLabel(label: HTMLElement) {
5960 }
6061}
6162
63+ export function dropdownHideEmptyDividers ( elDropdown : HTMLElement ) {
64+ const itemsContainer = elDropdown . querySelector ( '.scrolling.menu' ) ?? elDropdown . querySelector ( '.menu' ) ;
65+ if ( ! itemsContainer ) return ;
66+ let lastVisibleItemType : '' | 'divider' | 'item' = '' ;
67+ let lastVisibleItem : Element ;
68+ for ( const item of itemsContainer . children ) {
69+ if ( ! lastVisibleItemType && item . matches ( '.divider' ) ) {
70+ hideElem ( item ) ;
71+ continue ;
72+ }
73+ if ( item . matches ( '.tw-hidden, .filtered' ) ) continue ;
74+ // now, the item is visible
75+ if ( lastVisibleItemType === 'divider' && item . matches ( '.divider' ) ) {
76+ hideElem ( item ) ;
77+ continue ;
78+ }
79+ lastVisibleItemType = item . matches ( '.divider' ) ? 'divider' : 'item' ;
80+ lastVisibleItem = item ;
81+ }
82+ if ( lastVisibleItemType === 'divider' ) {
83+ hideElem ( lastVisibleItem ) ;
84+ }
85+ }
86+
6287// delegate the dropdown's template functions and callback functions to add aria attributes.
6388function delegateOne ( $dropdown : any ) {
6489 const dropdownCall = fomanticDropdownFn . bind ( $dropdown ) ;
@@ -72,6 +97,13 @@ function delegateOne($dropdown: any) {
7297 // * If the "dropdown icon" is clicked again when the menu is visible, Fomantic calls "blurSearch", so hide the menu
7398 dropdownCall ( 'internal' , 'blurSearch' , function ( ) { oldBlurSearch . call ( this ) ; dropdownCall ( 'hide' ) } ) ;
7499
100+ const oldFilterItems = dropdownCall ( 'internal' , 'filterItems' ) ;
101+ dropdownCall ( 'internal' , 'filterItems' , function ( ) {
102+ oldFilterItems . call ( this ) ;
103+ const onAfterFilterItems = dropdownCall ( 'setting' , 'onAfterFilterItems' ) ;
104+ if ( onAfterFilterItems ) onAfterFilterItems ( ) ;
105+ } ) ;
106+
75107 // the "template" functions are used for dynamic creation (eg: AJAX)
76108 const dropdownTemplates = { ...dropdownCall ( 'setting' , 'templates' ) , t : performance . now ( ) } ;
77109 const dropdownTemplatesMenuOld = dropdownTemplates . menu ;
0 commit comments