Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binded File Input Support #75

Open
lodev09 opened this issue Jul 6, 2016 · 3 comments
Open

Binded File Input Support #75

lodev09 opened this issue Jul 6, 2016 · 3 comments
Assignees
Projects
Milestone

Comments

@lodev09
Copy link

lodev09 commented Jul 6, 2016

In github comment box, you have the option to drag/drop, paste or select file/images. This plugin lacks the "select" using file input.

I achieved this by directly modifying a dist js (jquery version) by adding the option bindedFileInput. This should trigger the upload when change event occurs on the input element. I'm not that familiar with grunt/npm and don't have the time implement a build so if your kind enough to add this bits of code for me that would be awesome.

init (jquery)

if (typeof options.bindedFileInput != 'undefined') {
  var $input = typeof options.bindedFileInput === 'string' ? $(options.bindedFileInput) : options.bindedFileInput;
  $input.bind('change', function(e) {
    inlineattach.onBindedFileInputChange(e.originalEvent);
  });
}

inside class definition

 /**
 * called on bindedFileInput change event occured
 * @param {Event} e
 * @return {Boolean} if the event was handled
 */
inlineAttachment.prototype.onBindedFileInputChange = function(e) {
  var result = false,
    files = e.target.files || [];

  for (var i = 0; i < files.length; i++) {
    var file = files[i];
    if (this.isFileAllowed(file)) {
      result = true;
      this.onFileInserted(file);
      this.uploadFile(file);
    }
  }

  if (result) { e.preventDefault(); }

  return result;
}

add the option to defaults

/**
 * Binded File Input element to trigger uploaded when changed
 */
bindedFileInput: undefined,

great plugin btw.

@kylethielk
Copy link

@lodev09 thanks for posting this. Exactly what I was looking for and worked like a charm.

@Rovak Rovak added this to the 3.0 milestone Oct 25, 2016
@Rovak
Copy link
Owner

Rovak commented Oct 25, 2016

I'll add this to version 3.0

@Rovak Rovak self-assigned this Oct 25, 2016
@lodev09
Copy link
Author

lodev09 commented Oct 25, 2016

no problem @kylethielk glad I could help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants