anchor.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template lang="pug">
  2. .modal(v-bind:class='{ "is-active": isShown }')
  3. .modal-background
  4. .modal-container
  5. .modal-content
  6. header.is-blue
  7. span Copy link to this section
  8. section
  9. p.control.is-fullwidth
  10. input.input(type='text', ref='anchorURLinput', v-model='anchorURL')
  11. footer
  12. a.button.is-grey.is-outlined(v-on:click='cancel') Discard
  13. a.button.is-blue(v-clipboard='anchorURL', @success="clipboardSuccess", @error="clipboardError") Copy to Clipboard
  14. </template>
  15. <script>
  16. export default {
  17. name: 'anchor',
  18. data () {
  19. return {}
  20. },
  21. computed: {
  22. anchorURL () {
  23. return window.location.href.split('#')[0] + '#' + this.$store.state.anchor.hash
  24. },
  25. isShown () {
  26. return this.$store.state.anchor.shown
  27. }
  28. },
  29. methods: {
  30. cancel () {
  31. this.$store.dispatch('anchorClose')
  32. },
  33. clipboardSuccess () {
  34. this.$store.dispatch('alert', {
  35. style: 'blue',
  36. icon: 'clipboard',
  37. msg: 'The URL has been copied to your clipboard.'
  38. })
  39. this.$store.dispatch('anchorClose')
  40. },
  41. clipboardError () {
  42. this.$store.dispatch('alert', {
  43. style: 'red',
  44. icon: 'clipboard',
  45. msg: 'Clipboard copy failed. Copy the URL manually.'
  46. })
  47. this.$refs.anchorURLinput.select()
  48. }
  49. }
  50. }
  51. </script>