web/wp-includes/js/swfupload/handlers.dev.js
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
       
     1 var topWin = window.dialogArguments || opener || parent || top;
     1 
     2 
     2 function fileDialogStart() {
     3 function fileDialogStart() {
     3 	jQuery("#media-upload-error").empty();
     4 	jQuery("#media-upload-error").empty();
     4 }
     5 }
     5 
     6 
    17 	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>');
    18 	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>');
    18 	// Display the progress div
    19 	// Display the progress div
    19 	jQuery('.progress', '#media-item-' + fileObj.id).show();
    20 	jQuery('.progress', '#media-item-' + fileObj.id).show();
    20 
    21 
    21 	// Disable submit and enable cancel
    22 	// Disable submit and enable cancel
    22 	jQuery('#insert-gallery').attr('disabled', 'disabled');
    23 	jQuery('#insert-gallery').prop('disabled', true);
    23 	jQuery('#cancel-upload').attr('disabled', '');
    24 	jQuery('#cancel-upload').prop('disabled', false);
    24 }
    25 }
    25 
    26 
    26 function uploadStart(fileObj) {
    27 function uploadStart(fileObj) {
       
    28 	try {
       
    29 		if ( typeof topWin.tb_remove != 'undefined' )
       
    30 			topWin.jQuery('#TB_overlay').unbind('click', topWin.tb_remove); 
       
    31 	} catch(e){}
       
    32 
    27 	return true;
    33 	return true;
    28 }
    34 }
    29 
    35 
    30 function uploadProgress(fileObj, bytesDone, bytesTotal) {
    36 function uploadProgress(fileObj, bytesDone, bytesTotal) {
    31 	// Lengthen the progress bar
    37 	// Lengthen the progress bar
    41 	var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
    47 	var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
    42 	// Move the progress bar to 100%
    48 	// Move the progress bar to 100%
    43 	jQuery('.bar', item).remove();
    49 	jQuery('.bar', item).remove();
    44 	jQuery('.progress', item).hide();
    50 	jQuery('.progress', item).hide();
    45 
    51 
       
    52 	try {
       
    53 		if ( typeof topWin.tb_remove != 'undefined' )
       
    54 			topWin.jQuery('#TB_overlay').click(topWin.tb_remove);
       
    55 	} catch(e){}
       
    56 
    46 	// Old style: Append the HTML returned by the server -- thumbnail and form inputs
    57 	// Old style: Append the HTML returned by the server -- thumbnail and form inputs
    47 	if ( isNaN(serverData) || !serverData ) {
    58 	if ( isNaN(serverData) || !serverData ) {
    48 		item.append(serverData);
    59 		item.append(serverData);
    49 		prepareMediaItemInit(fileObj);
    60 		prepareMediaItemInit(fileObj);
    50 	}
    61 	}
    55 }
    66 }
    56 
    67 
    57 function prepareMediaItemInit(fileObj) {
    68 function prepareMediaItemInit(fileObj) {
    58 	var item = jQuery('#media-item-' + fileObj.id);
    69 	var item = jQuery('#media-item-' + fileObj.id);
    59 	// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
    70 	// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
    60 	jQuery('.thumbnail', item).clone().attr('className', 'pinkynail toggle').prependTo(item);
    71 	jQuery('.thumbnail', item).clone().attr('class', 'pinkynail toggle').prependTo(item);
    61 
    72 
    62 	// Replace the original filename with the new (unique) one assigned during upload
    73 	// Replace the original filename with the new (unique) one assigned during upload
    63 	jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
    74 	jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
    64 
    75 
    65 	// Also bind toggle to the links
    76 	// Also bind toggle to the links
    83 
    94 
    84 	// Bind AJAX to the new Delete button
    95 	// Bind AJAX to the new Delete button
    85 	jQuery('a.delete', item).click(function(){
    96 	jQuery('a.delete', item).click(function(){
    86 		// Tell the server to delete it. TODO: handle exceptions
    97 		// Tell the server to delete it. TODO: handle exceptions
    87 		jQuery.ajax({
    98 		jQuery.ajax({
    88 			url: 'admin-ajax.php',
    99 			url: ajaxurl,
    89 			type: 'post',
   100 			type: 'post',
    90 			success: deleteSuccess,
   101 			success: deleteSuccess,
    91 			error: deleteError,
   102 			error: deleteError,
    92 			id: fileObj.id,
   103 			id: fileObj.id,
    93 			data: {
   104 			data: {
   101 
   112 
   102 	// Bind AJAX to the new Undo button
   113 	// Bind AJAX to the new Undo button
   103 	jQuery('a.undo', item).click(function(){
   114 	jQuery('a.undo', item).click(function(){
   104 		// Tell the server to untrash it. TODO: handle exceptions
   115 		// Tell the server to untrash it. TODO: handle exceptions
   105 		jQuery.ajax({
   116 		jQuery.ajax({
   106 			url: 'admin-ajax.php',
   117 			url: ajaxurl,
   107 			type: 'post',
   118 			type: 'post',
   108 			id: fileObj.id,
   119 			id: fileObj.id,
   109 			data: {
   120 			data: {
   110 				id : this.id.replace(/[^0-9]/g,''),
   121 				id : this.id.replace(/[^0-9]/g,''),
   111 				action: 'untrash-post',
   122 				action: 'untrash-post',
   132 	// Open this item if it says to start open (e.g. to display an error)
   143 	// Open this item if it says to start open (e.g. to display an error)
   133 	jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle();
   144 	jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle();
   134 }
   145 }
   135 
   146 
   136 function itemAjaxError(id, html) {
   147 function itemAjaxError(id, html) {
   137 	var error = jQuery('#media-item-error' + id);
   148 	var item = jQuery('#media-item-' + id);
   138 
   149 	var filename = jQuery('.filename', item).text();
   139 	error.html('<div class="file-error"><button type="button" id="dismiss-'+id+'" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+html+'</div>');
   150 
   140 	jQuery('#dismiss-'+id).click(function(){jQuery(this).parents('.file-error').slideUp(200, function(){jQuery(this).empty();})});
   151 	item.html('<div class="error-div">'
       
   152 				+ '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>'
       
   153 				+ '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
       
   154 				+ html
       
   155 				+ '</div>');
       
   156 	item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
   141 }
   157 }
   142 
   158 
   143 function deleteSuccess(data, textStatus) {
   159 function deleteSuccess(data, textStatus) {
   144 	if ( data == '-1' )
   160 	if ( data == '-1' )
   145 		return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
   161 		return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
   214 }
   230 }
   215 
   231 
   216 function uploadComplete(fileObj) {
   232 function uploadComplete(fileObj) {
   217 	// If no more uploads queued, enable the submit button
   233 	// If no more uploads queued, enable the submit button
   218 	if ( swfu.getStats().files_queued == 0 ) {
   234 	if ( swfu.getStats().files_queued == 0 ) {
   219 		jQuery('#cancel-upload').attr('disabled', 'disabled');
   235 		jQuery('#cancel-upload').prop('disabled', true);
   220 		jQuery('#insert-gallery').attr('disabled', '');
   236 		jQuery('#insert-gallery').prop('disabled', false);
   221 	}
   237 	}
   222 }
   238 }
   223 
   239 
   224 
   240 
   225 // wp-specific error handlers
   241 // wp-specific error handlers
   229 	jQuery('#media-upload-error').show().text(message);
   245 	jQuery('#media-upload-error').show().text(message);
   230 }
   246 }
   231 
   247 
   232 // file-specific message
   248 // file-specific message
   233 function wpFileError(fileObj, message) {
   249 function wpFileError(fileObj, message) {
   234 	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();
   250 	var item = jQuery('#media-item-' + fileObj.id);
   235 	jQuery('#dismiss-' + fileObj.id).click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
   251 	var filename = jQuery('.filename', item).text();
       
   252 
       
   253 	item.html('<div class="error-div">'
       
   254 				+ '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>'
       
   255 				+ '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
       
   256 				+ message
       
   257 				+ '</div>');
       
   258 	item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
   236 }
   259 }
   237 
   260 
   238 function fileQueueError(fileObj, error_code, message)  {
   261 function fileQueueError(fileObj, error_code, message)  {
   239 	// Handle this error separately because we don't want to create a FileProgress element for it.
   262 	// Handle this error separately because we don't want to create a FileProgress element for it.
   240 	if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) {
   263 	if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) {