Skip to content

Commit 8327d62

Browse files
authored
Backport: Update 6.5.0 (#208)
* First batch of changes * Backport acf-input.min.js * Finish main min file * Update 90% of flexible content * Finish all JS * Update all PHP files and acf min * Update latest version * Rename issue
1 parent 844af67 commit 8327d62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2905
-1108
lines changed

assets/images/icons/icon-add-alt.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

assets/images/icons/icon-edit.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

assets/images/icons/icon-visible.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/src/js/_acf-field-date-picker.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,32 @@
4747
// add date picker
4848
acf.newDatePicker( $inputText, args );
4949

50-
// action
50+
// Check if default to today is enabled and field is empty
51+
if (
52+
$inputText.data( 'default-to-today' ) === 1 &&
53+
! $input.val()
54+
) {
55+
// Get current date
56+
const currentDate = new Date();
57+
58+
// Format display date
59+
const displayDate = $.datepicker.formatDate(
60+
args.dateFormat,
61+
currentDate
62+
);
63+
64+
// Set the display input value (what user sees)
65+
$inputText.val( `${ displayDate }` );
66+
67+
// Format hidden field date (for database storage)
68+
const hiddenDate = $.datepicker.formatDate(
69+
'yymmdd',
70+
currentDate
71+
);
72+
73+
// Set the hidden input value (what gets saved)
74+
$input.val( `${ hiddenDate }` );
75+
}
5176
acf.doAction( 'date_picker_init', $inputText, args, this );
5277
},
5378

assets/src/js/_acf-field-date-time-picker.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@
3434
// add date time picker
3535
acf.newDateTimePicker( $inputText, args );
3636

37+
// Check if default to today is enabled and field is empty
38+
if (
39+
$inputText.data( 'default-to-today' ) === 1 &&
40+
! $input.val()
41+
) {
42+
// Get current date
43+
const currentDate = new Date();
44+
45+
// Format display date and time
46+
const displayDate = $.datepicker.formatDate(
47+
args.dateFormat,
48+
currentDate
49+
);
50+
const displayTime = $.datepicker.formatTime( args.timeFormat, {
51+
hour: currentDate.getHours(),
52+
minute: currentDate.getMinutes(),
53+
second: currentDate.getSeconds(),
54+
} );
55+
56+
// Set the display input value (what user sees)
57+
$inputText.val( `${ displayDate } ${ displayTime }` );
58+
59+
// Format hidden field date and time (for database storage)
60+
const hiddenDate = $.datepicker.formatDate(
61+
'yy-mm-dd',
62+
currentDate
63+
);
64+
const hiddenTime = $.datepicker.formatTime( 'hh:mm:ss', {
65+
hour: currentDate.getHours(),
66+
minute: currentDate.getMinutes(),
67+
second: currentDate.getSeconds(),
68+
} );
69+
70+
// Set the hidden input value (what gets saved)
71+
$input.val( `${ hiddenDate } ${ hiddenTime }` );
72+
}
73+
3774
// action
3875
acf.doAction( 'date_time_picker_init', $inputText, args, this );
3976
},

assets/src/js/_acf-field-icon-picker.js

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
// Initialize the state of the icon picker.
5959
let typeAndValue = {
6060
type: this.$typeInput().val(),
61-
value: this.$valueInput().val()
61+
value: this.$valueInput().val(),
6262
};
6363

6464
// Store the type and value object.
@@ -135,15 +135,19 @@
135135
initializeIconLists( typeAndValue ) {
136136
const self = this;
137137

138-
this.$( '.acf-icon-list' ).each( function( i ) {
138+
this.$( '.acf-icon-list' ).each( function ( i ) {
139139
const tabName = $( this ).data( 'parent-tab' );
140140
const icons = self.getIconsList( tabName ) || [];
141141
self.set( tabName, icons );
142142
self.renderIconList( $( this ) );
143143

144144
if ( typeAndValue.type === tabName ) {
145145
// Select the correct icon.
146-
self.selectIcon( $( this ), typeAndValue.value, false ).then( () => {
146+
self.selectIcon(
147+
$( this ),
148+
typeAndValue.value,
149+
false
150+
).then( () => {
147151
// Scroll to the selected icon.
148152
self.scrollToSelectedIcon();
149153
} );
@@ -152,13 +156,9 @@
152156
},
153157

154158
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+
} );
162162
const self = this;
163163
icons.each( function () {
164164
self.unselectIcon( $( this ) );
@@ -179,12 +179,8 @@
179179
icon.key
180180
) } acf-icon-picker-list-icon" role="radio" data-icon="${ acf.strEscape(
181181
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>
188184
<input id="${ acf.strEscape(
189185
id
190186
) }" type="radio" class="acf-icon-picker-list-icon-radio" name="acf-icon-picker-list-icon-radio" value="${ acf.strEscape(
@@ -207,25 +203,29 @@
207203
},
208204

209205
getIconsList( tabName ) {
206+
let icons;
207+
210208
if ( 'dashicons' === tabName ) {
211209
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 } )
220212
);
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+
}
221221
}
222222

223-
return acf.get( `iconPickerIcons_${ tabName }` );
223+
return icons;
224224
},
225225

226226
getIconsBySearch( searchTerm, tabName ) {
227227
const lowercaseSearchTerm = searchTerm.toLowerCase();
228-
const icons = this.getIconsList( tabName);
228+
const icons = this.getIconsList( tabName );
229229

230230
const filteredIcons = icons.filter( function ( icon ) {
231231
const lowercaseIconLabel = icon.label.toLowerCase();
@@ -258,17 +258,13 @@
258258

259259
unselectIcon( $el ) {
260260
// 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' );
264262
this.set( 'selectedIcon', false );
265263
},
266264

267265
onIconRadioFocus( e ) {
268266
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' );
272268
const $iconsList = $tabs.find( '.acf-icon-list' );
273269

274270
const $newIcon = $iconsList.find(
@@ -292,9 +288,7 @@
292288

293289
onIconClick( e ) {
294290
e.preventDefault();
295-
const $iconList = this.$( e.target ).closest(
296-
'.acf-icon-list'
297-
);
291+
const $iconList = this.$( e.target ).closest( '.acf-icon-list' );
298292
const $iconElement = this.$( e.target );
299293
const icon = $iconElement.find( 'input' ).val();
300294

@@ -303,13 +297,14 @@
303297
);
304298

305299
// 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' );
307304
},
308305

309306
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' );
313308
const $iconList = $tabs.find( '.acf-icon-list' );
314309
const tabName = $tabs.data( 'tab' );
315310
const searchTerm = e.target.value;
@@ -335,7 +330,8 @@
335330
: searchTerm;
336331

337332
$tabs.find( '.acf-icon-list ' ).hide();
338-
$tabs.find( '.acf-icon-list-empty' )
333+
$tabs
334+
.find( '.acf-icon-list-empty' )
339335
.find( '.acf-invalid-icon-list-search-term' )
340336
.text( visualSearchTerm );
341337
$tabs.find( '.acf-icon-list-empty' ).css( 'display', 'flex' );

0 commit comments

Comments
 (0)