2008-01-25 14:21:11 -05:00
|
|
|
function fileDialogStart() {
|
|
|
|
jQuery("#media-upload-error").empty();
|
|
|
|
}
|
|
|
|
|
2008-02-26 14:30:10 -05:00
|
|
|
// progress and success handlers for media multi uploads
|
2008-02-22 00:53:47 -05:00
|
|
|
function fileQueued(fileObj) {
|
2008-02-28 16:29:51 -05:00
|
|
|
// Get rid of unused form
|
|
|
|
jQuery('.media-blank').remove();
|
2008-03-05 01:46:42 -05: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 14:21:11 -05:00
|
|
|
// Create a progress bar containing the filename
|
2008-04-14 16:48:11 -04:00
|
|
|
jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + post_id + '"><div class="progress"><div class="bar"></div></div><div class="filename original">' + fileObj.name + '</div></div>');
|
|
|
|
// Display the progress div
|
|
|
|
jQuery('#media-item-' + fileObj.id + ' .progress').show();
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
// Disable the submit button
|
2008-03-06 14:48:54 -05:00
|
|
|
jQuery('#insert-gallery').attr('disabled', 'disabled');
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
|
2008-02-22 00:53:47 -05:00
|
|
|
function uploadStart(fileObj) { return true; }
|
|
|
|
|
|
|
|
function uploadProgress(fileObj, bytesDone, bytesTotal) {
|
2008-01-25 14:21:11 -05:00
|
|
|
// Lengthen the progress bar
|
2008-02-26 14:30:10 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .bar').width(620*bytesDone/bytesTotal);
|
2008-03-10 19:55:26 -04:00
|
|
|
|
2008-04-01 17:12:35 -04:00
|
|
|
if ( bytesDone == bytesTotal )
|
|
|
|
jQuery('#media-item-' + fileObj.id + ' .bar').html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
|
2008-02-26 14:30:10 -05:00
|
|
|
function prepareMediaItem(fileObj, serverData) {
|
2008-01-25 14:21:11 -05:00
|
|
|
// Move the progress bar to 100%
|
2008-02-26 14:30:10 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .bar').remove();
|
2008-04-14 16:48:11 -04:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .progress').hide();
|
2008-01-25 14:21:11 -05:00
|
|
|
|
2008-09-27 04:17:55 -04:00
|
|
|
var f = ( typeof shortform == 'undefined' ) ? 1 : 2;
|
2008-04-14 19:09:14 -04:00
|
|
|
// Old style: Append the HTML returned by the server -- thumbnail and form inputs
|
|
|
|
if ( isNaN(serverData) || !serverData ) {
|
|
|
|
jQuery('#media-item-' + fileObj.id).append(serverData);
|
|
|
|
prepareMediaItemInit(fileObj);
|
|
|
|
}
|
|
|
|
// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
|
|
|
|
else {
|
2008-09-27 04:17:55 -04:00
|
|
|
jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
|
2008-04-14 19:09:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareMediaItemInit(fileObj) {
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
|
2008-02-26 14:30:10 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id);
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
// Replace the original filename with the new (unique) one assigned during upload
|
2008-02-26 14:30:10 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#media-item-' + fileObj.id + ' .filename.new'));
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
// Also bind toggle to the links
|
2008-11-25 21:27:37 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' a.toggle').bind('click', function(){jQuery(this).siblings('.slidetoggle').slideToggle(150, function(){var o=jQuery(this).offset();window.scrollTo(0,o.top-36);});jQuery(this).parent().eq(0).children('.toggle').toggle();jQuery(this).siblings('a.toggle').focus();return false;});
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
// Bind AJAX to the new Delete button
|
2008-02-26 14:30:10 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' a.delete').bind('click',function(){
|
|
|
|
// Tell the server to delete it. TODO: handle exceptions
|
2008-03-11 19:15:17 -04:00
|
|
|
jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{
|
2008-02-26 14:30:10 -05:00
|
|
|
id : this.id.replace(/[^0-9]/g,''),
|
|
|
|
action : 'delete-post',
|
|
|
|
_ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
|
|
|
|
});
|
|
|
|
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 16:54:47 -05:00
|
|
|
.removeClass('startopen')
|
|
|
|
.slideToggle(500)
|
|
|
|
.parent().eq(0).children('.toggle').toggle();
|
2008-02-26 14:30:10 -05:00
|
|
|
}
|
2008-02-22 00:53:47 -05:00
|
|
|
|
2008-03-11 19:15:17 -04:00
|
|
|
function itemAjaxError(id, html) {
|
|
|
|
var error = jQuery('#media-item-error' + id);
|
|
|
|
|
|
|
|
error.html('<div class="file-error"><button type="button" id="dismiss-'+id+'" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+html+'</div>');
|
|
|
|
jQuery('#dismiss-'+id).click(function(){jQuery(this).parents('.file-error').slideUp(200, function(){jQuery(this).empty();})});
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSuccess(data, textStatus) {
|
|
|
|
if ( data == '-1' )
|
|
|
|
return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
|
|
|
|
if ( data == '0' )
|
|
|
|
return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
|
|
|
|
|
|
|
|
var item = jQuery('#media-item-' + this.id);
|
|
|
|
|
|
|
|
// Decrement the counters.
|
|
|
|
if ( type = jQuery('#type-of-' + this.id).val() )
|
|
|
|
jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
|
|
|
|
if ( item.hasClass('child-of-'+post_id) )
|
|
|
|
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1);
|
|
|
|
|
|
|
|
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-03-21 19:21:27 -04:00
|
|
|
// Vanish it.
|
2008-03-11 19:15:17 -04:00
|
|
|
jQuery('#media-item-' + this.id + ' .filename:empty').remove();
|
|
|
|
jQuery('#media-item-' + this.id + ' .filename').append(' <span class="file-error">'+swfuploadL10n.deleted+'</span>').siblings('a.toggle').remove();
|
2008-03-21 19:21:27 -04:00
|
|
|
jQuery('#media-item-' + this.id).children('.describe').css({backgroundColor:'#fff'}).end()
|
|
|
|
.animate({backgroundColor:'#ffc0c0'}, {queue:false,duration:50})
|
2008-03-30 02:11:30 -04:00
|
|
|
.animate({minHeight:0,height:36}, 400, null, function(){jQuery(this).children('.describe').remove()})
|
2008-03-21 19:21:27 -04:00
|
|
|
.animate({backgroundColor:'#fff'}, 400)
|
|
|
|
.animate({height:0}, 800, null, function(){jQuery(this).remove();updateMediaForm();});
|
2008-03-11 19:15:17 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteError(X, textStatus, errorThrown) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2008-02-26 14:30:10 -05:00
|
|
|
function updateMediaForm() {
|
2008-12-02 05:29:54 -05:00
|
|
|
storeState();
|
2008-02-26 14:30:10 -05:00
|
|
|
// Just one file, no need for collapsible part
|
2008-02-28 16:29:51 -05:00
|
|
|
if ( jQuery('.type-form #media-items>*').length == 1 ) {
|
2008-02-26 14:30:10 -05:00
|
|
|
jQuery('#media-items .slidetoggle').slideDown(500).parent().eq(0).children('.toggle').toggle();
|
2008-02-28 16:29:51 -05:00
|
|
|
jQuery('.type-form .slidetoggle').siblings().addClass('hidden');
|
2008-02-26 14:30:10 -05:00
|
|
|
}
|
|
|
|
|
2008-03-10 21:30:15 -04:00
|
|
|
// Only show Save buttons when there is at least one file.
|
|
|
|
if ( jQuery('#media-items>*').not('.media-blank').length > 0 )
|
|
|
|
jQuery('.savebutton').show();
|
|
|
|
else
|
|
|
|
jQuery('.savebutton').hide();
|
|
|
|
|
2008-02-26 14:30:10 -05: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-10 19:55:26 -04:00
|
|
|
|
2008-02-26 14:30:10 -05:00
|
|
|
prepareMediaItem(fileObj, serverData);
|
|
|
|
updateMediaForm();
|
2008-02-28 16:29:51 -05: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 14:21:11 -05:00
|
|
|
}
|
|
|
|
|
2008-02-22 00:53:47 -05:00
|
|
|
function uploadComplete(fileObj) {
|
2008-01-25 14:21:11 -05:00
|
|
|
// If no more uploads queued, enable the submit button
|
|
|
|
if ( swfu.getStats().files_queued == 0 )
|
2008-03-06 14:48:54 -05:00
|
|
|
jQuery('#insert-gallery').attr('disabled', '');
|
2008-01-25 14:21:11 -05: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-11 19:15:17 -04:00
|
|
|
jQuery('#media-item-' + fileObj.id + ' .filename').after('<div class="file-error"><button type="button" id="dismiss-' + fileObj.id + '" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+message+'</div>').siblings('.toggle').remove();
|
|
|
|
jQuery('#dismiss-' + fileObj.id).click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
|
2008-01-25 14:21:11 -05: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 01:54:15 -05:00
|
|
|
fileQueued(fileObj);
|
2008-02-28 16:29:51 -05:00
|
|
|
wpFileError(fileObj, swfuploadL10n.file_exceeds_size_limit);
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) {
|
2008-02-29 01:54:15 -05:00
|
|
|
fileQueued(fileObj);
|
2008-02-28 16:29:51 -05:00
|
|
|
wpFileError(fileObj, swfuploadL10n.zero_byte_file);
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) {
|
2008-02-29 01:54:15 -05:00
|
|
|
fileQueued(fileObj);
|
2008-02-28 16:29:51 -05:00
|
|
|
wpFileError(fileObj, swfuploadL10n.invalid_filetype);
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
wpQueueError(swfuploadL10n.default_error);
|
|
|
|
}
|
2008-01-28 18:16:04 -05:00
|
|
|
}
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
function fileDialogComplete(num_files_queued) {
|
|
|
|
try {
|
|
|
|
if (num_files_queued > 0) {
|
|
|
|
this.startUpload();
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
this.debug(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
function swfuploadPreLoad() {
|
2008-11-01 13:20:55 -04:00
|
|
|
var swfupload_element = jQuery('#'+swfu.customSettings.swfupload_element_id).get(0);
|
2008-10-31 14:24:55 -04:00
|
|
|
jQuery('#' + swfu.customSettings.degraded_element_id).hide();
|
2008-11-01 13:20:55 -04:00
|
|
|
// Doing this directly because jQuery().show() seems to have timing problems
|
|
|
|
if ( swfupload_element && ! swfupload_element.style.display )
|
|
|
|
swfupload_element.style.display = 'block';
|
2008-10-30 19:13:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function swfuploadLoadFailed() {
|
2008-10-31 14:24:55 -04:00
|
|
|
jQuery('#' + swfu.customSettings.swfupload_element_id).hide();
|
|
|
|
jQuery('#' + swfu.customSettings.degraded_element_id).show();
|
2008-10-30 19:13:53 -04:00
|
|
|
}
|
|
|
|
|
2008-01-25 14:21:11 -05:00
|
|
|
function uploadError(fileObj, error_code, message) {
|
2008-02-22 00:53:47 -05: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 14:21:11 -05:00
|
|
|
|
2008-02-22 00:53:47 -05: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 14:21:11 -05:00
|
|
|
}
|
2008-11-12 22:07:39 -05:00
|
|
|
|
|
|
|
// remember the last used image size, alignment and url
|
2008-12-02 05:29:54 -05:00
|
|
|
var storeState;
|
|
|
|
(function($){
|
|
|
|
|
|
|
|
storeState = function(){
|
2008-11-12 22:07:39 -05:00
|
|
|
var align = getUserSetting('align') || '', imgsize = getUserSetting('imgsize') || '';
|
|
|
|
|
|
|
|
$('tr.align input[type="radio"]').click(function(){
|
|
|
|
setUserSetting('align', $(this).val());
|
|
|
|
}).filter(function(){
|
|
|
|
if ( $(this).val() == align )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}).attr('checked','checked');
|
|
|
|
|
|
|
|
$('tr.image-size input[type="radio"]').click(function(){
|
|
|
|
setUserSetting('imgsize', $(this).val());
|
|
|
|
}).filter(function(){
|
|
|
|
if ( $(this).attr('disabled') || $(this).val() != imgsize )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}).attr('checked','checked');
|
|
|
|
|
|
|
|
$('tr.url button').click(function(){
|
|
|
|
var c = this.className || '';
|
|
|
|
c = c.replace(/.*?(url[^ '"]+).*/, '$1');
|
|
|
|
if (c) setUserSetting('urlbutton', c);
|
|
|
|
$(this).siblings('.urlfield').val( $(this).attr('title') );
|
|
|
|
});
|
|
|
|
|
|
|
|
$('tr.url .urlfield').each(function(){
|
|
|
|
var b = getUserSetting('urlbutton');
|
|
|
|
$(this).val( $(this).siblings('button.'+b).attr('title') );
|
|
|
|
});
|
2008-12-02 05:29:54 -05:00
|
|
|
}
|
|
|
|
})(jQuery);
|