file-button-behavior.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <link rel="import" href="file-selection-behavior.html">
  2. <script>
  3. 'use strict';
  4. window.Chat = window.Chat || {};
  5. Chat.FileButtonBehaviorImpl = {
  6. get fileInput() {
  7. var fileInput = Polymer.dom(this).querySelector('.fileInput');
  8. if (!fileInput) {
  9. fileInput = document.createElement('input');
  10. fileInput.type = 'file';
  11. fileInput.multiple = 'true';
  12. fileInput.className = 'fileInput';
  13. fileInput.style.position = 'fixed';
  14. fileInput.style.top = '-10000px';
  15. fileInput.style.left = '-10000px';
  16. fileInput.style.opacity = 0;
  17. Polymer.dom(this).appendChild(fileInput);
  18. }
  19. return fileInput;
  20. },
  21. attached: function() {
  22. this.fileInput.onchange = function() {
  23. var files = this.fileInput.files;
  24. this.notifyFilesSelection(files);
  25. }.bind(this);
  26. this.addEventListener('click', function(e) {
  27. var button = e.which || e.button;
  28. if (button !== 1) {
  29. return;
  30. }
  31. this.fileInput.value = null;
  32. this.fileInput.click();
  33. }.bind(this), false);
  34. }
  35. };
  36. Chat.FileButtonBehavior = [Chat.FileButtonBehaviorImpl, Chat.FileSelectionBehavior];
  37. </script>