Cleanup playlists

This commit is contained in:
Pierre Rudloff 2017-04-25 01:53:38 +02:00
parent 3f053d9eed
commit 43cbd4f6fe
10 changed files with 175 additions and 121 deletions

View file

@ -2,7 +2,7 @@
/*jslint browser: true, nomen: true */
var castModule = (function () {
'use strict';
var launchBtn, disabledBtn, stopBtn, session, videoLink;
var launchBtn, disabledBtn, stopBtn, session;
function receiverListener(e) {
return (e === chrome.cast.ReceiverAvailability.AVAILABLE);
@ -51,7 +51,7 @@ var castModule = (function () {
function onRequestSessionSuccess(e) {
session = e;
var videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
}
@ -59,23 +59,19 @@ var castModule = (function () {
throw e.description;
}
function launchCast(event) {
videoLink = event.target || event.srcElement;
function launchCast() {
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
}
function onInitSuccess() {
launchBtn = document.getElementsByClassName('cast_btn_launch');
disabledBtn = document.getElementsByClassName('cast_disabled');
stopBtn = document.getElementsByClassName('cast_btn_stop');
if (launchBtn.length > 0) {
var i;
for (i = 0; i < launchBtn.length; i++) {
disabledBtn[i].classList.add('cast_hidden');
launchBtn[i].classList.remove('cast_hidden');
launchBtn[i].addEventListener('click', launchCast, false);
stopBtn[i].addEventListener('click', stopCast, false);
}
launchBtn = document.getElementById('cast_btn_launch');
disabledBtn = document.getElementById('cast_disabled');
stopBtn = document.getElementById('cast_btn_stop');
if (launchBtn) {
disabledBtn.classList.add('cast_hidden');
launchBtn.classList.remove('cast_hidden');
launchBtn.addEventListener('click', launchCast, false);
stopBtn.addEventListener('click', stopCast, false);
}
}
@ -98,11 +94,11 @@ var castModule = (function () {
return {
init: function () {
var intro = document.getElementsByClassName('download_intro'), i;
for (i = 0; i < intro.length; i++) {
intro[i].insertAdjacentHTML('beforeend', '<img class="cast_disabled cast_icon" id="cast_disabled'+i+'" src="img/ic_media_route_disabled_holo_light.png" alt="" title="Google Cast is not supported on this browser." /> <img class="cast_btn_launch cast_btn cast_hidden cast_icon" id="cast_btn_launch'+i+'" src="img/ic_media_route_off_holo_light.png" title="Cast to ChromeCast" alt="Google Cast™" /> <img src="img/ic_media_route_on_holo_light.png" alt="Casting to ChromeCast…" title="Stop casting" id="cast_btn_stop'+i+'" class="cast_btn_stop cast_btn cast_hidden cast_icon" />');
var intro = document.getElementById('download_intro');
if (intro) {
intro.insertAdjacentHTML('beforeend', '<img class="cast_icon" id="cast_disabled" src="img/ic_media_route_disabled_holo_light.png" alt="" title="Google Cast is not supported on this browser." /> <img class="cast_btn cast_hidden cast_icon" id="cast_btn_launch" src="img/ic_media_route_off_holo_light.png" title="Cast to ChromeCast" alt="Google Cast™" /> <img src="img/ic_media_route_on_holo_light.png" alt="Casting to ChromeCast…" title="Stop casting" id="cast_btn_stop" class="cast_btn cast_hidden cast_icon" />');
window.__onGCastApiAvailable = loadCastApi;
}
window.__onGCastApiAvailable = loadCastApi;
}
};
}());