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-button-group.js
44 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.Field.extend( { |
| 3 | type: 'button_group', |
| 4 | |
| 5 | events: { |
| 6 | 'click input[type="radio"]': 'onClick', |
| 7 | }, |
| 8 | |
| 9 | $control: function () { |
| 10 | return this.$( '.acf-button-group' ); |
| 11 | }, |
| 12 | |
| 13 | $input: function () { |
| 14 | return this.$( 'input:checked' ); |
| 15 | }, |
| 16 | |
| 17 | setValue: function ( val ) { |
| 18 | this.$( 'input[value="' + val + '"]' ) |
| 19 | .prop( 'checked', true ) |
| 20 | .trigger( 'change' ); |
| 21 | }, |
| 22 | |
| 23 | onClick: function ( e, $el ) { |
| 24 | // vars |
| 25 | var $label = $el.parent( 'label' ); |
| 26 | var selected = $label.hasClass( 'selected' ); |
| 27 | |
| 28 | // remove previous selected |
| 29 | this.$( '.selected' ).removeClass( 'selected' ); |
| 30 | |
| 31 | // add active class |
| 32 | $label.addClass( 'selected' ); |
| 33 | |
| 34 | // allow null |
| 35 | if ( this.get( 'allow_null' ) && selected ) { |
| 36 | $label.removeClass( 'selected' ); |
| 37 | $el.prop( 'checked', false ).trigger( 'change' ); |
| 38 | } |
| 39 | }, |
| 40 | } ); |
| 41 | |
| 42 | acf.registerFieldType( Field ); |
| 43 | } )( jQuery ); |
| 44 |