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.

106 lines
4.3 KiB

  1. <template lang="pug">
  2. v-list(nav, dense)
  3. v-list-item(@click='', ref='copyUrlButton')
  4. v-icon(color='grey', small) mdi-content-copy
  5. v-list-item-title.px-3 Copy URL
  6. v-list-item(:href='`mailto:?subject=` + encodeURIComponent(title) + `&body=` + encodeURIComponent(url) + `%0D%0A%0D%0A` + encodeURIComponent(description)')
  7. v-icon(color='grey', small) mdi-email-outline
  8. v-list-item-title.px-3 Email
  9. v-list-item(@click='openSocialPop(`https://www.facebook.com/sharer/sharer.php?u=` + encodeURIComponent(url) + `&title=` + encodeURIComponent(title) + `&description=` + encodeURIComponent(description))')
  10. v-icon(color='grey', small) mdi-facebook-box
  11. v-list-item-title.px-3 Facebook
  12. v-list-item(@click='openSocialPop(`https://www.linkedin.com/shareArticle?mini=true&url=` + encodeURIComponent(url) + `&title=` + encodeURIComponent(title) + `&summary=` + encodeURIComponent(description))')
  13. v-icon(color='grey', small) mdi-linkedin-box
  14. v-list-item-title.px-3 LinkedIn
  15. v-list-item(@click='openSocialPop(`https://www.reddit.com/submit?url=` + encodeURIComponent(url) + `&title=` + encodeURIComponent(title))')
  16. v-icon(color='grey', small) mdi-reddit
  17. v-list-item-title.px-3 Reddit
  18. v-list-item(@click='openSocialPop(`https://t.me/share/url?url=` + encodeURIComponent(url) + `&text=` + encodeURIComponent(title))')
  19. v-icon(color='grey', small) mdi-telegram
  20. v-list-item-title.px-3 Telegram
  21. v-list-item(@click='openSocialPop(`https://twitter.com/intent/tweet?url=` + encodeURIComponent(url) + `&text=` + encodeURIComponent(title))')
  22. v-icon(color='grey', small) mdi-twitter
  23. v-list-item-title.px-3 Twitter
  24. v-list-item(:href='`viber://forward?text=` + encodeURIComponent(url) + ` ` + encodeURIComponent(description)')
  25. v-icon(color='grey', small) mdi-phone-in-talk
  26. v-list-item-title.px-3 Viber
  27. v-list-item(@click='openSocialPop(`http://service.weibo.com/share/share.php?url=` + encodeURIComponent(url) + `&title=` + encodeURIComponent(title))')
  28. v-icon(color='grey', small) mdi-sina-weibo
  29. v-list-item-title.px-3 Weibo
  30. v-list-item(@click='openSocialPop(`https://api.whatsapp.com/send?text=` + encodeURIComponent(title) + `%0D%0A` + encodeURIComponent(url))')
  31. v-icon(color='grey', small) mdi-whatsapp
  32. v-list-item-title.px-3 Whatsapp
  33. </template>
  34. <script>
  35. import ClipboardJS from 'clipboard'
  36. export default {
  37. props: {
  38. url: {
  39. type: String,
  40. default: window.location.url
  41. },
  42. title: {
  43. type: String,
  44. default: 'Untitled Page'
  45. },
  46. description: {
  47. type: String,
  48. default: ''
  49. }
  50. },
  51. data () {
  52. return {
  53. width: 626,
  54. height: 436,
  55. left: 0,
  56. top: 0
  57. }
  58. },
  59. methods: {
  60. openSocialPop (url) {
  61. const popupWindow = window.open(
  62. url,
  63. 'sharer',
  64. `status=no,height=${this.height},width=${this.width},resizable=yes,left=${this.left},top=${this.top},screenX=${this.left},screenY=${this.top},toolbar=no,menubar=no,scrollbars=no,location=no,directories=no`
  65. )
  66. popupWindow.focus()
  67. }
  68. },
  69. mounted () {
  70. const clip = new ClipboardJS(this.$refs.copyUrlButton.$el, {
  71. text: () => { return this.url }
  72. })
  73. clip.on('success', () => {
  74. this.$store.commit('showNotification', {
  75. style: 'success',
  76. message: `URL copied successfully`,
  77. icon: 'content-copy'
  78. })
  79. })
  80. clip.on('error', () => {
  81. this.$store.commit('showNotification', {
  82. style: 'red',
  83. message: `Failed to copy to clipboard`,
  84. icon: 'alert'
  85. })
  86. })
  87. /**
  88. * Center the popup on dual screens
  89. * http://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen/32261263
  90. */
  91. const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left
  92. const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top
  93. const width = window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width)
  94. const height = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height)
  95. this.left = ((width / 2) - (this.width / 2)) + dualScreenLeft
  96. this.top = ((height / 2) - (this.height / 2)) + dualScreenTop
  97. }
  98. }
  99. </script>