|
58 | 58 | // Initialize the state of the icon picker.
|
59 | 59 | let typeAndValue = {
|
60 | 60 | type: this.$typeInput().val(),
|
61 |
| - value: this.$valueInput().val() |
| 61 | + value: this.$valueInput().val(), |
62 | 62 | };
|
63 | 63 |
|
64 | 64 | // Store the type and value object.
|
|
135 | 135 | initializeIconLists( typeAndValue ) {
|
136 | 136 | const self = this;
|
137 | 137 |
|
138 |
| - this.$( '.acf-icon-list' ).each( function( i ) { |
| 138 | + this.$( '.acf-icon-list' ).each( function ( i ) { |
139 | 139 | const tabName = $( this ).data( 'parent-tab' );
|
140 | 140 | const icons = self.getIconsList( tabName ) || [];
|
141 | 141 | self.set( tabName, icons );
|
142 | 142 | self.renderIconList( $( this ) );
|
143 | 143 |
|
144 | 144 | if ( typeAndValue.type === tabName ) {
|
145 | 145 | // Select the correct icon.
|
146 |
| - self.selectIcon( $( this ), typeAndValue.value, false ).then( () => { |
| 146 | + self.selectIcon( |
| 147 | + $( this ), |
| 148 | + typeAndValue.value, |
| 149 | + false |
| 150 | + ).then( () => { |
147 | 151 | // Scroll to the selected icon.
|
148 | 152 | self.scrollToSelectedIcon();
|
149 | 153 | } );
|
|
152 | 156 | },
|
153 | 157 |
|
154 | 158 | alignIconListTabsToCurrentValue( typeAndValue ) {
|
155 |
| - const icons = this.$( '.acf-icon-list' ).filter( |
156 |
| - function () { |
157 |
| - return ( |
158 |
| - $( this ).data( 'parent-tab' ) !== typeAndValue.type |
159 |
| - ); |
160 |
| - } |
161 |
| - ); |
| 159 | + const icons = this.$( '.acf-icon-list' ).filter( function () { |
| 160 | + return $( this ).data( 'parent-tab' ) !== typeAndValue.type; |
| 161 | + } ); |
162 | 162 | const self = this;
|
163 | 163 | icons.each( function () {
|
164 | 164 | self.unselectIcon( $( this ) );
|
|
179 | 179 | icon.key
|
180 | 180 | ) } acf-icon-picker-list-icon" role="radio" data-icon="${ acf.strEscape(
|
181 | 181 | icon.key
|
182 |
| - ) }" style="${ style }" title="${ acf.strEscape( |
183 |
| - icon.label |
184 |
| - ) }"> |
185 |
| - <label for="${ acf.strEscape( id ) }">${ acf.strEscape( |
186 |
| - icon.label |
187 |
| - ) }</label> |
| 182 | + ) }" style="${ style }" title="${ acf.strEscape( icon.label ) }"> |
| 183 | + <label for="${ acf.strEscape( id ) }">${ acf.strEscape( icon.label ) }</label> |
188 | 184 | <input id="${ acf.strEscape(
|
189 | 185 | id
|
190 | 186 | ) }" type="radio" class="acf-icon-picker-list-icon-radio" name="acf-icon-picker-list-icon-radio" value="${ acf.strEscape(
|
|
207 | 203 | },
|
208 | 204 |
|
209 | 205 | getIconsList( tabName ) {
|
| 206 | + let icons; |
| 207 | + |
210 | 208 | if ( 'dashicons' === tabName ) {
|
211 | 209 | const iconPickeri10n = acf.get( 'iconPickeri10n' ) || [];
|
212 |
| - |
213 |
| - return Object.entries( iconPickeri10n ).map( |
214 |
| - ( [ key, value ] ) => { |
215 |
| - return { |
216 |
| - key, |
217 |
| - label: value, |
218 |
| - }; |
219 |
| - } |
| 210 | + icons = Object.entries( iconPickeri10n ).map( |
| 211 | + ( [ key, label ] ) => ( { key, label } ) |
220 | 212 | );
|
| 213 | + } else { |
| 214 | + const iconList = this.$( |
| 215 | + `.acf-icon-list[data-parent-tab="${ tabName }"]` |
| 216 | + ); |
| 217 | + if ( iconList.length !== 0 ) { |
| 218 | + const iconsData = iconList.data( 'icons' ); |
| 219 | + icons = Array.isArray( iconsData ) ? iconsData : []; |
| 220 | + } |
221 | 221 | }
|
222 | 222 |
|
223 |
| - return acf.get( `iconPickerIcons_${ tabName }` ); |
| 223 | + return icons; |
224 | 224 | },
|
225 | 225 |
|
226 | 226 | getIconsBySearch( searchTerm, tabName ) {
|
227 | 227 | const lowercaseSearchTerm = searchTerm.toLowerCase();
|
228 |
| - const icons = this.getIconsList( tabName); |
| 228 | + const icons = this.getIconsList( tabName ); |
229 | 229 |
|
230 | 230 | const filteredIcons = icons.filter( function ( icon ) {
|
231 | 231 | const lowercaseIconLabel = icon.label.toLowerCase();
|
|
258 | 258 |
|
259 | 259 | unselectIcon( $el ) {
|
260 | 260 | // Remove the currently active dashicon, if any.
|
261 |
| - $el |
262 |
| - .find( '.acf-icon-picker-list-icon' ) |
263 |
| - .removeClass( 'active' ); |
| 261 | + $el.find( '.acf-icon-picker-list-icon' ).removeClass( 'active' ); |
264 | 262 | this.set( 'selectedIcon', false );
|
265 | 263 | },
|
266 | 264 |
|
267 | 265 | onIconRadioFocus( e ) {
|
268 | 266 | const icon = e.target.value;
|
269 |
| - const $tabs = this.$( e.target ).closest( |
270 |
| - '.acf-icon-picker-tabs' |
271 |
| - ); |
| 267 | + const $tabs = this.$( e.target ).closest( '.acf-icon-picker-tabs' ); |
272 | 268 | const $iconsList = $tabs.find( '.acf-icon-list' );
|
273 | 269 |
|
274 | 270 | const $newIcon = $iconsList.find(
|
|
292 | 288 |
|
293 | 289 | onIconClick( e ) {
|
294 | 290 | e.preventDefault();
|
295 |
| - const $iconList = this.$( e.target ).closest( |
296 |
| - '.acf-icon-list' |
297 |
| - ); |
| 291 | + const $iconList = this.$( e.target ).closest( '.acf-icon-list' ); |
298 | 292 | const $iconElement = this.$( e.target );
|
299 | 293 | const icon = $iconElement.find( 'input' ).val();
|
300 | 294 |
|
|
303 | 297 | );
|
304 | 298 |
|
305 | 299 | // By forcing focus on the input, we fire onIconRadioFocus.
|
306 |
| - $newIconElement.find( 'input' ).prop( 'checked', true ).trigger( 'focus' ); |
| 300 | + $newIconElement |
| 301 | + .find( 'input' ) |
| 302 | + .prop( 'checked', true ) |
| 303 | + .trigger( 'focus' ); |
307 | 304 | },
|
308 | 305 |
|
309 | 306 | onIconSearch( e ) {
|
310 |
| - const $tabs = this.$( e.target ).closest( |
311 |
| - '.acf-icon-picker-tabs' |
312 |
| - ); |
| 307 | + const $tabs = this.$( e.target ).closest( '.acf-icon-picker-tabs' ); |
313 | 308 | const $iconList = $tabs.find( '.acf-icon-list' );
|
314 | 309 | const tabName = $tabs.data( 'tab' );
|
315 | 310 | const searchTerm = e.target.value;
|
|
335 | 330 | : searchTerm;
|
336 | 331 |
|
337 | 332 | $tabs.find( '.acf-icon-list ' ).hide();
|
338 |
| - $tabs.find( '.acf-icon-list-empty' ) |
| 333 | + $tabs |
| 334 | + .find( '.acf-icon-list-empty' ) |
339 | 335 | .find( '.acf-invalid-icon-list-search-term' )
|
340 | 336 | .text( visualSearchTerm );
|
341 | 337 | $tabs.find( '.acf-icon-list-empty' ).css( 'display', 'flex' );
|
|
0 commit comments