1 | import videojs from 'video.js';
|
2 | import guid from './guid.js';
|
3 |
|
4 | let Component = videojs.getComponent('Component');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export class Title extends Component {
|
10 | constructor(player, options) {
|
11 | super(player, options);
|
12 |
|
13 | let tech = player.$('.vjs-tech');
|
14 |
|
15 | tech.setAttribute('aria-labelledby', this.title.id);
|
16 | tech.setAttribute('aria-describedby', this.description.id);
|
17 | }
|
18 |
|
19 | createEl() {
|
20 | let title = videojs.createEl('div', {
|
21 | className: 'vjs-dock-title',
|
22 | title: this.options_.title,
|
23 | innerHTML: this.options_.title
|
24 | }, {
|
25 | id: `vjs-dock-title-${guid()}`
|
26 | });
|
27 | let desc = videojs.createEl('div', {
|
28 | className: 'vjs-dock-description',
|
29 | title: this.options_.description,
|
30 | innerHTML: this.options_.description
|
31 | }, {
|
32 | id: `vjs-dock-description-${guid()}`
|
33 | });
|
34 | let el = super.createEl('div', {
|
35 | className: 'vjs-dock-text'
|
36 | });
|
37 |
|
38 | this.title = title;
|
39 | this.description = desc;
|
40 |
|
41 | el.appendChild(title);
|
42 | el.appendChild(desc);
|
43 | return el;
|
44 | }
|
45 |
|
46 | update(title, description) {
|
47 | this.title.innerHTML = '';
|
48 | this.description.innerHTML = '';
|
49 | this.title.appendChild(document.createTextNode(title));
|
50 | this.description.appendChild(document.createTextNode(description));
|
51 | }
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | export class Shelf extends Component {
|
58 | createEl() {
|
59 | return super.createEl('div', {
|
60 | className: 'vjs-dock-shelf'
|
61 | });
|
62 | }
|
63 | }
|
64 |
|
65 | videojs.registerComponent('Title', Title);
|
66 | videojs.registerComponent('Shelf', Shelf);
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | const dock = function(options) {
|
81 | let opts = options || {};
|
82 | let settings = {
|
83 | title: {
|
84 | title: opts.title || '',
|
85 | description: opts.description || ''
|
86 | }
|
87 | };
|
88 |
|
89 | let title = this.title;
|
90 | let shelf = this.shelf;
|
91 |
|
92 | this.addClass('vjs-dock');
|
93 |
|
94 | if (!title) {
|
95 | title = this.title = this.addChild('title', settings.title);
|
96 | } else {
|
97 | title.update(settings.title.title, settings.title.description);
|
98 | }
|
99 | if (!shelf) {
|
100 | shelf = this.shelf = this.addChild('shelf', settings);
|
101 | }
|
102 |
|
103 | this.one(title, 'dispose', function() {
|
104 | this.title = null;
|
105 | });
|
106 |
|
107 | this.one(shelf, 'dispose', function() {
|
108 | this.shelf = null;
|
109 | });
|
110 | };
|
111 |
|
112 |
|
113 | videojs.plugin('dock', dock);
|
114 |
|
115 | export default dock;
|