Событие клика для прикрепления файлов, ссылка не привязана в Firefox - PullRequest
0 голосов
/ 26 марта 2011

Пока загрузка работает в Chrome в Linux, OSX и Windows, а также в IE в Windows, но в Firefox происходит сбой для всех ОС.

Кажется, что проблема заключается в том, что к приложенному файлу не привязано ни одно событиессылка, которую можно увидеть при использовании плагина Visual Event Аллана Джардина.

Однако в онлайн-демо http://plupload.com/example_custom.php, событие, связанное с событием click, можно увидеть с помощью плагина.

Любая идея, почему Firefox терпит неудачу в этом случае?

<form action="/notes" class="new_note" data-remote="true" id="new_note" method="post">
  <h3>Create Note</h3>
  <textarea cols="40" id="note_content" name="note[content]" rows="1"></textarea>
  <table>
    <tr>
      <td id='attachments'>
        <a href="#" id="attach-files" style="display:none">Add Attachment</a>
        <a href="#" id="upload-files" style="display:none">Upload Files</a>
      </td>
      <td id='button'>
        <input class="button button-green" disabled="disabled" id="note_submit" name="commit" type="submit" value="Post Note" />
      </td>
    </tr>
  </table>
</form>

javascript

bind_plupload: function(url) {
  // plupload setup
  var uploader = new plupload.Uploader({
    runtimes : 'html5,flash,silverlight',
    browse_button : 'attach-files',
    container : 'attachments',
    max_file_size : '2mb',
    url : url,
    multipart: true,   
    flash_swf_url : '/javascripts/plugins/plupload/plupload.flash.swf',
    silverlight_xap_url : '/javascripts/plugins/plupload/plupload.silverlight.xap',
    filters : [
      {title : "Images", extensions : "jpg,gif,png"},
      {title : "Documents", extensions : "pdf,doc,docx,odt,txt,xls"}
    ]
  });

  // push files to server after file is selected
  if ($.browser.msie) {
    $("#upload-files").show().click(function() {
      uploader.start();
      return false;
    });
  }
  else {
    $("#upload-files").remove()
    $(":file").live("change", function(e) {
      uploader.start();
    });
  }

  uploader.bind('FilesAdded', function(up, files) {
    $.each(files, function(i, file) {
      var msg = sprintf("<div id=\"%s\">%s <b></b></div>", file.id, file.name);
      $('#attachments').append(msg);
    });
    up.refresh(); // Reposition Flash/Silverlight
  });

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

  uploader.bind('Error', function(up, err) {
    var msg = sprintf("<div>%s%s</div>", err.message, (err.file ? " "+err.file.name : ""))
    $('#attachments').append(msg);
    up.refresh(); // Reposition Flash/Silverlight
  });

  uploader.bind('FileUploaded', function(up, file) {
    $('#' + file.id + " b").html("100%");
  });

  uploader.init();
} // bind plupload

Ответы [ 2 ]

0 голосов
/ 01 апреля 2011

В Firefox, когда идентификатор 'attachments' был перемещен из элемента во вновь вложенный тег, все работало.

<td>
    <div id='attachments'>
        <a href="#" id="attach-files" style="display:none">Add Attachment</a>
        <a href="#" id="upload-files" style="display:none">Upload Files</a>
    </div>
</td>

Я думаю, это будет считаться ошибкой.

0 голосов
/ 26 марта 2011

Идентификаторы не должны содержать дефисы.

Попробуйте изменить идентификаторы на attach_files, upload_files и т. Д. И посмотрите, работает ли он.

Nevermind. (См. Комментарии.)

...