Sync plugins from current page

Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
2019-09-11 19:08:46 +02:00
parent 85d41e4216
commit 8515ff9587
1847 changed files with 505469 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
(function($, undefined){
var Field = acf.models.ImageField.extend({
type: 'file',
$control: function(){
return this.$('.acf-file-uploader');
},
$input: function(){
return this.$('input[type="hidden"]');
},
validateAttachment: function( attachment ){
// defaults
attachment = attachment || {};
// WP attachment
if( attachment.id !== undefined ) {
attachment = attachment.attributes;
}
// args
attachment = acf.parseArgs(attachment, {
url: '',
alt: '',
title: '',
filename: '',
filesizeHumanReadable: '',
icon: '/wp-includes/images/media/default.png'
});
// return
return attachment;
},
render: function( attachment ){
// vars
attachment = this.validateAttachment( attachment );
// update image
this.$('img').attr({
src: attachment.icon,
alt: attachment.alt,
title: attachment.title
});
// update elements
this.$('[data-name="title"]').text( attachment.title );
this.$('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url );
this.$('[data-name="filesize"]').text( attachment.filesizeHumanReadable );
// vars
var val = attachment.id || '';
// update val
acf.val( this.$input(), val );
// update class
if( val ) {
this.$control().addClass('has-value');
} else {
this.$control().removeClass('has-value');
}
},
selectAttachment: function(){
// vars
var parent = this.parent();
var multiple = (parent && parent.get('type') === 'repeater');
// new frame
var frame = acf.newMediaPopup({
mode: 'select',
title: acf.__('Select File'),
field: this.get('key'),
multiple: multiple,
library: this.get('library'),
allowedTypes: this.get('mime_types'),
select: $.proxy(function( attachment, i ) {
if( i > 0 ) {
this.append( attachment, parent );
} else {
this.render( attachment );
}
}, this)
});
},
editAttachment: function(){
// vars
var val = this.val();
// bail early if no val
if( !val ) {
return false;
}
// popup
var frame = acf.newMediaPopup({
mode: 'edit',
title: acf.__('Edit File'),
button: acf.__('Update File'),
attachment: val,
field: this.get('key'),
select: $.proxy(function( attachment, i ) {
this.render( attachment );
}, this)
});
}
});
acf.registerFieldType( Field );
})(jQuery);