file-sharing-button-behavior.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <script>
  2. 'use strict';
  3. Chat.FileSharingButtonBehavior = {
  4. properties: {
  5. file: {
  6. type: String
  7. }
  8. },
  9. get fileInput(){
  10. var fileInput=document.querySelector('input');
  11. },
  12. attached: function() {
  13. this.$.file.onchange = function(value) {
  14. this.file = this.$.file.value;
  15. console.log(this.file);
  16. var files = this.$.file.files;
  17. for (var i = 0; i < files.length; i++) {
  18. var file = files[i];
  19. var reader = new FileReader();
  20. reader.onload = function(e2) {
  21. // finished reading file data.
  22. console.log('file dropped');
  23. this.fire('file-uploaded', {
  24. url: e2.target.result,
  25. name: file.name
  26. });
  27. }.bind(this);
  28. reader.readAsDataURL(file); // start reading the file data.
  29. }
  30. }.bind(this);
  31. },
  32. _upload: function() {
  33. this.$.file.click();
  34. }
  35. };
  36. </script>