-
+ FC72CA2E9F5C2E47C6633759BD86ECC5BF71A9DD8B3FDE34E54EB0D5075F36294B929F1B9749C0E32AAADA6AA78E57FF19B85A87604C49E46874BC04F50B007Cmp-wp/wp-includes/js/swfupload/handlers.js(0 . 0)(1 . 287)
116110 function fileDialogStart() {
116111 jQuery("#media-upload-error").empty();
116112 }
116113
116114 // progress and success handlers for media multi uploads
116115 function fileQueued(fileObj) {
116116 // Get rid of unused form
116117 jQuery('.media-blank').remove();
116118 // Collapse a single item
116119 if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
116120 jQuery('.toggle').toggle();
116121 jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
116122 }
116123 // Create a progress bar containing the filename
116124 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>');
116125 // Display the progress div
116126 jQuery('#media-item-' + fileObj.id + ' .progress').show();
116127
116128 // Disable the submit button
116129 jQuery('#insert-gallery').attr('disabled', 'disabled');
116130 }
116131
116132 function uploadStart(fileObj) { return true; }
116133
116134 function uploadProgress(fileObj, bytesDone, bytesTotal) {
116135 // Lengthen the progress bar
116136 jQuery('#media-item-' + fileObj.id + ' .bar').width(620*bytesDone/bytesTotal);
116137
116138 if ( bytesDone == bytesTotal )
116139 jQuery('#media-item-' + fileObj.id + ' .bar').html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
116140 }
116141
116142 function prepareMediaItem(fileObj, serverData) {
116143 // Move the progress bar to 100%
116144 jQuery('#media-item-' + fileObj.id + ' .bar').remove();
116145 jQuery('#media-item-' + fileObj.id + ' .progress').hide();
116146
116147 var f = ( typeof shortform == 'undefined' ) ? 1 : 2;
116148 // Old style: Append the HTML returned by the server -- thumbnail and form inputs
116149 if ( isNaN(serverData) || !serverData ) {
116150 jQuery('#media-item-' + fileObj.id).append(serverData);
116151 prepareMediaItemInit(fileObj);
116152 }
116153 // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
116154 else {
116155 jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
116156 }
116157 }
116158
116159 function prepareMediaItemInit(fileObj) {
116160
116161 // Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
116162 jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id);
116163
116164 // Replace the original filename with the new (unique) one assigned during upload
116165 jQuery('#media-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#media-item-' + fileObj.id + ' .filename.new'));
116166
116167 // Also bind toggle to the links
116168 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;});
116169
116170 // Bind AJAX to the new Delete button
116171 jQuery('#media-item-' + fileObj.id + ' a.delete').bind('click',function(){
116172 // Tell the server to delete it. TODO: handle exceptions
116173 jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{
116174 id : this.id.replace(/[^0-9]/g,''),
116175 action : 'delete-post',
116176 _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
116177 });
116178 return false;
116179 });
116180
116181 // Open this item if it says to start open (e.g. to display an error)
116182 jQuery('#media-item-' + fileObj.id + '.startopen')
116183 .removeClass('startopen')
116184 .slideToggle(500)
116185 .parent().eq(0).children('.toggle').toggle();
116186 }
116187
116188 function itemAjaxError(id, html) {
116189 var error = jQuery('#media-item-error' + id);
116190
116191 error.html('<div class="file-error"><button type="button" id="dismiss-'+id+'" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+html+'</div>');
116192 jQuery('#dismiss-'+id).click(function(){jQuery(this).parents('.file-error').slideUp(200, function(){jQuery(this).empty();})});
116193 }
116194
116195 function deleteSuccess(data, textStatus) {
116196 if ( data == '-1' )
116197 return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
116198 if ( data == '0' )
116199 return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
116200
116201 var item = jQuery('#media-item-' + this.id);
116202
116203 // Decrement the counters.
116204 if ( type = jQuery('#type-of-' + this.id).val() )
116205 jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
116206 if ( item.hasClass('child-of-'+post_id) )
116207 jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1);
116208
116209 if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
116210 jQuery('.toggle').toggle();
116211 jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
116212 }
116213
116214 // Vanish it.
116215 jQuery('#media-item-' + this.id + ' .filename:empty').remove();
116216 jQuery('#media-item-' + this.id + ' .filename').append(' <span class="file-error">'+swfuploadL10n.deleted+'</span>').siblings('a.toggle').remove();
116217 jQuery('#media-item-' + this.id).children('.describe').css({backgroundColor:'#fff'}).end()
116218 .animate({backgroundColor:'#ffc0c0'}, {queue:false,duration:50})
116219 .animate({minHeight:0,height:36}, 400, null, function(){jQuery(this).children('.describe').remove()})
116220 .animate({backgroundColor:'#fff'}, 400)
116221 .animate({height:0}, 800, null, function(){jQuery(this).remove();updateMediaForm();});
116222
116223 return;
116224 }
116225
116226 function deleteError(X, textStatus, errorThrown) {
116227 // TODO
116228 }
116229
116230 function updateMediaForm() {
116231 storeState();
116232 // Just one file, no need for collapsible part
116233 if ( jQuery('.type-form #media-items>*').length == 1 ) {
116234 jQuery('#media-items .slidetoggle').slideDown(500).parent().eq(0).children('.toggle').toggle();
116235 jQuery('.type-form .slidetoggle').siblings().addClass('hidden');
116236 }
116237
116238 // Only show Save buttons when there is at least one file.
116239 if ( jQuery('#media-items>*').not('.media-blank').length > 0 )
116240 jQuery('.savebutton').show();
116241 else
116242 jQuery('.savebutton').hide();
116243
116244 // Only show Gallery button when there are at least two files.
116245 if ( jQuery('#media-items>*').length > 1 )
116246 jQuery('.insert-gallery').show();
116247 else
116248 jQuery('.insert-gallery').hide();
116249 }
116250
116251 function uploadSuccess(fileObj, serverData) {
116252 // if async-upload returned an error message, place it in the media item div and return
116253 if ( serverData.match('media-upload-error') ) {
116254 jQuery('#media-item-' + fileObj.id).html(serverData);
116255 return;
116256 }
116257
116258 prepareMediaItem(fileObj, serverData);
116259 updateMediaForm();
116260
116261 // Increment the counter.
116262 if ( jQuery('#media-item-' + fileObj.id).hasClass('child-of-' + post_id) )
116263 jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1);
116264 }
116265
116266 function uploadComplete(fileObj) {
116267 // If no more uploads queued, enable the submit button
116268 if ( swfu.getStats().files_queued == 0 )
116269 jQuery('#insert-gallery').attr('disabled', '');
116270 }
116271
116272
116273 // wp-specific error handlers
116274
116275 // generic message
116276 function wpQueueError(message) {
116277 jQuery('#media-upload-error').show().text(message);
116278 }
116279
116280 // file-specific message
116281 function wpFileError(fileObj, message) {
116282 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();
116283 jQuery('#dismiss-' + fileObj.id).click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
116284 }
116285
116286 function fileQueueError(fileObj, error_code, message) {
116287 // Handle this error separately because we don't want to create a FileProgress element for it.
116288 if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) {
116289 wpQueueError(swfuploadL10n.queue_limit_exceeded);
116290 }
116291 else if ( error_code == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT ) {
116292 fileQueued(fileObj);
116293 wpFileError(fileObj, swfuploadL10n.file_exceeds_size_limit);
116294 }
116295 else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) {
116296 fileQueued(fileObj);
116297 wpFileError(fileObj, swfuploadL10n.zero_byte_file);
116298 }
116299 else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) {
116300 fileQueued(fileObj);
116301 wpFileError(fileObj, swfuploadL10n.invalid_filetype);
116302 }
116303 else {
116304 wpQueueError(swfuploadL10n.default_error);
116305 }
116306 }
116307
116308 function fileDialogComplete(num_files_queued) {
116309 try {
116310 if (num_files_queued > 0) {
116311 this.startUpload();
116312 }
116313 } catch (ex) {
116314 this.debug(ex);
116315 }
116316 }
116317
116318 function swfuploadPreLoad() {
116319 var swfupload_element = jQuery('#'+swfu.customSettings.swfupload_element_id).get(0);
116320 jQuery('#' + swfu.customSettings.degraded_element_id).hide();
116321 // Doing this directly because jQuery().show() seems to have timing problems
116322 if ( swfupload_element && ! swfupload_element.style.display )
116323 swfupload_element.style.display = 'block';
116324 }
116325
116326 function swfuploadLoadFailed() {
116327 jQuery('#' + swfu.customSettings.swfupload_element_id).hide();
116328 jQuery('#' + swfu.customSettings.degraded_element_id).show();
116329 }
116330
116331 function uploadError(fileObj, error_code, message) {
116332 // first the file specific error
116333 if ( error_code == SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL ) {
116334 wpFileError(fileObj, swfuploadL10n.missing_upload_url);
116335 }
116336 else if ( error_code == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED ) {
116337 wpFileError(fileObj, swfuploadL10n.upload_limit_exceeded);
116338 }
116339 else {
116340 wpFileError(fileObj, swfuploadL10n.default_error);
116341 }
116342
116343 // now the general upload status
116344 if ( error_code == SWFUpload.UPLOAD_ERROR.HTTP_ERROR ) {
116345 wpQueueError(swfuploadL10n.http_error);
116346 }
116347 else if ( error_code == SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED ) {
116348 wpQueueError(swfuploadL10n.upload_failed);
116349 }
116350 else if ( error_code == SWFUpload.UPLOAD_ERROR.IO_ERROR ) {
116351 wpQueueError(swfuploadL10n.io_error);
116352 }
116353 else if ( error_code == SWFUpload.UPLOAD_ERROR.SECURITY_ERROR ) {
116354 wpQueueError(swfuploadL10n.security_error);
116355 }
116356 else if ( error_code == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED ) {
116357 wpQueueError(swfuploadL10n.security_error);
116358 }
116359 }
116360
116361 // remember the last used image size, alignment and url
116362 var storeState;
116363 (function($){
116364
116365 storeState = function(){
116366 var align = getUserSetting('align') || '', imgsize = getUserSetting('imgsize') || '';
116367
116368 $('tr.align input[type="radio"]').click(function(){
116369 setUserSetting('align', $(this).val());
116370 }).filter(function(){
116371 if ( $(this).val() == align )
116372 return true;
116373 return false;
116374 }).attr('checked','checked');
116375
116376 $('tr.image-size input[type="radio"]').click(function(){
116377 setUserSetting('imgsize', $(this).val());
116378 }).filter(function(){
116379 if ( $(this).attr('disabled') || $(this).val() != imgsize )
116380 return false;
116381 return true;
116382 }).attr('checked','checked');
116383
116384 $('tr.url button').click(function(){
116385 var c = this.className || '';
116386 c = c.replace(/.*?(url[^ '"]+).*/, '$1');
116387 if (c) setUserSetting('urlbutton', c);
116388 $(this).siblings('.urlfield').val( $(this).attr('title') );
116389 });
116390
116391 $('tr.url .urlfield').each(function(){
116392 var b = getUserSetting('urlbutton');
116393 $(this).val( $(this).siblings('button.'+b).attr('title') );
116394 });
116395 }
116396 })(jQuery);