index.js 640 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @fileoverview audio 插件
  3. */
  4. const context = require('./context')
  5. let index = 0
  6. function Audio (vm) {
  7. this.vm = vm
  8. }
  9. Audio.prototype.onUpdate = function () {
  10. this.audios = []
  11. }
  12. Audio.prototype.onParse = function (node) {
  13. if (node.name === 'audio') {
  14. if (!node.attrs.id) {
  15. node.attrs.id = 'a' + index++
  16. }
  17. this.audios.push(node.attrs.id)
  18. }
  19. }
  20. Audio.prototype.onLoad = function () {
  21. setTimeout(() => {
  22. for (let i = 0; i < this.audios.length; i++) {
  23. const ctx = context.get(this.audios[i])
  24. ctx.id = this.audios[i]
  25. this.vm._videos.push(ctx)
  26. }
  27. }, 500)
  28. }
  29. module.exports = Audio