Add a "Beta Media" button to the post editor. Currently, it is only capable of inserting images. Other attachment types and galleries need not apply... yet.

* Added `wp.media.string.image( attachment, props )` for generating an image as a string from an attachment and relevant attachment display properties.
* Properly localized the gallery workflow.
* Added `Workflow.update()`, which closes the modal, triggers an `update` event, and resets the selection.
* Added `wp.mce.media` to manage the various media workflows for editors.

see #21813, #21814, #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22036 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith
2012-09-27 04:09:43 +00:00
parent d849e65a30
commit 692d806fff
6 changed files with 160 additions and 56 deletions
+2
View File
@@ -381,6 +381,8 @@ function media_buttons($editor_id = 'content') {
$img = '<img src="' . esc_url( admin_url( 'images/media-button.png?ver=20111005' ) ) . '" width="16" height="16" />';
echo '<a href="#" class="button insert-media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . sprintf( __('%s Beta Media'), $img ) . '</a>';
echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
}
add_action( 'media_buttons', 'media_buttons' );
+63
View File
@@ -86,3 +86,66 @@ var tb_position;
});
})(jQuery);
// WordPress, TinyMCE, and Media
// -----------------------------
(function($){
// Stores the editors' `wp.media.controller.Workflow` instaces.
var workflows = {};
wp.mce.media = {
insert: send_to_editor,
add: function( id, options ) {
var workflow = this.get( id );
if ( workflow )
return workflow;
workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
multiple: true
} ) );
workflow.on( 'update', function( selection ) {
this.insert( '\n' + selection.map( function( attachment ) {
return wp.media.string.image( attachment );
}).join('\n\n') + '\n' );
}, this );
return workflow;
},
get: function( id ) {
return workflows[ id ];
},
remove: function( id ) {
delete workflows[ id ];
},
init: function() {
$('.insert-media').on( 'click', function( event ) {
var editor = $(this).data('editor'),
workflow;
event.preventDefault();
if ( ! editor )
return;
workflow = wp.mce.media.get( editor );
// If the workflow exists, just open it.
if ( workflow ) {
workflow.open();
return;
}
// Initialize the editor's workflow if we haven't yet.
wp.mce.media.add( editor );
});
}
};
$( wp.mce.media.init )
}(jQuery));