PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / _acf-helpers.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 1 week ago pro 1 week ago _acf-compatibility.js 1 year ago _acf-condition-types.js 7 months ago _acf-condition.js 1 year ago _acf-conditions.js 1 year ago _acf-field-accordion.js 6 months ago _acf-field-button-group.js 7 months ago _acf-field-checkbox.js 1 month ago _acf-field-color-picker.js 7 months ago _acf-field-date-picker.js 1 month ago _acf-field-date-time-picker.js 1 month ago _acf-field-file.js 1 month ago _acf-field-google-map.js 6 months ago _acf-field-icon-picker.js 1 month ago _acf-field-image.js 1 month ago _acf-field-link.js 1 year ago _acf-field-oembed.js 1 month ago _acf-field-page-link.js 1 year ago _acf-field-post-object.js 1 year ago _acf-field-radio.js 1 month ago _acf-field-range.js 1 year ago _acf-field-relationship.js 1 month ago _acf-field-select.js 1 month ago _acf-field-tab.js 3 weeks ago _acf-field-taxonomy.js 7 months ago _acf-field-time-picker.js 1 month ago _acf-field-true-false.js 1 month ago _acf-field-url.js 1 year ago _acf-field-user.js 1 year ago _acf-field-wysiwyg.js 1 month ago _acf-field.js 1 year ago _acf-fields.js 1 year ago _acf-helpers.js 1 year ago _acf-hooks.js 1 year ago _acf-internal-post-type.js 7 months ago _acf-media.js 1 week ago _acf-modal.js 1 year ago _acf-model.js 1 year ago _acf-notice.js 7 months ago _acf-panel.js 1 year ago _acf-popup.js 7 months ago _acf-postbox.js 1 year ago _acf-screen.js 10 months ago _acf-select2.js 1 year ago _acf-tinymce.js 6 months ago _acf-tooltip.js 10 months ago _acf-unload.js 1 year ago _acf-validation.js 1 month ago _acf.js 7 months ago _browse-fields-modal.js 7 months ago _field-group-compatibility.js 1 year ago _field-group-conditions.js 1 year ago _field-group-field.js 3 months ago _field-group-fields.js 10 months ago _field-group-locations.js 1 year ago _field-group-settings.js 1 year ago _field-group.js 10 months ago acf-escaped-html-notice.js 1 year ago acf-field-group.js 1 year ago acf-input.js 1 year ago acf-internal-post-type.js 1 year ago acf.js 1 year ago
_acf-helpers.js
375 lines
1 ( function ( $, undefined ) {
2 /**
3 * refreshHelper
4 *
5 * description
6 *
7 * @date 1/7/18
8 * @since ACF 5.6.9
9 *
10 * @param type $var Description. Default.
11 * @return type Description.
12 */
13
14 var refreshHelper = new acf.Model( {
15 priority: 90,
16 actions: {
17 new_field: 'refresh',
18 show_field: 'refresh',
19 hide_field: 'refresh',
20 remove_field: 'refresh',
21 unmount_field: 'refresh',
22 remount_field: 'refresh',
23 },
24 refresh: function () {
25 acf.refresh();
26 },
27 } );
28
29 /**
30 * mountHelper
31 *
32 * Adds compatibility for the 'unmount' and 'remount' actions added in 5.8.0
33 *
34 * @date 7/3/19
35 * @since ACF 5.7.14
36 *
37 * @param void
38 * @return void
39 */
40 var mountHelper = new acf.Model( {
41 priority: 1,
42 actions: {
43 sortstart: 'onSortstart',
44 sortstop: 'onSortstop',
45 },
46 onSortstart: function ( $item ) {
47 acf.doAction( 'unmount', $item );
48 },
49 onSortstop: function ( $item ) {
50 acf.doAction( 'remount', $item );
51 },
52 } );
53
54 /**
55 * sortableHelper
56 *
57 * Adds compatibility for sorting a <tr> element
58 *
59 * @date 6/3/18
60 * @since ACF 5.6.9
61 *
62 * @param void
63 * @return void
64 */
65
66 var sortableHelper = new acf.Model( {
67 actions: {
68 sortstart: 'onSortstart',
69 },
70 onSortstart: function ( $item, $placeholder ) {
71 // if $item is a tr, apply some css to the elements
72 if ( $item.is( 'tr' ) ) {
73 // replace $placeholder children with a single td
74 // fixes "width calculation issues" due to conditional logic hiding some children
75 $placeholder.html(
76 '<td style="padding:0;" colspan="' +
77 $placeholder.children().length +
78 '"></td>'
79 );
80
81 // add helper class to remove absolute positioning
82 $item.addClass( 'acf-sortable-tr-helper' );
83
84 // set fixed widths for children
85 $item.children().each( function () {
86 $( this ).width( $( this ).width() );
87 } );
88
89 // mimic height
90 $placeholder.height( $item.height() + 'px' );
91
92 // remove class
93 $item.removeClass( 'acf-sortable-tr-helper' );
94 }
95 },
96 } );
97
98 /**
99 * duplicateHelper
100 *
101 * Fixes browser bugs when duplicating an element
102 *
103 * @date 6/3/18
104 * @since ACF 5.6.9
105 *
106 * @param void
107 * @return void
108 */
109
110 var duplicateHelper = new acf.Model( {
111 actions: {
112 after_duplicate: 'onAfterDuplicate',
113 },
114 onAfterDuplicate: function ( $el, $el2 ) {
115 // get original values
116 var vals = [];
117 $el.find( 'select' ).each( function ( i ) {
118 vals.push( $( this ).val() );
119 } );
120
121 // set duplicate values
122 $el2.find( 'select' ).each( function ( i ) {
123 $( this ).val( vals[ i ] );
124 } );
125 },
126 } );
127
128 /**
129 * tableHelper
130 *
131 * description
132 *
133 * @date 6/3/18
134 * @since ACF 5.6.9
135 *
136 * @param type $var Description. Default.
137 * @return type Description.
138 */
139
140 var tableHelper = new acf.Model( {
141 id: 'tableHelper',
142
143 priority: 20,
144
145 actions: {
146 refresh: 'renderTables',
147 },
148
149 renderTables: function ( $el ) {
150 // loop
151 var self = this;
152 $( '.acf-table:visible' ).each( function () {
153 self.renderTable( $( this ) );
154 } );
155 },
156
157 renderTable: function ( $table ) {
158 // vars
159 var $ths = $table.find( '> thead > tr:visible > th[data-key]' );
160 var $tds = $table.find( '> tbody > tr:visible > td[data-key]' );
161
162 // bail early if no thead
163 if ( ! $ths.length || ! $tds.length ) {
164 return false;
165 }
166
167 // visibility
168 $ths.each( function ( i ) {
169 // vars
170 var $th = $( this );
171 var key = $th.data( 'key' );
172 var $cells = $tds.filter( '[data-key="' + key + '"]' );
173 var $hidden = $cells.filter( '.acf-hidden' );
174
175 // always remove empty and allow cells to be hidden
176 $cells.removeClass( 'acf-empty' );
177
178 // hide $th if all cells are hidden
179 if ( $cells.length === $hidden.length ) {
180 acf.hide( $th );
181
182 // force all hidden cells to appear empty
183 } else {
184 acf.show( $th );
185 $hidden.addClass( 'acf-empty' );
186 }
187 } );
188
189 // clear width
190 $ths.css( 'width', 'auto' );
191
192 // get visible
193 $ths = $ths.not( '.acf-hidden' );
194
195 // vars
196 var availableWidth = 100;
197 var colspan = $ths.length;
198
199 // set custom widths first
200 var $fixedWidths = $ths.filter( '[data-width]' );
201 $fixedWidths.each( function () {
202 var width = $( this ).data( 'width' );
203 $( this ).css( 'width', width + '%' );
204 availableWidth -= width;
205 } );
206
207 // set auto widths
208 var $auoWidths = $ths.not( '[data-width]' );
209 if ( $auoWidths.length ) {
210 var width = availableWidth / $auoWidths.length;
211 $auoWidths.css( 'width', width + '%' );
212 availableWidth = 0;
213 }
214
215 // avoid stretching issue
216 if ( availableWidth > 0 ) {
217 $ths.last().css( 'width', 'auto' );
218 }
219
220 // update colspan on collapsed
221 $tds.filter( '.-collapsed-target' ).each( function () {
222 // vars
223 var $td = $( this );
224
225 // check if collapsed
226 if ( $td.parent().hasClass( '-collapsed' ) ) {
227 $td.attr( 'colspan', $ths.length );
228 } else {
229 $td.removeAttr( 'colspan' );
230 }
231 } );
232 },
233 } );
234
235 /**
236 * fieldsHelper
237 *
238 * description
239 *
240 * @date 6/3/18
241 * @since ACF 5.6.9
242 *
243 * @param type $var Description. Default.
244 * @return type Description.
245 */
246
247 var fieldsHelper = new acf.Model( {
248 id: 'fieldsHelper',
249
250 priority: 30,
251
252 actions: {
253 refresh: 'renderGroups',
254 },
255
256 renderGroups: function () {
257 // loop
258 var self = this;
259 $( '.acf-fields:visible' ).each( function () {
260 self.renderGroup( $( this ) );
261 } );
262 },
263
264 renderGroup: function ( $el ) {
265 // vars
266 var top = 0;
267 var height = 0;
268 var $row = $();
269
270 // get fields
271 var $fields = $el.children( '.acf-field[data-width]:visible' );
272
273 // bail early if no fields
274 if ( ! $fields.length ) {
275 return false;
276 }
277
278 // bail early if is .-left
279 if ( $el.hasClass( '-left' ) ) {
280 $fields.removeAttr( 'data-width' );
281 $fields.css( 'width', 'auto' );
282 return false;
283 }
284
285 // reset fields
286 $fields.removeClass( '-r0 -c0' ).css( { 'min-height': 0 } );
287
288 // loop
289 $fields.each( function ( i ) {
290 // vars
291 var $field = $( this );
292 var position = $field.position();
293 var thisTop = Math.ceil( position.top );
294 var thisLeft = Math.ceil( position.left );
295
296 // detect change in row
297 if ( $row.length && thisTop > top ) {
298 // set previous heights
299 $row.css( { 'min-height': height + 'px' } );
300
301 // update position due to change in row above
302 position = $field.position();
303 thisTop = Math.ceil( position.top );
304 thisLeft = Math.ceil( position.left );
305
306 // reset vars
307 top = 0;
308 height = 0;
309 $row = $();
310 }
311
312 // rtl
313 if ( acf.get( 'rtl' ) ) {
314 thisLeft = Math.ceil(
315 $field.parent().width() -
316 ( position.left + $field.outerWidth() )
317 );
318 }
319
320 // add classes
321 if ( thisTop == 0 ) {
322 $field.addClass( '-r0' );
323 } else if ( thisLeft == 0 ) {
324 $field.addClass( '-c0' );
325 }
326
327 // get height after class change
328 // - add 1 for subpixel rendering
329 var thisHeight = Math.ceil( $field.outerHeight() ) + 1;
330
331 // set height
332 height = Math.max( height, thisHeight );
333
334 // set y
335 top = Math.max( top, thisTop );
336
337 // append
338 $row = $row.add( $field );
339 } );
340
341 // clean up
342 if ( $row.length ) {
343 $row.css( { 'min-height': height + 'px' } );
344 }
345 },
346 } );
347
348 /**
349 * Adds a body class when holding down the "shift" key.
350 *
351 * @date 06/05/2020
352 * @since ACF 5.9.0
353 */
354 var bodyClassShiftHelper = new acf.Model( {
355 id: 'bodyClassShiftHelper',
356 events: {
357 keydown: 'onKeyDown',
358 keyup: 'onKeyUp',
359 },
360 isShiftKey: function ( e ) {
361 return e.keyCode === 16;
362 },
363 onKeyDown: function ( e ) {
364 if ( this.isShiftKey( e ) ) {
365 $( 'body' ).addClass( 'acf-keydown-shift' );
366 }
367 },
368 onKeyUp: function ( e ) {
369 if ( this.isShiftKey( e ) ) {
370 $( 'body' ).removeClass( 'acf-keydown-shift' );
371 }
372 },
373 } );
374 } )( jQuery );
375