2008-02-22 06:53:47 +01:00
|
|
|
function uploadLoaded() {
|
|
|
|
jQuery("#html-upload-ui").remove();
|
|
|
|
jQuery("#flash-upload-ui").show();
|
2008-02-16 22:54:47 +01:00
|
|
|
}
|
|
|
|
|
2008-01-25 20:21:11 +01:00
|
|
|
function fileDialogStart() {
|
|
|
|
jQuery("#media-upload-error").empty();
|
|
|
|
}
|
|
|
|
|
2008-02-26 20:30:10 +01:00
|
|
|
// progress and success handlers for media multi uploads
|
2008-02-22 06:53:47 +01:00
|
|
|
function fileQueued(fileObj) {
|
2008-02-28 22:29:51 +01:00
|
|
|
// Get rid of unused form
|
|
|
|
jQuery('.media-blank').remove();
|
2008-03-05 07:46:42 +01:00
|
|
|
// Collapse a single item
|
|
|
|
if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
|
|
|
|
jQuery('.toggle').toggle();
|
|
|
|
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
|
|
|
|
}
|
2008-01-25 20:21:11 +01:00
|
|
|
// Create a progress bar containing the filename
|
2008-03-05 07:46:42 +01:00
|
|
|
jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + post_id + '"><div class="filename original">' + fileObj.name + '</div><div class="progress"><div class="bar"></div></div></div>');
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Disable the submit button
|
2008-03-06 20:48:54 +01:00
|
|
|
jQuery('#insert-gallery').attr('disabled', 'disabled');
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-22 06:53:47 +01:00
|
|
|
function uploadStart(fileObj) { return true; }
|
|
|
|
|
|
|
|
function uploadProgress(fileObj, bytesDone, bytesTotal) {
|
2008-01-25 20:21:11 +01:00
|
|
|
// Lengthen the progress bar
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .bar').width(620*bytesDone/bytesTotal);
|
2008-03-11 00:55:26 +01:00
|
|
|
|
|
|
|
if ( bytesDone== bytesTotal )
|
|
|
|
jQuery('#media-item-' + fileObj.id + ' .bar').html('<strong style="display: block; padding-top: 9px; padding-left: 1em;">Crunching…</strong>');
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-26 20:30:10 +01:00
|
|
|
function prepareMediaItem(fileObj, serverData) {
|
2008-01-25 20:21:11 +01:00
|
|
|
// Move the progress bar to 100%
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .bar').remove();
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Append the HTML returned by the server -- thumbnail and form inputs
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id).append(serverData);
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id);
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Replace the original filename with the new (unique) one assigned during upload
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#media-item-' + fileObj.id + ' .filename.new'));
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Bind toggle function to a new mask over the progress bar area
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .progress').clone().empty().addClass('clickmask').bind('click', function(){jQuery(this).siblings('.slidetoggle').slideToggle(150);jQuery(this).siblings('.toggle').toggle();}).appendTo('#media-item-' + fileObj.id);
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Also bind toggle to the links
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' a.toggle').bind('click', function(){jQuery(this).siblings('.slidetoggle').slideToggle(150);jQuery(this).parent().eq(0).children('.toggle').toggle();jQuery(this).siblings('a.toggle').focus();return false;});
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
// Bind AJAX to the new Delete button
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' a.delete').bind('click',function(){
|
|
|
|
// Tell the server to delete it. TODO: handle exceptions
|
|
|
|
jQuery.ajax({url:'admin-ajax.php',type:'post',data:{
|
|
|
|
id : this.id.replace(/[^0-9]/g,''),
|
|
|
|
action : 'delete-post',
|
|
|
|
_ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
|
|
|
|
});
|
2008-02-28 22:29:51 +01:00
|
|
|
|
|
|
|
// Decrement the counters.
|
|
|
|
if ( type = jQuery('#type-of-' + this.id.replace(/[^0-9]/g,'')).val() )
|
|
|
|
jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
|
|
|
|
if ( jQuery(this).parents('.media-item').eq(0).hasClass('child-of-'+post_id) )
|
|
|
|
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1);
|
|
|
|
|
2008-02-26 20:30:10 +01:00
|
|
|
// Vanish it.
|
|
|
|
jQuery(this).parents(".media-item").eq(0).slideToggle(300,function(){jQuery(this).remove();if(jQuery('.media-item').length==0)jQuery('.insert-gallery').hide();updateMediaForm();});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Open this item if it says to start open (e.g. to display an error)
|
|
|
|
jQuery('#media-item-' + fileObj.id + '.startopen')
|
2008-02-16 22:54:47 +01:00
|
|
|
.removeClass('startopen')
|
|
|
|
.slideToggle(500)
|
|
|
|
.parent().eq(0).children('.toggle').toggle();
|
2008-02-26 20:30:10 +01:00
|
|
|
}
|
2008-02-22 06:53:47 +01:00
|
|
|
|
2008-02-26 20:30:10 +01:00
|
|
|
function updateMediaForm() {
|
|
|
|
// Just one file, no need for collapsible part
|
2008-02-28 22:29:51 +01:00
|
|
|
if ( jQuery('.type-form #media-items>*').length == 1 ) {
|
2008-02-26 20:30:10 +01:00
|
|
|
jQuery('#media-items .slidetoggle').slideDown(500).parent().eq(0).children('.toggle').toggle();
|
2008-02-28 22:29:51 +01:00
|
|
|
jQuery('.type-form .slidetoggle').siblings().addClass('hidden');
|
2008-02-26 20:30:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only show Gallery button when there are at least two files.
|
|
|
|
if ( jQuery('#media-items>*').length > 1 )
|
|
|
|
jQuery('.insert-gallery').show();
|
|
|
|
else
|
|
|
|
jQuery('.insert-gallery').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadSuccess(fileObj, serverData) {
|
|
|
|
// if async-upload returned an error message, place it in the media item div and return
|
|
|
|
if ( serverData.match('media-upload-error') ) {
|
|
|
|
jQuery('#media-item-' + fileObj.id).html(serverData);
|
|
|
|
return;
|
|
|
|
}
|
2008-03-11 00:55:26 +01:00
|
|
|
|
2008-02-26 20:30:10 +01:00
|
|
|
prepareMediaItem(fileObj, serverData);
|
|
|
|
updateMediaForm();
|
2008-02-28 22:29:51 +01:00
|
|
|
|
|
|
|
// Increment the counter.
|
|
|
|
if ( jQuery('#media-item-' + fileObj.id).hasClass('child-of-' + post_id) )
|
|
|
|
jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1);
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-22 06:53:47 +01:00
|
|
|
function uploadComplete(fileObj) {
|
2008-01-25 20:21:11 +01:00
|
|
|
// If no more uploads queued, enable the submit button
|
|
|
|
if ( swfu.getStats().files_queued == 0 )
|
2008-03-06 20:48:54 +01:00
|
|
|
jQuery('#insert-gallery').attr('disabled', '');
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// wp-specific error handlers
|
|
|
|
|
|
|
|
// generic message
|
|
|
|
function wpQueueError(message) {
|
|
|
|
jQuery('#media-upload-error').show().text(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// file-specific message
|
|
|
|
function wpFileError(fileObj, message) {
|
2008-03-05 07:46:42 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .filename').after('<div class="file-error"><button type="button" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+message+'</div>').siblings('.progress').remove();
|
2008-02-29 07:54:15 +01:00
|
|
|
jQuery('.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function fileQueueError(fileObj, error_code, message) {
|
|
|
|
// Handle this error separately because we don't want to create a FileProgress element for it.
|
|
|
|
if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) {
|
|
|
|
wpQueueError(swfuploadL10n.queue_limit_exceeded);
|
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT ) {
|
2008-02-29 07:54:15 +01:00
|
|
|
fileQueued(fileObj);
|
2008-02-28 22:29:51 +01:00
|
|
|
wpFileError(fileObj, swfuploadL10n.file_exceeds_size_limit);
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) {
|
2008-02-29 07:54:15 +01:00
|
|
|
fileQueued(fileObj);
|
2008-02-28 22:29:51 +01:00
|
|
|
wpFileError(fileObj, swfuploadL10n.zero_byte_file);
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) {
|
2008-02-29 07:54:15 +01:00
|
|
|
fileQueued(fileObj);
|
2008-02-28 22:29:51 +01:00
|
|
|
wpFileError(fileObj, swfuploadL10n.invalid_filetype);
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
wpQueueError(swfuploadL10n.default_error);
|
|
|
|
}
|
2008-01-29 00:16:04 +01:00
|
|
|
}
|
2008-01-25 20:21:11 +01:00
|
|
|
|
|
|
|
function fileDialogComplete(num_files_queued) {
|
|
|
|
try {
|
|
|
|
if (num_files_queued > 0) {
|
|
|
|
this.startUpload();
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
this.debug(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadError(fileObj, error_code, message) {
|
2008-02-22 06:53:47 +01:00
|
|
|
// first the file specific error
|
|
|
|
if ( error_code == SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL ) {
|
|
|
|
wpFileError(fileObj, swfuploadL10n.missing_upload_url);
|
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED ) {
|
|
|
|
wpFileError(fileObj, swfuploadL10n.upload_limit_exceeded);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wpFileError(fileObj, swfuploadL10n.default_error);
|
|
|
|
}
|
2008-01-25 20:21:11 +01:00
|
|
|
|
2008-02-22 06:53:47 +01:00
|
|
|
// now the general upload status
|
|
|
|
if ( error_code == SWFUpload.UPLOAD_ERROR.HTTP_ERROR ) {
|
|
|
|
wpQueueError(swfuploadL10n.http_error);
|
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED ) {
|
|
|
|
wpQueueError(swfuploadL10n.upload_failed);
|
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.UPLOAD_ERROR.IO_ERROR ) {
|
|
|
|
wpQueueError(swfuploadL10n.io_error);
|
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.UPLOAD_ERROR.SECURITY_ERROR ) {
|
|
|
|
wpQueueError(swfuploadL10n.security_error);
|
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED ) {
|
|
|
|
wpQueueError(swfuploadL10n.security_error);
|
|
|
|
}
|
2008-01-25 20:21:11 +01:00
|
|
|
}
|