PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.1
Secure Custom Fields v6.9.1
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / _acf-field-file.js
secure-custom-fields / assets / src / js Last commit date
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-file.js
163 lines
1 ( function ( $, undefined ) {
2 const 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 events: {
13 'click a[data-name="add"]': 'onClickAdd',
14 'click a[data-name="edit"]': 'onClickEdit',
15 'click a[data-name="remove"]': 'onClickRemove',
16 'change input[type="file"]': 'onChange',
17 'keydown .file-wrap': 'onImageWrapKeydown',
18 },
19 validateAttachment: function ( attachment ) {
20 // defaults
21 attachment = attachment || {};
22
23 // WP attachment
24 if ( attachment.id !== undefined ) {
25 attachment = attachment.attributes;
26 }
27
28 // args
29 attachment = acf.parseArgs( attachment, {
30 url: '',
31 alt: '',
32 title: '',
33 filename: '',
34 filesizeHumanReadable: '',
35 icon: '/wp-includes/images/media/default.png',
36 } );
37
38 // return
39 return attachment;
40 },
41
42 render: function ( attachment ) {
43 // vars
44 attachment = this.validateAttachment( attachment );
45
46 // update image
47 this.$( 'img' ).attr( {
48 src: attachment.icon,
49 alt: attachment.alt,
50 title: attachment.title,
51 } );
52
53 // update elements
54 this.$( '[data-name="title"]' ).text( attachment.title );
55 this.$( '[data-name="filename"]' )
56 .text( attachment.filename )
57 .attr( 'href', attachment.url );
58 this.$( '[data-name="filesize"]' ).text(
59 attachment.filesizeHumanReadable
60 );
61
62 // vars
63 const val = attachment.id || '';
64
65 // update val
66 acf.val( this.$input(), val );
67 if ( val ) {
68 // update class
69 this.$control().addClass( 'has-value' );
70 const fileWrap = this.$( '.file-wrap' );
71 if ( fileWrap.length ) {
72 fileWrap.trigger( 'focus' );
73 }
74 } else {
75 this.$control().removeClass( 'has-value' );
76 }
77 },
78
79 setValue: function ( val ) {
80 val = val ? String( val ) : '';
81
82 if ( acf.val( this.$input(), val, true ) === false ) {
83 return;
84 }
85
86 if ( val ) {
87 if ( window.wp && wp.media && wp.media.attachment ) {
88 const attachment = wp.media.attachment( val );
89 attachment.fetch().then(
90 $.proxy( function () {
91 this.render( attachment );
92 }, this )
93 );
94 } else {
95 this.$control().addClass( 'has-value' );
96 }
97 } else {
98 this.render( false );
99 }
100 },
101
102 selectAttachment: function () {
103 // vars
104 const parent = this.parent();
105 const multiple = parent && parent.get( 'type' ) === 'repeater';
106
107 // new frame
108 const frame = acf.newMediaPopup( {
109 mode: 'select',
110 title: acf.__( 'Select File' ),
111 field: this.get( 'key' ),
112 multiple: multiple,
113 library: this.get( 'library' ),
114 allowedTypes: this.get( 'mime_types' ),
115 select: $.proxy( function ( attachment, i ) {
116 if ( i > 0 ) {
117 this.append( attachment, parent );
118 } else {
119 this.render( attachment );
120 }
121 }, this ),
122 } );
123 },
124
125 editAttachment: function ( button ) {
126 // vars
127 const val = this.val();
128
129 // bail early if no val
130 if ( ! val ) {
131 return false;
132 }
133
134 // popup
135 var frame = acf.newMediaPopup( {
136 mode: 'edit',
137 title: acf.__( 'Edit File' ),
138 button: acf.__( 'Update File' ),
139 attachment: val,
140 field: this.get( 'key' ),
141 select: $.proxy( function ( attachment ) {
142 this.render( attachment );
143 }, this ),
144 close: $.proxy( function () {
145 if ( 'edit-button' === button ) {
146 const edit = this.$el.find( 'a[data-name="edit"]' );
147 if ( edit.length ) {
148 edit.trigger( 'focus' );
149 }
150 } else {
151 const imageWrap = this.$el.find( '.image-wrap' );
152 if ( imageWrap.length ) {
153 imageWrap.trigger( 'focus' );
154 }
155 }
156 }, this ),
157 } );
158 },
159 } );
160
161 acf.registerFieldType( Field );
162 } )( jQuery );
163