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-time-picker.js
101 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.models.DatePickerField.extend( { |
| 3 | type: 'time_picker', |
| 4 | |
| 5 | $control: function () { |
| 6 | return this.$( '.acf-time-picker' ); |
| 7 | }, |
| 8 | |
| 9 | setValue: function ( val ) { |
| 10 | acf.val( this.$input(), val ); |
| 11 | |
| 12 | const $inputText = this.$inputText(); |
| 13 | if ( val && $inputText.length ) { |
| 14 | try { |
| 15 | const timeFormat = |
| 16 | this.get( 'time_format' ) || |
| 17 | $inputText.timepicker( 'option', 'timeFormat' ); |
| 18 | const matches = val.match( /^(\d{2}):(\d{2}):(\d{2})$/ ); |
| 19 | |
| 20 | if ( matches && $.datepicker && $.datepicker.formatTime ) { |
| 21 | const timeText = $.datepicker.formatTime( timeFormat, { |
| 22 | hour: parseInt( matches[ 1 ], 10 ), |
| 23 | minute: parseInt( matches[ 2 ], 10 ), |
| 24 | second: parseInt( matches[ 3 ], 10 ), |
| 25 | } ); |
| 26 | $inputText.val( timeText ); |
| 27 | } else { |
| 28 | $inputText.val( val ); |
| 29 | } |
| 30 | } catch ( e ) { |
| 31 | $inputText.val( val ); |
| 32 | } |
| 33 | } else { |
| 34 | $inputText.val( '' ); |
| 35 | } |
| 36 | }, |
| 37 | |
| 38 | initialize: function () { |
| 39 | // vars |
| 40 | var $input = this.$input(); |
| 41 | var $inputText = this.$inputText(); |
| 42 | |
| 43 | // args |
| 44 | var args = { |
| 45 | timeFormat: this.get( 'time_format' ), |
| 46 | altField: $input, |
| 47 | altFieldTimeOnly: false, |
| 48 | altTimeFormat: 'HH:mm:ss', |
| 49 | showButtonPanel: true, |
| 50 | controlType: 'select', |
| 51 | oneLine: true, |
| 52 | closeText: acf.get( 'dateTimePickerL10n' ).selectText, |
| 53 | timeOnly: true, |
| 54 | }; |
| 55 | |
| 56 | // add custom 'Close = Select' functionality |
| 57 | args.onClose = function ( value, dp_instance, t_instance ) { |
| 58 | // vars |
| 59 | var $close = dp_instance.dpDiv.find( '.ui-datepicker-close' ); |
| 60 | |
| 61 | // if clicking close button |
| 62 | if ( ! value && $close.is( ':hover' ) ) { |
| 63 | t_instance._updateDateTime(); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | // filter |
| 68 | args = acf.applyFilters( 'time_picker_args', args, this ); |
| 69 | |
| 70 | // add date time picker |
| 71 | acf.newTimePicker( $inputText, args ); |
| 72 | |
| 73 | // action |
| 74 | acf.doAction( 'time_picker_init', $inputText, args, this ); |
| 75 | }, |
| 76 | } ); |
| 77 | |
| 78 | acf.registerFieldType( Field ); |
| 79 | |
| 80 | // add |
| 81 | acf.newTimePicker = function ( $input, args ) { |
| 82 | // bail early if no datepicker library |
| 83 | if ( typeof $.timepicker === 'undefined' ) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | // defaults |
| 88 | args = args || {}; |
| 89 | |
| 90 | // initialize |
| 91 | $input.timepicker( args ); |
| 92 | |
| 93 | // wrap the datepicker (only if it hasn't already been wrapped) |
| 94 | if ( $( 'body > #ui-datepicker-div' ).exists() ) { |
| 95 | $( 'body > #ui-datepicker-div' ).wrap( |
| 96 | '<div class="acf-ui-datepicker" />' |
| 97 | ); |
| 98 | } |
| 99 | }; |
| 100 | } )( jQuery ); |
| 101 |