pro
1 year ago
_acf-compatibility.js
1 year ago
_acf-condition-types.js
1 year ago
_acf-condition.js
1 year ago
_acf-conditions.js
1 year ago
_acf-field-accordion.js
1 year ago
_acf-field-button-group.js
1 year ago
_acf-field-checkbox.js
1 year ago
_acf-field-color-picker.js
1 year ago
_acf-field-date-picker.js
1 year ago
_acf-field-date-time-picker.js
1 year ago
_acf-field-file.js
1 year ago
_acf-field-google-map.js
1 year ago
_acf-field-icon-picker.js
1 year ago
_acf-field-image.js
1 year ago
_acf-field-link.js
1 year ago
_acf-field-oembed.js
1 year ago
_acf-field-page-link.js
1 year ago
_acf-field-post-object.js
1 year ago
_acf-field-radio.js
1 year ago
_acf-field-range.js
1 year ago
_acf-field-relationship.js
1 year ago
_acf-field-select.js
1 year ago
_acf-field-tab.js
1 year ago
_acf-field-taxonomy.js
1 year ago
_acf-field-time-picker.js
1 year ago
_acf-field-true-false.js
1 year ago
_acf-field-url.js
1 year ago
_acf-field-user.js
1 year ago
_acf-field-wysiwyg.js
1 year 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
1 year ago
_acf-media.js
1 year ago
_acf-modal.js
1 year ago
_acf-model.js
1 year ago
_acf-notice.js
1 year ago
_acf-panel.js
1 year ago
_acf-popup.js
1 year ago
_acf-postbox.js
1 year ago
_acf-screen.js
1 year ago
_acf-select2.js
1 year ago
_acf-tinymce.js
1 year ago
_acf-tooltip.js
1 year ago
_acf-unload.js
1 year ago
_acf-validation.js
1 year ago
_acf.js
1 year ago
_browse-fields-modal.js
1 year ago
_field-group-compatibility.js
1 year ago
_field-group-conditions.js
1 year ago
_field-group-field.js
1 year ago
_field-group-fields.js
1 year ago
_field-group-locations.js
1 year ago
_field-group-settings.js
1 year ago
_field-group.js
1 year 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-select.js
63 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.Field.extend( { |
| 3 | type: 'select', |
| 4 | |
| 5 | select2: false, |
| 6 | |
| 7 | wait: 'load', |
| 8 | |
| 9 | events: { |
| 10 | removeField: 'onRemove', |
| 11 | duplicateField: 'onDuplicate', |
| 12 | }, |
| 13 | |
| 14 | $input: function () { |
| 15 | return this.$( 'select' ); |
| 16 | }, |
| 17 | |
| 18 | initialize: function () { |
| 19 | // vars |
| 20 | var $select = this.$input(); |
| 21 | |
| 22 | // inherit data |
| 23 | this.inherit( $select ); |
| 24 | |
| 25 | // select2 |
| 26 | if ( this.get( 'ui' ) ) { |
| 27 | // populate ajax_data (allowing custom attribute to already exist) |
| 28 | var ajaxAction = this.get( 'ajax_action' ); |
| 29 | if ( ! ajaxAction ) { |
| 30 | ajaxAction = 'acf/fields/' + this.get( 'type' ) + '/query'; |
| 31 | } |
| 32 | |
| 33 | // select2 |
| 34 | this.select2 = acf.newSelect2( $select, { |
| 35 | field: this, |
| 36 | ajax: this.get( 'ajax' ), |
| 37 | multiple: this.get( 'multiple' ), |
| 38 | placeholder: this.get( 'placeholder' ), |
| 39 | allowNull: this.get( 'allow_null' ), |
| 40 | ajaxAction: ajaxAction, |
| 41 | } ); |
| 42 | } |
| 43 | }, |
| 44 | |
| 45 | onRemove: function () { |
| 46 | if ( this.select2 ) { |
| 47 | this.select2.destroy(); |
| 48 | } |
| 49 | }, |
| 50 | |
| 51 | onDuplicate: function ( e, $el, $duplicate ) { |
| 52 | if ( this.select2 ) { |
| 53 | $duplicate.find( '.select2-container' ).remove(); |
| 54 | $duplicate |
| 55 | .find( 'select' ) |
| 56 | .removeClass( 'select2-hidden-accessible' ); |
| 57 | } |
| 58 | }, |
| 59 | } ); |
| 60 | |
| 61 | acf.registerFieldType( Field ); |
| 62 | } )( jQuery ); |
| 63 |