1

我正在尝试为 Wordpress 创建一个图库插件,并且正在使用Plupload上传一些图像。

在用户上传新图库的图像之前,必须添加图库名称。由于我使用拖放,如果画廊名称为空,我需要中止文件上传。

我尝试了各种解决方案,但我无法停止文件上传(我认为)。

在我的 SJ 脚本的底部,我正在检查dragover. 我想中止的地方标有//HERE FILE UPLOAD MUST ABORT

但我不确定这是否是正确的地方。谁能告诉我在哪里可以中止dragover(和drop)上的上传?

// 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');
        }
    }
}
4

1 回答 1

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);
        }
});
于 2013-02-20T08:56:15.893 回答