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-color-picker.js
71 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.Field.extend( { |
| 3 | type: 'color_picker', |
| 4 | |
| 5 | wait: 'load', |
| 6 | |
| 7 | events: { |
| 8 | duplicateField: 'onDuplicate', |
| 9 | }, |
| 10 | |
| 11 | $control: function () { |
| 12 | return this.$( '.acf-color-picker' ); |
| 13 | }, |
| 14 | |
| 15 | $input: function () { |
| 16 | return this.$( 'input[type="hidden"]' ); |
| 17 | }, |
| 18 | |
| 19 | $inputText: function () { |
| 20 | return this.$( 'input[type="text"]' ); |
| 21 | }, |
| 22 | |
| 23 | setValue: function ( val ) { |
| 24 | // update input (with change) |
| 25 | acf.val( this.$input(), val ); |
| 26 | |
| 27 | // update iris |
| 28 | this.$inputText().iris( 'color', val ); |
| 29 | }, |
| 30 | |
| 31 | initialize: function () { |
| 32 | // vars |
| 33 | var $input = this.$input(); |
| 34 | var $inputText = this.$inputText(); |
| 35 | |
| 36 | // event |
| 37 | var onChange = function ( e ) { |
| 38 | // timeout is required to ensure the $input val is correct |
| 39 | setTimeout( function () { |
| 40 | acf.val( $input, $inputText.val() ); |
| 41 | }, 1 ); |
| 42 | }; |
| 43 | |
| 44 | // args |
| 45 | var args = { |
| 46 | defaultColor: false, |
| 47 | palettes: true, |
| 48 | hide: true, |
| 49 | change: onChange, |
| 50 | clear: onChange, |
| 51 | }; |
| 52 | |
| 53 | // filter |
| 54 | var args = acf.applyFilters( 'color_picker_args', args, this ); |
| 55 | |
| 56 | // initialize |
| 57 | $inputText.wpColorPicker( args ); |
| 58 | }, |
| 59 | |
| 60 | onDuplicate: function ( e, $el, $duplicate ) { |
| 61 | // The wpColorPicker library does not provide a destroy method. |
| 62 | // Manually reset DOM by replacing elements back to their original state. |
| 63 | $colorPicker = $duplicate.find( '.wp-picker-container' ); |
| 64 | $inputText = $duplicate.find( 'input[type="text"]' ); |
| 65 | $colorPicker.replaceWith( $inputText ); |
| 66 | }, |
| 67 | } ); |
| 68 | |
| 69 | acf.registerFieldType( Field ); |
| 70 | } )( jQuery ); |
| 71 |