]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/plupload/handlers.js
WordPress 3.9
[autoinstalls/wordpress.git] / wp-includes / js / plupload / handlers.js
index 7b1a7b09530b5d3f65b6d12294003e303d6c9618..d6a9958c7eeac3f3661c09c5553961d880296319 100644 (file)
@@ -1,5 +1,4 @@
-/* global plupload, pluploadL10n, ajaxurl, post_id, wpUploaderInit, deleteUserSetting, setUserSetting, getUserSetting */
-/* global resize_width, resize_height, shortform */
+/* global plupload, pluploadL10n, ajaxurl, post_id, wpUploaderInit, deleteUserSetting, setUserSetting, getUserSetting, shortform */
 var topWin = window.dialogArguments || opener || parent || top, uploader, uploader_init;
 
 // progress and success handlers for media multi uploads
@@ -42,19 +41,19 @@ function uploadProgress(up, file) {
 }
 
 // check to see if a large file failed to upload
-function fileUploading(up, file) {
-       var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
+function fileUploading( up, file ) {
+       var hundredmb = 100 * 1024 * 1024,
+               max = parseInt( up.settings.max_file_size, 10 );
 
        if ( max > hundredmb && file.size > hundredmb ) {
-               setTimeout(function(){
-                       
+               setTimeout( function() {
                        if ( file.status < 3 && file.loaded === 0 ) { // not uploading
-                               wpFileError(file, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>'));
+                               wpFileError( file, pluploadL10n.big_upload_failed.replace( '%1$s', '<a class="uploader-html" href="#">' ).replace( '%2$s', '</a>' ) );
                                up.stop(); // stops the whole queue
-                               up.removeFile(file);
+                               up.removeFile( file );
                                up.start(); // restart the queue
                        }
-               }, 10000); // wait for 10 sec. for the file to start uploading
+               }, 10000 ); // wait for 10 sec. for the file to start uploading
        }
 }
 
@@ -67,7 +66,7 @@ function updateMediaForm() {
                jQuery('.insert-gallery').hide();
        } else if ( items.length > 1 ) {
                items.removeClass('open');
-               // Only show Gallery button when there are at least two files.
+               // Only show Gallery/Playlist buttons when there are at least two files.
                jQuery('.insert-gallery').show();
        }
 
@@ -100,15 +99,20 @@ function uploadSuccess(fileObj, serverData) {
                jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1);
 }
 
-function setResize(arg) {
+function setResize( arg ) {
        if ( arg ) {
-               if ( uploader.features.jpgresize )
-                       uploader.settings.resize = { width: resize_width, height: resize_height, quality: 100 };
-               else
+               if ( window.resize_width && window.resize_height ) {
+                       uploader.settings.resize = {
+                               enabled: true,
+                               width: window.resize_width,
+                               height: window.resize_height,
+                               quality: 100
+                       };
+               } else {
                        uploader.settings.multipart_params.image_resize = true;
+               }
        } else {
-               delete(uploader.settings.resize);
-               delete(uploader.settings.multipart_params.image_resize);
+               delete( uploader.settings.multipart_params.image_resize );
        }
 }
 
@@ -171,7 +175,7 @@ function prepareMediaItemInit(fileObj) {
                        success: function( ){
                                var type,
                                        item = jQuery('#media-item-' + fileObj.id);
-                               
+
                                if ( type = jQuery('#type-of-' + fileObj.id).val() )
                                        jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-0+1);
 
@@ -299,10 +303,10 @@ function uploadError(fileObj, errorCode, message, uploader) {
                        wpQueueError(pluploadL10n.upload_failed);
                        break;
                case plupload.IO_ERROR:
-                       max = parseInt(uploader.settings.max_file_size, 10);
+                       max = parseInt( uploader.settings.filters.max_file_size, 10 );
 
                        if ( max > hundredmb && fileObj.size > hundredmb )
-                               wpFileError(fileObj, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>'));
+                               wpFileError( fileObj, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>') );
                        else
                                wpQueueError(pluploadL10n.io_error);
                        break;
@@ -396,6 +400,16 @@ jQuery(document).ready(function($){
 
        // init and set the uploader
        uploader_init = function() {
+               var isIE = navigator.userAgent.indexOf('Trident/') != -1 || navigator.userAgent.indexOf('MSIE ') != -1;
+
+               // Make sure flash sends cookies (seems in IE it does whitout switching to urlstream mode)
+               if ( ! isIE && 'flash' === plupload.predictRuntime( wpUploaderInit ) &&
+                       ( ! wpUploaderInit.required_features || ! wpUploaderInit.required_features.hasOwnProperty( 'send_binary_string' ) ) ) {
+
+                       wpUploaderInit.required_features = wpUploaderInit.required_features || {};
+                       wpUploaderInit.required_features.send_binary_string = true;
+               }
+
                uploader = new plupload.Uploader(wpUploaderInit);
 
                $('#image_resize').bind('change', function() {
@@ -426,31 +440,25 @@ jQuery(document).ready(function($){
                                $('#drag-drop-area').unbind('.wp-uploader');
                        }
 
-                       if ( up.runtime == 'html4' )
+                       if ( up.runtime === 'html4' ) {
                                $('.upload-flash-bypass').hide();
+                       }
                });
 
                uploader.init();
 
-               uploader.bind('FilesAdded', function(up, files) {
-                       var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
-
+               uploader.bind('FilesAdded', function( up, files ) {
                        $('#media-upload-error').html('');
                        uploadStart();
 
-                       plupload.each(files, function(file){
-                               if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' )
-                                       uploadSizeError( up, file, true );
-                               else
-                                       fileQueued(file);
+                       plupload.each( files, function( file ) {
+                               fileQueued( file );
                        });
 
                        up.refresh();
                        up.start();
                });
 
-               // uploader.bind('BeforeUpload', function(up, file) {});
-
                uploader.bind('UploadFile', function(up, file) {
                        fileUploading(up, file);
                });