+var topWin = window.dialogArguments || opener || parent || top;
+
function fileDialogStart() {
jQuery("#media-upload-error").empty();
}
// Get rid of unused form
jQuery('.media-blank').remove();
// Collapse a single item
- if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
- jQuery('.toggle').toggle();
+ if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
+ jQuery('.describe-toggle-on').show();
+ jQuery('.describe-toggle-off').hide();
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
}
// Create a progress bar containing the filename
- 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>');
+ 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"><span class="percent"></span> ' + fileObj.name + '</div></div>');
// Display the progress div
- jQuery('#media-item-' + fileObj.id + ' .progress').show();
+ jQuery('.progress', '#media-item-' + fileObj.id).show();
- // Disable the submit button
- jQuery('#insert-gallery').attr('disabled', 'disabled');
+ // Disable submit and enable cancel
+ jQuery('#insert-gallery').prop('disabled', true);
+ jQuery('#cancel-upload').prop('disabled', false);
}
-function uploadStart(fileObj) { return true; }
+function uploadStart(fileObj) {
+ try {
+ if ( typeof topWin.tb_remove != 'undefined' )
+ topWin.jQuery('#TB_overlay').unbind('click', topWin.tb_remove);
+ } catch(e){}
+
+ return true;
+}
function uploadProgress(fileObj, bytesDone, bytesTotal) {
// Lengthen the progress bar
- jQuery('#media-item-' + fileObj.id + ' .bar').width(620*bytesDone/bytesTotal);
+ var w = jQuery('#media-items').width() - 2, item = jQuery('#media-item-' + fileObj.id);
+ jQuery('.bar', item).width( w * bytesDone / bytesTotal );
+ jQuery('.percent', item).html( Math.ceil(bytesDone / bytesTotal * 100) + '%' );
if ( bytesDone == bytesTotal )
- jQuery('#media-item-' + fileObj.id + ' .bar').html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
+ jQuery('.bar', item).html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
}
function prepareMediaItem(fileObj, serverData) {
+ var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
// Move the progress bar to 100%
- jQuery('#media-item-' + fileObj.id + ' .bar').remove();
- jQuery('#media-item-' + fileObj.id + ' .progress').hide();
+ jQuery('.bar', item).remove();
+ jQuery('.progress', item).hide();
+
+ try {
+ if ( typeof topWin.tb_remove != 'undefined' )
+ topWin.jQuery('#TB_overlay').click(topWin.tb_remove);
+ } catch(e){}
// Old style: Append the HTML returned by the server -- thumbnail and form inputs
if ( isNaN(serverData) || !serverData ) {
- jQuery('#media-item-' + fileObj.id).append(serverData);
+ item.append(serverData);
prepareMediaItemInit(fileObj);
}
// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
else {
- jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:1}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
+ item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
}
}
-
-function prepareMediaItemInit(fileObj) {
+function prepareMediaItemInit(fileObj) {
+ var item = jQuery('#media-item-' + fileObj.id);
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
- jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id);
+ jQuery('.thumbnail', item).clone().attr('class', 'pinkynail toggle').prependTo(item);
// Replace the original filename with the new (unique) one assigned during upload
- jQuery('#media-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#media-item-' + fileObj.id + ' .filename.new'));
+ jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
// Also bind toggle to the links
- 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;});
+ jQuery('a.toggle', item).click(function(){
+ jQuery(this).siblings('.slidetoggle').slideToggle(350, function(){
+ var w = jQuery(window).height(), t = jQuery(this).offset().top, h = jQuery(this).height(), b;
+
+ if ( w && t && h ) {
+ b = t + h;
+
+ if ( b > w && (h + 48) < w )
+ window.scrollBy(0, b - w + 13);
+ else if ( b > w )
+ window.scrollTo(0, t - 36);
+ }
+ });
+ jQuery(this).siblings('.toggle').andSelf().toggle();
+ jQuery(this).siblings('a.toggle').focus();
+ return false;
+ });
// Bind AJAX to the new Delete button
- jQuery('#media-item-' + fileObj.id + ' a.delete').bind('click',function(){
+ jQuery('a.delete', item).click(function(){
// Tell the server to delete it. TODO: handle exceptions
- jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{
- id : this.id.replace(/[^0-9]/g,''),
- action : 'delete-post',
- _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
- });
+ jQuery.ajax({
+ url: ajaxurl,
+ type: 'post',
+ success: deleteSuccess,
+ error: deleteError,
+ id: fileObj.id,
+ data: {
+ id : this.id.replace(/[^0-9]/g, ''),
+ action : 'trash-post',
+ _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')
+ }
+ });
+ return false;
+ });
+
+ // Bind AJAX to the new Undo button
+ jQuery('a.undo', item).click(function(){
+ // Tell the server to untrash it. TODO: handle exceptions
+ jQuery.ajax({
+ url: ajaxurl,
+ type: 'post',
+ id: fileObj.id,
+ data: {
+ id : this.id.replace(/[^0-9]/g,''),
+ action: 'untrash-post',
+ _ajax_nonce: this.href.replace(/^.*wpnonce=/,'')
+ },
+ success: function(data, textStatus){
+ var item = jQuery('#media-item-' + fileObj.id);
+
+ if ( type = jQuery('#type-of-' + fileObj.id).val() )
+ jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-0+1);
+ if ( item.hasClass('child-of-'+post_id) )
+ jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1);
+
+ jQuery('.filename .trashnotice', item).remove();
+ jQuery('.filename .title', item).css('font-weight','normal');
+ jQuery('a.undo', item).addClass('hidden');
+ jQuery('a.describe-toggle-on, .menu_order_input', item).show();
+ item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery(this).css({backgroundColor:''}); } }).removeClass('undo');
+ }
+ });
return false;
});
// Open this item if it says to start open (e.g. to display an error)
- jQuery('#media-item-' + fileObj.id + '.startopen')
- .removeClass('startopen')
- .slideToggle(500)
- .parent().eq(0).children('.toggle').toggle();
+ jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle();
}
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();})});
+ var item = jQuery('#media-item-' + id);
+ var filename = jQuery('.filename', item).text();
+
+ item.html('<div class="error-div">'
+ + '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>'
+ + '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
+ + html
+ + '</div>');
+ item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
}
function deleteSuccess(data, textStatus) {
if ( data == '0' )
return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
- var item = jQuery('#media-item-' + this.id);
+ var id = this.id, item = jQuery('#media-item-' + id);
// Decrement the counters.
- if ( type = jQuery('#type-of-' + this.id).val() )
- jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
+ if ( type = jQuery('#type-of-' + 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);
+ jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 );
- if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
+ if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
jQuery('.toggle').toggle();
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
}
// Vanish it.
- 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();
- jQuery('#media-item-' + this.id).children('.describe').css({backgroundColor:'#fff'}).end()
- .animate({backgroundColor:'#ffc0c0'}, {queue:false,duration:50})
- .animate({minHeight:0,height:36}, 400, null, function(){jQuery(this).children('.describe').remove()})
- .animate({backgroundColor:'#fff'}, 400)
- .animate({height:0}, 800, null, function(){jQuery(this).remove();updateMediaForm();});
+ jQuery('.toggle', item).toggle();
+ jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden');
+ item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass('undo');
+
+ jQuery('.filename:empty', item).remove();
+ jQuery('.filename .title', item).css('font-weight','bold');
+ jQuery('.filename', item).append('<span class="trashnotice"> ' + swfuploadL10n.deleted + ' </span>').siblings('a.toggle').hide();
+ jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') );
+ jQuery('.menu_order_input', item).hide();
return;
}
}
function updateMediaForm() {
+ var one = jQuery('form.type-form #media-items').children(), items = jQuery('#media-items').children();
+
// Just one file, no need for collapsible part
- if ( jQuery('.type-form #media-items>*').length == 1 ) {
- jQuery('#media-items .slidetoggle').slideDown(500).parent().eq(0).children('.toggle').toggle();
- jQuery('.type-form .slidetoggle').siblings().addClass('hidden');
+ if ( one.length == 1 ) {
+ jQuery('.slidetoggle', one).slideDown(500).siblings().addClass('hidden').filter('.toggle').toggle();
}
// Only show Save buttons when there is at least one file.
- if ( jQuery('#media-items>*').not('.media-blank').length > 0 )
+ if ( items.not('.media-blank').length > 0 )
jQuery('.savebutton').show();
else
jQuery('.savebutton').hide();
// Only show Gallery button when there are at least two files.
- if ( jQuery('#media-items>*').length > 1 )
+ if ( items.length > 1 )
jQuery('.insert-gallery').show();
else
jQuery('.insert-gallery').hide();
function uploadComplete(fileObj) {
// If no more uploads queued, enable the submit button
- if ( swfu.getStats().files_queued == 0 )
- jQuery('#insert-gallery').attr('disabled', '');
+ if ( swfu.getStats().files_queued == 0 ) {
+ jQuery('#cancel-upload').prop('disabled', true);
+ jQuery('#insert-gallery').prop('disabled', false);
+ }
}
// file-specific message
function wpFileError(fileObj, message) {
- 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();})});
+ var item = jQuery('#media-item-' + fileObj.id);
+ var filename = jQuery('.filename', item).text();
+
+ item.html('<div class="error-div">'
+ + '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>'
+ + '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
+ + message
+ + '</div>');
+ item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
}
function fileQueueError(fileObj, error_code, message) {
}
}
-function uploadError(fileObj, error_code, message) {
- // 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);
+function switchUploader(s) {
+ var f = document.getElementById(swfu.customSettings.swfupload_element_id), h = document.getElementById(swfu.customSettings.degraded_element_id);
+ if ( s ) {
+ f.style.display = 'block';
+ h.style.display = 'none';
+ } else {
+ f.style.display = 'none';
+ h.style.display = 'block';
}
+}
- // 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);
+function swfuploadPreLoad() {
+ if ( !uploaderMode ) {
+ switchUploader(1);
+ } else {
+ switchUploader(0);
}
- 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);
+}
+
+function swfuploadLoadFailed() {
+ switchUploader(0);
+ jQuery('.upload-html-bypass').hide();
+}
+
+function uploadError(fileObj, errorCode, message) {
+
+ switch (errorCode) {
+ case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
+ wpFileError(fileObj, swfuploadL10n.missing_upload_url);
+ break;
+ case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
+ wpFileError(fileObj, swfuploadL10n.upload_limit_exceeded);
+ break;
+ case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
+ wpQueueError(swfuploadL10n.http_error);
+ break;
+ case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
+ wpQueueError(swfuploadL10n.upload_failed);
+ break;
+ case SWFUpload.UPLOAD_ERROR.IO_ERROR:
+ wpQueueError(swfuploadL10n.io_error);
+ break;
+ case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
+ wpQueueError(swfuploadL10n.security_error);
+ break;
+ case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
+ case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
+ jQuery('#media-item-' + fileObj.id).remove();
+ break;
+ default:
+ wpFileError(fileObj, swfuploadL10n.default_error);
}
}
+
+function cancelUpload() {
+ swfu.cancelQueue();
+}
+
+// remember the last used image size, alignment and url
+jQuery(document).ready(function($){
+ $('input[type="radio"]', '#media-items').live('click', function(){
+ var tr = $(this).closest('tr');
+
+ if ( $(tr).hasClass('align') )
+ setUserSetting('align', $(this).val());
+ else if ( $(tr).hasClass('image-size') )
+ setUserSetting('imgsize', $(this).val());
+ });
+
+ $('button.button', '#media-items').live('click', function(){
+ var c = this.className || '';
+ c = c.match(/url([^ '"]+)/);
+ if ( c && c[1] ) {
+ setUserSetting('urlbutton', c[1]);
+ $(this).siblings('.urlfield').val( $(this).attr('title') );
+ }
+ });
+});