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-field.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 2 weeks ago pro 2 weeks 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 2 weeks 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-field.js
536 lines
1 ( function ( $, undefined ) {
2 // vars
3 var storage = [];
4
5 /**
6 * acf.Field
7 *
8 * description
9 *
10 * @date 23/3/18
11 * @since ACF 5.6.9
12 *
13 * @param type $var Description. Default.
14 * @return type Description.
15 */
16
17 acf.Field = acf.Model.extend( {
18 // field type
19 type: '',
20
21 // class used to avoid nested event triggers
22 eventScope: '.acf-field',
23
24 // initialize events on 'ready'
25 wait: 'ready',
26
27 /**
28 * setup
29 *
30 * Called during the constructor function to setup this field ready for initialization
31 *
32 * @date 8/5/18
33 * @since ACF 5.6.9
34 *
35 * @param jQuery $field The field element.
36 * @return void
37 */
38
39 setup: function ( $field ) {
40 // set $el
41 this.$el = $field;
42
43 // inherit $field data
44 this.inherit( $field );
45
46 // inherit control data
47 this.inherit( this.$control() );
48 },
49
50 /**
51 * val
52 *
53 * Sets or returns the field's value
54 *
55 * @date 8/5/18
56 * @since ACF 5.6.9
57 *
58 * @param mixed val Optional. The value to set
59 * @return mixed
60 */
61
62 val: function ( val ) {
63 // Set.
64 if ( val !== undefined ) {
65 return this.setValue( val );
66
67 // Get.
68 } else {
69 return this.prop( 'disabled' ) ? null : this.getValue();
70 }
71 },
72
73 /**
74 * getValue
75 *
76 * returns the field's value
77 *
78 * @date 8/5/18
79 * @since ACF 5.6.9
80 *
81 * @param void
82 * @return mixed
83 */
84
85 getValue: function () {
86 return this.$input().val();
87 },
88
89 /**
90 * setValue
91 *
92 * sets the field's value and returns true if changed
93 *
94 * @date 8/5/18
95 * @since ACF 5.6.9
96 *
97 * @param mixed val
98 * @return boolean. True if changed.
99 */
100
101 setValue: function ( val ) {
102 return acf.val( this.$input(), val );
103 },
104
105 /**
106 * __
107 *
108 * i18n helper to be removed
109 *
110 * @date 8/5/18
111 * @since ACF 5.6.9
112 *
113 * @param type $var Description. Default.
114 * @return type Description.
115 */
116
117 __: function ( string ) {
118 return acf._e( this.type, string );
119 },
120
121 /**
122 * $control
123 *
124 * returns the control jQuery element used for inheriting data. Uses this.control setting.
125 *
126 * @date 8/5/18
127 * @since ACF 5.6.9
128 *
129 * @param void
130 * @return jQuery
131 */
132
133 $control: function () {
134 return false;
135 },
136
137 /**
138 * $input
139 *
140 * returns the input jQuery element used for saving values. Uses this.input setting.
141 *
142 * @date 8/5/18
143 * @since ACF 5.6.9
144 *
145 * @param void
146 * @return jQuery
147 */
148
149 $input: function () {
150 return this.$( '[name]:first' );
151 },
152
153 /**
154 * $inputWrap
155 *
156 * description
157 *
158 * @date 12/5/18
159 * @since ACF 5.6.9
160 *
161 * @param type $var Description. Default.
162 * @return type Description.
163 */
164
165 $inputWrap: function () {
166 return this.$( '.acf-input:first' );
167 },
168
169 /**
170 * $inputWrap
171 *
172 * description
173 *
174 * @date 12/5/18
175 * @since ACF 5.6.9
176 *
177 * @param type $var Description. Default.
178 * @return type Description.
179 */
180
181 $labelWrap: function () {
182 return this.$( '.acf-label:first' );
183 },
184
185 /**
186 * getInputName
187 *
188 * Returns the field's input name
189 *
190 * @date 8/5/18
191 * @since ACF 5.6.9
192 *
193 * @param void
194 * @return string
195 */
196
197 getInputName: function () {
198 return this.$input().attr( 'name' ) || '';
199 },
200
201 /**
202 * parent
203 *
204 * returns the field's parent field or false on failure.
205 *
206 * @date 8/5/18
207 * @since ACF 5.6.9
208 *
209 * @param void
210 * @return object|false
211 */
212
213 parent: function () {
214 // vars
215 var parents = this.parents();
216
217 // return
218 return parents.length ? parents[ 0 ] : false;
219 },
220
221 /**
222 * parents
223 *
224 * description
225 *
226 * @date 9/7/18
227 * @since ACF 5.6.9
228 *
229 * @param type $var Description. Default.
230 * @return type Description.
231 */
232
233 parents: function () {
234 // vars
235 var $parents = this.$el.parents( '.acf-field' );
236
237 // convert
238 var parents = acf.getFields( $parents );
239
240 // return
241 return parents;
242 },
243
244 show: function ( lockKey, context ) {
245 // show field and store result
246 var changed = acf.show( this.$el, lockKey );
247
248 // do action if visibility has changed
249 if ( changed ) {
250 this.prop( 'hidden', false );
251 acf.doAction( 'show_field', this, context );
252
253 if ( context === 'conditional_logic' ) {
254 this.setFieldSettingsLastVisible();
255 }
256 }
257
258 // return
259 return changed;
260 },
261
262 hide: function ( lockKey, context ) {
263 // hide field and store result
264 var changed = acf.hide( this.$el, lockKey );
265
266 // do action if visibility has changed
267 if ( changed ) {
268 this.prop( 'hidden', true );
269 acf.doAction( 'hide_field', this, context );
270
271 if ( context === 'conditional_logic' ) {
272 this.setFieldSettingsLastVisible();
273 }
274 }
275
276 // return
277 return changed;
278 },
279
280 setFieldSettingsLastVisible: function () {
281 // Ensure this conditional logic trigger has happened inside a field settings tab.
282 var $parents = this.$el.parents( '.acf-field-settings-main' );
283 if ( ! $parents.length ) return;
284
285 var $fields = $parents.find( '.acf-field' );
286
287 $fields.removeClass( 'acf-last-visible' );
288 $fields.not( '.acf-hidden' ).last().addClass( 'acf-last-visible' );
289 },
290
291 enable: function ( lockKey, context ) {
292 // enable field and store result
293 var changed = acf.enable( this.$el, lockKey );
294
295 // do action if disabled has changed
296 if ( changed ) {
297 this.prop( 'disabled', false );
298 acf.doAction( 'enable_field', this, context );
299 }
300
301 // return
302 return changed;
303 },
304
305 disable: function ( lockKey, context ) {
306 // disabled field and store result
307 var changed = acf.disable( this.$el, lockKey );
308
309 // do action if disabled has changed
310 if ( changed ) {
311 this.prop( 'disabled', true );
312 acf.doAction( 'disable_field', this, context );
313 }
314
315 // return
316 return changed;
317 },
318
319 showEnable: function ( lockKey, context ) {
320 // enable
321 this.enable.apply( this, arguments );
322
323 // show and return true if changed
324 return this.show.apply( this, arguments );
325 },
326
327 hideDisable: function ( lockKey, context ) {
328 // disable
329 this.disable.apply( this, arguments );
330
331 // hide and return true if changed
332 return this.hide.apply( this, arguments );
333 },
334
335 showNotice: function ( props ) {
336 // ensure object
337 if ( typeof props !== 'object' ) {
338 props = { text: props };
339 }
340
341 // remove old notice
342 if ( this.notice ) {
343 this.notice.remove();
344 }
345
346 // create new notice
347 props.target = this.$inputWrap();
348 this.notice = acf.newNotice( props );
349 },
350
351 removeNotice: function ( timeout ) {
352 if ( this.notice ) {
353 this.notice.away( timeout || 0 );
354 this.notice = false;
355 }
356 },
357
358 showError: function ( message, location = 'before' ) {
359 // add class
360 this.$el.addClass( 'acf-error' );
361
362 // add message
363 if ( message !== undefined ) {
364 this.showNotice( {
365 text: message,
366 type: 'error',
367 dismiss: false,
368 location: location,
369 } );
370 }
371
372 // action
373 acf.doAction( 'invalid_field', this );
374
375 // add event
376 this.$el.one(
377 'focus change',
378 'input, select, textarea',
379 $.proxy( this.removeError, this )
380 );
381 },
382
383 removeError: function () {
384 // remove class
385 this.$el.removeClass( 'acf-error' );
386
387 // remove notice
388 this.removeNotice( 250 );
389
390 // action
391 acf.doAction( 'valid_field', this );
392 },
393
394 trigger: function ( name, args, bubbles ) {
395 // allow some events to bubble
396 if ( name == 'invalidField' ) {
397 bubbles = true;
398 }
399
400 // return
401 return acf.Model.prototype.trigger.apply( this, [
402 name,
403 args,
404 bubbles,
405 ] );
406 },
407 } );
408
409 /**
410 * newField
411 *
412 * description
413 *
414 * @date 14/12/17
415 * @since ACF 5.6.5
416 *
417 * @param type $var Description. Default.
418 * @return type Description.
419 */
420
421 acf.newField = function ( $field ) {
422 // vars
423 var type = $field.data( 'type' );
424 var mid = modelId( type );
425 var model = acf.models[ mid ] || acf.Field;
426
427 // instantiate
428 var field = new model( $field );
429
430 // actions
431 acf.doAction( 'new_field', field );
432
433 // return
434 return field;
435 };
436
437 /**
438 * mid
439 *
440 * Calculates the model ID for a field type
441 *
442 * @date 15/12/17
443 * @since ACF 5.6.5
444 *
445 * @param string type
446 * @return string
447 */
448
449 var modelId = function ( type ) {
450 return acf.strPascalCase( type || '' ) + 'Field';
451 };
452
453 /**
454 * registerFieldType
455 *
456 * description
457 *
458 * @date 14/12/17
459 * @since ACF 5.6.5
460 *
461 * @param type $var Description. Default.
462 * @return type Description.
463 */
464
465 acf.registerFieldType = function ( model ) {
466 // vars
467 var proto = model.prototype;
468 var type = proto.type;
469 var mid = modelId( type );
470
471 // store model
472 acf.models[ mid ] = model;
473
474 // store reference
475 storage.push( type );
476 };
477
478 /**
479 * acf.getFieldType
480 *
481 * description
482 *
483 * @date 1/2/18
484 * @since ACF 5.6.5
485 *
486 * @param type $var Description. Default.
487 * @return type Description.
488 */
489
490 acf.getFieldType = function ( type ) {
491 var mid = modelId( type );
492 return acf.models[ mid ] || false;
493 };
494
495 /**
496 * acf.getFieldTypes
497 *
498 * description
499 *
500 * @date 1/2/18
501 * @since ACF 5.6.5
502 *
503 * @param type $var Description. Default.
504 * @return type Description.
505 */
506
507 acf.getFieldTypes = function ( args ) {
508 // defaults
509 args = acf.parseArgs( args, {
510 category: '',
511 // hasValue: true
512 } );
513
514 // clone available types
515 var types = [];
516
517 // loop
518 storage.map( function ( type ) {
519 // vars
520 var model = acf.getFieldType( type );
521 var proto = model.prototype;
522
523 // check operator
524 if ( args.category && proto.category !== args.category ) {
525 return;
526 }
527
528 // append
529 types.push( model );
530 } );
531
532 // return
533 return types;
534 };
535 } )( jQuery );
536