diff options
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/vdr_status.js | 89 |
1 files changed, 73 insertions, 16 deletions
diff --git a/javascript/vdr_status.js b/javascript/vdr_status.js index 2a2a0d1..829b19c 100644 --- a/javascript/vdr_status.js +++ b/javascript/vdr_status.js @@ -8,35 +8,92 @@ var vst_timer; var vst_boxId = null; var vst_url = null; -function LiveStatusAjaxRequest(url, containerid) +function LiveStatusRequest(url, containerid) { if (vst_url == null) + { vst_url = url; + } if (vst_boxId == null) vst_boxId = containerid; - var status = new LiveAjaxCall("text", url); + var status = new LiveAjaxCall("xml", url); status.oncomplete = function() { - document.getElementById(containerid).innerHTML = this.xml.responseText; + try { + LiveStatusShowInfo(this.xml.responseXML, containerid); + } + catch (e) { + LiveStatusReportError(e.message, containerid); + } if (vst_reload) - vst_timer = window.setTimeout("LiveStatusAjaxRequest('" + url + "', '" + containerid + "')", 1000); + vst_timer = window.setTimeout("LiveStatusRequest('" + url + "', '" + containerid + "')", 1000); } status.onerror = function(message) { vst_reload = false; - document.getElementById(containerid).innerHTML = - '<div class="statuscontent>' + - '<div class="st_header">' + - '<div class="caption">ERROR</div>' + - '<div class="now"> <img id="statusReloadBtn" src="reload.png" alt="toggle reload on and off" onclick="LiveStatusToggleUpdate()" /> ERROR</div>' + - '</div>' + - '<div class="st_content">' + - '<div class="name">' + message + '</div>' + - '</div>' + - '</div>'; + LiveStatusReportError(message, containerid); + } + status.request("update", vst_reload ? "1" : "0"); +} + +function LiveStatusShowInfo(xmldoc, containerId) +{ + var epgInfo = xmldoc.getElementsByTagName('epginfo').item(0); + + for (var i = 0; i < epgInfo.childNodes.length; i++) { + var node = epgInfo.childNodes.item(i); + if (node.nodeType == 1) { + var textContent = ""; + if (node.firstChild != null) + textContent = node.firstChild.nodeValue; + LiveStatusSetTextContent(containerId, node.nodeName, textContent); } - status.request("", ""); + } +} + +function LiveStatusReportError(message, containerId) +{ + LiveStatusSetTextContent(containerId, 'caption', 'ERROR'); + LiveStatusSetTextContent(containerId, 'name', message); +} + +function LiveStatusSetTextContent(containerId, nodeName, textContent) +{ + var docNode = document.getElementById(containerId + '_' + nodeName); + if (docNode != null) { + switch (nodeName) { + case "caption": + case "timenow": + case "name": + case "duration": + { + if (docNode.innerHTML != textContent) + docNode.innerHTML = textContent; + break; + } + case "elapsed": + { + var width = textContent + "px"; + if (docNode.style.width != width) + docNode.style.width = width; + break; + } + case "nextchan": + case "prevchan": + { + if (textContent != "") { + docNode.href = "javascript:LiveSimpleAjaxRequest('switch_channel.xml', 'param', '" + textContent + "');"; + docNode.style.visibility = "visible"; + } + else { + docNode.style.visibility = "hidden"; + } + } + default: + break; + } + } } function LiveStatusToggleUpdate() @@ -48,7 +105,7 @@ function LiveStatusToggleUpdate() } else { vst_reload = true; - LiveStatusAjaxRequest(vst_url, vst_boxId); + LiveStatusRequest(vst_url, vst_boxId); } var img = document.getElementById('statusReloadBtn'); if (img != null) { |