Drag and drop files on the editor to upload: add new argument to wp_editor() to enable, fixes #27465

Built from https://develop.svn.wordpress.org/trunk@27901


git-svn-id: http://core.svn.wordpress.org/trunk@27732 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-04-02 02:42:16 +00:00
parent 08770f6b88
commit 668235fb42
7 changed files with 28 additions and 10 deletions

View File

@ -479,6 +479,7 @@ if ( post_type_supports($post_type, 'editor') ) {
<?php wp_editor( $post->post_content, 'content', array( <?php wp_editor( $post->post_content, 'content', array(
'dfw' => true, 'dfw' => true,
'drag_drop_upload' => true,
'tabfocus_elements' => 'insert-media-button,save-post', 'tabfocus_elements' => 'insert-media-button,save-post',
'editor_height' => 360, 'editor_height' => 360,
'tinymce' => array( 'tinymce' => array(

View File

@ -24,6 +24,7 @@ final class _WP_Editors {
private static $has_quicktags = false; private static $has_quicktags = false;
private static $has_medialib = false; private static $has_medialib = false;
private static $editor_buttons_css = true; private static $editor_buttons_css = true;
private static $drag_drop_upload = false;
private function __construct() {} private function __construct() {}
@ -38,6 +39,8 @@ final class _WP_Editors {
* @type bool $media_buttons Whether to show the Add Media/other media buttons. * @type bool $media_buttons Whether to show the Add Media/other media buttons.
* @type string $default_editor When both TinyMCE and Quicktags are used, set which * @type string $default_editor When both TinyMCE and Quicktags are used, set which
* editor is shown on page load. Default empty. * editor is shown on page load. Default empty.
* @type bool $drag_drop_upload Whether to enable drag & drop on the editor uploading. Default false.
* Requires the media modal.
* @type string $textarea_name Give the textarea a unique name here. Square brackets * @type string $textarea_name Give the textarea a unique name here. Square brackets
* can be used here. Default $editor_id. * can be used here. Default $editor_id.
* @type int $textarea_rows Number rows in the editor textarea. Default 20. * @type int $textarea_rows Number rows in the editor textarea. Default 20.
@ -63,6 +66,7 @@ final class _WP_Editors {
'wpautop' => true, 'wpautop' => true,
'media_buttons' => true, 'media_buttons' => true,
'default_editor' => '', 'default_editor' => '',
'drag_drop_upload' => false,
'textarea_name' => $editor_id, 'textarea_name' => $editor_id,
'textarea_rows' => 20, 'textarea_rows' => 20,
'tabindex' => '', 'tabindex' => '',
@ -124,6 +128,10 @@ final class _WP_Editors {
$switch_class = 'html-active'; $switch_class = 'html-active';
$toolbar = $buttons = $autocomplete = ''; $toolbar = $buttons = $autocomplete = '';
if ( $set['drag_drop_upload'] ) {
self::$drag_drop_upload = true;
}
if ( ! empty( $set['editor_height'] ) ) if ( ! empty( $set['editor_height'] ) )
$height = ' style="height: ' . $set['editor_height'] . 'px"'; $height = ' style="height: ' . $set['editor_height'] . 'px"';
else else
@ -980,6 +988,13 @@ final class _WP_Editors {
tinyMCEPreInit = { tinyMCEPreInit = {
baseURL: "<?php echo self::$baseurl; ?>", baseURL: "<?php echo self::$baseurl; ?>",
suffix: "<?php echo $suffix; ?>", suffix: "<?php echo $suffix; ?>",
<?php
if ( self::$drag_drop_upload ) {
echo 'dragDropUpload: true,';
}
?>
mceInit: <?php echo $mceInit; ?>, mceInit: <?php echo $mceInit; ?>,
qtInit: <?php echo $qtInit; ?>, qtInit: <?php echo $qtInit; ?>,
ref: <?php echo self::_parse_init( $ref ); ?>, ref: <?php echo self::_parse_init( $ref ); ?>,

View File

@ -3131,8 +3131,8 @@
this.initialized = false; this.initialized = false;
// Bail if UA does not support drag'n'drop or File API. // Bail if not enabled or UA does not support drag'n'drop or File API.
if ( ! this.browserSupport() ) { if ( ! window.tinyMCEPreInit || ! window.tinyMCEPreInit.dragDropUpload || ! this.browserSupport() ) {
return this; return this;
} }

File diff suppressed because one or more lines are too long

View File

@ -311,12 +311,14 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
window.jQuery( document ).triggerHandler( 'tinymce-editor-init', [editor] ); window.jQuery( document ).triggerHandler( 'tinymce-editor-init', [editor] );
} }
dom.bind( doc, 'dragstart dragend dragover drop', function( event ) { if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) {
if ( typeof window.jQuery !== 'undefined' ) { dom.bind( doc, 'dragstart dragend dragover drop', function( event ) {
// Trigger the jQuery handlers. if ( typeof window.jQuery !== 'undefined' ) {
window.jQuery( document ).triggerHandler( event.type ); // Trigger the jQuery handlers.
} window.jQuery( document ).triggerHandler( event.type );
}); }
});
}
}); });
// Word count // Word count

File diff suppressed because one or more lines are too long