Correctly insert non-image attachments as links.
* Adds `wp.media.string.link( attachment )` for printing attachment links. * Adds the `link` attribute to `Attachment` models that corresponds to the link to the attachment post. see #21390, #21836. git-svn-id: https://develop.svn.wordpress.org/trunk@22170 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ecc9b897d8
commit
a830567a92
@ -108,9 +108,12 @@ var tb_position;
|
||||
} ) );
|
||||
|
||||
workflow.on( 'update:insert', function( selection ) {
|
||||
this.insert( '\n' + selection.map( function( attachment ) {
|
||||
return wp.media.string.image( attachment );
|
||||
}).join('\n\n') + '\n' );
|
||||
this.insert( selection.map( function( attachment ) {
|
||||
if ( 'image' === attachment.get('type') )
|
||||
return '\n' + wp.media.string.image( attachment ) + '\n';
|
||||
else
|
||||
return wp.media.string.link( attachment ) + ' ';
|
||||
}).join('') );
|
||||
}, this );
|
||||
|
||||
workflow.on( 'update:gallery', function( selection ) {
|
||||
|
@ -371,6 +371,24 @@ window.wp = window.wp || {};
|
||||
var mceview = wp.mce.view;
|
||||
|
||||
wp.media.string = {};
|
||||
|
||||
wp.media.string.link = function( attachment ) {
|
||||
var linkTo = getUserSetting( 'urlbutton', 'post' ),
|
||||
options = {
|
||||
tag: 'a',
|
||||
content: attachment.get('title') || attachment.get('filename'),
|
||||
attrs: {
|
||||
rel: 'attachment wp-att-' + attachment.id
|
||||
}
|
||||
};
|
||||
|
||||
// Attachments can be linked to attachment post pages or to the direct
|
||||
// URL. `none` is not a valid option.
|
||||
options.attrs.href = ( linkTo === 'file' ) ? attachment.get('url') : attachment.get('link');
|
||||
|
||||
return wp.html.string( options );
|
||||
};
|
||||
|
||||
wp.media.string.image = function( attachment, props ) {
|
||||
var classes, img, options, size;
|
||||
|
||||
|
@ -1246,6 +1246,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
||||
'title' => $attachment->post_title,
|
||||
'filename' => basename( $attachment->guid ),
|
||||
'url' => $attachment_url,
|
||||
'link' => get_attachment_link( $attachment->ID ),
|
||||
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
||||
'author' => $attachment->post_author,
|
||||
'description' => $attachment->post_content,
|
||||
|
Loading…
Reference in New Issue
Block a user