我正在尝试为Wordpress创建一个图库插件,我正在使用Plupload上传一些图片。
在用户上传新图库的图片之前,必须添加图库名称。由于我正在使用拖放操作,如果库名称为空,我需要中止文件上传。
我尝试了各种解决方案,但我无法停止文件上传(我认为)。
在我的SJ脚本的底部,我正在检查dragover
。我想要中止的地方标有//HERE FILE UPLOAD MUST ABORT
。
但我不确定这是不是正确的地方。谁能告诉我哪里可以中止dragover上传(并放弃)?
// PHP code - I'm adding this data here, because I need some WP data
function plupload_init() {
//$image_size = get_option('sim_gallery_max_width_height');
$plupload_arr = array(
'runtimes' => 'html5,silverlight,flash,html4,browserplus,gears',
'browse_button' => 'plupload-browse-button', // will be adjusted per uploader
'container' => 'plupload-upload-ui', // will be adjusted per uploader
'drop_element' => 'drag-drop-area', // will be adjusted per uploader
'file_data_name' => 'async-upload', // will be adjusted per uploader
'multiple_queues' => true,
'max_file_size' => wp_max_upload_size() . 'b',
'url' => admin_url('admin-ajax.php'),
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
'filters' => array(array('title' => __('Image files'), 'extensions' => 'jpg,jpeg,gif,png')),
'multipart' => true,
'urlstream_upload' => true,
'multi_selection' => false, // will be added per uploader
// additional post data to send to our ajax hook
'multipart_params' => array(
'_ajax_nonce' => "", // will be added per uploader
'action' => 'plupload_action', // the ajax action name
'imgid' => 0 // will be added per uploader
)
);
?>
<script type="text/javascript">
var plupload_config_vars = <?php echo json_encode($plupload_arr); ?>;
</script>
<?php
}
// JS scrip
function init_image_upload() {
if(jQuery('#image-upload').length == 0)
return;
var plupload_config = JSON.parse(JSON.stringify(plupload_config_vars));
var uploader = new plupload.Uploader(plupload_config);
// Control gallery name
control_gallery_name();
uploader.bind('Init', function(up){});
uploader.init();
// a file was added in the queue
uploader.bind('FilesAdded', function(up, files){
});
// Change border color on drop zone
function drop_area_visual_feedback(up) {
var uploaddiv = jQuery('#plupload-upload-ui');
if ( up.features.dragdrop) {
uploaddiv.addClass('drag-drop');
jQuery('#drag-drop-area').bind('dragover.wp-uploader', function(){ // dragenter doesn't fire right :(
if(!jQuery('input[name="gallery-name"]').val()) {
jQuery('label.missing-name').removeClass('hidden');
//HERE FILE UPLOAD MUST ABORT
} else {
uploaddiv.addClass('drag-over');
}
}).bind('dragleave.wp-uploader, drop.wp-uploader', function(){
uploaddiv.removeClass('drag-over');
});
} else {
uploaddiv.removeClass('drag-drop');
jQuery('#drag-drop-area').unbind('.wp-uploader');
}
}
}
答案 0 :(得分:1)
您是否尝试过将代码放在FilesAdded处理程序中,就像这样?
// a file was added in the queue
uploader.bind('FilesAdded', function(up, files){
if(!jQuery('input[name="gallery-name"]').val()) {
jQuery('label.missing-name').removeClass('hidden');
up.splice(0);
}
});