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-field-true-false.js
97 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.Field.extend( { |
| 3 | type: 'true_false', |
| 4 | |
| 5 | events: { |
| 6 | 'change .acf-switch-input': 'onChange', |
| 7 | 'focus .acf-switch-input': 'onFocus', |
| 8 | 'blur .acf-switch-input': 'onBlur', |
| 9 | 'keypress .acf-switch-input': 'onKeypress', |
| 10 | }, |
| 11 | |
| 12 | $input: function () { |
| 13 | return this.$( 'input[type="checkbox"]' ); |
| 14 | }, |
| 15 | |
| 16 | $switch: function () { |
| 17 | return this.$( '.acf-switch' ); |
| 18 | }, |
| 19 | |
| 20 | setValue: function ( val ) { |
| 21 | if ( val && val !== '0' ) { |
| 22 | this.switchOn(); |
| 23 | } else { |
| 24 | this.switchOff(); |
| 25 | } |
| 26 | }, |
| 27 | |
| 28 | getValue: function () { |
| 29 | return this.$input().prop( 'checked' ) ? 1 : 0; |
| 30 | }, |
| 31 | |
| 32 | initialize: function () { |
| 33 | this.render(); |
| 34 | }, |
| 35 | |
| 36 | render: function () { |
| 37 | // vars |
| 38 | var $switch = this.$switch(); |
| 39 | |
| 40 | // bail early if no $switch |
| 41 | if ( ! $switch.length ) return; |
| 42 | |
| 43 | // vars |
| 44 | var $on = $switch.children( '.acf-switch-on' ); |
| 45 | var $off = $switch.children( '.acf-switch-off' ); |
| 46 | var width = Math.max( $on.width(), $off.width() ); |
| 47 | |
| 48 | // bail early if no width |
| 49 | if ( ! width ) return; |
| 50 | |
| 51 | // set widths |
| 52 | $on.css( 'min-width', width ); |
| 53 | $off.css( 'min-width', width ); |
| 54 | }, |
| 55 | |
| 56 | switchOn: function () { |
| 57 | this.$input().prop( 'checked', true ); |
| 58 | this.$switch().addClass( '-on' ); |
| 59 | }, |
| 60 | |
| 61 | switchOff: function () { |
| 62 | this.$input().prop( 'checked', false ); |
| 63 | this.$switch().removeClass( '-on' ); |
| 64 | }, |
| 65 | |
| 66 | onChange: function ( e, $el ) { |
| 67 | if ( $el.prop( 'checked' ) ) { |
| 68 | this.switchOn(); |
| 69 | } else { |
| 70 | this.switchOff(); |
| 71 | } |
| 72 | }, |
| 73 | |
| 74 | onFocus: function ( e, $el ) { |
| 75 | this.$switch().addClass( '-focus' ); |
| 76 | }, |
| 77 | |
| 78 | onBlur: function ( e, $el ) { |
| 79 | this.$switch().removeClass( '-focus' ); |
| 80 | }, |
| 81 | |
| 82 | onKeypress: function ( e, $el ) { |
| 83 | // left |
| 84 | if ( e.keyCode === 37 ) { |
| 85 | return this.switchOff(); |
| 86 | } |
| 87 | |
| 88 | // right |
| 89 | if ( e.keyCode === 39 ) { |
| 90 | return this.switchOn(); |
| 91 | } |
| 92 | }, |
| 93 | } ); |
| 94 | |
| 95 | acf.registerFieldType( Field ); |
| 96 | } )( jQuery ); |
| 97 |