plupload智能手机和平板电脑浏览按钮事件不解雇

时间:2016-04-29 12:11:26

标签: javascript twitter-bootstrap javascript-events smartphone plupload

我在metronic bootstrap框架上使用plupload。在桌面上它可以正常工作但在智能手机或平板电脑上,我的浏览按钮没有打开窗口来选择文件。

<div class="col-md-8">
    <div id="engine"></div>
    <div id="dev_uploader">
    <div id="filelist"></div>
</div>
<a id="addImg" class="btn btn-bg btn-block"><i class="fa fa-plus"></i> add attachement</a>

这是plupload脚本:

jQuery(function() {
    var uploader = new plupload.Uploader({
        runtimes : 'html5,flash,silverlight,gears',
        browse_button : 'addImg',
        container : 'dev_uploader',
        drop_element : 'dev_uploader',
        max_file_size : '10mb',
        chunk_size: '1mb',
        url : '/upload.php',
        flash_swf_url : '/js/plupload/Moxie.swf',
        silverlight_xap_url : '/js/plupload/Moxie.xap',
        filters : [{
            title : "Images",
            extensions : "jpg,png,pdf"
        }],
        dragdrop: true,
        multi_selection: false
    });

    uploader.bind('Init', function(up, params) {
        jQuery('#engine').html("Current runtime: " + params.runtime);

        if (uploader.features.dragdrop) {

            var target = $("devis_uploader");

            target.ondragover = function(event) {
                event.dataTransfer.dropEffect = "copy";
            };

            target.ondragenter = function() {
                this.className = "dragover";
            };

            target.ondragleave = function() {
                this.className = "";
            };

            target.ondrop = function() {
                this.className = "";
            };
        }

    });

    uploader.init();

    // identify image div to refresh
    uploader.bind('BeforeUpload', function (up, file) {
        uploader.settings.multipart_params = {
            site : '{$site.id}',
            page : 'tender',
            code : '{$newcode}',
            id   : file.id
        }
    });

    // after files added
    uploader.bind('FilesAdded', function(up, files) {
        imgs = files;
        jQuery.each(files, function(i, file) {
            //var ext = file.name.substr(file.name.lastIndexOf('.') + 1);
            jQuery('#filelist').append(
                '<div id="' + file.id 
                + '" class="filethumb new"><span>' 
                + '(' + plupload.formatSize(file.size) 
                + ')</span> | <b>0%</b></div>'
            );
        });

        //uploader.settings.multipart_params["id"] = i;
        uploader.start();

        //e.preventDefault();
        up.refresh(); // Reposition Flash/Silverlight
    });

    uploader.bind('UploadProgress', function(up, file) {
        jQuery('#' + file.id + " b").html(file.percent + "%");
    });

    uploader.bind('Error', function(up, err) {
        if(err.file) {
            jQuery('#' + err.file.id).html('<i data-original-title="' + response.error.message +
            '" id="popinfo' + file.id + '" style="color: #CCC" class="fa fa-exclamation-triangle fa-4x" data-toggle="tooltip" data-placement="top" title=""></i>');
        }
        jQuery('#popinfo' + file.id).tooltip();
        up.refresh();
    });

    uploader.refresh();
});

我是否需要绑定特定于移动设备的事件才能让我的设备进行浏览?

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

解决方案是让我手动触发按钮上的事件:

https://stackoverflow.com/a/28592812/2282880