diff --git a/src/main/resources/kinosearch/webapp/static/js/ksplayer.js b/src/main/resources/kinosearch/webapp/static/js/ksplayer.js index a129f99..3a67a03 100644 --- a/src/main/resources/kinosearch/webapp/static/js/ksplayer.js +++ b/src/main/resources/kinosearch/webapp/static/js/ksplayer.js @@ -9,6 +9,7 @@ const KSPlayer = function(containerId, data) { let seasonSerials = []; const _self = this; let lastActiveSerialItem; + let lastActiveSeasonItem; /* --- PRIVATE FUNCTIONS --- */ @@ -75,6 +76,7 @@ const KSPlayer = function(containerId, data) { div.id = 'pl-season'; div.className = 'dropdown'; div.style = 'display: inline-block'; + div.kspSerialMenuElement = undefined; let button = document.createElement('button'); button.className = 'btn btn-default dropdown-toggle'; @@ -101,7 +103,23 @@ const KSPlayer = function(containerId, data) { a.href = '#'; a.innerText = item.title; a.setAttribute('data-number', idx); - a.onclick = function() { return false; } + a.onclick = function() { + text.nodeValue = item.title; + + if (lastActiveSeasonItem) { + lastActiveSeasonItem.classList.remove('active'); + } + li.classList.add('active'); + lastActiveSeasonItem = li; + + if (div.kspSerialMenuElement) { + containerElement.removeChild(div.kspSerialMenuElement); + } + containerElement.insertAfter(seasonSerials[idx], div); + div.kspSerialMenuElement = seasonSerials[idx]; + + return false; + } seasonSerials.push(createSerialMenuElement(item.serials)); li.appendChild(a); @@ -197,6 +215,10 @@ const KSPlayer = function(containerId, data) { throw `Container "${containerId}" not found!`; } + containerElement.insertAfter = function(newChild, refChild) { + this.insertBefore(newChild, refChild.nextSibling); + } + let videoElement = createVideoElement(); if (data.hasOwnProperty('title')) {