From 7b272d3a26553683258ac9d098aa17da10209df0 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 2 Apr 2014 02:41:24 +0000 Subject: [PATCH] Drag and drop files on the editor to upload: add new argument to wp_editor() to enable, fixes #27465 git-svn-id: https://develop.svn.wordpress.org/trunk@27901 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/edit-form-advanced.php | 1 + src/wp-includes/class-wp-editor.php | 15 +++++++++++++++ src/wp-includes/js/media-views.js | 4 ++-- .../js/tinymce/plugins/wordpress/plugin.js | 14 ++++++++------ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/edit-form-advanced.php b/src/wp-admin/edit-form-advanced.php index b1d0bf57fa..606ea6d5da 100644 --- a/src/wp-admin/edit-form-advanced.php +++ b/src/wp-admin/edit-form-advanced.php @@ -479,6 +479,7 @@ if ( post_type_supports($post_type, 'editor') ) { post_content, 'content', array( 'dfw' => true, + 'drag_drop_upload' => true, 'tabfocus_elements' => 'insert-media-button,save-post', 'editor_height' => 360, 'tinymce' => array( diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 9c6d7ec33c..3560e84a18 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -24,6 +24,7 @@ final class _WP_Editors { private static $has_quicktags = false; private static $has_medialib = false; private static $editor_buttons_css = true; + private static $drag_drop_upload = false; 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 string $default_editor When both TinyMCE and Quicktags are used, set which * 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 * can be used here. Default $editor_id. * @type int $textarea_rows Number rows in the editor textarea. Default 20. @@ -63,6 +66,7 @@ final class _WP_Editors { 'wpautop' => true, 'media_buttons' => true, 'default_editor' => '', + 'drag_drop_upload' => false, 'textarea_name' => $editor_id, 'textarea_rows' => 20, 'tabindex' => '', @@ -124,6 +128,10 @@ final class _WP_Editors { $switch_class = 'html-active'; $toolbar = $buttons = $autocomplete = ''; + if ( $set['drag_drop_upload'] ) { + self::$drag_drop_upload = true; + } + if ( ! empty( $set['editor_height'] ) ) $height = ' style="height: ' . $set['editor_height'] . 'px"'; else @@ -980,6 +988,13 @@ final class _WP_Editors { tinyMCEPreInit = { baseURL: "", suffix: "", + mceInit: , qtInit: , ref: , diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index fef88de2ce..def3993369 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -3131,8 +3131,8 @@ this.initialized = false; - // Bail if UA does not support drag'n'drop or File API. - if ( ! this.browserSupport() ) { + // Bail if not enabled or UA does not support drag'n'drop or File API. + if ( ! window.tinyMCEPreInit || ! window.tinyMCEPreInit.dragDropUpload || ! this.browserSupport() ) { return this; } diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index e8429671bb..234e2d0f98 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -311,12 +311,14 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { window.jQuery( document ).triggerHandler( 'tinymce-editor-init', [editor] ); } - dom.bind( doc, 'dragstart dragend dragover drop', function( event ) { - if ( typeof window.jQuery !== 'undefined' ) { - // Trigger the jQuery handlers. - window.jQuery( document ).triggerHandler( event.type ); - } - }); + if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) { + dom.bind( doc, 'dragstart dragend dragover drop', function( event ) { + if ( typeof window.jQuery !== 'undefined' ) { + // Trigger the jQuery handlers. + window.jQuery( document ).triggerHandler( event.type ); + } + }); + } }); // Word count