Edit File by line
/home/barbar84/public_h.../wp-inclu.../js/plupload
File: handlers.js
/* global plupload, pluploadL10n, ajaxurl, post_id, wpUploaderInit, deleteUserSetting, setUserSetting, getUserSetting, shortform */
[0] Fix | Delete
var topWin = window.dialogArguments || opener || parent || top, uploader, uploader_init;
[1] Fix | Delete
[2] Fix | Delete
// Progress and success handlers for media multi uploads.
[3] Fix | Delete
function fileQueued( fileObj ) {
[4] Fix | Delete
// Get rid of unused form.
[5] Fix | Delete
jQuery( '.media-blank' ).remove();
[6] Fix | Delete
[7] Fix | Delete
var items = jQuery( '#media-items' ).children(), postid = post_id || 0;
[8] Fix | Delete
[9] Fix | Delete
// Collapse a single item.
[10] Fix | Delete
if ( items.length == 1 ) {
[11] Fix | Delete
items.removeClass( 'open' ).find( '.slidetoggle' ).slideUp( 200 );
[12] Fix | Delete
}
[13] Fix | Delete
// Create a progress bar containing the filename.
[14] Fix | Delete
jQuery( '<div class="media-item">' )
[15] Fix | Delete
.attr( 'id', 'media-item-' + fileObj.id )
[16] Fix | Delete
.addClass( 'child-of-' + postid )
[17] Fix | Delete
.append( '<div class="progress"><div class="percent">0%</div><div class="bar"></div></div>',
[18] Fix | Delete
jQuery( '<div class="filename original">' ).text( ' ' + fileObj.name ) )
[19] Fix | Delete
.appendTo( jQuery( '#media-items' ) );
[20] Fix | Delete
[21] Fix | Delete
// Disable submit.
[22] Fix | Delete
jQuery( '#insert-gallery' ).prop( 'disabled', true );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
function uploadStart() {
[26] Fix | Delete
try {
[27] Fix | Delete
if ( typeof topWin.tb_remove != 'undefined' )
[28] Fix | Delete
topWin.jQuery( '#TB_overlay' ).unbind( 'click', topWin.tb_remove );
[29] Fix | Delete
} catch( e ){}
[30] Fix | Delete
[31] Fix | Delete
return true;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
function uploadProgress( up, file ) {
[35] Fix | Delete
var item = jQuery( '#media-item-' + file.id );
[36] Fix | Delete
[37] Fix | Delete
jQuery( '.bar', item ).width( ( 200 * file.loaded ) / file.size );
[38] Fix | Delete
jQuery( '.percent', item ).html( file.percent + '%' );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
// Check to see if a large file failed to upload.
[42] Fix | Delete
function fileUploading( up, file ) {
[43] Fix | Delete
var hundredmb = 100 * 1024 * 1024,
[44] Fix | Delete
max = parseInt( up.settings.max_file_size, 10 );
[45] Fix | Delete
[46] Fix | Delete
if ( max > hundredmb && file.size > hundredmb ) {
[47] Fix | Delete
setTimeout( function() {
[48] Fix | Delete
if ( file.status < 3 && file.loaded === 0 ) { // Not uploading.
[49] Fix | Delete
wpFileError( file, pluploadL10n.big_upload_failed.replace( '%1$s', '<a class="uploader-html" href="#">' ).replace( '%2$s', '</a>' ) );
[50] Fix | Delete
up.stop(); // Stop the whole queue.
[51] Fix | Delete
up.removeFile( file );
[52] Fix | Delete
up.start(); // Restart the queue.
[53] Fix | Delete
}
[54] Fix | Delete
}, 10000 ); // Wait for 10 seconds for the file to start uploading.
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
function updateMediaForm() {
[59] Fix | Delete
var items = jQuery( '#media-items' ).children();
[60] Fix | Delete
[61] Fix | Delete
// Just one file, no need for collapsible part.
[62] Fix | Delete
if ( items.length == 1 ) {
[63] Fix | Delete
items.addClass( 'open' ).find( '.slidetoggle' ).show();
[64] Fix | Delete
jQuery( '.insert-gallery' ).hide();
[65] Fix | Delete
} else if ( items.length > 1 ) {
[66] Fix | Delete
items.removeClass( 'open' );
[67] Fix | Delete
// Only show Gallery/Playlist buttons when there are at least two files.
[68] Fix | Delete
jQuery( '.insert-gallery' ).show();
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// Only show Save buttons when there is at least one file.
[72] Fix | Delete
if ( items.not( '.media-blank' ).length > 0 )
[73] Fix | Delete
jQuery( '.savebutton' ).show();
[74] Fix | Delete
else
[75] Fix | Delete
jQuery( '.savebutton' ).hide();
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
function uploadSuccess( fileObj, serverData ) {
[79] Fix | Delete
var item = jQuery( '#media-item-' + fileObj.id );
[80] Fix | Delete
[81] Fix | Delete
// On success serverData should be numeric,
[82] Fix | Delete
// fix bug in html4 runtime returning the serverData wrapped in a <pre> tag.
[83] Fix | Delete
if ( typeof serverData === 'string' ) {
[84] Fix | Delete
serverData = serverData.replace( /^<pre>(\d+)<\/pre>$/, '$1' );
[85] Fix | Delete
[86] Fix | Delete
// If async-upload returned an error message, place it in the media item div and return.
[87] Fix | Delete
if ( /media-upload-error|error-div/.test( serverData ) ) {
[88] Fix | Delete
item.html( serverData );
[89] Fix | Delete
return;
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
item.find( '.percent' ).html( pluploadL10n.crunching );
[94] Fix | Delete
[95] Fix | Delete
prepareMediaItem( fileObj, serverData );
[96] Fix | Delete
updateMediaForm();
[97] Fix | Delete
[98] Fix | Delete
// Increment the counter.
[99] Fix | Delete
if ( post_id && item.hasClass( 'child-of-' + post_id ) ) {
[100] Fix | Delete
jQuery( '#attachments-count' ).text( 1 * jQuery( '#attachments-count' ).text() + 1 );
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
function setResize( arg ) {
[105] Fix | Delete
if ( arg ) {
[106] Fix | Delete
if ( window.resize_width && window.resize_height ) {
[107] Fix | Delete
uploader.settings.resize = {
[108] Fix | Delete
enabled: true,
[109] Fix | Delete
width: window.resize_width,
[110] Fix | Delete
height: window.resize_height,
[111] Fix | Delete
quality: 100
[112] Fix | Delete
};
[113] Fix | Delete
} else {
[114] Fix | Delete
uploader.settings.multipart_params.image_resize = true;
[115] Fix | Delete
}
[116] Fix | Delete
} else {
[117] Fix | Delete
delete( uploader.settings.multipart_params.image_resize );
[118] Fix | Delete
}
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
function prepareMediaItem( fileObj, serverData ) {
[122] Fix | Delete
var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery( '#media-item-' + fileObj.id );
[123] Fix | Delete
if ( f == 2 && shortform > 2 )
[124] Fix | Delete
f = shortform;
[125] Fix | Delete
[126] Fix | Delete
try {
[127] Fix | Delete
if ( typeof topWin.tb_remove != 'undefined' )
[128] Fix | Delete
topWin.jQuery( '#TB_overlay' ).click( topWin.tb_remove );
[129] Fix | Delete
} catch( e ){}
[130] Fix | Delete
[131] Fix | Delete
if ( isNaN( serverData ) || !serverData ) {
[132] Fix | Delete
// Old style: Append the HTML returned by the server -- thumbnail and form inputs.
[133] Fix | Delete
item.append( serverData );
[134] Fix | Delete
prepareMediaItemInit( fileObj );
[135] Fix | Delete
} else {
[136] Fix | Delete
// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server.
[137] Fix | Delete
item.load( 'async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit( fileObj );updateMediaForm();});
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
function prepareMediaItemInit( fileObj ) {
[142] Fix | Delete
var item = jQuery( '#media-item-' + fileObj.id );
[143] Fix | Delete
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename.
[144] Fix | Delete
jQuery( '.thumbnail', item ).clone().attr( 'class', 'pinkynail toggle' ).prependTo( item );
[145] Fix | Delete
[146] Fix | Delete
// Replace the original filename with the new (unique) one assigned during upload.
[147] Fix | Delete
jQuery( '.filename.original', item ).replaceWith( jQuery( '.filename.new', item ) );
[148] Fix | Delete
[149] Fix | Delete
// Bind Ajax to the new Delete button.
[150] Fix | Delete
jQuery( 'a.delete', item ).click( function(){
[151] Fix | Delete
// Tell the server to delete it. TODO: Handle exceptions.
[152] Fix | Delete
jQuery.ajax({
[153] Fix | Delete
url: ajaxurl,
[154] Fix | Delete
type: 'post',
[155] Fix | Delete
success: deleteSuccess,
[156] Fix | Delete
error: deleteError,
[157] Fix | Delete
id: fileObj.id,
[158] Fix | Delete
data: {
[159] Fix | Delete
id : this.id.replace(/[^0-9]/g, '' ),
[160] Fix | Delete
action : 'trash-post',
[161] Fix | Delete
_ajax_nonce : this.href.replace(/^.*wpnonce=/,'' )
[162] Fix | Delete
}
[163] Fix | Delete
});
[164] Fix | Delete
return false;
[165] Fix | Delete
});
[166] Fix | Delete
[167] Fix | Delete
// Bind Ajax to the new Undo button.
[168] Fix | Delete
jQuery( 'a.undo', item ).click( function(){
[169] Fix | Delete
// Tell the server to untrash it. TODO: Handle exceptions.
[170] Fix | Delete
jQuery.ajax({
[171] Fix | Delete
url: ajaxurl,
[172] Fix | Delete
type: 'post',
[173] Fix | Delete
id: fileObj.id,
[174] Fix | Delete
data: {
[175] Fix | Delete
id : this.id.replace(/[^0-9]/g,'' ),
[176] Fix | Delete
action: 'untrash-post',
[177] Fix | Delete
_ajax_nonce: this.href.replace(/^.*wpnonce=/,'' )
[178] Fix | Delete
},
[179] Fix | Delete
success: function( ){
[180] Fix | Delete
var type,
[181] Fix | Delete
item = jQuery( '#media-item-' + fileObj.id );
[182] Fix | Delete
[183] Fix | Delete
if ( type = jQuery( '#type-of-' + fileObj.id ).val() )
[184] Fix | Delete
jQuery( '#' + type + '-counter' ).text( jQuery( '#' + type + '-counter' ).text()-0+1 );
[185] Fix | Delete
[186] Fix | Delete
if ( post_id && item.hasClass( 'child-of-'+post_id ) )
[187] Fix | Delete
jQuery( '#attachments-count' ).text( jQuery( '#attachments-count' ).text()-0+1 );
[188] Fix | Delete
[189] Fix | Delete
jQuery( '.filename .trashnotice', item ).remove();
[190] Fix | Delete
jQuery( '.filename .title', item ).css( 'font-weight','normal' );
[191] Fix | Delete
jQuery( 'a.undo', item ).addClass( 'hidden' );
[192] Fix | Delete
jQuery( '.menu_order_input', item ).show();
[193] Fix | Delete
item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery( this ).css({backgroundColor:''}); } }).removeClass( 'undo' );
[194] Fix | Delete
}
[195] Fix | Delete
});
[196] Fix | Delete
return false;
[197] Fix | Delete
});
[198] Fix | Delete
[199] Fix | Delete
// Open this item if it says to start open (e.g. to display an error).
[200] Fix | Delete
jQuery( '#media-item-' + fileObj.id + '.startopen' ).removeClass( 'startopen' ).addClass( 'open' ).find( 'slidetoggle' ).fadeIn();
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
// Generic error message.
[204] Fix | Delete
function wpQueueError( message ) {
[205] Fix | Delete
jQuery( '#media-upload-error' ).show().html( '<div class="error"><p>' + message + '</p></div>' );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
// File-specific error messages.
[209] Fix | Delete
function wpFileError( fileObj, message ) {
[210] Fix | Delete
itemAjaxError( fileObj.id, message );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
function itemAjaxError( id, message ) {
[214] Fix | Delete
var item = jQuery( '#media-item-' + id ), filename = item.find( '.filename' ).text(), last_err = item.data( 'last-err' );
[215] Fix | Delete
[216] Fix | Delete
if ( last_err == id ) // Prevent firing an error for the same file twice.
[217] Fix | Delete
return;
[218] Fix | Delete
[219] Fix | Delete
item.html( '<div class="error-div">' +
[220] Fix | Delete
'<a class="dismiss" href="#">' + pluploadL10n.dismiss + '</a>' +
[221] Fix | Delete
'<strong>' + pluploadL10n.error_uploading.replace( '%s', jQuery.trim( filename )) + '</strong> ' +
[222] Fix | Delete
message +
[223] Fix | Delete
'</div>' ).data( 'last-err', id );
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
function deleteSuccess( data ) {
[227] Fix | Delete
var type, id, item;
[228] Fix | Delete
if ( data == '-1' )
[229] Fix | Delete
return itemAjaxError( this.id, 'You do not have permission. Has your session expired?' );
[230] Fix | Delete
[231] Fix | Delete
if ( data == '0' )
[232] Fix | Delete
return itemAjaxError( this.id, 'Could not be deleted. Has it been deleted already?' );
[233] Fix | Delete
[234] Fix | Delete
id = this.id;
[235] Fix | Delete
item = jQuery( '#media-item-' + id );
[236] Fix | Delete
[237] Fix | Delete
// Decrement the counters.
[238] Fix | Delete
if ( type = jQuery( '#type-of-' + id ).val() )
[239] Fix | Delete
jQuery( '#' + type + '-counter' ).text( jQuery( '#' + type + '-counter' ).text() - 1 );
[240] Fix | Delete
[241] Fix | Delete
if ( post_id && item.hasClass( 'child-of-'+post_id ) )
[242] Fix | Delete
jQuery( '#attachments-count' ).text( jQuery( '#attachments-count' ).text() - 1 );
[243] Fix | Delete
[244] Fix | Delete
if ( jQuery( 'form.type-form #media-items' ).children().length == 1 && jQuery( '.hidden', '#media-items' ).length > 0 ) {
[245] Fix | Delete
jQuery( '.toggle' ).toggle();
[246] Fix | Delete
jQuery( '.slidetoggle' ).slideUp( 200 ).siblings().removeClass( 'hidden' );
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
// Vanish it.
[250] Fix | Delete
jQuery( '.toggle', item ).toggle();
[251] Fix | Delete
jQuery( '.slidetoggle', item ).slideUp( 200 ).siblings().removeClass( 'hidden' );
[252] Fix | Delete
item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass( 'undo' );
[253] Fix | Delete
[254] Fix | Delete
jQuery( '.filename:empty', item ).remove();
[255] Fix | Delete
jQuery( '.filename .title', item ).css( 'font-weight','bold' );
[256] Fix | Delete
jQuery( '.filename', item ).append( '<span class="trashnotice"> ' + pluploadL10n.deleted + ' </span>' ).siblings( 'a.toggle' ).hide();
[257] Fix | Delete
jQuery( '.filename', item ).append( jQuery( 'a.undo', item ).removeClass( 'hidden' ) );
[258] Fix | Delete
jQuery( '.menu_order_input', item ).hide();
[259] Fix | Delete
[260] Fix | Delete
return;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
function deleteError() {
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
function uploadComplete() {
[267] Fix | Delete
jQuery( '#insert-gallery' ).prop( 'disabled', false );
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
function switchUploader( s ) {
[271] Fix | Delete
if ( s ) {
[272] Fix | Delete
deleteUserSetting( 'uploader' );
[273] Fix | Delete
jQuery( '.media-upload-form' ).removeClass( 'html-uploader' );
[274] Fix | Delete
[275] Fix | Delete
if ( typeof( uploader ) == 'object' )
[276] Fix | Delete
uploader.refresh();
[277] Fix | Delete
} else {
[278] Fix | Delete
setUserSetting( 'uploader', '1' ); // 1 == html uploader.
[279] Fix | Delete
jQuery( '.media-upload-form' ).addClass( 'html-uploader' );
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
function uploadError( fileObj, errorCode, message, up ) {
[284] Fix | Delete
var hundredmb = 100 * 1024 * 1024, max;
[285] Fix | Delete
[286] Fix | Delete
switch ( errorCode ) {
[287] Fix | Delete
case plupload.FAILED:
[288] Fix | Delete
wpFileError( fileObj, pluploadL10n.upload_failed );
[289] Fix | Delete
break;
[290] Fix | Delete
case plupload.FILE_EXTENSION_ERROR:
[291] Fix | Delete
wpFileExtensionError( up, fileObj, pluploadL10n.invalid_filetype );
[292] Fix | Delete
break;
[293] Fix | Delete
case plupload.FILE_SIZE_ERROR:
[294] Fix | Delete
uploadSizeError( up, fileObj );
[295] Fix | Delete
break;
[296] Fix | Delete
case plupload.IMAGE_FORMAT_ERROR:
[297] Fix | Delete
wpFileError( fileObj, pluploadL10n.not_an_image );
[298] Fix | Delete
break;
[299] Fix | Delete
case plupload.IMAGE_MEMORY_ERROR:
[300] Fix | Delete
wpFileError( fileObj, pluploadL10n.image_memory_exceeded );
[301] Fix | Delete
break;
[302] Fix | Delete
case plupload.IMAGE_DIMENSIONS_ERROR:
[303] Fix | Delete
wpFileError( fileObj, pluploadL10n.image_dimensions_exceeded );
[304] Fix | Delete
break;
[305] Fix | Delete
case plupload.GENERIC_ERROR:
[306] Fix | Delete
wpQueueError( pluploadL10n.upload_failed );
[307] Fix | Delete
break;
[308] Fix | Delete
case plupload.IO_ERROR:
[309] Fix | Delete
max = parseInt( up.settings.filters.max_file_size, 10 );
[310] Fix | Delete
[311] Fix | Delete
if ( max > hundredmb && fileObj.size > hundredmb ) {
[312] Fix | Delete
wpFileError( fileObj, pluploadL10n.big_upload_failed.replace( '%1$s', '<a class="uploader-html" href="#">' ).replace( '%2$s', '</a>' ) );
[313] Fix | Delete
} else {
[314] Fix | Delete
wpQueueError( pluploadL10n.io_error );
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
break;
[318] Fix | Delete
case plupload.HTTP_ERROR:
[319] Fix | Delete
wpQueueError( pluploadL10n.http_error );
[320] Fix | Delete
break;
[321] Fix | Delete
case plupload.INIT_ERROR:
[322] Fix | Delete
jQuery( '.media-upload-form' ).addClass( 'html-uploader' );
[323] Fix | Delete
break;
[324] Fix | Delete
case plupload.SECURITY_ERROR:
[325] Fix | Delete
wpQueueError( pluploadL10n.security_error );
[326] Fix | Delete
break;
[327] Fix | Delete
/* case plupload.UPLOAD_ERROR.UPLOAD_STOPPED:
[328] Fix | Delete
case plupload.UPLOAD_ERROR.FILE_CANCELLED:
[329] Fix | Delete
jQuery( '#media-item-' + fileObj.id ).remove();
[330] Fix | Delete
break;*/
[331] Fix | Delete
default:
[332] Fix | Delete
wpFileError( fileObj, pluploadL10n.default_error );
[333] Fix | Delete
}
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
function uploadSizeError( up, file ) {
[337] Fix | Delete
var message, errorDiv;
[338] Fix | Delete
[339] Fix | Delete
message = pluploadL10n.file_exceeds_size_limit.replace( '%s', file.name );
[340] Fix | Delete
[341] Fix | Delete
// Construct the error div.
[342] Fix | Delete
errorDiv = jQuery( '<div />' )
[343] Fix | Delete
.attr( {
[344] Fix | Delete
'id': 'media-item-' + file.id,
[345] Fix | Delete
'class': 'media-item error'
[346] Fix | Delete
} )
[347] Fix | Delete
.append(
[348] Fix | Delete
jQuery( '<p />' )
[349] Fix | Delete
.text( message )
[350] Fix | Delete
);
[351] Fix | Delete
[352] Fix | Delete
// Append the error.
[353] Fix | Delete
jQuery( '#media-items' ).append( errorDiv );
[354] Fix | Delete
up.removeFile( file );
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
function wpFileExtensionError( up, file, message ) {
[358] Fix | Delete
jQuery( '#media-items' ).append( '<div id="media-item-' + file.id + '" class="media-item error"><p>' + message + '</p></div>' );
[359] Fix | Delete
up.removeFile( file );
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
jQuery( document ).ready( function( $ ) {
[363] Fix | Delete
var tryAgainCount = {};
[364] Fix | Delete
var tryAgain;
[365] Fix | Delete
[366] Fix | Delete
$( '.media-upload-form' ).bind( 'click.uploader', function( e ) {
[367] Fix | Delete
var target = $( e.target ), tr, c;
[368] Fix | Delete
[369] Fix | Delete
if ( target.is( 'input[type="radio"]' ) ) { // Remember the last used image size and alignment.
[370] Fix | Delete
tr = target.closest( 'tr' );
[371] Fix | Delete
[372] Fix | Delete
if ( tr.hasClass( 'align' ) )
[373] Fix | Delete
setUserSetting( 'align', target.val() );
[374] Fix | Delete
else if ( tr.hasClass( 'image-size' ) )
[375] Fix | Delete
setUserSetting( 'imgsize', target.val() );
[376] Fix | Delete
[377] Fix | Delete
} else if ( target.is( 'button.button' ) ) { // Remember the last used image link url.
[378] Fix | Delete
c = e.target.className || '';
[379] Fix | Delete
c = c.match( /url([^ '"]+)/ );
[380] Fix | Delete
[381] Fix | Delete
if ( c && c[1] ) {
[382] Fix | Delete
setUserSetting( 'urlbutton', c[1] );
[383] Fix | Delete
target.siblings( '.urlfield' ).val( target.data( 'link-url' ) );
[384] Fix | Delete
}
[385] Fix | Delete
} else if ( target.is( 'a.dismiss' ) ) {
[386] Fix | Delete
target.parents( '.media-item' ).fadeOut( 200, function() {
[387] Fix | Delete
$( this ).remove();
[388] Fix | Delete
} );
[389] Fix | Delete
} else if ( target.is( '.upload-flash-bypass a' ) || target.is( 'a.uploader-html' ) ) { // Switch uploader to html4.
[390] Fix | Delete
$( '#media-items, p.submit, span.big-file-warning' ).css( 'display', 'none' );
[391] Fix | Delete
switchUploader( 0 );
[392] Fix | Delete
e.preventDefault();
[393] Fix | Delete
} else if ( target.is( '.upload-html-bypass a' ) ) { // Switch uploader to multi-file.
[394] Fix | Delete
$( '#media-items, p.submit, span.big-file-warning' ).css( 'display', '' );
[395] Fix | Delete
switchUploader( 1 );
[396] Fix | Delete
e.preventDefault();
[397] Fix | Delete
} else if ( target.is( 'a.describe-toggle-on' ) ) { // Show.
[398] Fix | Delete
target.parent().addClass( 'open' );
[399] Fix | Delete
target.siblings( '.slidetoggle' ).fadeIn( 250, function() {
[400] Fix | Delete
var S = $( window ).scrollTop(),
[401] Fix | Delete
H = $( window ).height(),
[402] Fix | Delete
top = $( this ).offset().top,
[403] Fix | Delete
h = $( this ).height(),
[404] Fix | Delete
b,
[405] Fix | Delete
B;
[406] Fix | Delete
[407] Fix | Delete
if ( H && top && h ) {
[408] Fix | Delete
b = top + h;
[409] Fix | Delete
B = S + H;
[410] Fix | Delete
[411] Fix | Delete
if ( b > B ) {
[412] Fix | Delete
if ( b - B < top - S )
[413] Fix | Delete
window.scrollBy( 0, ( b - B ) + 10 );
[414] Fix | Delete
else
[415] Fix | Delete
window.scrollBy( 0, top - S - 40 );
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
} );
[419] Fix | Delete
[420] Fix | Delete
e.preventDefault();
[421] Fix | Delete
} else if ( target.is( 'a.describe-toggle-off' ) ) { // Hide.
[422] Fix | Delete
target.siblings( '.slidetoggle' ).fadeOut( 250, function() {
[423] Fix | Delete
target.parent().removeClass( 'open' );
[424] Fix | Delete
} );
[425] Fix | Delete
[426] Fix | Delete
e.preventDefault();
[427] Fix | Delete
}
[428] Fix | Delete
});
[429] Fix | Delete
[430] Fix | Delete
// Attempt to create image sub-sizes when an image was uploaded successfully
[431] Fix | Delete
// but the server responded with an HTTP 5xx error.
[432] Fix | Delete
tryAgain = function( up, error ) {
[433] Fix | Delete
var file = error.file;
[434] Fix | Delete
var times;
[435] Fix | Delete
var id;
[436] Fix | Delete
[437] Fix | Delete
if ( ! error || ! error.responseHeaders ) {
[438] Fix | Delete
wpQueueError( pluploadL10n.http_error_image );
[439] Fix | Delete
return;
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
id = error.responseHeaders.match( /x-wp-upload-attachment-id:\s*(\d+)/i );
[443] Fix | Delete
[444] Fix | Delete
if ( id && id[1] ) {
[445] Fix | Delete
id = id[1];
[446] Fix | Delete
} else {
[447] Fix | Delete
wpQueueError( pluploadL10n.http_error_image );
[448] Fix | Delete
return;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
times = tryAgainCount[ file.id ];
[452] Fix | Delete
[453] Fix | Delete
if ( times && times > 4 ) {
[454] Fix | Delete
/*
[455] Fix | Delete
* The file may have been uploaded and attachment post created,
[456] Fix | Delete
* but post-processing and resizing failed...
[457] Fix | Delete
* Do a cleanup then tell the user to scale down the image and upload it again.
[458] Fix | Delete
*/
[459] Fix | Delete
$.ajax({
[460] Fix | Delete
type: 'post',
[461] Fix | Delete
url: ajaxurl,
[462] Fix | Delete
dataType: 'json',
[463] Fix | Delete
data: {
[464] Fix | Delete
action: 'media-create-image-subsizes',
[465] Fix | Delete
_wpnonce: wpUploaderInit.multipart_params._wpnonce,
[466] Fix | Delete
attachment_id: id,
[467] Fix | Delete
_wp_upload_failed_cleanup: true,
[468] Fix | Delete
}
[469] Fix | Delete
});
[470] Fix | Delete
[471] Fix | Delete
if ( error.message && ( error.status < 500 || error.status >= 600 ) ) {
[472] Fix | Delete
wpQueueError( error.message );
[473] Fix | Delete
} else {
[474] Fix | Delete
wpQueueError( pluploadL10n.http_error_image );
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
return;
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
if ( ! times ) {
[481] Fix | Delete
tryAgainCount[ file.id ] = 1;
[482] Fix | Delete
} else {
[483] Fix | Delete
tryAgainCount[ file.id ] = ++times;
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
// Try to create the missing image sizes.
[487] Fix | Delete
$.ajax({
[488] Fix | Delete
type: 'post',
[489] Fix | Delete
url: ajaxurl,
[490] Fix | Delete
dataType: 'json',
[491] Fix | Delete
data: {
[492] Fix | Delete
action: 'media-create-image-subsizes',
[493] Fix | Delete
_wpnonce: wpUploaderInit.multipart_params._wpnonce,
[494] Fix | Delete
attachment_id: id,
[495] Fix | Delete
_legacy_support: 'true',
[496] Fix | Delete
}
[497] Fix | Delete
}).done( function( response ) {
[498] Fix | Delete
var message;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function