From 440ec7ef3dc7634ac26a890e79892a69c47ee244 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Thu, 22 Nov 2012 11:46:03 +0000 Subject: [PATCH] Media: Make friends with media_upload_form. Adds notices for browser incompatibility, upload limits, maximum file size, and large file issues to the uploader. fixes #22243, see #22186, #21390. git-svn-id: http://core.svn.wordpress.org/trunk@22821 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/css/media-views.css | 16 +++++++---- wp-includes/js/media-views.js | 50 +++++++++------------------------ wp-includes/media.php | 37 +++++++++++++++++++++++- 3 files changed, 59 insertions(+), 44 deletions(-) diff --git a/wp-includes/css/media-views.css b/wp-includes/css/media-views.css index 90ee1edb37..68e677ea65 100644 --- a/wp-includes/css/media-views.css +++ b/wp-includes/css/media-views.css @@ -883,10 +883,6 @@ a.media-modal-close { display: block; } -.upload-flash-bypass { - font-size: 12px; -} - .region-content.uploader-inline { margin: 20px; padding: 20px; @@ -905,16 +901,24 @@ a.media-modal-close { } .uploader-inline h3 { - display: none; font-size: 20px; + line-height: 28px; font-weight: 200; margin-bottom: 1.6em; } -.supports-drag-drop .uploader-inline h3 { +.uploader-inline .drop-instructions { + display: none; +} + +.supports-drag-drop .uploader-inline .drop-instructions { display: block; } +.uploader-inline p { + font-size: 12px; +} + .uploader-inline .media-progress-bar { display: none; } diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index a0f762f341..6841da1d1e 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1100,6 +1100,11 @@ }); } + // Force the uploader off if the upload limit has been exceeded or + // if the browser isn't supported. + if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) + this.options.uploader = false; + // Initialize window-wide uploader. if ( this.options.uploader ) { this.uploader = new media.view.UploaderWindow({ @@ -1785,51 +1790,22 @@ initialize: function() { this.controller = this.options.controller; - if ( ! this.options.$browser ) + if ( ! this.options.$browser && this.controller.uploader ) this.options.$browser = this.controller.uploader.$browser; - - // Track uploading attachments. - wp.Uploader.queue.on( 'add remove reset change:percent', this.renderUploadProgress, this ); }, - dispose: function() { - wp.Uploader.queue.off( null, null, this ); - media.View.prototype.dispose.apply( this, arguments ); - return this; - }, - - render: function() { + ready: function() { var $browser = this.options.$browser, $placeholder; - this.renderUploadProgress(); - this.$el.html( this.template( this.options ) ); + if ( this.controller.uploader ) { + $placeholder = this.$('.browser'); + $browser.detach().text( $placeholder.text() ); + $browser[0].className = $placeholder[0].className; + $placeholder.replaceWith( $browser.show() ); + } - $placeholder = this.$('.browser'); - $browser.detach().text( $placeholder.text() ); - $browser[0].className = $placeholder[0].className; - $placeholder.replaceWith( $browser.show() ); - - this.$bar = this.$('.media-progress-bar div'); - - this.views.render(); return this; - }, - - renderUploadProgress: function() { - var queue = wp.Uploader.queue; - - this.$el.toggleClass( 'uploading', !! queue.length ); - - if ( ! this.$bar || ! queue.length ) - return; - - this.$bar.width( ( queue.reduce( function( memo, attachment ) { - if ( attachment.get('uploading') ) - return memo + ( attachment.get('percent') || 0 ); - else - return memo + 100; - }, 0 ) / queue.length ) + '%' ); } }); diff --git a/wp-includes/media.php b/wp-includes/media.php index 13f3e9feda..248c14eb4c 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1271,6 +1271,7 @@ function wp_plupload_default_settings() { 'mobile' => wp_is_mobile(), 'supported' => _device_can_upload(), ), + 'limitExceeded' => is_multisite() && ! is_upload_space_available() ); $script = 'var _wpPluploadSettings = ' . json_encode( $settings ) . ';'; @@ -1484,8 +1485,15 @@ function wp_print_media_templates( $attachment ) {