index.js 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @fileoverview txv-video 插件
  3. * Include txv-video (https://github.com/tvfe/txv-miniprogram-plugin)
  4. */
  5. const TxvVideo = function (vm) {
  6. this.vm = vm
  7. }
  8. // #ifdef MP-WEIXIN || MP-QQ
  9. const TxvContext = requirePlugin('tencentvideo')
  10. TxvVideo.prototype.onUpdate = function (_, config) {
  11. config.trustTags['txv-video'] = true
  12. this.videos = []
  13. }
  14. TxvVideo.prototype.onParse = function (node, parser) {
  15. if (node.name === 'iframe' && (node.attrs.src || '').includes('vid')) {
  16. const vid = node.attrs.src.match(/vid=([^&\s]+)/)
  17. if (vid) {
  18. node.name = 'txv-video'
  19. node.attrs.vid = vid[1]
  20. this.videos.push(vid[1])
  21. node.attrs.src = undefined
  22. parser.expose()
  23. }
  24. }
  25. }
  26. TxvVideo.prototype.onLoad = function () {
  27. setTimeout(() => {
  28. for (let i = 0; i < this.videos.length; i++) {
  29. const ctx = TxvContext.getTxvContext(this.videos[i])
  30. ctx.id = this.videos[i]
  31. this.vm._videos.push(ctx)
  32. }
  33. }, 50)
  34. }
  35. // #endif
  36. module.exports = TxvVideo