Skip to content

Commit e05bafd

Browse files
committed
chore: Adds poster.js, video_accessible_menu
1 parent 527a0c4 commit e05bafd

3 files changed

Lines changed: 163 additions & 31 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import $ from 'jquery'; // jQuery import
2+
import _ from 'underscore';
3+
4+
'use strict';
5+
6+
/**
7+
* VideoPoster function
8+
*
9+
* @constructor
10+
* @param {jQuery} element
11+
* @param {Object} options
12+
*/
13+
function VideoPoster(element, options) {
14+
if (!(this instanceof VideoPoster)) {
15+
return new VideoPoster(element, options);
16+
}
17+
18+
_.bindAll(this, 'onClick', 'destroy');
19+
this.element = element;
20+
this.container = element.find('.video-player');
21+
this.options = options || {};
22+
this.initialize();
23+
}
24+
25+
VideoPoster.moduleName = 'Poster';
26+
VideoPoster.prototype = {
27+
template: _.template([
28+
'<div class="video-pre-roll is-<%- type %> poster" ',
29+
'style="background-image: url(<%- url %>)">',
30+
'<button class="btn-play btn-pre-roll">',
31+
'<img src="/static/images/play.png" alt="">',
32+
'<span class="sr">', gettext('Play video'), '</span>',
33+
'</button>',
34+
'</div>'
35+
].join('')),
36+
37+
initialize: function () {
38+
this.el = $(this.template({
39+
url: this.options.poster.url,
40+
type: this.options.poster.type
41+
}));
42+
this.element.addClass('is-pre-roll');
43+
this.render();
44+
this.bindHandlers();
45+
},
46+
47+
bindHandlers: function () {
48+
this.el.on('click', this.onClick);
49+
this.element.on('destroy', this.destroy);
50+
},
51+
52+
render: function () {
53+
this.container.append(this.el);
54+
},
55+
56+
onClick: function () {
57+
if (_.isFunction(this.options.onClick)) {
58+
this.options.onClick();
59+
}
60+
this.destroy();
61+
},
62+
63+
destroy: function () {
64+
this.element.off('destroy', this.destroy).removeClass('is-pre-roll');
65+
this.el.remove();
66+
},
67+
};
68+
69+
export {VideoPoster};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import _ from 'underscore';
2+
3+
/**
4+
* Video Download Transcript control module.
5+
*
6+
* @constructor
7+
* @param {jQuery} element
8+
* @param {Object} options
9+
*/
10+
function VideoTranscriptDownloadHandler(element, options = {}) {
11+
if (!(this instanceof VideoTranscriptDownloadHandler)) {
12+
return new VideoTranscriptDownloadHandler(element, options);
13+
}
14+
15+
_.bindAll(this, 'clickHandler');
16+
17+
this.container = element;
18+
this.options = options;
19+
20+
if (this.container.find('.wrapper-downloads .wrapper-download-transcripts')) {
21+
this.initialize();
22+
}
23+
}
24+
25+
VideoTranscriptDownloadHandler.prototype = {
26+
// Initializes the module.
27+
initialize() {
28+
this.value = this.options.storage.getItem('transcript_download_format');
29+
this.el = this.container.find('.list-download-transcripts');
30+
this.el.on('click', '.btn-link', this.clickHandler);
31+
},
32+
33+
// Event handler. We delay link clicks until the file type is set
34+
clickHandler(event) {
35+
event.preventDefault();
36+
37+
const fileType = $(event.target).data('value');
38+
const data = {transcript_download_format: fileType};
39+
const downloadUrl = $(event.target).attr('href');
40+
41+
$.ajax({
42+
url: this.options.saveStateUrl,
43+
type: 'POST',
44+
dataType: 'json',
45+
data: data,
46+
success: () => {
47+
this.options.storage.setItem('transcript_download_format', fileType);
48+
},
49+
complete: () => {
50+
document.location.href = downloadUrl;
51+
},
52+
});
53+
},
54+
};
55+
56+
export {VideoTranscriptDownloadHandler};

xmodule/assets/video/public/js/video_block_main.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Import required modules and dependencies
2+
import $ from 'jquery';
3+
import _ from 'underscore';
24
import {VideoStorage} from './video_storage';
5+
import {VideoPoster} from './poster';
6+
import {VideoTranscriptDownloadHandler} from './video_accessible_menu';
7+
38
// TODO: Uncomment the imports
49
// import { initialize } from './initialize'; // Assuming this function is imported
510
// import {
@@ -23,21 +28,23 @@ import {VideoStorage} from './video_storage';
2328
// VideoPlaySkipControl,
2429
// VideoSkipControl,
2530
// VideoEventsBumperPlugin,
26-
// VideoPoster,
2731
// VideoSocialSharing,
28-
// VideoAccessibleMenu,
2932
// VideoBumper,
3033
// } from './video_modules'; // Assuming all necessary modules are grouped here
3134

35+
// Stub gettext if the runtime doesn't provide it
36+
if (typeof window.gettext === 'undefined') {
37+
window.gettext = function (text) {
38+
return text;
39+
};
40+
}
41+
42+
3243
'use strict';
3344

3445
console.log('In video_block_main.js file');
3546

36-
(function (require, $) {
37-
// TODO: Following code needs to be reviewed, why we are not getting $
38-
if (!$) {
39-
$ = window.jQuery;
40-
}
47+
(function () {
4148
var youtubeXhr = null;
4249
var oldVideo = window.Video;
4350

@@ -113,34 +120,34 @@ console.log('In video_block_main.js file');
113120
};
114121
};
115122

116-
// VideoAccessibleMenu(el, {
117-
// storage: storage,
118-
// saveStateUrl: state.metadata.saveStateUrl,
119-
// });
123+
VideoTranscriptDownloadHandler(el, {
124+
storage: storage,
125+
saveStateUrl: state.metadata.saveStateUrl,
126+
});
120127

121128
// VideoSocialSharing(el);
122129

123130
if (bumperMetadata) {
124-
// VideoPoster(el, {
125-
// poster: el.data('poster'),
126-
// onClick: _.once(function () {
127-
// const mainVideoPlayer = player(state);
128-
//
129-
// if (storage.getItem('isBumperShown')) {
130-
// mainVideoPlayer();
131-
// } else {
132-
// const bumperState = getBumperState(bumperMetadata);
133-
// const bumper = new VideoBumper(player(bumperState), bumperState);
134-
//
135-
// state.bumperState = bumperState;
136-
//
137-
// bumper.getPromise().then(() => {
138-
// delete state.bumperState;
139-
// mainVideoPlayer();
140-
// });
141-
// }
142-
// }),
143-
// });
131+
VideoPoster(el, {
132+
poster: el.data('poster'),
133+
onClick: _.once(function () {
134+
const mainVideoPlayer = player(state);
135+
136+
if (storage.getItem('isBumperShown')) {
137+
mainVideoPlayer();
138+
} else {
139+
const bumperState = getBumperState(bumperMetadata);
140+
const bumper = new VideoBumper(player(bumperState), bumperState);
141+
142+
state.bumperState = bumperState;
143+
144+
bumper.getPromise().then(() => {
145+
delete state.bumperState;
146+
mainVideoPlayer();
147+
});
148+
}
149+
}),
150+
});
144151
} else {
145152
// TODO: Uncomment following initialize method calling
146153
// initialize(state, element);

0 commit comments

Comments
 (0)