Wordpress/wp-includes/js/plupload/handlers.js
2011-07-29 08:59:35 +00:00

23 lines
9.0 KiB
JavaScript

var topWin=window.dialogArguments||opener||parent||top;function fileDialogStart(){jQuery("#media-upload-error").empty()}
function fileQueued(a){jQuery(".media-blank").remove();jQuery("form.type-form #media-items").children().length==1&&jQuery(".hidden","#media-items").length>0&&(jQuery(".describe-toggle-on").show(),jQuery(".describe-toggle-off").hide(),jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden"));jQuery("#media-items").append('<div id="media-item-'+a.id+'" class="media-item child-of-'+post_id+'"><div class="progress"><div class="bar"></div></div><div class="filename original"><span class="percent"></span> '+
a.name+"</div></div>");jQuery(".progress","#media-item-"+a.id).show();jQuery("#insert-gallery").attr("disabled","disabled");jQuery("#cancel-upload").attr("disabled","")}function uploadStart(){try{typeof topWin.tb_remove!="undefined"&&topWin.jQuery("#TB_overlay").unbind("click",topWin.tb_remove)}catch(a){}return!0}
function uploadProgress(a,b,c){var d=jQuery("#media-items").width()-2,a=jQuery("#media-item-"+a.id);jQuery(".bar",a).width(d*b/c);jQuery(".percent",a).html(Math.ceil(b/c*100)+"%");b==c&&jQuery(".bar",a).html('<strong class="crunching">'+pluploadL10n.crunching+"</strong>")}
function updateMediaForm(){var a=jQuery("form.type-form #media-items").children(),b=jQuery("#media-items").children();a.length==1&&jQuery(".slidetoggle",a).slideDown(500).siblings().addClass("hidden").filter(".toggle").toggle();b.not(".media-blank").length>0?jQuery(".savebutton").show():jQuery(".savebutton").hide();b.length>1?jQuery(".insert-gallery").show():jQuery(".insert-gallery").hide()}
function uploadSuccess(a,b){b.match("media-upload-error")?jQuery("#media-item-"+a.id).html(b):(prepareMediaItem(a,b),updateMediaForm(),jQuery("#media-item-"+a.id).hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1))}
function setResize(a){jQuery("#image_resize").prop("checked",a);a?(uploader.settings.resize={width:resize_width,height:resize_height,quality:100},uploader.settings.multipart_params.image_resize=!0):(uploader.settings.resize={},uploader.settings.multipart_params.image_resize=null)}
function prepareMediaItem(a,b){var c=typeof shortform=="undefined"?1:2,d=jQuery("#media-item-"+a.id);jQuery(".bar",d).remove();jQuery(".progress",d).hide();try{typeof topWin.tb_remove!="undefined"&&topWin.jQuery("#TB_overlay").click(topWin.tb_remove)}catch(e){}isNaN(b)||!b?(d.append(b),prepareMediaItemInit(a)):d.load("async-upload.php",{attachment_id:b,fetch:c},function(){prepareMediaItemInit(a);updateMediaForm()})}
function prepareMediaItemInit(a){var b=jQuery("#media-item-"+a.id);jQuery(".thumbnail",b).clone().attr("class","pinkynail toggle").prependTo(b);jQuery(".filename.original",b).replaceWith(jQuery(".filename.new",b));jQuery("a.toggle",b).click(function(){jQuery(this).siblings(".slidetoggle").slideToggle(350,function(){var a=jQuery(window).height(),b=jQuery(this).offset().top,e=jQuery(this).height(),f;a&&b&&e&&(f=b+e,f>a&&e+48<a?window.scrollBy(0,f-a+13):f>a&&window.scrollTo(0,b-36))});jQuery(this).siblings(".toggle").andSelf().toggle();
jQuery(this).siblings("a.toggle").focus();return!1});jQuery("a.delete",b).click(function(){jQuery.ajax({url:"admin-ajax.php",type:"post",success:deleteSuccess,error:deleteError,id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"trash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")}});return!1});jQuery("a.undo",b).click(function(){jQuery.ajax({url:"admin-ajax.php",type:"post",id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"untrash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,
"")},success:function(){var b=jQuery("#media-item-"+a.id);(type=jQuery("#type-of-"+a.id).val())&&jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-0+1);b.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-0+1);jQuery(".filename .trashnotice",b).remove();jQuery(".filename .title",b).css("font-weight","normal");jQuery("a.undo",b).addClass("hidden");jQuery("a.describe-toggle-on, .menu_order_input",b).show();b.css({backgroundColor:"#ceb"}).animate({backgroundColor:"#fff"},
{queue:!1,duration:500,complete:function(){jQuery(this).css({backgroundColor:""})}}).removeClass("undo")}});return!1});jQuery("#media-item-"+a.id+".startopen").removeClass("startopen").slideToggle(500).siblings(".toggle").toggle()}function cancelUpload(){uploader.stop();jQuery.each(uploader.files,function(a,b){b.status==plupload.STOPPED&&jQuery("#media-item-"+b.id).remove()})}function wpQueueError(a){jQuery("#media-upload-error").show().text(a)}
function wpFileError(a,b){var c=jQuery("#media-item-"+a.id),d=jQuery(".filename",c).text();c.html('<div class="error-div"><a class="dismiss" href="#">'+pluploadL10n.dismiss+"</a><strong>"+pluploadL10n.error_uploading.replace("%s",d)+"</strong><br />"+b+"</div>");c.find("a.dismiss").click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}
function itemAjaxError(a,b){var c=jQuery("#media-item-"+a),d=jQuery(".filename",c).text();c.html('<div class="error-div"><a class="dismiss" href="#">'+pluploadL10n.dismiss+"</a><strong>"+pluploadL10n.error_uploading.replace("%s",d)+"</strong><br />"+b+"</div>");c.find("a.dismiss").click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}
function deleteSuccess(a){if(a=="-1")return itemAjaxError(this.id,"You do not have permission. Has your session expired?");if(a=="0")return itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?");var a=this.id,b=jQuery("#media-item-"+a);(type=jQuery("#type-of-"+a).val())&&jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-1);b.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1);jQuery("form.type-form #media-items").children().length==
1&&jQuery(".hidden","#media-items").length>0&&(jQuery(".toggle").toggle(),jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden"));jQuery(".toggle",b).toggle();jQuery(".slidetoggle",b).slideUp(200).siblings().removeClass("hidden");b.css({backgroundColor:"#faa"}).animate({backgroundColor:"#f4f4f4"},{queue:!1,duration:500}).addClass("undo");jQuery(".filename:empty",b).remove();jQuery(".filename .title",b).css("font-weight","bold");jQuery(".filename",b).append('<span class="trashnotice"> '+
pluploadL10n.deleted+" </span>").siblings("a.toggle").hide();jQuery(".filename",b).append(jQuery("a.undo",b).removeClass("hidden"));jQuery(".menu_order_input",b).hide()}function deleteError(){}function uploadComplete(){swfu.getStats().files_queued==0&&(jQuery("#cancel-upload").attr("disabled","disabled"),jQuery("#insert-gallery").attr("disabled",""))}function wpQueueError(a){jQuery("#media-upload-error").show().text(a)}
function wpFileError(a,b){var c=jQuery("#media-item-"+a.id),d=jQuery(".filename",c).text();c.html('<div class="error-div"><a class="dismiss" href="#">'+pluploadL10n.dismiss+"</a><strong>"+pluploadL10n.error_uploading.replace("%s",d)+"</strong><br />"+b+"</div>");c.find("a.dismiss").click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}
function switchUploader(a){var b=document.getElementById("flash-upload-ui"),c=document.getElementById("html-upload-ui");a?(b.style.display="block",c.style.display="none"):(b.style.display="none",c.style.display="block")}function dndHelper(a){document.getElementById("dnd-helper").style.display=a?"block":"none"}function swfuploadPreLoad(){uploaderMode?switchUploader(0):switchUploader(1)}function swfuploadLoadFailed(){switchUploader(0);jQuery(".upload-html-bypass").hide()}
function uploadError(a,b){switch(b){case plupload.FAILED:wpFileError(a,pluploadL10n.upload_failed);break;case plupload.FILE_EXTENSION_ERROR:wpFileError(a,pluploadL10n.invalid_filetype);break;case plupload.FILE_SIZE_ERROR:wpFileError(a,pluploadL10n.upload_limit_exceeded);break;case plupload.IMAGE_FORMAT_ERROR:wpFileError(a,pluploadL10n.not_an_image);break;case plupload.IMAGE_MEMORY_ERROR:wpFileError(a,pluploadL10n.image_memory_exceeded);break;case plupload.IMAGE_DIMENSIONS_ERROR:wpFileError(a,pluploadL10n.image_dimensions_exceeded);
break;case plupload.GENERIC_ERROR:wpQueueError(pluploadL10n.upload_failed);break;case plupload.IO_ERROR:wpQueueError(pluploadL10n.io_error);break;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;default:wpFileError(a,pluploadL10n.default_error)}}
jQuery(document).ready(function(a){a('input[type="radio"]',"#media-items").live("click",function(){var b=a(this).closest("tr");a(b).hasClass("align")?setUserSetting("align",a(this).val()):a(b).hasClass("image-size")&&setUserSetting("imgsize",a(this).val())});a("button.button","#media-items").live("click",function(){var b=this.className||"";if((b=b.match(/url([^ '"]+)/))&&b[1])setUserSetting("urlbutton",b[1]),a(this).siblings(".urlfield").val(a(this).attr("title"))})});