2011-09-15 01:30:58 -04:00
|
|
|
var topWin = window.dialogArguments || opener || parent || top, uploader, uploader_init;
|
2009-05-17 08:29:58 -04:00
|
|
|
|
2009-01-10 04:29:39 -05:00
|
|
|
function fileDialogStart() {
|
|
|
|
jQuery("#media-upload-error").empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// progress and success handlers for media multi uploads
|
|
|
|
function fileQueued(fileObj) {
|
|
|
|
// Get rid of unused form
|
|
|
|
jQuery('.media-blank').remove();
|
2011-11-10 15:33:26 -05:00
|
|
|
|
2011-11-19 16:50:33 -05:00
|
|
|
var items = jQuery('#media-items').children(), postid = post_id || 0;
|
2011-11-10 15:33:26 -05:00
|
|
|
|
2009-01-10 04:29:39 -05:00
|
|
|
// Collapse a single item
|
2011-11-10 15:33:26 -05:00
|
|
|
if ( items.length == 1 ) {
|
|
|
|
items.removeClass('open').find('.slidetoggle').slideUp(200);
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
|
|
|
// Create a progress bar containing the filename
|
2011-11-19 16:50:33 -05:00
|
|
|
jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + postid + '"><div class="progress"><div class="percent">0%</div><div class="bar"></div></div><div class="filename original"> ' + fileObj.name + '</div></div>');
|
2009-01-10 04:29:39 -05:00
|
|
|
|
2011-11-02 21:47:12 -04:00
|
|
|
// Disable submit
|
2011-05-24 21:04:12 -04:00
|
|
|
jQuery('#insert-gallery').prop('disabled', true);
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
|
|
|
|
2011-11-11 19:52:26 -05:00
|
|
|
function uploadStart() {
|
2010-01-07 00:55:26 -05:00
|
|
|
try {
|
|
|
|
if ( typeof topWin.tb_remove != 'undefined' )
|
2011-11-12 21:01:13 -05:00
|
|
|
topWin.jQuery('#TB_overlay').unbind('click', topWin.tb_remove);
|
2010-01-07 00:55:26 -05:00
|
|
|
} catch(e){}
|
|
|
|
|
2009-05-17 08:29:58 -04:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-10 04:29:39 -05:00
|
|
|
|
2011-11-12 21:01:13 -05:00
|
|
|
function uploadProgress(up, file) {
|
|
|
|
var item = jQuery('#media-item-' + file.id);
|
|
|
|
|
2011-11-15 16:22:27 -05:00
|
|
|
jQuery('.bar', item).width( (200 * file.loaded) / file.size );
|
2011-11-12 21:01:13 -05:00
|
|
|
jQuery('.percent', item).html( file.percent + '%' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if a large file failed to upload
|
|
|
|
function fileUploading(up, file) {
|
|
|
|
var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
|
|
|
|
|
|
|
|
if ( max > hundredmb && file.size > hundredmb ) {
|
|
|
|
setTimeout(function(){
|
|
|
|
if ( file.status == 2 && file.loaded == 0 ) { // not uploading
|
|
|
|
wpFileError(file, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>'));
|
|
|
|
|
|
|
|
if ( up.current && up.current.file.id == file.id && up.current.xhr.abort )
|
|
|
|
up.current.xhr.abort();
|
|
|
|
}
|
2011-11-13 13:37:30 -05:00
|
|
|
}, 10000); // wait for 10 sec. for the file to start uploading
|
2011-11-12 21:01:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 04:59:35 -04:00
|
|
|
function updateMediaForm() {
|
2011-11-10 15:33:26 -05:00
|
|
|
var items = jQuery('#media-items').children();
|
2011-07-29 04:59:35 -04:00
|
|
|
|
|
|
|
// Just one file, no need for collapsible part
|
2011-11-10 15:33:26 -05:00
|
|
|
if ( items.length == 1 ) {
|
2011-11-18 22:15:42 -05:00
|
|
|
items.addClass('open').find('.slidetoggle').show();
|
2011-11-10 15:33:26 -05:00
|
|
|
jQuery('.insert-gallery').hide();
|
|
|
|
} else if ( items.length > 1 ) {
|
|
|
|
items.removeClass('open');
|
|
|
|
// Only show Gallery button when there are at least two files.
|
|
|
|
jQuery('.insert-gallery').show();
|
2011-07-29 04:59:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only show Save buttons when there is at least one file.
|
|
|
|
if ( items.not('.media-blank').length > 0 )
|
|
|
|
jQuery('.savebutton').show();
|
|
|
|
else
|
|
|
|
jQuery('.savebutton').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadSuccess(fileObj, serverData) {
|
2011-11-10 15:33:26 -05:00
|
|
|
var item = jQuery('#media-item-' + fileObj.id);
|
|
|
|
|
2011-11-19 20:10:50 -05:00
|
|
|
// on success serverData should be numeric, fix bug in html4 runtime returning the serverData wrapped in a <pre> tag
|
|
|
|
serverData = serverData.replace(/^<pre>(\d+)<\/pre>$/, '$1');
|
|
|
|
|
2011-07-29 04:59:35 -04:00
|
|
|
// if async-upload returned an error message, place it in the media item div and return
|
|
|
|
if ( serverData.match('media-upload-error') ) {
|
2011-11-10 15:33:26 -05:00
|
|
|
item.html(serverData);
|
2011-07-29 04:59:35 -04:00
|
|
|
return;
|
2011-11-18 22:15:42 -05:00
|
|
|
} else {
|
2011-11-15 16:22:27 -05:00
|
|
|
jQuery('.percent', item).html( pluploadL10n.crunching );
|
2011-07-29 04:59:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
prepareMediaItem(fileObj, serverData);
|
|
|
|
updateMediaForm();
|
|
|
|
|
|
|
|
// Increment the counter.
|
2011-11-19 16:50:33 -05:00
|
|
|
if ( post_id && item.hasClass('child-of-' + post_id) )
|
2011-07-29 04:59:35 -04:00
|
|
|
jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1);
|
|
|
|
}
|
|
|
|
|
2011-11-08 17:34:09 -05:00
|
|
|
function setResize(arg) {
|
|
|
|
if ( arg ) {
|
|
|
|
if ( uploader.features.jpgresize )
|
|
|
|
uploader.settings['resize'] = { width: resize_width, height: resize_height, quality: 100 };
|
|
|
|
else
|
|
|
|
uploader.settings.multipart_params.image_resize = true;
|
|
|
|
} else {
|
|
|
|
delete(uploader.settings.resize);
|
|
|
|
delete(uploader.settings.multipart_params.image_resize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 04:29:39 -05:00
|
|
|
function prepareMediaItem(fileObj, serverData) {
|
2009-10-30 03:09:55 -04:00
|
|
|
var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
|
2009-01-10 04:29:39 -05:00
|
|
|
|
2010-01-07 00:55:26 -05:00
|
|
|
try {
|
|
|
|
if ( typeof topWin.tb_remove != 'undefined' )
|
|
|
|
topWin.jQuery('#TB_overlay').click(topWin.tb_remove);
|
|
|
|
} catch(e){}
|
2009-12-27 16:03:54 -05:00
|
|
|
|
2011-11-18 22:15:42 -05:00
|
|
|
if ( isNaN(serverData) || !serverData ) { // Old style: Append the HTML returned by the server -- thumbnail and form inputs
|
2009-10-30 03:09:55 -04:00
|
|
|
item.append(serverData);
|
2009-01-10 04:29:39 -05:00
|
|
|
prepareMediaItemInit(fileObj);
|
2011-11-18 22:15:42 -05:00
|
|
|
} else { // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
|
2009-10-30 03:09:55 -04:00
|
|
|
item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-30 03:09:55 -04:00
|
|
|
function prepareMediaItemInit(fileObj) {
|
|
|
|
var item = jQuery('#media-item-' + fileObj.id);
|
2009-01-10 04:29:39 -05:00
|
|
|
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
|
2011-05-12 18:00:31 -04:00
|
|
|
jQuery('.thumbnail', item).clone().attr('class', 'pinkynail toggle').prependTo(item);
|
2009-01-10 04:29:39 -05:00
|
|
|
|
|
|
|
// Replace the original filename with the new (unique) one assigned during upload
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
|
2009-01-10 04:29:39 -05:00
|
|
|
|
|
|
|
// Bind AJAX to the new Delete button
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('a.delete', item).click(function(){
|
2009-01-10 04:29:39 -05:00
|
|
|
// Tell the server to delete it. TODO: handle exceptions
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery.ajax({
|
|
|
|
url: 'admin-ajax.php',
|
|
|
|
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: 'admin-ajax.php',
|
|
|
|
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);
|
2011-11-19 16:50:33 -05:00
|
|
|
|
|
|
|
if ( post_id && item.hasClass('child-of-'+post_id) )
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1);
|
|
|
|
|
|
|
|
jQuery('.filename .trashnotice', item).remove();
|
2009-11-27 21:56:15 -05:00
|
|
|
jQuery('.filename .title', item).css('font-weight','normal');
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('a.undo', item).addClass('hidden');
|
2011-11-10 15:33:26 -05:00
|
|
|
jQuery('.menu_order_input', item).show();
|
2009-11-29 05:29:12 -05:00
|
|
|
item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery(this).css({backgroundColor:''}); } }).removeClass('undo');
|
2009-10-30 03:09:55 -04:00
|
|
|
}
|
|
|
|
});
|
2009-01-10 04:29:39 -05:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Open this item if it says to start open (e.g. to display an error)
|
2011-11-13 13:37:30 -05:00
|
|
|
jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').addClass('open').find('slidetoggle').fadeIn();
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
|
|
|
|
2011-11-02 21:47:12 -04:00
|
|
|
// generic error message
|
2011-07-29 04:59:35 -04:00
|
|
|
function wpQueueError(message) {
|
2011-11-01 07:56:20 -04:00
|
|
|
jQuery('#media-upload-error').show().html( '<div class="error"><p>' + message + '</p></div>' );
|
2011-07-29 04:59:35 -04:00
|
|
|
}
|
|
|
|
|
2011-11-02 21:47:12 -04:00
|
|
|
// file-specific error messages
|
2011-07-29 04:59:35 -04:00
|
|
|
function wpFileError(fileObj, message) {
|
2011-11-12 21:01:13 -05:00
|
|
|
itemAjaxError(fileObj.id, message);
|
2011-07-29 04:59:35 -04:00
|
|
|
}
|
|
|
|
|
2011-11-12 21:01:13 -05:00
|
|
|
function itemAjaxError(id, message) {
|
2011-11-13 13:37:30 -05:00
|
|
|
var item = jQuery('#media-item-' + id), filename = item.find('.filename').text(), last_err = item.data('last-err');
|
|
|
|
|
|
|
|
if ( last_err == id ) // prevent firing an error for the same file twice
|
|
|
|
return;
|
2010-05-23 06:59:52 -04:00
|
|
|
|
|
|
|
item.html('<div class="error-div">'
|
2011-07-29 04:59:35 -04:00
|
|
|
+ '<a class="dismiss" href="#">' + pluploadL10n.dismiss + '</a>'
|
2011-11-12 21:01:13 -05:00
|
|
|
+ '<strong>' + pluploadL10n.error_uploading.replace('%s', jQuery.trim(filename)) + '</strong> '
|
|
|
|
+ message
|
2011-11-13 13:37:30 -05:00
|
|
|
+ '</div>').data('last-err', id);
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSuccess(data, textStatus) {
|
|
|
|
if ( data == '-1' )
|
|
|
|
return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
|
2011-11-19 16:50:33 -05:00
|
|
|
|
2009-01-10 04:29:39 -05:00
|
|
|
if ( data == '0' )
|
|
|
|
return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
|
|
|
|
|
2009-10-30 03:09:55 -04:00
|
|
|
var id = this.id, item = jQuery('#media-item-' + id);
|
2009-01-10 04:29:39 -05:00
|
|
|
|
|
|
|
// Decrement the counters.
|
2009-10-30 03:09:55 -04:00
|
|
|
if ( type = jQuery('#type-of-' + id).val() )
|
|
|
|
jQuery('#' + type + '-counter').text( jQuery('#' + type + '-counter').text() - 1 );
|
2011-11-19 16:50:33 -05:00
|
|
|
|
|
|
|
if ( post_id && item.hasClass('child-of-'+post_id) )
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 );
|
2009-01-10 04:29:39 -05:00
|
|
|
|
2009-10-30 03:09:55 -04:00
|
|
|
if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
|
2009-01-10 04:29:39 -05:00
|
|
|
jQuery('.toggle').toggle();
|
|
|
|
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vanish it.
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('.toggle', item).toggle();
|
|
|
|
jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden');
|
2009-11-29 05:29:12 -05:00
|
|
|
item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass('undo');
|
2009-10-30 03:09:55 -04:00
|
|
|
|
|
|
|
jQuery('.filename:empty', item).remove();
|
2009-11-27 21:56:15 -05:00
|
|
|
jQuery('.filename .title', item).css('font-weight','bold');
|
2011-07-29 04:59:35 -04:00
|
|
|
jQuery('.filename', item).append('<span class="trashnotice"> ' + pluploadL10n.deleted + ' </span>').siblings('a.toggle').hide();
|
2009-10-30 03:09:55 -04:00
|
|
|
jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') );
|
|
|
|
jQuery('.menu_order_input', item).hide();
|
2009-12-09 07:24:45 -05:00
|
|
|
|
2009-01-10 04:29:39 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteError(X, textStatus, errorThrown) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:38:28 -04:00
|
|
|
function uploadComplete() {
|
|
|
|
jQuery('#insert-gallery').prop('disabled', false);
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
|
|
|
|
2009-04-04 06:21:43 -04:00
|
|
|
function switchUploader(s) {
|
|
|
|
if ( s ) {
|
2011-11-12 21:01:13 -05:00
|
|
|
deleteUserSetting('uploader');
|
|
|
|
jQuery('.media-upload-form').removeClass('html-uploader');
|
|
|
|
|
|
|
|
if ( typeof(uploader) == 'object' )
|
|
|
|
uploader.refresh();
|
2009-04-04 06:21:43 -04:00
|
|
|
} else {
|
2011-11-12 21:01:13 -05:00
|
|
|
setUserSetting('uploader', '1'); // 1 == html uploader
|
|
|
|
jQuery('.media-upload-form').addClass('html-uploader');
|
2009-04-04 06:21:43 -04:00
|
|
|
}
|
|
|
|
}
|
2009-03-27 04:36:51 -04:00
|
|
|
|
2011-07-29 04:59:35 -04:00
|
|
|
function dndHelper(s) {
|
|
|
|
var d = document.getElementById('dnd-helper');
|
2011-07-29 15:21:21 -04:00
|
|
|
|
2011-07-29 04:59:35 -04:00
|
|
|
if ( s ) {
|
|
|
|
d.style.display = 'block';
|
|
|
|
} else {
|
|
|
|
d.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 20:10:25 -05:00
|
|
|
function uploadError(fileObj, errorCode, message, uploader) {
|
2011-11-13 13:37:30 -05:00
|
|
|
var hundredmb = 100 * 1024 * 1024, max;
|
2009-10-30 03:09:55 -04:00
|
|
|
|
2009-05-17 08:29:58 -04:00
|
|
|
switch (errorCode) {
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.FAILED:
|
|
|
|
wpFileError(fileObj, pluploadL10n.upload_failed);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.FILE_EXTENSION_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.invalid_filetype);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.FILE_SIZE_ERROR:
|
2011-11-17 20:10:25 -05:00
|
|
|
uploadSizeError(uploader, fileObj);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.IMAGE_FORMAT_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.not_an_image);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.IMAGE_MEMORY_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.image_memory_exceeded);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.IMAGE_DIMENSIONS_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.image_dimensions_exceeded);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.GENERIC_ERROR:
|
|
|
|
wpQueueError(pluploadL10n.upload_failed);
|
|
|
|
break;
|
|
|
|
case plupload.IO_ERROR:
|
2011-11-13 13:37:30 -05:00
|
|
|
max = parseInt(uploader.settings.max_file_size, 10);
|
|
|
|
|
|
|
|
if ( max > hundredmb && fileObj.size > hundredmb )
|
|
|
|
wpFileError(fileObj, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>'));
|
|
|
|
else
|
|
|
|
wpQueueError(pluploadL10n.io_error);
|
2009-05-17 08:29:58 -04:00
|
|
|
break;
|
2011-07-29 04:59:35 -04:00
|
|
|
case plupload.HTTP_ERROR:
|
|
|
|
wpQueueError(pluploadL10n.http_error);
|
|
|
|
break;
|
|
|
|
case plupload.INIT_ERROR:
|
2011-11-11 19:52:26 -05:00
|
|
|
jQuery('.media-upload-form').addClass('html-uploader');
|
2011-07-29 04:59:35 -04:00
|
|
|
break;
|
|
|
|
case plupload.SECURITY_ERROR:
|
|
|
|
wpQueueError(pluploadL10n.security_error);
|
|
|
|
break;
|
|
|
|
/* case plupload.UPLOAD_ERROR.UPLOAD_STOPPED:
|
|
|
|
case plupload.UPLOAD_ERROR.FILE_CANCELLED:
|
|
|
|
jQuery('#media-item-' + fileObj.id).remove();
|
|
|
|
break;*/
|
2009-05-17 08:29:58 -04:00
|
|
|
default:
|
2011-07-29 04:59:35 -04:00
|
|
|
wpFileError(fileObj, pluploadL10n.default_error);
|
2009-01-10 04:29:39 -05:00
|
|
|
}
|
2009-05-17 08:29:58 -04:00
|
|
|
}
|
2009-01-10 04:29:39 -05:00
|
|
|
|
2011-11-17 20:10:25 -05:00
|
|
|
function uploadSizeError( up, file, over100mb ) {
|
|
|
|
var message;
|
2011-11-11 19:52:26 -05:00
|
|
|
|
2011-11-17 20:10:25 -05:00
|
|
|
if ( over100mb )
|
|
|
|
message = pluploadL10n.big_upload_queued.replace('%s', file.name) + ' ' + pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>');
|
|
|
|
else
|
|
|
|
message = pluploadL10n.file_exceeds_size_limit.replace('%s', file.name);
|
|
|
|
|
|
|
|
jQuery('#media-items').append('<div id="media-item-' + file.id + '" class="media-item error"><p>' + message + '</p></div>');
|
2011-11-11 19:52:26 -05:00
|
|
|
up.removeFile(file);
|
|
|
|
}
|
|
|
|
|
2009-11-15 20:37:30 -05:00
|
|
|
jQuery(document).ready(function($){
|
2011-11-12 21:01:13 -05:00
|
|
|
$('.media-upload-form').bind('click.uploader', function(e) {
|
|
|
|
var target = $(e.target), tr, c;
|
2009-01-10 04:29:39 -05:00
|
|
|
|
2011-11-12 21:01:13 -05:00
|
|
|
if ( target.is('input[type="radio"]') ) { // remember the last used image size and alignment
|
|
|
|
tr = target.closest('tr');
|
|
|
|
|
|
|
|
if ( $(tr).hasClass('align') )
|
|
|
|
setUserSetting('align', target.val());
|
|
|
|
else if ( $(tr).hasClass('image-size') )
|
|
|
|
setUserSetting('imgsize', target.val());
|
|
|
|
|
|
|
|
} else if ( target.is('button.button') ) { // remember the last used image link url
|
|
|
|
c = e.target.className || '';
|
|
|
|
c = c.match(/url([^ '"]+)/);
|
|
|
|
|
|
|
|
if ( c && c[1] ) {
|
|
|
|
setUserSetting('urlbutton', c[1]);
|
|
|
|
target.siblings('.urlfield').val( target.attr('title') );
|
|
|
|
}
|
|
|
|
} else if ( target.is('a.dismiss') ) {
|
|
|
|
target.parents('.media-item').fadeOut(200, function(){
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
} else if ( target.is('.upload-flash-bypass a') || target.is('a.uploader-html') ) { // switch uploader to html4
|
2011-11-14 18:21:16 -05:00
|
|
|
$('#media-items, p.submit, span.big-file-warning').css('display', 'none');
|
2011-11-12 21:01:13 -05:00
|
|
|
switchUploader(0);
|
|
|
|
return false;
|
|
|
|
} else if ( target.is('.upload-html-bypass a') ) { // switch uploader to multi-file
|
2011-11-14 18:21:16 -05:00
|
|
|
$('#media-items, p.submit, span.big-file-warning').css('display', '');
|
2011-11-12 21:01:13 -05:00
|
|
|
switchUploader(1);
|
|
|
|
return false;
|
2011-11-13 13:37:30 -05:00
|
|
|
} else if ( target.is('a.describe-toggle-on') ) { // Show
|
|
|
|
target.parent().addClass('open');
|
|
|
|
target.siblings('.slidetoggle').fadeIn(250, function(){
|
|
|
|
var S = $(window).scrollTop(), H = $(window).height(), top = $(this).offset().top, h = $(this).height(), b, B;
|
|
|
|
|
|
|
|
if ( H && top && h ) {
|
|
|
|
b = top + h;
|
|
|
|
B = S + H;
|
|
|
|
|
|
|
|
if ( b > B ) {
|
|
|
|
if ( b - B < top - S )
|
|
|
|
window.scrollBy(0, (b - B) + 10);
|
|
|
|
else
|
|
|
|
window.scrollBy(0, top - S - 40);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
} else if ( target.is('a.describe-toggle-off') ) { // Hide
|
|
|
|
target.siblings('.slidetoggle').fadeOut(250, function(){
|
|
|
|
target.parent().removeClass('open');
|
|
|
|
});
|
|
|
|
return false;
|
2009-11-15 20:37:30 -05:00
|
|
|
}
|
2009-01-10 04:29:39 -05:00
|
|
|
});
|
2011-09-15 01:30:58 -04:00
|
|
|
|
|
|
|
// init and set the uploader
|
|
|
|
uploader_init = function() {
|
|
|
|
uploader = new plupload.Uploader(wpUploaderInit);
|
|
|
|
|
2011-11-08 17:34:09 -05:00
|
|
|
$('#image_resize').bind('change', function() {
|
|
|
|
var arg = $(this).prop('checked');
|
|
|
|
|
|
|
|
setResize( arg );
|
|
|
|
|
|
|
|
if ( arg )
|
|
|
|
setUserSetting('upload_resize', '1');
|
|
|
|
else
|
|
|
|
deleteUserSetting('upload_resize');
|
|
|
|
});
|
|
|
|
|
2011-09-15 01:30:58 -04:00
|
|
|
uploader.bind('Init', function(up) {
|
2011-11-20 14:16:35 -05:00
|
|
|
var uploaddiv = $('#plupload-upload-ui');
|
|
|
|
|
2011-11-08 17:34:09 -05:00
|
|
|
setResize( getUserSetting('upload_resize', false) );
|
|
|
|
|
2011-10-12 18:24:53 -04:00
|
|
|
if ( up.features.dragdrop ) {
|
2011-11-20 14:16:35 -05:00
|
|
|
uploaddiv.addClass('drag-drop');
|
2011-10-12 18:24:53 -04:00
|
|
|
$('#drag-drop-area').bind('dragover.wp-uploader', function(){ // dragenter doesn't fire right :(
|
2011-11-20 14:16:35 -05:00
|
|
|
uploaddiv.addClass('drag-over');
|
2011-10-12 18:24:53 -04:00
|
|
|
}).bind('dragleave.wp-uploader, drop.wp-uploader', function(){
|
2011-11-20 14:16:35 -05:00
|
|
|
uploaddiv.removeClass('drag-over');
|
2011-10-12 18:24:53 -04:00
|
|
|
});
|
2011-11-10 15:33:26 -05:00
|
|
|
} else {
|
2011-11-20 14:16:35 -05:00
|
|
|
uploaddiv.removeClass('drag-drop');
|
2011-11-10 15:33:26 -05:00
|
|
|
$('#drag-drop-area').unbind('.wp-uploader');
|
2011-10-12 18:24:53 -04:00
|
|
|
}
|
2011-09-15 01:30:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
uploader.init();
|
|
|
|
|
|
|
|
uploader.bind('FilesAdded', function(up, files) {
|
2011-11-17 20:10:25 -05:00
|
|
|
var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
|
|
|
|
|
2011-11-11 19:52:26 -05:00
|
|
|
$('#media-upload-error').html('');
|
|
|
|
uploadStart();
|
2011-11-17 20:10:25 -05:00
|
|
|
|
2011-11-18 22:15:42 -05:00
|
|
|
plupload.each(files, function(file){
|
|
|
|
if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' )
|
|
|
|
uploadSizeError( up, file, true );
|
|
|
|
else
|
|
|
|
fileQueued(file);
|
|
|
|
});
|
2011-11-17 20:10:25 -05:00
|
|
|
|
2011-09-15 01:30:58 -04:00
|
|
|
up.refresh();
|
|
|
|
up.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('BeforeUpload', function(up, file) {
|
2011-11-18 22:15:42 -05:00
|
|
|
// something
|
2011-09-15 01:30:58 -04:00
|
|
|
});
|
2011-11-11 19:52:26 -05:00
|
|
|
|
2011-11-12 21:01:13 -05:00
|
|
|
uploader.bind('UploadFile', function(up, file) {
|
|
|
|
fileUploading(up, file);
|
|
|
|
});
|
|
|
|
|
2011-09-15 01:30:58 -04:00
|
|
|
uploader.bind('UploadProgress', function(up, file) {
|
2011-11-12 21:01:13 -05:00
|
|
|
uploadProgress(up, file);
|
2011-09-15 01:30:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('Error', function(up, err) {
|
2011-11-17 20:10:25 -05:00
|
|
|
uploadError(err.file, err.code, err.message, up);
|
|
|
|
up.refresh();
|
2011-09-15 01:30:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('FileUploaded', function(up, file, response) {
|
|
|
|
uploadSuccess(file, response.response);
|
|
|
|
});
|
2011-10-31 17:38:28 -04:00
|
|
|
|
|
|
|
uploader.bind('UploadComplete', function(up, files) {
|
|
|
|
uploadComplete();
|
|
|
|
});
|
2011-09-15 01:30:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof(wpUploaderInit) == 'object' )
|
|
|
|
uploader_init();
|
|
|
|
|
2011-05-12 18:00:31 -04:00
|
|
|
});
|