2011-09-15 07:30:58 +02:00
|
|
|
var topWin = window.dialogArguments || opener || parent || top, uploader, uploader_init;
|
2009-05-17 14:29:58 +02:00
|
|
|
|
2009-01-10 10:29:39 +01: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();
|
|
|
|
// Collapse a single item
|
2009-10-30 08:09:55 +01:00
|
|
|
if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
|
2009-05-17 14:29:58 +02:00
|
|
|
jQuery('.describe-toggle-on').show();
|
|
|
|
jQuery('.describe-toggle-off').hide();
|
2009-01-10 10:29:39 +01:00
|
|
|
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
|
|
|
|
}
|
|
|
|
// Create a progress bar containing the filename
|
2009-05-17 14:29:58 +02:00
|
|
|
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>');
|
2009-01-10 10:29:39 +01:00
|
|
|
// Display the progress div
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('.progress', '#media-item-' + fileObj.id).show();
|
2009-01-10 10:29:39 +01:00
|
|
|
|
2009-05-17 14:29:58 +02:00
|
|
|
// Disable submit and enable cancel
|
2011-05-25 03:04:12 +02:00
|
|
|
jQuery('#insert-gallery').prop('disabled', true);
|
|
|
|
jQuery('#cancel-upload').prop('disabled', false);
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
2009-05-17 14:29:58 +02:00
|
|
|
function uploadStart(fileObj) {
|
2010-01-07 06:55:26 +01:00
|
|
|
try {
|
|
|
|
if ( typeof topWin.tb_remove != 'undefined' )
|
|
|
|
topWin.jQuery('#TB_overlay').unbind('click', topWin.tb_remove);
|
|
|
|
} catch(e){}
|
|
|
|
|
2009-05-17 14:29:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-10 10:29:39 +01:00
|
|
|
|
2011-07-29 21:21:21 +02:00
|
|
|
function uploadProgress(fileObj, bytesDone, bytesTotal) { // Lengthen the progress bar
|
2009-10-30 08:09:55 +01:00
|
|
|
var w = jQuery('#media-items').width() - 2, item = jQuery('#media-item-' + fileObj.id);
|
2011-07-29 21:21:21 +02:00
|
|
|
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('.bar', item).width( w * bytesDone / bytesTotal );
|
|
|
|
jQuery('.percent', item).html( Math.ceil(bytesDone / bytesTotal * 100) + '%' );
|
2009-01-10 10:29:39 +01:00
|
|
|
|
|
|
|
if ( bytesDone == bytesTotal )
|
2011-07-29 10:59:35 +02:00
|
|
|
jQuery('.bar', item).html('<strong class="crunching">' + pluploadL10n.crunching + '</strong>');
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ( 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 ( 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 ( items.length > 1 )
|
|
|
|
jQuery('.insert-gallery').show();
|
|
|
|
else
|
|
|
|
jQuery('.insert-gallery').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadSuccess(fileObj, serverData) {
|
|
|
|
// if async-upload returned an error message, place it in the media item div and return
|
|
|
|
if ( serverData.match('media-upload-error') ) {
|
|
|
|
jQuery('#media-item-' + fileObj.id).html(serverData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareMediaItem(fileObj, serverData);
|
|
|
|
updateMediaForm();
|
|
|
|
|
|
|
|
// Increment the counter.
|
|
|
|
if ( jQuery('#media-item-' + fileObj.id).hasClass('child-of-' + post_id) )
|
|
|
|
jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1);
|
|
|
|
}
|
|
|
|
|
2011-09-15 07:30:58 +02: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;
|
2011-07-29 10:59:35 +02:00
|
|
|
} else {
|
2011-09-15 07:30:58 +02:00
|
|
|
delete(uploader.settings.resize);
|
|
|
|
delete(uploader.settings.multipart_params.image_resize);
|
2011-07-29 10:59:35 +02:00
|
|
|
}
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepareMediaItem(fileObj, serverData) {
|
2009-10-30 08:09:55 +01:00
|
|
|
var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
|
2009-01-10 10:29:39 +01:00
|
|
|
// Move the progress bar to 100%
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('.bar', item).remove();
|
|
|
|
jQuery('.progress', item).hide();
|
2009-01-10 10:29:39 +01:00
|
|
|
|
2010-01-07 06:55:26 +01:00
|
|
|
try {
|
|
|
|
if ( typeof topWin.tb_remove != 'undefined' )
|
|
|
|
topWin.jQuery('#TB_overlay').click(topWin.tb_remove);
|
|
|
|
} catch(e){}
|
2009-12-27 22:03:54 +01:00
|
|
|
|
2009-01-10 10:29:39 +01:00
|
|
|
// Old style: Append the HTML returned by the server -- thumbnail and form inputs
|
|
|
|
if ( isNaN(serverData) || !serverData ) {
|
2009-10-30 08:09:55 +01:00
|
|
|
item.append(serverData);
|
2009-01-10 10:29:39 +01:00
|
|
|
prepareMediaItemInit(fileObj);
|
|
|
|
}
|
|
|
|
// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
|
|
|
|
else {
|
2009-10-30 08:09:55 +01:00
|
|
|
item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-30 08:09:55 +01:00
|
|
|
function prepareMediaItemInit(fileObj) {
|
|
|
|
var item = jQuery('#media-item-' + fileObj.id);
|
2009-01-10 10:29:39 +01:00
|
|
|
// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
|
2011-05-13 00:00:31 +02:00
|
|
|
jQuery('.thumbnail', item).clone().attr('class', 'pinkynail toggle').prependTo(item);
|
2009-01-10 10:29:39 +01:00
|
|
|
|
|
|
|
// Replace the original filename with the new (unique) one assigned during upload
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
|
2009-01-10 10:29:39 +01:00
|
|
|
|
|
|
|
// Also bind toggle to the links
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('a.toggle', item).click(function(){
|
|
|
|
jQuery(this).siblings('.slidetoggle').slideToggle(350, function(){
|
2009-12-09 13:24:45 +01:00
|
|
|
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);
|
|
|
|
}
|
2009-05-17 14:29:58 +02:00
|
|
|
});
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery(this).siblings('.toggle').andSelf().toggle();
|
2009-05-17 14:29:58 +02:00
|
|
|
jQuery(this).siblings('a.toggle').focus();
|
|
|
|
return false;
|
|
|
|
});
|
2009-01-10 10:29:39 +01:00
|
|
|
|
|
|
|
// Bind AJAX to the new Delete button
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('a.delete', item).click(function(){
|
2009-01-10 10:29:39 +01:00
|
|
|
// Tell the server to delete it. TODO: handle exceptions
|
2009-10-30 08:09:55 +01: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);
|
|
|
|
if ( item.hasClass('child-of-'+post_id) )
|
|
|
|
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1);
|
|
|
|
|
|
|
|
jQuery('.filename .trashnotice', item).remove();
|
2009-11-28 03:56:15 +01:00
|
|
|
jQuery('.filename .title', item).css('font-weight','normal');
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('a.undo', item).addClass('hidden');
|
|
|
|
jQuery('a.describe-toggle-on, .menu_order_input', item).show();
|
2009-11-29 11:29:12 +01:00
|
|
|
item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery(this).css({backgroundColor:''}); } }).removeClass('undo');
|
2009-10-30 08:09:55 +01:00
|
|
|
}
|
|
|
|
});
|
2009-01-10 10:29:39 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Open this item if it says to start open (e.g. to display an error)
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle();
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-29 10:59:35 +02:00
|
|
|
function cancelUpload() {
|
|
|
|
uploader.stop();
|
|
|
|
jQuery.each(uploader.files, function(i,file) {
|
|
|
|
if (file.status == plupload.STOPPED)
|
|
|
|
jQuery('#media-item-' + file.id).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// wp-specific error handlers
|
|
|
|
|
|
|
|
// generic message
|
|
|
|
function wpQueueError(message) {
|
|
|
|
jQuery('#media-upload-error').show().text(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// file-specific message
|
|
|
|
function wpFileError(fileObj, message) {
|
2011-07-29 21:21:21 +02:00
|
|
|
var item = jQuery('#media-item-' + fileObj.id), filename = jQuery('.filename', item).text();
|
2011-07-29 10:59:35 +02:00
|
|
|
|
|
|
|
item.html('<div class="error-div">'
|
|
|
|
+ '<a class="dismiss" href="#">' + pluploadL10n.dismiss + '</a>'
|
|
|
|
+ '<strong>' + pluploadL10n.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();})});
|
|
|
|
}
|
|
|
|
|
2009-01-10 10:29:39 +01:00
|
|
|
function itemAjaxError(id, html) {
|
2011-07-29 21:21:21 +02:00
|
|
|
var item = jQuery('#media-item-' + id), filename = jQuery('.filename', item).text();
|
2010-05-23 12:59:52 +02:00
|
|
|
|
|
|
|
item.html('<div class="error-div">'
|
2011-07-29 10:59:35 +02:00
|
|
|
+ '<a class="dismiss" href="#">' + pluploadL10n.dismiss + '</a>'
|
|
|
|
+ '<strong>' + pluploadL10n.error_uploading.replace('%s', filename) + '</strong><br />'
|
2010-05-23 12:59:52 +02:00
|
|
|
+ html
|
|
|
|
+ '</div>');
|
|
|
|
item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSuccess(data, textStatus) {
|
|
|
|
if ( data == '-1' )
|
|
|
|
return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
|
|
|
|
if ( data == '0' )
|
|
|
|
return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
|
|
|
|
|
2009-10-30 08:09:55 +01:00
|
|
|
var id = this.id, item = jQuery('#media-item-' + id);
|
2009-01-10 10:29:39 +01:00
|
|
|
|
|
|
|
// Decrement the counters.
|
2009-10-30 08:09:55 +01:00
|
|
|
if ( type = jQuery('#type-of-' + id).val() )
|
|
|
|
jQuery('#' + type + '-counter').text( jQuery('#' + type + '-counter').text() - 1 );
|
2009-01-10 10:29:39 +01:00
|
|
|
if ( item.hasClass('child-of-'+post_id) )
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 );
|
2009-01-10 10:29:39 +01:00
|
|
|
|
2009-10-30 08:09:55 +01:00
|
|
|
if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
|
2009-01-10 10:29:39 +01:00
|
|
|
jQuery('.toggle').toggle();
|
|
|
|
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vanish it.
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('.toggle', item).toggle();
|
|
|
|
jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden');
|
2009-11-29 11:29:12 +01:00
|
|
|
item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass('undo');
|
2009-10-30 08:09:55 +01:00
|
|
|
|
|
|
|
jQuery('.filename:empty', item).remove();
|
2009-11-28 03:56:15 +01:00
|
|
|
jQuery('.filename .title', item).css('font-weight','bold');
|
2011-07-29 10:59:35 +02:00
|
|
|
jQuery('.filename', item).append('<span class="trashnotice"> ' + pluploadL10n.deleted + ' </span>').siblings('a.toggle').hide();
|
2009-10-30 08:09:55 +01:00
|
|
|
jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') );
|
|
|
|
jQuery('.menu_order_input', item).hide();
|
2009-12-09 13:24:45 +01:00
|
|
|
|
2009-01-10 10:29:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteError(X, textStatus, errorThrown) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2011-07-29 21:21:21 +02:00
|
|
|
// SWFUpload?
|
2009-01-10 10:29:39 +01:00
|
|
|
function uploadComplete(fileObj) {
|
|
|
|
// If no more uploads queued, enable the submit button
|
2009-05-17 14:29:58 +02:00
|
|
|
if ( swfu.getStats().files_queued == 0 ) {
|
2011-07-29 21:21:21 +02:00
|
|
|
jQuery('#cancel-upload').prop('disabled', true);
|
|
|
|
jQuery('#insert-gallery').prop('disabled', false);
|
2009-05-17 14:29:58 +02:00
|
|
|
}
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
2009-04-04 12:21:43 +02:00
|
|
|
function switchUploader(s) {
|
2011-07-29 10:59:35 +02:00
|
|
|
var p = document.getElementById('flash-upload-ui'), h = document.getElementById('html-upload-ui');
|
2011-07-29 21:21:21 +02:00
|
|
|
|
2009-04-04 12:21:43 +02:00
|
|
|
if ( s ) {
|
2011-07-29 10:59:35 +02:00
|
|
|
p.style.display = 'block';
|
2009-04-04 12:21:43 +02:00
|
|
|
h.style.display = 'none';
|
|
|
|
} else {
|
2011-07-29 10:59:35 +02:00
|
|
|
p.style.display = 'none';
|
2009-04-04 12:21:43 +02:00
|
|
|
h.style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
2009-03-27 09:36:51 +01:00
|
|
|
|
2011-07-29 10:59:35 +02:00
|
|
|
function dndHelper(s) {
|
|
|
|
var d = document.getElementById('dnd-helper');
|
2011-07-29 21:21:21 +02:00
|
|
|
|
2011-07-29 10:59:35 +02:00
|
|
|
if ( s ) {
|
|
|
|
d.style.display = 'block';
|
|
|
|
} else {
|
|
|
|
d.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 21:21:21 +02:00
|
|
|
// SWFUpload?
|
2009-04-04 12:21:43 +02:00
|
|
|
function swfuploadPreLoad() {
|
|
|
|
if ( !uploaderMode ) {
|
|
|
|
switchUploader(1);
|
|
|
|
} else {
|
|
|
|
switchUploader(0);
|
|
|
|
}
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-29 21:21:21 +02:00
|
|
|
// SWFUpload?
|
2009-01-10 10:29:39 +01:00
|
|
|
function swfuploadLoadFailed() {
|
2009-04-04 12:21:43 +02:00
|
|
|
switchUploader(0);
|
|
|
|
jQuery('.upload-html-bypass').hide();
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
|
|
|
|
2009-05-17 14:29:58 +02:00
|
|
|
function uploadError(fileObj, errorCode, message) {
|
2009-10-30 08:09:55 +01:00
|
|
|
|
2009-05-17 14:29:58 +02:00
|
|
|
switch (errorCode) {
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.FAILED:
|
|
|
|
wpFileError(fileObj, pluploadL10n.upload_failed);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.FILE_EXTENSION_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.invalid_filetype);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.FILE_SIZE_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.upload_limit_exceeded);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.IMAGE_FORMAT_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.not_an_image);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.IMAGE_MEMORY_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.image_memory_exceeded);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.IMAGE_DIMENSIONS_ERROR:
|
|
|
|
wpFileError(fileObj, pluploadL10n.image_dimensions_exceeded);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.GENERIC_ERROR:
|
|
|
|
wpQueueError(pluploadL10n.upload_failed);
|
|
|
|
break;
|
|
|
|
case plupload.IO_ERROR:
|
|
|
|
wpQueueError(pluploadL10n.io_error);
|
2009-05-17 14:29:58 +02:00
|
|
|
break;
|
2011-07-29 10:59:35 +02:00
|
|
|
case plupload.HTTP_ERROR:
|
|
|
|
wpQueueError(pluploadL10n.http_error);
|
|
|
|
break;
|
|
|
|
case plupload.INIT_ERROR:
|
|
|
|
switchUploader(0);
|
|
|
|
jQuery('.upload-html-bypass').hide();
|
|
|
|
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 14:29:58 +02:00
|
|
|
default:
|
2011-07-29 10:59:35 +02:00
|
|
|
wpFileError(fileObj, pluploadL10n.default_error);
|
2009-01-10 10:29:39 +01:00
|
|
|
}
|
2009-05-17 14:29:58 +02:00
|
|
|
}
|
2009-01-10 10:29:39 +01:00
|
|
|
|
2009-11-16 02:37:30 +01:00
|
|
|
jQuery(document).ready(function($){
|
2011-09-15 07:30:58 +02:00
|
|
|
// remember the last used image size, alignment and url
|
2009-11-16 02:37:30 +01:00
|
|
|
$('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());
|
2009-01-10 10:29:39 +01:00
|
|
|
});
|
|
|
|
|
2009-11-16 02:37:30 +01:00
|
|
|
$('button.button', '#media-items').live('click', function(){
|
|
|
|
var c = this.className || '';
|
2009-11-16 08:16:34 +01:00
|
|
|
c = c.match(/url([^ '"]+)/);
|
|
|
|
if ( c && c[1] ) {
|
|
|
|
setUserSetting('urlbutton', c[1]);
|
2009-11-16 02:37:30 +01:00
|
|
|
$(this).siblings('.urlfield').val( $(this).attr('title') );
|
|
|
|
}
|
2009-01-10 10:29:39 +01:00
|
|
|
});
|
2011-09-15 07:30:58 +02:00
|
|
|
|
|
|
|
// init and set the uploader
|
|
|
|
uploader_init = function() {
|
|
|
|
uploader = new plupload.Uploader(wpUploaderInit);
|
|
|
|
|
|
|
|
$('#image_resize').bind('change', function() {
|
|
|
|
var arg = $(this).prop('checked');
|
|
|
|
|
|
|
|
setResize( arg );
|
|
|
|
|
|
|
|
if ( arg )
|
|
|
|
setUserSetting('upload_resize', '1');
|
|
|
|
else
|
|
|
|
deleteUserSetting('upload_resize');
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('Init', function(up) {
|
|
|
|
setResize( getUserSetting('upload_resize', false) );
|
|
|
|
|
|
|
|
if ( up.features.dragdrop ) {
|
|
|
|
$('.dragdrop-info').show();
|
|
|
|
|
|
|
|
if ( $('#media-upload').length )
|
|
|
|
up.settings.drop_element = 'media-upload';
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.init();
|
|
|
|
|
|
|
|
uploader.bind('FilesAdded', function(up, files) {
|
|
|
|
$.each(files, function(i, file) {
|
|
|
|
/*
|
|
|
|
if ( up.features.chunks && up.runtime != 'flash' && file.size > 1048576 )
|
|
|
|
up.settings.chunk_size = '1048576';
|
|
|
|
else
|
|
|
|
delete(up.settings.chunk_size);
|
|
|
|
*/
|
|
|
|
|
|
|
|
fileQueued(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
up.refresh();
|
|
|
|
up.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('BeforeUpload', function(up, file) {
|
|
|
|
uploadStart(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('UploadProgress', function(up, file) {
|
|
|
|
uploadProgress(file, file.loaded, file.size);
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('Error', function(up, err) {
|
|
|
|
uploadError(err.file, err.code, err.message);
|
|
|
|
|
|
|
|
up.refresh();
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('FileUploaded', function(up, file, response) {
|
|
|
|
uploadSuccess(file, response.response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof(wpUploaderInit) == 'object' )
|
|
|
|
uploader_init();
|
|
|
|
|
2011-05-13 00:00:31 +02:00
|
|
|
});
|