0

KSPlayer: заполнение меню серий

This commit is contained in:
2017-12-13 21:45:30 +03:00
parent 9b6bd13c36
commit bbc891b83b
2 changed files with 38 additions and 19 deletions

View File

@@ -29,6 +29,6 @@
<div id="ksplayer"></div> <div id="ksplayer"></div>
<br> <br>
<script type="text/javascript"> <script type="text/javascript">
const ksplayer = new KSPlayer('ksplayer'); const ksplayer = new KSPlayer('ksplayer', ${json});
</script> </script>
[#include "/fother.inc.ftl"] [#include "/fother.inc.ftl"]

View File

@@ -1,12 +1,15 @@
const KSPlayer = function(containerId) { const KSPlayer = function(containerId, data) {
/* --- FIELDS -------------- */ /* --- FIELDS -------------- */
let videoType = 'unknown';
let isShowTitle = false; let isShowTitle = false;
/* --- PRIVATE FIELDS ------ */
let titleElement;
/* --- PRIVATE FUNCTIONS --- */ /* --- PRIVATE FUNCTIONS --- */
function createSerialMenuElement() { function createSerialMenuElement(serials) {
let div = document.createElement('div'); let div = document.createElement('div');
div.id = 'pl-serial'; div.id = 'pl-serial';
div.className = 'dropdown'; div.className = 'dropdown';
@@ -31,13 +34,18 @@ const KSPlayer = function(containerId) {
ul.className = 'dropdown-menu'; ul.className = 'dropdown-menu';
ul.setAttribute('aria-labelledby', 'dropdownSerial'); ul.setAttribute('aria-labelledby', 'dropdownSerial');
let li = document.createElement('li'); serials.forEach(item => {
let a = document.createElement('a'); let li = document.createElement('li');
a.href = '#'; let a = document.createElement('a');
a.innerText = 'Serial'; a.href = '#';
a.innerText = item.title;
a.setAttribute('data-file', item.file);
a.onclick = function() { return false; }
li.appendChild(a);
ul.appendChild(li);
});
li.appendChild(a);
ul.appendChild(li);
button.appendChild(text); button.appendChild(text);
button.appendChild(span); button.appendChild(span);
div.appendChild(button); div.appendChild(button);
@@ -86,6 +94,11 @@ const KSPlayer = function(containerId) {
return div; return div;
} }
function initTitleElement() {
titleElement = document.createElement('h2');
titleElement.id = 'title';
}
/* --- CONSTRUCTOR --------- */ /* --- CONSTRUCTOR --------- */
const containerElement = document.getElementById(containerId); const containerElement = document.getElementById(containerId);
@@ -99,16 +112,20 @@ const KSPlayer = function(containerId) {
videoElement.setAttribute('controls', 'controls'); videoElement.setAttribute('controls', 'controls');
videoElement.setAttribute('preload', 'none'); videoElement.setAttribute('preload', 'none');
let titleElement = document.createElement('h2'); if (data.hasOwnProperty('title')) {
titleElement.id = 'title'; this.setTitle(data.title);
}
let seasonMenu = createSeasonMenuElement(); if (data.type === 'simple_serial') {
let serialMenu = createSerialMenuElement(); let serialMenu = createSerialMenuElement(data.serials);
containerElement.appendChild(serialMenu);
containerElement.appendChild(document.createElement('br'));
containerElement.appendChild(document.createElement('br'));
}
// let seasonMenu = createSeasonMenuElement();
// containerElement.appendChild(seasonMenu);
containerElement.appendChild(seasonMenu);
containerElement.appendChild(serialMenu);
containerElement.appendChild(document.createElement('br'));
containerElement.appendChild(document.createElement('br'));
containerElement.appendChild(videoElement); containerElement.appendChild(videoElement);
/* --- FUNCTIONS ----------- */ /* --- FUNCTIONS ----------- */
@@ -119,13 +136,15 @@ const KSPlayer = function(containerId) {
this.setTitle = function(text) { this.setTitle = function(text) {
if (text) { if (text) {
if (!titleElement) initTitleElement();
titleElement.innerText = text; titleElement.innerText = text;
if (!isShowTitle) { if (!isShowTitle) {
containerElement.insertBefore(titleElement, videoElement); containerElement.insertBefore(titleElement, videoElement);
isShowTitle = true; isShowTitle = true;
} }
} else { } else {
if (isShowTitle) { if (isShowTitle && titleElement) {
containerElement.removeChild(titleElement); containerElement.removeChild(titleElement);
isShowTitle = false; isShowTitle = false;
} }