Первые наброски объекта-плеера
This commit is contained in:
47
src/main/resources/kinosearch/webapp/static/js/ksplayer.js
Normal file
47
src/main/resources/kinosearch/webapp/static/js/ksplayer.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const KSPlayer = function(containerId) {
|
||||
/* --- FIELDS -------------- */
|
||||
|
||||
var videoType = 'unknown';
|
||||
var isShowTitle = false;
|
||||
|
||||
/* --- PRIVATE FUNCTIONS --- */
|
||||
|
||||
/* --- CONSTRUCTOR --------- */
|
||||
|
||||
const containerElement = document.getElementById(containerId);
|
||||
if (containerElement === null) {
|
||||
throw `Container "${containerId}" not found!`;
|
||||
}
|
||||
|
||||
let videoElement = document.createElement('video');
|
||||
videoElement.id = 'player';
|
||||
videoElement.className = 'center-block';
|
||||
videoElement.setAttribute('controls', 'controls');
|
||||
videoElement.setAttribute('preload', 'none');
|
||||
|
||||
var titleElement = document.createElement('h2');
|
||||
titleElement.id = 'title';
|
||||
|
||||
containerElement.appendChild(videoElement);
|
||||
|
||||
/* --- FUNCTIONS ----------- */
|
||||
|
||||
this.getType = function() {
|
||||
return videoType;
|
||||
}
|
||||
|
||||
this.setTitle = function(text) {
|
||||
if (text) {
|
||||
titleElement.innerText = text;
|
||||
if (!isShowTitle) {
|
||||
containerElement.insertBefore(titleElement, videoElement);
|
||||
isShowTitle = true;
|
||||
}
|
||||
} else {
|
||||
if (isShowTitle) {
|
||||
containerElement.removeChild(titleElement);
|
||||
isShowTitle = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user