UNPKG

2.72 kBJavaScriptView Raw
1import videojs from 'video.js';
2import guid from './guid.js';
3
4let Component = videojs.getComponent('Component');
5
6/**
7 * Title Component
8 */
9export 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 * Shelf Component
56 */
57export class Shelf extends Component {
58 createEl() {
59 return super.createEl('div', {
60 className: 'vjs-dock-shelf'
61 });
62 }
63}
64
65videojs.registerComponent('Title', Title);
66videojs.registerComponent('Shelf', Shelf);
67
68/**
69 * A video.js plugin.
70 *
71 * In the plugin function, the value of `this` is a video.js `Player`
72 * instance. You cannot rely on the player being in a "ready" state here,
73 * depending on how the plugin is invoked. This may or may not be important
74 * to you; if not, remove the wait for "ready"!
75 *
76 * @function dock
77 * @param {Object} [options={}]
78 * An object of options left to the plugin author to define.
79 */
80const 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// Register the plugin with video.js.
113videojs.plugin('dock', dock);
114
115export default dock;