File tree Expand file tree Collapse file tree 1 file changed +30
-11
lines changed Expand file tree Collapse file tree 1 file changed +30
-11
lines changed Original file line number Diff line number Diff line change @@ -92,17 +92,36 @@ export function urlExists(url) {
92
92
*/
93
93
94
94
$ . fn . sortSelect = function ( text = "" ) {
95
- const op = this . children ( "option" ) ;
96
-
97
- op . sort ( ( a , b ) => {
98
- if ( a . text === text ) {
99
- return - 1 ;
100
- }
101
- if ( b . text === text ) {
102
- return 1 ;
103
- }
104
- return a . text . localeCompare ( b . text , window . navigator . language , { ignorePunctuation : true } ) ;
95
+ this . each ( function ( ) {
96
+ const select = this ;
97
+ // Collect option data
98
+ const optionData = Array . from ( select . options ) . map ( opt => ( {
99
+ value : opt . value ,
100
+ text : opt . text ,
101
+ selected : opt . selected ,
102
+ disabled : opt . disabled ,
103
+ } ) ) ;
104
+
105
+ // Sort option data
106
+ optionData . sort ( ( a , b ) => {
107
+ if ( a . text === text ) { return - 1 ; }
108
+ if ( b . text === text ) { return 1 ; }
109
+ return a . text . localeCompare ( b . text , window . navigator . language , { ignorePunctuation : true } ) ;
110
+ } ) ;
111
+
112
+ // Remove all options
113
+ while ( select . options . length ) { select . remove ( 0 ) ; }
114
+
115
+ // Add sorted options
116
+ optionData . forEach ( opt => {
117
+ const option = document . createElement ( "option" ) ;
118
+ option . value = opt . value ;
119
+ option . text = opt . text ;
120
+ option . selected = opt . selected ;
121
+ option . disabled = opt . disabled ;
122
+ select . add ( option ) ;
123
+ } ) ;
105
124
} ) ;
106
125
107
- return this . empty ( ) . append ( op ) ;
126
+ return this ;
108
127
} ;
You can’t perform that action at this time.
0 commit comments