12

这是用于在我的 Rails 应用程序中触发 Plupload 的代码:

<% content_for :deferred_js do %>
    $("#uploader").pluploadQueue({  
        runtimes : 'gears,html5,flash,browserplus,silverlight,html4',
           url : '/uploads.js',
           //browse_button : 'pickfiles',
           max_file_size : '10mb',
           chunk_size : '2mb',
           unique_names : false,
           container: 'uploader',
           autostart: true,
           //RoR - make sure form is multipart
           //multipart: true,

           // Specify what files to browse for
           filters : [
             {title : "Image files", extensions : "jpg,gif,png,bmp"}
           ],

            // PreInit events, bound before any internal events
            preinit : {

        UploadFile: function(up, file) {
    up.settings.multipart_params = {"upload[stage_id]" :    compv.steps.selectedStage.getID(), "authenticity_token" : compv.tools.csrf_token()};
                }
            },

            // Post init events, bound after the internal events
            init : {

                FilesAdded: function(up, files) {
                    // Called when files are added to queue
                    up.start();
                },


                FileUploaded: function(up, file, info) {
                    // Called when a file has finished uploading
                    console.log('[FileUploaded] File:', file, "Info:", info);
                    info.responseText = info.response;
                    compv.updateStepView('upload', info);
                    $('tr[data-upload] td.selectable-step').each(function(index){
                        compv.steps.selectedUpload.primeUploadDisplay($(this));
                    });
                },

                Error: function(up, args) {
                    // Called when an error has occured
                    up.stop();
                    compv.tools.clientError();
                }
            },

           // Flash settings
           flash_swf_url : '/plupload/js/plupload.flash.swf',

           // Silverlight settings
           silverlight_xap_url : '/plupload/js/plupload.silverlight.xap'
         });
         compv.steps.selectedUpload.uploader = $('div#uploader').pluploadQueue();
         //compv.steps.selectedUpload.uploader.init();

         // Client side form validation
         $('form#new_upload').submit(function(e) {
           var uploader = $('#uploader').pluploadQueue();

           // Validate number of uploaded files
           if (uploader.total.uploaded == 0) {
             // Files in queue upload them first
             if (uploader.files.length > 0) {
               // When all files are uploaded submit form
               uploader.bind('UploadProgress', function() {
                 if (uploader.total.uploaded == uploader.files.length)
                   $('form').submit();
               });

               uploader.start();
             } else
                $('div#upload-empty-dialog').dialog("open");
             e.preventDefault();
           }
      });
    $('div#upload-empty-dialog').dialog({modal:true, autoOpen: false, minWidth: 325, buttons: { "Ok": function() { $(this).dialog("close"); } }});
    $('div#upload-cancel-dialog').dialog({modal:true, autoOpen: false, minWidth: 325});
<% end %>
<div class="dialog" id="upload-empty-dialog" title="No Files">
<p>You must select files to upload first.</p>
</div>
<div class="dialog" id="upload-cancel-dialog" title="Cancel Uploading?">
<p>Do you want to stop uploading these images? Any images which have not been uploaded will be lost.</p>
</div>

有什么明显的跳出可能导致这种情况吗?

Edit1:顺便说一句,当我尝试这个上传表单时 - http://jsfiddle.net/Atpgu/1/ - 添加文件按钮在 Chrome 和 FF 上都会为我触发 - 所以我怀疑它与我的 JS 有关,我只是不知道是什么。

Edit2:这就是定义compv。我知道这有点冗长,我打算减少它 - 但决定不冒删除重要内容的风险。

var compv = {
    exists: true,
    tools: { exists: true,
         csrf_param : null,
         csrf_token : null},
    comments: { exists: true,
            updateView: null,
            selectImage: null,
            upvote:null,
            downvote:null,
            showVotes:null,
            getUploadID: function(element){
                    return $(element).parents("li").attr("data-upload-id");
                }},
    steps: { exists: true,
         selectFn:{},
         selectedClass: "selected-step",
         selectableClass: "selectable-step",
         selectedClient: { element: null,
                           id: null,
                   stepType: "client",
                   ajaxSuccess: null },
         selectedProject: { element: null,
                    id: null,
                    stepType: "project",
                            ajaxSuccess: null },
            selectedStage: { element: null,
                  id: null,
                  stepType: "stage",
                  ajaxSuccess: null,
                  getID: function(){
                    return compv.steps.selectedStage.id;
                        },
                  displayCompare: function(){
                    window.open($(this).attr('data-url'), "_blank");
                    }},
             selectedUpload: { element: null,
                  id: null,
                  stepType: "image",
                      primeUploadDisplay: null,
                  ajaxSuccess: null,
                  uploader: null,
                  noCloseDialog: false} }
};
4

4 回答 4

34

Plupload 没有正确渲染隐藏元素,这就是为什么它应该在显示后刷新。在给定的示例中,打开 DIALOG 后,应添加几行代码:

var uploader = $('#uploader').pluploadQueue();
uploader.refresh();

我注意到,在 chrome 中,为输入容器正确设置 z-index 存在问题。要解决此问题,只需在前两行之后添加另一行:

$('#uploader > div.plupload').css('z-index','99999');
于 2011-03-30T09:07:18.440 回答
3

通过将browse_button(=选择文件按钮)的css设置为更高的z-index(z-index:99999),您可以更轻松地使用Chrome解决这个问题!

卢西安

于 2012-11-20T11:10:19.477 回答
2

我知道这是一个老问题,但似乎 z-index 问题在 plupload 的更高版本(1.5.2)中仍然存在。

问题是由plupload.html5.js专门为 Webkit 浏览器更改“添加文件”按钮的 z-index 的代码引起的,这样做会破坏:

zIndex = parseInt(plupload.getStyle(browseButton, 'z-index'), 10);
if (isNaN(zIndex)) {
    zIndex = 0;
}

plupload.extend(browseButton.style, {
    zIndex : zIndex
});

plupload.extend(inputContainer.style, {
    zIndex : zIndex - 1
});

如果您查看 DOM,您将看到它style="z-index: 0;"被添加到#uploader_browser锚元素中,并且包含“添加文件”按钮的 div 的 z-index 为 -1,这有效地将其隐藏在页面后面(取决于您的页面 z-index课程)。

为了解决这个问题,我将上述文件中的 zIndex 值设置为高于显示 plupload div 的页面的值。

于 2012-01-18T22:38:21.770 回答
1

Deele 的 css 解决方案很好,但更好的是这样做:

$('#uploader > div.plupload input').css('z-index','99999');

这样按钮的悬停不会被破坏......

于 2013-05-22T00:30:00.923 回答