file-sharing.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <link rel="import" href="../../../bower_components/paper-dialog/paper-dialog.html">
  2. <link rel="import" href="file-reader.html">
  3. <dom-module id="file-sharing">
  4. <template>
  5. <style>
  6. :host {
  7. display: block;
  8. position: fixed;
  9. z-index: 100;
  10. }
  11. </style>
  12. <paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdro>
  13. <h2>File Received</h2>
  14. <p>You received file {{file.name}}</p>
  15. <div class="buttons">
  16. <paper-button dialog-dismiss>Dismiss</paper-button>
  17. <paper-button dialog-confirm on-tap="_download">Download</paper-button>
  18. </div>
  19. </paper-dialog>
  20. </template>
  21. <script>
  22. 'use strict';
  23. Polymer({
  24. is: 'file-sharing',
  25. attached: function() {
  26. document.querySelector('x-app').addEventListener('file-received', function(e) {
  27. this.fileReceived(e.detail);
  28. }.bind(this), false);
  29. },
  30. fileReceived: function(file) {
  31. this.set('file', file);
  32. this.$.dialog.open();
  33. },
  34. _download: function() {
  35. var link = document.createElement('a');
  36. link.download = this.file.name;
  37. // Construct the uri
  38. var uri = this.file.url;
  39. link.href = uri;
  40. document.body.appendChild(link);
  41. link.click();
  42. // Cleanup the DOM
  43. document.body.removeChild(link);
  44. //delete link;
  45. }
  46. });
  47. </script>
  48. </dom-module>