bindings
1 year ago
commands
1 year ago
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-file.js
118 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.models.ImageField.extend( { |
| 3 | type: 'file', |
| 4 | |
| 5 | $control: function () { |
| 6 | return this.$( '.acf-file-uploader' ); |
| 7 | }, |
| 8 | |
| 9 | $input: function () { |
| 10 | return this.$( 'input[type="hidden"]:first' ); |
| 11 | }, |
| 12 | |
| 13 | validateAttachment: function ( attachment ) { |
| 14 | // defaults |
| 15 | attachment = attachment || {}; |
| 16 | |
| 17 | // WP attachment |
| 18 | if ( attachment.id !== undefined ) { |
| 19 | attachment = attachment.attributes; |
| 20 | } |
| 21 | |
| 22 | // args |
| 23 | attachment = acf.parseArgs( attachment, { |
| 24 | url: '', |
| 25 | alt: '', |
| 26 | title: '', |
| 27 | filename: '', |
| 28 | filesizeHumanReadable: '', |
| 29 | icon: '/wp-includes/images/media/default.png', |
| 30 | } ); |
| 31 | |
| 32 | // return |
| 33 | return attachment; |
| 34 | }, |
| 35 | |
| 36 | render: function ( attachment ) { |
| 37 | // vars |
| 38 | attachment = this.validateAttachment( attachment ); |
| 39 | |
| 40 | // update image |
| 41 | this.$( 'img' ).attr( { |
| 42 | src: attachment.icon, |
| 43 | alt: attachment.alt, |
| 44 | title: attachment.title, |
| 45 | } ); |
| 46 | |
| 47 | // update elements |
| 48 | this.$( '[data-name="title"]' ).text( attachment.title ); |
| 49 | this.$( '[data-name="filename"]' ) |
| 50 | .text( attachment.filename ) |
| 51 | .attr( 'href', attachment.url ); |
| 52 | this.$( '[data-name="filesize"]' ).text( |
| 53 | attachment.filesizeHumanReadable |
| 54 | ); |
| 55 | |
| 56 | // vars |
| 57 | var val = attachment.id || ''; |
| 58 | |
| 59 | // update val |
| 60 | acf.val( this.$input(), val ); |
| 61 | |
| 62 | // update class |
| 63 | if ( val ) { |
| 64 | this.$control().addClass( 'has-value' ); |
| 65 | } else { |
| 66 | this.$control().removeClass( 'has-value' ); |
| 67 | } |
| 68 | }, |
| 69 | |
| 70 | selectAttachment: function () { |
| 71 | // vars |
| 72 | var parent = this.parent(); |
| 73 | var multiple = parent && parent.get( 'type' ) === 'repeater'; |
| 74 | |
| 75 | // new frame |
| 76 | var frame = acf.newMediaPopup( { |
| 77 | mode: 'select', |
| 78 | title: acf.__( 'Select File' ), |
| 79 | field: this.get( 'key' ), |
| 80 | multiple: multiple, |
| 81 | library: this.get( 'library' ), |
| 82 | allowedTypes: this.get( 'mime_types' ), |
| 83 | select: $.proxy( function ( attachment, i ) { |
| 84 | if ( i > 0 ) { |
| 85 | this.append( attachment, parent ); |
| 86 | } else { |
| 87 | this.render( attachment ); |
| 88 | } |
| 89 | }, this ), |
| 90 | } ); |
| 91 | }, |
| 92 | |
| 93 | editAttachment: function () { |
| 94 | // vars |
| 95 | var val = this.val(); |
| 96 | |
| 97 | // bail early if no val |
| 98 | if ( ! val ) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | // popup |
| 103 | var frame = acf.newMediaPopup( { |
| 104 | mode: 'edit', |
| 105 | title: acf.__( 'Edit File' ), |
| 106 | button: acf.__( 'Update File' ), |
| 107 | attachment: val, |
| 108 | field: this.get( 'key' ), |
| 109 | select: $.proxy( function ( attachment, i ) { |
| 110 | this.render( attachment ); |
| 111 | }, this ), |
| 112 | } ); |
| 113 | }, |
| 114 | } ); |
| 115 | |
| 116 | acf.registerFieldType( Field ); |
| 117 | } )( jQuery ); |
| 118 |