You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0 KiB

  1. <template lang="pug">
  2. div.preview
  3. object(v-if="isPDF", v-bind:data="url", type="application/pdf")
  4. embed(v-bind:src="url", type="application/pdf")
  5. iframe(v-else-if="isWord", v-bind:src="officeViewer")
  6. iframe(v-else, v-bind:src="url")
  7. </template>
  8. <style scoped>
  9. .preview, object, iframe {
  10. width: 100%;
  11. height: 100%;
  12. }
  13. </style>
  14. <script>
  15. export default {
  16. props: {
  17. url: {
  18. type: String,
  19. default: '',
  20. },
  21. },
  22. computed: {
  23. fileExtension() {
  24. const filename = new URL(this.url).pathname.split('/').pop();
  25. const extension = filename.match(/[^#?]+/)[0].split('.').pop();
  26. return extension.toLowerCase();
  27. },
  28. isPDF() {
  29. return this.fileExtension === 'pdf';
  30. },
  31. isWord() {
  32. return [
  33. 'doc',
  34. 'dot',
  35. 'docx',
  36. 'docm',
  37. 'dotm',
  38. ].indexOf(this.fileExtension) !== -1;
  39. },
  40. officeViewer() {
  41. return `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(this.url)}`;
  42. },
  43. },
  44. };
  45. </script>