1
1
import $ from 'jquery' ;
2
2
import { generateAriaId } from './base.ts' ;
3
3
import type { FomanticInitFunction } from '../../types.ts' ;
4
+ import { hideElem } from '../../utils/dom.ts' ;
4
5
5
6
const ariaPatchKey = '_giteaAriaPatchDropdown' ;
6
7
const fomanticDropdownFn = $ . fn . dropdown ;
@@ -59,6 +60,30 @@ function updateSelectionLabel(label: HTMLElement) {
59
60
}
60
61
}
61
62
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
+
62
87
// delegate the dropdown's template functions and callback functions to add aria attributes.
63
88
function delegateOne ( $dropdown : any ) {
64
89
const dropdownCall = fomanticDropdownFn . bind ( $dropdown ) ;
@@ -72,6 +97,13 @@ function delegateOne($dropdown: any) {
72
97
// * If the "dropdown icon" is clicked again when the menu is visible, Fomantic calls "blurSearch", so hide the menu
73
98
dropdownCall ( 'internal' , 'blurSearch' , function ( ) { oldBlurSearch . call ( this ) ; dropdownCall ( 'hide' ) } ) ;
74
99
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
+
75
107
// the "template" functions are used for dynamic creation (eg: AJAX)
76
108
const dropdownTemplates = { ...dropdownCall ( 'setting' , 'templates' ) , t : performance . now ( ) } ;
77
109
const dropdownTemplatesMenuOld = dropdownTemplates . menu ;
0 commit comments