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.

94 lines
3.1 KiB

  1. <template lang="pug">
  2. transition(:duration="400")
  3. .modal(v-show='isShown', v-cloak)
  4. transition(name='modal-background')
  5. .modal-background(v-show='isShown')
  6. .modal-container
  7. transition(name='modal-content')
  8. .modal-content(v-show='isShown')
  9. header.is-green
  10. span {{ $t('editor.videotitle') }}
  11. section
  12. label.label
  13. p.control.is-fullwidth
  14. input.input(type='text', placeholder='https://www.youtube.com/watch?v=xxxxxxxxxxx', v-model='link', ref='editorVideoInput', @keyup.enter='insertVideo', @keyup.esc='cancel')
  15. span.help.is-red(v-show='isInvalid') {{ $t('editor.videonotsupported') }}
  16. .note {{ $t('editor.videosupportedtitle') }}
  17. ul
  18. li
  19. i.icon-youtube-play
  20. span Youtube
  21. li
  22. i.icon-vimeo
  23. span Vimeo
  24. li
  25. i.nc-icon-outline.media-1_play-69
  26. span Dailymotion
  27. li
  28. i.icon-video
  29. span {{ $t('editor.videoanymp4file') }}
  30. footer
  31. a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('editor.discard') }}
  32. a.button.is-green(v-on:click='insertVideo') {{ $t('editor.videoinsert') }}
  33. </template>
  34. <script>
  35. const videoRules = {
  36. 'youtube': new RegExp(/(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/, 'i'),
  37. 'vimeo': new RegExp(/vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:$|\/|\?)/, 'i'),
  38. 'dailymotion': new RegExp(/(?:dailymotion\.com(?:\/embed)?(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[-_0-9a-zA-Z]+(?:#video=)?([a-z0-9]+)?)?/, 'i')
  39. }
  40. export default {
  41. name: 'editor-video',
  42. data () {
  43. return {
  44. link: '',
  45. isInvalid: false
  46. }
  47. },
  48. computed: {
  49. isShown () {
  50. return this.$store.state.editorVideo.shown
  51. }
  52. },
  53. methods: {
  54. init () {
  55. let self = this
  56. self.isInvalid = false
  57. self._.delay(() => {
  58. self.$refs.editorVideoInput.focus()
  59. }, 100)
  60. },
  61. cancel () {
  62. this.$store.dispatch('editorVideo/close')
  63. },
  64. insertVideo () {
  65. let self = this
  66. if (this._.isEmpty(self.link) || self.link.length < 5) {
  67. this.isInvalid = true
  68. return
  69. }
  70. let videoType = this._.findKey(videoRules, (vr) => {
  71. return vr.test(self.link)
  72. })
  73. if (this._.isNil(videoType)) {
  74. videoType = 'video'
  75. }
  76. let videoText = '[video](' + this.link + '){.' + videoType + '}\n'
  77. this.$store.dispatch('editor/insert', videoText)
  78. this.$store.dispatch('alert', {
  79. style: 'blue',
  80. icon: 'media-1_action-74',
  81. msg: self.$t('editor.videosuccess')
  82. })
  83. this.cancel()
  84. }
  85. },
  86. mounted () {
  87. this.$root.$on('editorVideo/init', this.init)
  88. }
  89. }
  90. </script>