简体   繁体   中英

Bug on Cordova camera plugin

I have code with cordova-camera-plugin below to browse file from mobile device, when I run on device it works only once. On the next try, when I choose a file the dialog does not hide.

Please help me what's wrong with my code.

HTML :

<div data-page="do-job" class="page navbar-fixed">
  <div class="navbar">
    <div class="navbar-inner">
      <div class="left"><a href="index-content.html" class="link icon-only"><i class="icon icon-back"></i></a></div>
      <div class="center"><a href="index-content.html" class="link">Kerjakan Tugas</a></div>
    </div>
  </div>  
    <div id="camerass">
    <div class="page-content">
    <form action="#" id="form">
    <input type="hidden" name="attachment" id="post_image" value="">
    <input type="hidden" name="job_id" id="job_id" value="">
    <div class="list-block inputs-list">
      <ul>  
        <li class="align-top">
          <div class="item-content">
            <div class="item-inner"> 
              <div class="item-title label">Desc</div>
              <div class="item-input">
                <textarea class="resizable isi" name="isi" id="isi" rows="4"  class='required'></textarea>
              </div>
            </div>
          </div>
        </li>
      </ul>
    <div class="image-list">
      <div class="file-chooser">                
        <i class="fagambar2 fa fa-image"></i>
        <i class="fagambar fa fa-plus"></i>
      </div>
    </div>  
    </div>
      <div class="content-block"><a href="#" class="button button-fill kirim_pekerjaan">Send Job</a></div>
    </form>    
  </div>
  </div>

Javasript :

  $(document).on('click','.file-chooser', function (e)
  {
    var ini=$(this);
    ini.attr('disabled',true);
    var html='';
    var opt={
      sourceType:0|2,
      mediaType: Camera.MediaType.ALLMEDIA
    };
    navigator.camera.getPicture(function(imageData){
      console.log(imageData);
      if(isImage(imageData))
      {
        html+='<div class="image-added"  data-src="'+imageData+'" ><img src="'+imageData+'" class="image-kirim-thumbnail"/></div>';
      }else
      {
        html+='<div class="image-added" data-src="'+imageData+'"><i class="fa fa-video-camera"></i> </div>';
      }
        $('.image-list').prepend(html);
        var win = function (r) {
          console.log("Code = ");
          console.log(r);
          var resp=JSON.parse(r.response);

          if(resp.STATUS=='SUCCESS')
          { 
            dataUpload.push(resp.DESCRIPTION);
            $('#post_image').val(dataUpload.toString());
          }
          ini.removeAttr('disabled');
        }
        var fail = function (error) {
          console.log('error');
          console.log(error);
        }
        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = 'file_image.jpg';
        options.httpMethod="POST";
        if(getFileType(imageData)=='image')
        {          
          options.mimeType = 'image/jpeg';
        }else
        {
          options.mimeType = 'video/mp4';
        }

        var params = {};
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;
        var ft = new FileTransfer();
        var path_url=APIPath+'upload_file/uploadFile/'+window.localStorage.getItem('token_id');
        ft.upload(imageData, encodeURI(path_url), win, fail, options);  
    }, function(msg){
      console.log("Error");
      console.log(msg);
    },opt);
 
  });

I have found the answer for my problem,

The problem is, the element listen more than one click event. So i add a variable called cameraMode. When

if(kameraMode===true)
{

  kamera.getPicture(function(imageData){
  kameraMode=false;

.............................

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM