1
var topWin = window.dialogArguments || opener || parent || top;
3
function fileDialogStart() {
4
jQuery("#media-upload-error").empty();
7
// progress and success handlers for media multi uploads
8
function fileQueued(fileObj) {
9
// Get rid of unused form
10
jQuery('.media-blank').remove();
11
// Collapse a single item
12
if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
13
jQuery('.describe-toggle-on').show();
14
jQuery('.describe-toggle-off').hide();
15
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
17
// Create a progress bar containing the filename
18
jQuery('<div class="media-item">')
19
.attr( 'id', 'media-item-' + fileObj.id )
20
.addClass('child-of-' + post_id)
21
.append('<div class="progress"><div class="bar"></div></div>',
22
jQuery('<div class="filename original"><span class="percent"></span>').text( ' ' + fileObj.name ))
23
.appendTo( jQuery('#media-items' ) );
24
// Display the progress div
25
jQuery('.progress', '#media-item-' + fileObj.id).show();
27
// Disable submit and enable cancel
28
jQuery('#insert-gallery').prop('disabled', true);
29
jQuery('#cancel-upload').prop('disabled', false);
32
function uploadStart(fileObj) {
34
if ( typeof topWin.tb_remove != 'undefined' )
35
topWin.jQuery('#TB_overlay').unbind('click', topWin.tb_remove);
41
function uploadProgress(fileObj, bytesDone, bytesTotal) {
42
// Lengthen the progress bar
43
var w = jQuery('#media-items').width() - 2, item = jQuery('#media-item-' + fileObj.id);
44
jQuery('.bar', item).width( w * bytesDone / bytesTotal );
45
jQuery('.percent', item).html( Math.ceil(bytesDone / bytesTotal * 100) + '%' );
47
if ( bytesDone == bytesTotal )
48
jQuery('.bar', item).html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
51
function prepareMediaItem(fileObj, serverData) {
52
var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
53
// Move the progress bar to 100%
54
jQuery('.bar', item).remove();
55
jQuery('.progress', item).hide();
58
if ( typeof topWin.tb_remove != 'undefined' )
59
topWin.jQuery('#TB_overlay').click(topWin.tb_remove);
62
// Old style: Append the HTML returned by the server -- thumbnail and form inputs
63
if ( isNaN(serverData) || !serverData ) {
64
item.append(serverData);
65
prepareMediaItemInit(fileObj);
67
// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
69
item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
73
function prepareMediaItemInit(fileObj) {
74
var item = jQuery('#media-item-' + fileObj.id);
75
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
76
jQuery('.thumbnail', item).clone().attr('class', 'pinkynail toggle').prependTo(item);
78
// Replace the original filename with the new (unique) one assigned during upload
79
jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
81
// Also bind toggle to the links
82
jQuery('a.toggle', item).click(function(){
83
jQuery(this).siblings('.slidetoggle').slideToggle(350, function(){
84
var w = jQuery(window).height(), t = jQuery(this).offset().top, h = jQuery(this).height(), b;
89
if ( b > w && (h + 48) < w )
90
window.scrollBy(0, b - w + 13);
92
window.scrollTo(0, t - 36);
95
jQuery(this).siblings('.toggle').andSelf().toggle();
96
jQuery(this).siblings('a.toggle').focus();
100
// Bind AJAX to the new Delete button
101
jQuery('a.delete', item).click(function(){
102
// Tell the server to delete it. TODO: handle exceptions
106
success: deleteSuccess,
110
id : this.id.replace(/[^0-9]/g, ''),
111
action : 'trash-post',
112
_ajax_nonce : this.href.replace(/^.*wpnonce=/,'')
118
// Bind AJAX to the new Undo button
119
jQuery('a.undo', item).click(function(){
120
// Tell the server to untrash it. TODO: handle exceptions
126
id : this.id.replace(/[^0-9]/g,''),
127
action: 'untrash-post',
128
_ajax_nonce: this.href.replace(/^.*wpnonce=/,'')
130
success: function(data, textStatus){
131
var item = jQuery('#media-item-' + fileObj.id);
133
if ( type = jQuery('#type-of-' + fileObj.id).val() )
134
jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-0+1);
135
if ( item.hasClass('child-of-'+post_id) )
136
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1);
138
jQuery('.filename .trashnotice', item).remove();
139
jQuery('.filename .title', item).css('font-weight','normal');
140
jQuery('a.undo', item).addClass('hidden');
141
jQuery('a.describe-toggle-on, .menu_order_input', item).show();
142
item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery(this).css({backgroundColor:''}); } }).removeClass('undo');
148
// Open this item if it says to start open (e.g. to display an error)
149
jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle();
152
function itemAjaxError(id, html) {
153
var item = jQuery('#media-item-' + id);
154
var filename = jQuery('.filename', item).text();
156
item.html('<div class="error-div">'
157
+ '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>'
158
+ '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
161
item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
164
function deleteSuccess(data, textStatus) {
166
return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
168
return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
170
var id = this.id, item = jQuery('#media-item-' + id);
172
// Decrement the counters.
173
if ( type = jQuery('#type-of-' + id).val() )
174
jQuery('#' + type + '-counter').text( jQuery('#' + type + '-counter').text() - 1 );
175
if ( item.hasClass('child-of-'+post_id) )
176
jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 );
178
if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
179
jQuery('.toggle').toggle();
180
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
184
jQuery('.toggle', item).toggle();
185
jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden');
186
item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass('undo');
188
jQuery('.filename:empty', item).remove();
189
jQuery('.filename .title', item).css('font-weight','bold');
190
jQuery('.filename', item).append('<span class="trashnotice"> ' + swfuploadL10n.deleted + ' </span>').siblings('a.toggle').hide();
191
jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') );
192
jQuery('.menu_order_input', item).hide();
197
function deleteError(X, textStatus, errorThrown) {
201
function updateMediaForm() {
202
var one = jQuery('form.type-form #media-items').children(), items = jQuery('#media-items').children();
204
// Just one file, no need for collapsible part
205
if ( one.length == 1 ) {
206
jQuery('.slidetoggle', one).slideDown(500).siblings().addClass('hidden').filter('.toggle').toggle();
209
// Only show Save buttons when there is at least one file.
210
if ( items.not('.media-blank').length > 0 )
211
jQuery('.savebutton').show();
213
jQuery('.savebutton').hide();
215
// Only show Gallery buttons when there are at least two files.
216
if ( items.length > 1 ) {
217
jQuery('.insert-gallery').show();
219
jQuery('.insert-gallery').hide();
223
function uploadSuccess(fileObj, serverData) {
224
// if async-upload returned an error message, place it in the media item div and return
225
if ( serverData.match('media-upload-error') ) {
226
jQuery('#media-item-' + fileObj.id).html(serverData);
230
prepareMediaItem(fileObj, serverData);
233
// Increment the counter.
234
if ( jQuery('#media-item-' + fileObj.id).hasClass('child-of-' + post_id) )
235
jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1);
238
function uploadComplete(fileObj) {
239
// If no more uploads queued, enable the submit button
240
if ( swfu.getStats().files_queued == 0 ) {
241
jQuery('#cancel-upload').prop('disabled', true);
242
jQuery('#insert-gallery').prop('disabled', false);
247
// wp-specific error handlers
250
function wpQueueError(message) {
251
jQuery('#media-upload-error').show().text(message);
254
// file-specific message
255
function wpFileError(fileObj, message) {
256
var item = jQuery('#media-item-' + fileObj.id);
257
var filename = jQuery('.filename', item).text();
259
item.html('<div class="error-div">'
260
+ '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>'
261
+ '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
264
item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
267
function fileQueueError(fileObj, error_code, message) {
268
// Handle this error separately because we don't want to create a FileProgress element for it.
269
if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) {
270
wpQueueError(swfuploadL10n.queue_limit_exceeded);
272
else if ( error_code == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT ) {
274
wpFileError(fileObj, swfuploadL10n.file_exceeds_size_limit);
276
else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) {
278
wpFileError(fileObj, swfuploadL10n.zero_byte_file);
280
else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) {
282
wpFileError(fileObj, swfuploadL10n.invalid_filetype);
285
wpQueueError(swfuploadL10n.default_error);
289
function fileDialogComplete(num_files_queued) {
291
if (num_files_queued > 0) {
299
function switchUploader(s) {
300
var f = document.getElementById(swfu.customSettings.swfupload_element_id), h = document.getElementById(swfu.customSettings.degraded_element_id);
302
f.style.display = 'block';
303
h.style.display = 'none';
305
f.style.display = 'none';
306
h.style.display = 'block';
310
function swfuploadPreLoad() {
311
if ( !uploaderMode ) {
318
function swfuploadLoadFailed() {
320
jQuery('.upload-html-bypass').hide();
323
function uploadError(fileObj, errorCode, message) {
326
case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
327
wpFileError(fileObj, swfuploadL10n.missing_upload_url);
329
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
330
wpFileError(fileObj, swfuploadL10n.upload_limit_exceeded);
332
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
333
wpQueueError(swfuploadL10n.http_error);
335
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
336
wpQueueError(swfuploadL10n.upload_failed);
338
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
339
wpQueueError(swfuploadL10n.io_error);
341
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
342
wpQueueError(swfuploadL10n.security_error);
344
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
345
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
346
jQuery('#media-item-' + fileObj.id).remove();
349
wpFileError(fileObj, swfuploadL10n.default_error);
353
function cancelUpload() {
357
// remember the last used image size, alignment and url
358
jQuery(document).ready(function($){
359
$('input[type="radio"]', '#media-items').live('click', function(){
360
var tr = $(this).closest('tr');
362
if ( $(tr).hasClass('align') )
363
setUserSetting('align', $(this).val());
364
else if ( $(tr).hasClass('image-size') )
365
setUserSetting('imgsize', $(this).val());
368
$('button.button', '#media-items').live('click', function(){
369
var c = this.className || '';
370
c = c.match(/url([^ '"]+)/);
372
setUserSetting('urlbutton', c[1]);
373
$(this).siblings('.urlfield').val( $(this).attr('title') );