/* Roku.Body */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Body = { all : null }; Roku.classes.push(Roku.Body); Roku.Body.onInit = function() { this.all = this.scanClassElements(document.body); var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.initialize) == "function")) entry.initialize(); } //this.all = null; Roku.Util.eventHandler(document.body, "mousedown", this.onMouseDown); Roku.Util.eventHandler(document.body, "mousemove", this.onMouseMove); Roku.Util.eventHandler(document.body, "mouseup", this.onMouseUp); } Roku.Body.doRefresh = function(root) { this.all = this.scanClassElements(root ? root : document.body); var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.refresh) == "function")) entry.refresh(root); } this.all = null; } Roku.Body.doRefreshContent = function(root, source, reason) { this.all = this.scanClassElements(root ? root : document.body); var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.refresh_content) == "function")) entry.refresh_content(root, source, reason); } this.all = null; } Roku.Body.onLoad = function() { //reuse all from onInit //this.all = this.scanClassElements(document.body); var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.onBodyLoad) == "function")) entry.onBodyLoad(); } this.all = null; } Roku.Body.onUnload = function() { this.all = this.scanClassElements(document.body); var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.onBodyUnload) == "function")) entry.onBodyUnload(); } this.all = null; } Roku.Body.onMouseDown = function() { var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.need_mouse_down) == "function") && entry.need_mouse_down() && (typeof(entry.on_mouse_down) == "function")) entry.on_mouse_down((0 < arguments.length) ? arguments[0] : null); } } Roku.Body.onMouseMove = function() { var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.need_mouse_move) == "function") && entry.need_mouse_move() && (typeof(entry.on_mouse_move) == "function")) entry.on_mouse_move((0 < arguments.length) ? arguments[0] : null); } } Roku.Body.onMouseUp = function() { var count = Roku.classes.length; for(var index = 0; index < count; index++) { var entry = Roku.classes[index]; if(entry && (typeof(entry.need_mouse_up) == "function") && entry.need_mouse_up() && (typeof(entry.on_mouse_up) == "function")) entry.on_mouse_up((0 < arguments.length) ? arguments[0] : null); } } Roku.Body.scanClassElements = function(element, all) { if(!element) return; if(!all) { all = []; this.scanClassElements(element, all); return all; } if(element.className) { if(!all[element.className]) all[element.className] = []; all[element.className].push(element); } var children = element.childNodes; if(!children) return; var length = children.length; for(var index = 0; index < length; index++) this.scanClassElements(children[index], all); } /* Roku.Widget */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Widget = { widgetClassName : "widget", widgetContentBarClassName : "bd", widgetTitleBarClassName : "handler", widgetControlsBarClassName : "controls", widgetMinButtonClassName : "btnMin", widgetCloseButtonClassName : "btnClose", dropLocationClassName : "dropLocation", contentTableClassName : "widgets_content", showAllElementId : "showAll", showAllTargetElementId : "showAllTarget", footerElementId : "document_footer", widgetsPlacementAttribName : "widgets_placement", queryKeyAttribName : "query_key", queryValueAttribName : "query_value", overlaperClassName : "widget_overlaper", disabledAttribName : "widget_disabled", min_restoreEventName : "on_min_restore", dragElement : null, dragOffsetX : 0, dragOffsetY : 0, dragScrollX : 0, dragScrollY : 0, dragAnimX : null, dragAnimY : null, dragSpeed : null, scrollHoldElement : null, scrollX : 0, scrollY : 0, scrollIntervalId : null, scrollOffset : 15, scrollStep : 10, scrollTimeout : 10, mouseDownData : null, mouseDownTimeout : 500, mouseDownOffset : 3, dropStationWidget : null, dragStation : null, dragStationOpacity : null, dragStationTimeoutId : null, dragStationAnimTimeout : 15, dragStationAnimStep : 2, dragStationInitAnim : { stationDropOpacity : 0.30, stationDropFilter : "alpha(opacity=30)" } }; Roku.classes.push(Roku.Widget); Roku.Widget.on_mouse_down = function(ev) { var element = Roku.Util.srcEventElement(ev); if(this.dragElement || !element || !ev) return; this.mouseDownData = { element : element, offsetX : ev.offsetX, offsetY : ev.offsetY, clientX : ev.clientX, clientY : ev.clientY, pageX : ev.pageX, pageY : ev.pageY }; window.setTimeout("Roku.Widget.do_mouse_down()", this.mouseDownTimeout); //this.do_mouse_down(); Roku.Util.eventCancel(ev); } Roku.Widget.do_mouse_down = function() { if(!this.mouseDownData) return; var ev = this.mouseDownData; this.mouseDownData = null; var element = ev.element; if(this.dragElement || !element) return; this.dragElement = Roku.Util.parentClassElement(element, this.widgetClassName); if(!this.dragElement) return; var rect = Roku.Util.elementRect(this.dragElement); if(ev.offsetX && ev.offsetY) { // IE this.dragOffsetX = ev.offsetX; this.dragOffsetY = ev.offsetY; this.dragScrollX = rect.left - (ev.clientX - ev.offsetX); this.dragScrollY = rect.top - (ev.clientY - ev.offsetY); } else if(ev.pageX && ev.pageY) { // Mozilla this.dragScrollX = ev.pageX - ev.clientX; this.dragScrollY = ev.pageY - ev.clientY; this.dragOffsetX = ev.clientX + this.dragScrollX - rect.left; this.dragOffsetY = ev.clientY + this.dragScrollY - rect.top; } var content_table = Roku.Util.childClassElement(document.body, this.contentTableClassName); var content_rect = Roku.Util.elementRect(content_table); this.scrollHoldElement = document.createElement("div"); this.scrollHoldElement.style.position = "absolute"; this.scrollHoldElement.style.left = content_rect.left + "px"; this.scrollHoldElement.style.top = content_rect.top + "px"; this.scrollHoldElement.style.width = content_rect.width + "px"; this.scrollHoldElement.style.height = content_rect.height + "px"; //this.scrollHoldElement.style.backgroundColor = "#ABABAB"; //this.scrollHoldElement.style.filter = "alpha(opacity=80)"; //this.scrollHoldElement.style.opacity = 0.8; document.body.appendChild(this.scrollHoldElement); this.dragElement.style.left = (this.dragScrollX + ev.clientX - this.dragOffsetX) + "px"; this.dragElement.style.top = (this.dragScrollY + ev.clientY - this.dragOffsetY) + "px"; this.dragElement.style.width = this.dragElement.offsetWidth + "px"; this.dragElement.style.height = this.dragElement.offsetHeight + "px"; this.dragElement.style.position = "absolute"; this.dragElement.style.zIndex = 999; this.dragElement.style.opacity = 0.30; this.dragElement.style.filter = "alpha(opacity=30)" var dropTargetElement = this.createDropTargetElement(this.dragElement.offsetWidth, this.dragElement.offsetHeight); this.dragElement.parentNode.parentNode.parentNode.insertBefore(dropTargetElement, this.dragElement.parentNode.parentNode); this.scrollX = 0; this.scrollY = 0; if(this.dragElement.setCapture) this.dragElement.setCapture(); } Roku.Widget.on_mouse_move = function(ev) { if(this.mouseDownData) { if((this.mouseDownOffset < Math.abs(this.mouseDownData.clientX - ev.clientX)) || (this.mouseDownOffset < Math.abs(this.mouseDownData.clientY - ev.clientY))) this.do_mouse_down(); else Roku.Util.eventCancel(ev); } if(!this.dragElement || !ev || this.dragAnimX || this.dragAnimY) return; this.dragElement.style.left = (this.dragScrollX + ev.clientX - this.dragOffsetX) + "px"; this.dragElement.style.top = (this.dragScrollY + ev.clientY - this.dragOffsetY) + "px"; var colTable = this.targetXElement(this.dragScrollX + ev.clientX); if(colTable) { var target = this.targetYElement(this.dragScrollY + ev.clientY, colTable); if(target) { this.removeDropTargetElement(); var dropTargetElement = this.createDropTargetElement(this.dragElement.offsetWidth, this.dragElement.offsetHeight); if(target == colTable) Roku.Util.childTagElement(colTable, "tbody").appendChild(dropTargetElement); else target.parentNode.insertBefore(dropTargetElement, target); } } if(this.scrollHoldElement) { var content_table = Roku.Util.childClassElement(document.body, this.contentTableClassName); var content_rect = Roku.Util.elementRect(content_table); if(this.scrollHoldElement.offsetHeight < content_rect.height) this.scrollHoldElement.style.height = content_rect.height + "px"; } var right = Roku.Util.clientWidth(); var bottom = Roku.Util.clientHeight(); if(ev.clientX < this.scrollOffset) this.scrollX = -this.scrollStep; else if((right - this.scrollOffset) < ev.clientX) this.scrollX = this.scrollStep; else this.scrollX = 0; if(ev.clientY < this.scrollOffset) this.scrollY = -this.scrollStep; else if((bottom - this.scrollOffset) < ev.clientY) this.scrollY = this.scrollStep; else this.scrollY = 0; var doScroll = ((this.scrollX != 0) || (this.scrollY != 0)); if(doScroll && !this.scrollIntervalId) { this.scrollIntervalId = window.setInterval("Roku.Widget.on_scroll()", this.scrollTimeout); } else if(!doScroll && this.scrollIntervalId) { window.clearInterval(this.scrollIntervalId); this.scrollIntervalId = null; } if(document.selection) document.selection.empty(); } Roku.Widget.need_mouse_move = function() { return (this.dragElement || this.mouseDownData); } Roku.Widget.on_scroll = function() { var content_table = Roku.Util.childClassElement(document.body, this.contentTableClassName); var content_rect = Roku.Util.elementRect(content_table); var drag_rect = Roku.Util.elementRect(this.dragElement); if(this.scrollX < 0) this.scrollX = Math.max(this.scrollX, -this.dragScrollX); if(0 < this.scrollX) { var content_right = content_rect.left + content_rect.width; var window_right = this.dragScrollX; if(window.innerWidth) window_right += window.innerWidth; else if(0 < document.documentElement.clientWidth) window_right += document.documentElement.clientWidth; else window_right += document.body.clientWidth; this.scrollX = Math.min(this.scrollX, content_right - window_right); } if(this.scrollY < 0) this.scrollY = Math.max(this.scrollY, -this.dragScrollY); if(0 < this.scrollY) { var content_bottom = content_rect.top + content_rect.height; var window_bottom = this.dragScrollY; if(window.innerHeight) window_bottom += window.innerHeight; else if(0 < document.documentElement.clientHeight) window_bottom += document.documentElement.clientHeight; else window_bottom += document.body.clientHeight; this.scrollY = Math.min(this.scrollY, content_bottom - window_bottom); } if((this.scrollY != 0) || (this.scrollX != 0)) { this.dragScrollX += this.scrollX; this.dragScrollY += this.scrollY; this.dragElement.style.left = (drag_rect.left + this.scrollX) + "px"; this.dragElement.style.top = (drag_rect.top + this.scrollY) + "px"; window.scrollBy(this.scrollX, this.scrollY); } else { window.clearInterval(this.scrollIntervalId); this.scrollIntervalId = null; } } Roku.Widget.on_mouse_up = function() { if(this.mouseDownData) this.mouseDownData = null; if(!this.dragElement) return; if(this.scrollHoldElement) document.body.removeChild(this.scrollHoldElement); this.scrollHoldElement = null; this.scrollX = 0; this.scrollY = 0; var dropTargetElement = Roku.Util.childClassElement(document.body, this.dropLocationClassName); if(dropTargetElement) { var rect = Roku.Util.elementRect(dropTargetElement); this.dragAnimX = rect.left; this.dragAnimY = rect.top; this.dragSpeed = 5; this.animateDrop(); } } Roku.Widget.need_mouse_up = function() { return (this.dragElement || this.mouseDownData); } Roku.Widget.animateDrop = function() { if(!this.dragElement) return; var d = 25; var x = this.dragElement.offsetLeft; var y = this.dragElement.offsetTop; if(Math.sqrt((this.dragAnimX - x)*(this.dragAnimX - x) + (this.dragAnimY - y)*(this.dragAnimY - y)) < this.dragSpeed) this.doDrop(); else { this.dragElement.style.left = Math.ceil(x + this.dragSpeed * (this.dragAnimX - x) / Math.sqrt((this.dragAnimX - x)*(this.dragAnimX - x) + (this.dragAnimY - y)*(this.dragAnimY - y))) + "px"; this.dragElement.style.top = Math.ceil(y + this.dragSpeed * (this.dragAnimY - y) / Math.sqrt((this.dragAnimX - x)*(this.dragAnimX - x) + (this.dragAnimY - y)*(this.dragAnimY - y))) + "px"; this.dragSpeed *= 1.33; } window.setTimeout("Roku.Widget.animateDrop()", 10); } Roku.Widget.doDrop = function() { if(!this.dragElement) return; this.dragElement.style.zIndex = ""; this.dragElement.style.position = ""; this.dragElement.style.left = ""; this.dragElement.style.top = ""; this.dragElement.style.width = ""; this.dragElement.style.height = ""; this.dragElement.style.filter = ""; this.dragElement.style.opacity = ""; var dropTargetElement = Roku.Util.childClassElement(document.body, this.dropLocationClassName); if(dropTargetElement) { // remove drag element from its old location this.dragElement.parentNode.parentNode.parentNode.removeChild(this.dragElement.parentNode.parentNode); // insert drag element to the new location dropTargetElement.parentNode.parentNode.parentNode.insertBefore(this.dragElement.parentNode.parentNode, dropTargetElement.parentNode.parentNode); // remove drop target element dropTargetElement.parentNode.parentNode.parentNode.removeChild(dropTargetElement.parentNode.parentNode); } //removeDropTargetElement(); if(this.dragElement.releaseCapture) this.dragElement.releaseCapture(); this.dragAnimX = null; this.dragAnimY = null; this.dragElement = null; } Roku.Widget.targetXElement = function(x) { var root = Roku.Util.childClassElement(document.body, this.contentTableClassName); // var cols = Roku.Util.childTagElement(root, "tbody", "tr").childNodes; // array of
var minX = 10000, maxX = 0; var minElem = null, maxElem = null; var length = cols.length; for(var index = 0; index < length; index++) { var element = Roku.Util.childTagElement(cols[index], "table"); if(element) { var rect = Roku.Util.elementRect(element); if(rect.left <= minX) { minX = rect.left; minElem = element; } if(maxX <= (rect.left + rect.width)) { maxX = (rect.left + rect.width); maxElem = element; } if((rect.left <= x) && (x <= (rect.left + rect.width))) { return element; } } } if(x <= minX) return minElem; if(maxX <= x) return maxElem; return null; } Roku.Widget.targetYElement = function(y, parent) { if(!parent) return null; // parent is var rows = Roku.Util.childTagElement(parent, "tbody").childNodes; // array of var minY = 10000, maxY = 0; var minElem = null, maxElem = null; var length = rows.length; for(var index = 0; index < length; index++) { var element = rows[index]; if(!Roku.Util.CompareNoCase(element.tagName, "tr")) continue; var widgetElement = Roku.Util.childClassElement(element, this.widgetClassName); var dropElement = Roku.Util.childClassElement(element, this.dropLocationClassName); if(!widgetElement && !dropElement) continue; var rect = Roku.Util.elementRect(element); if(rect.top <= minY) { minY = rect.top; minElem = element; } if(maxY <= (rect.top + rect.height)) { maxY = (rect.top + rect.height); maxElem = element; } var posY = y - rect.top; if((0 <= posY) && (posY <= rect.height)) { if(dropElement) return null; else if((posY < (rect.height / 2))) { // lookup prev element - omit if dropLocation for(--index; 0 <= index; index--) { var prev_element = rows[index]; if(!Roku.Util.CompareNoCase(prev_element.tagName, "tr")) continue; var prev_dropElement = Roku.Util.childClassElement(prev_element, this.dropLocationClassName); if(prev_dropElement) return null; } return element; // before element } else { // lookup next element for(++index; index < length; index++) { var next_element = rows[index]; if(!Roku.Util.CompareNoCase(next_element.tagName, "tr")) continue; var next_dropElement = Roku.Util.childClassElement(next_element, this.dropLocationClassName); if(next_dropElement) return null; // omit - do nothing var next_widgetElement = Roku.Util.childClassElement(next_element, this.widgetClassName); if(next_widgetElement) return next_element; // before this } return parent; // at end } } } if(minElem && (y <= minY)) { var min_dropElement = Roku.Util.childClassElement(minElem, this.dropLocationClassName); if(min_dropElement) return null; else return minElem; } if(maxElem && (maxY <= y)) { var max_dropElement = Roku.Util.childClassElement(maxElem, this.dropLocationClassName); if(max_dropElement) return null; else return parent; // at end } return parent; // at end } Roku.Widget.createDropTargetElement = function(width, height) { // // var div = document.createElement("div"); div.className = "dropLocation"; div.style.width = (width) + "px"; div.style.height = (height - 1) + "px"; var td = document.createElement("td"); td.className = "entryCell"; td.align = "center"; td.appendChild(div); var tr = document.createElement("tr"); tr.className = "entryRow"; tr.appendChild(td); return tr; } Roku.Widget.removeDropTargetElement = function() { var dropTargetElement = Roku.Util.childClassElement(document.body, this.dropLocationClassName); if(dropTargetElement) { try { dropTargetElement.parentNode.parentNode.parentNode.removeChild(dropTargetElement.parentNode.parentNode); } catch(x) {} } } Roku.Widget.on_close = function(ev) { var element = Roku.Util.srcEventElement(ev); var widgetElement = Roku.Util.parentClassElement(element, this.widgetClassName); this.hideWidget(widgetElement); } Roku.Widget.hideWidget = function(widgetElement) { if(widgetElement) widgetElement.style.display = "none"; var showAllElement = document.getElementById(this.showAllElementId); if(showAllElement) showAllElement.style.display = "inline"; }; Roku.Widget.on_show_all = function() { this.showAllWidgets(); } Roku.Widget.showAllWidgets = function(parent) { if(!parent) { parent = document.body; var showAllElement = document.getElementById(this.showAllElementId); if(showAllElement) showAllElement.style.display = "none"; } var elements = parent.childNodes; if(!elements) return; var count = elements.length; for(var i = 0; i < count; i++) { var element = elements[i]; if(element && (element.className == this.widgetClassName)) { if(!element.getAttribute(this.disabledAttribName)) element.style.display = "block"; } else this.showAllWidgets(element); } }; Roku.Widget.on_min_restore = function(ev) { var element = Roku.Util.srcEventElement(ev); var widgetElement = Roku.Util.parentClassElement(element, this.widgetClassName); this.min_restore_Widget(widgetElement); } Roku.Widget.min_restore_Widget = function(widgetElement) { var contentBar = Roku.Util.childClassElement(widgetElement, this.widgetContentBarClassName); if(!contentBar) return; var btnMin = Roku.Util.childClassElement(widgetElement, this.widgetMinButtonClassName); var contentDisplay = contentBar.style.display; if(contentDisplay != "none") { contentBar.style.display = "none"; if(btnMin != null) btnMin.src = "images/btn-restore.gif"; } else { contentBar.style.display = "block"; if(btnMin != null) btnMin.src = "images/btn-minimize.gif"; } if(widgetElement && (typeof(widgetElement[this.min_restoreEventName]) == "function")) widgetElement[this.min_restoreEventName](widgetElement); if(document.selection != null) document.selection.empty(); }; Roku.Widget.onStationDragEnter = function(target, station) { var widgetElement = Roku.Util.parentClassElement(target, this.widgetClassName); if(!widgetElement) return false; if(widgetElement.style.display == "none") // not visible / closed return false; var contentBar = Roku.Util.childClassElement(widgetElement, this.widgetContentBarClassName); if(!contentBar || (contentBar.style.display != "none")) // restored state - nothing to do return false; this.dropStationWidget = widgetElement; this.dragStation = station; this.dragStationOpacity = Math.ceil(this.dragStationInitAnim.stationDropOpacity * 100); this.dragStationTimeoutId = window.setTimeout("Roku.Widget.animateTimeout()", this.dragStationAnimTimeout); return this.dragStationInitAnim; } Roku.Widget.animateTimeout = function() { this.dragStationTimeoutId = null; if(!this.dragStation) return; this.dragStationOpacity = Math.min(100, this.dragStationOpacity + this.dragStationAnimStep); this.dragStation.style.opacity = this.dragStationOpacity / 100.0; this.dragStation.style.filter = "alpha(opacity=" + this.dragStationOpacity +")"; if(this.dragStationOpacity < 100) this.dragStationTimeoutId = window.setTimeout("Roku.Widget.animateTimeout()", this.dragStationAnimTimeout); else { this.min_restore_Widget(this.dropStationWidget); Roku.Station.setDropTarget(null); this.clearDragStationData(); } } Roku.Widget.onStationDragLeave = function(target, station) { this.clearDragStationData(); } Roku.Widget.onStationDrop = function(target, station) { this.clearDragStationData(); } Roku.Widget.clearDragStationData = function() { if(this.dragStationTimeoutId != null) window.clearTimeout(this.dragStationTimeoutId); this.dropStationWidget = null; this.dragStation = null; this.dragStationOpacity = null; this.dragStationTimeoutId = null; } Roku.Widget.enabled = function(widget) { return !this.disabled(); } Roku.Widget.disabled = function(widget) { return Roku.Util.childClassElement(widget, this.overlaperClassName) != null; } Roku.Widget.enable = function(widget, enable) { if(!widget) return; if(enable) { var overlap = Roku.Util.childClassElement(widget, this.overlaperClassName); if(overlap) widget.removeChild(overlap); } else if(this.enabled()) { var widgetRect = Roku.Util.elementRect(widget); var overlap = document.createElement("div"); overlap.className = this.overlaperClassName; overlap.style.left = widgetRect.left + "px"; overlap.style.top = widgetRect.top + "px"; overlap.style.width = widgetRect.width + "px"; overlap.style.height = widgetRect.height + "px"; widget.appendChild(overlap); } } Roku.Widget.getCurrentWidgetsPlacement = function() { var placement = ""; var contentTable = Roku.Util.childClassElement(document.body, this.contentTableClassName); if(contentTable) { var currentCol = 0; var cols = Roku.Util.childTagElement(contentTable, "tbody", "tr").childNodes; // array of var rows_count = rows.length; for(var iRow = 0; iRow < rows_count; iRow++) { var row = rows[iRow]; if(row && Roku.Util.CompareNoCase(row.tagName, "tr")) { var widget = Roku.Util.childClassElement(row, this.widgetClassName); if(widget && !widget.getAttribute(this.disabledAttribName)) { widgetElements.push( {element : row, column : current_col} ); if(0 < current_placement.length) current_placement += ";"; current_placement += widget.id + "=" + current_col + "|" + current_row + "|"; current_row++; } } } current_col++; } } // remove exisiting widgets from content table var widgetElementsCount = widgetElements.length; for(var index = 0; index < widgetElementsCount; index++) widgetElements[index].element.parentNode.removeChild(widgetElements[index].element); // get placement string from document cookie if(!placement) placement = current_placement; // init widgetInfos from cookie string var aWidgetInfo = []; var aCookieEntriesStr = placement.split(";"); var cookieEntriesStrCount = aCookieEntriesStr.length; for(var index = 0; index < cookieEntriesStrCount; index++) { var aCookieEntry = aCookieEntriesStr[index].split('='); if(aCookieEntry.length == 2) { var widgetInfo = {}; widgetInfo.id = aCookieEntry[0]; // widget name var aCookieData = aCookieEntry[1].split("|"); if(2 <= aCookieData.length) { widgetInfo.col = aCookieData[0]; // widget col widgetInfo.row = aCookieData[1]; // widget row widgetInfo.min = false; // widget minimized widgetInfo.close = false; // widget closed if(3 <= aCookieData.length) { if(0 <= aCookieData[2].indexOf("m")) widgetInfo.min = true; if(0 <= aCookieData[2].indexOf("c")) widgetInfo.close = true; } aWidgetInfo.push(widgetInfo); } } } // sort widgetInfos in order to be added in "content table" var updated; var widgetInfoCount = aWidgetInfo.length; do { updated = false; for(var index = 1; index < widgetInfoCount; index++) { var widgetInfo1 = aWidgetInfo[index - 1]; var widgetInfo2 = aWidgetInfo[index]; // compare widgetInfo1 and widgetInfo2 if((widgetInfo2.col < widgetInfo1.col) || ((widgetInfo2.col == widgetInfo1.col) && (widgetInfo2.row < widgetInfo1.row))) { aWidgetInfo[index - 1] = widgetInfo2; aWidgetInfo[index] = widgetInfo1; updated = true; } } } while(updated); // set widget elements from widgetElements pool to content table as described in aWidgetInfo var showAllElement = document.getElementById("showAll"); for(var index = 0; index < widgetInfoCount; index++) { var widgetElem = null; var widgetInfo = aWidgetInfo[index]; for(var i = 0; i < widgetElementsCount; i++) if(widgetElements[i].element && Roku.Util.childTagElement(widgetElements[i].element, "td", "div").id == widgetInfo.id) { widgetElem = widgetElements[i].element; widgetElements[i].element = null; break; } if(widgetElem) { var widget = Roku.Util.childClassElement(widgetElem, this.widgetClassName); if(!widget) continue; widget.style.display = widgetInfo.close ? "none" : "block"; if(showAllElement && (widget.style.display == "none")) showAllElement.style.display = "inline"; var widgetContent = Roku.Util.childClassElement(widgetElem, this.widgetContentBarClassName); if(widgetContent) widgetContent.style.display = widgetInfo.min ? "none" : "block"; var btnMin = Roku.Util.childClassElement(widgetElem, this.widgetMinButtonClassName); if(btnMin) btnMin.src = widgetInfo.min ? "images/btn-restore.gif" : "images/btn-minimize.gif"; if(typeof(widget[this.min_restoreEventName]) == "function") widget[this.min_restoreEventName](widget); var col = Roku.Util.indexTagElement(cols, "td", widgetInfo.col); if(col) Roku.Util.childTagElement(col, "table", "tbody").appendChild(widgetElem); } } // widgets left in source pool that are not set by cookie (new widgets - add them also) for(var i = 0; i < widgetElementsCount; i++) if(widgetElements[i].element) { var widgetElem = widgetElements[i].element; var widget = Roku.Util.childClassElement(widgetElem, this.widgetClassName); if(widget) widget.style.display = "block"; var col = Roku.Util.indexTagElement(cols, "td", widgetElements[i].column); if(col) Roku.Util.childTagElement(col, "table", "tbody").appendChild(widgetElem); } } Roku.Widget.storeCurrentWidgetsPlacement = function() { var placement = this.getCurrentWidgetsPlacement(); var contentTable = Roku.Util.childClassElement(document.body, this.contentTableClassName); var query_key = contentTable ? contentTable.getAttribute(this.queryKeyAttribName) : ""; var query_value = contentTable ? contentTable.getAttribute(this.queryValueAttribName) : ""; if(query_key && query_value) Roku.Query.invoke_sync(query_key + "=" + query_value + "&value=" + placement); } Roku.Widget.loadCurrentWidgetsPlacement = function() { var contentTable = Roku.Util.childClassElement(document.body, this.contentTableClassName); var placement = contentTable ? contentTable.getAttribute(this.widgetsPlacementAttribName) : ""; this.setCurrentWidgetsPlacement(placement); } Roku.Widget.initialize = function() { var mouseDownHandler = function() { return Roku.Widget.on_mouse_down((0 < arguments.length) ? arguments[0] : null); }; var mouseMoveHandler = function() { return Roku.Widget.on_mouse_move((0 < arguments.length) ? arguments[0] : null); }; var mouseUpHandler = function() { return Roku.Widget.on_mouse_up((0 < arguments.length) ? arguments[0] : null); }; var min_restore_Handler = function() { return Roku.Widget.on_min_restore((0 < arguments.length) ? arguments[0] : null); }; var closeHandler = function() { return Roku.Widget.on_close((0 < arguments.length) ? arguments[0] : null); }; var showAllHandler = function() { return Roku.Widget.on_show_all((0 < arguments.length) ? arguments[0] : null); }; var widgets = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.widgetClassName] : Roku.Util.childrenClassElements(document.body, this.widgetClassName); var widgets_count = widgets ? widgets.length : 0; for(var index = 0; index < widgets_count; index++) { var widget = widgets[index]; var widgetMinButton = Roku.Util.childClassElement(widget, this.widgetMinButtonClassName); Roku.Util.eventHandler(widgetMinButton, "click", min_restore_Handler); var widgetCloseButton = Roku.Util.childClassElement(widget, this.widgetCloseButtonClassName); Roku.Util.eventHandler(widgetCloseButton, "click", closeHandler); var widgetTitleBar = Roku.Util.childClassElement(widget, this.widgetTitleBarClassName); if(widgetTitleBar) { Roku.Util.eventHandler(widgetTitleBar, "mousedown", mouseDownHandler); Roku.Util.eventHandler(widgetTitleBar, "dblclick", min_restore_Handler); widgetTitleBar.onstationdragenter = function(target, station) { return Roku.Widget.onStationDragEnter(target, station); }; widgetTitleBar.onstationdragleave = function(target, station) { return Roku.Widget.onStationDragLeave(target, station); }; widgetTitleBar.onstationdrop = function(target, station) { return Roku.Widget.onStationDrop(target, station); }; //Roku.Util.eventHandler(widgetTitleBar, "mousemove", mouseMoveHandler); //Roku.Util.eventHandler(widgetTitleBar, "mouseup", mouseUpHandler); } var widgetControlsBar = Roku.Util.childClassElement(widget, this.widgetControlsBarClassName); if(widgetControlsBar && !Roku.Util.CompareNoCase(window.navigator.appName, "Microsoft Internet Explorer")) widgetControlsBar.style.marginRight = "10px"; } var showAllElement = document.getElementById(this.showAllElementId); var showAllTargetElement = Roku.Util.childIdElement(showAllElement, this.showAllTargetElementId); if(!showAllTargetElement) showAllTargetElement = showAllElement; Roku.Util.eventHandler(showAllTargetElement, "click", showAllHandler); } Roku.Widget.onBodyLoad = function() { this.loadCurrentWidgetsPlacement(); var footer = document.getElementById(this.footerElementId); if(footer) footer.style.display = "block"; } Roku.Widget.onBodyUnload = function() { this.storeCurrentWidgetsPlacement(); } /* Roku.LanguageMenu */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.LanguageMenu = { menu_id : "language_menu", drop_id : "lang_drop", menuEntryClassName : "menu_entry", menuIconClassName : "menu_icon", menuTextClassName : "menu_text", dropLanguageIconId : "lang_icon", queryKeyAttribName : "query_key", queryValueAttribName: "query_value", menu : null, drop : null, drop_lang_icon : null, menu_visible : false, query_key : "", query_value : "" }; Roku.classes.push(Roku.LanguageMenu); Roku.LanguageMenu.on_click_drop = function(ev) { Roku.Util.eventCancel(ev); this.show_menu(!this.menu_visible); } Roku.LanguageMenu.show_menu = function(show) { if(!this.menu) return; if(show) { var rect = Roku.Util.elementRect(this.drop); rect.left += this.drop.scrollLeft; rect.top += this.drop.scrollTop; this.menu.style.left = (rect.left) + "px"; this.menu.style.top = (rect.top + rect.height) + "px"; } this.menu_visible = show; this.menu.style.display = show ? "block" : "none"; } Roku.LanguageMenu.need_mouse_down = function() { return this.menu_visible; } Roku.LanguageMenu.on_mouse_down = function(ev) { var element = Roku.Util.srcEventElement(ev); if(!element) return; if(Roku.Util.parentIdElement(element, this.menu_id)) { // clicked menu entry this.on_menu_entry(ev); } else if(Roku.Util.parentIdElement(element, this.drop_id)) { // clicked drop entry // this.on_click_drop(ev); } else { // clicked elsewhere this.show_menu(false); } } Roku.LanguageMenu.on_mouse_entry = function(ev) { if(!ev) return; var element = Roku.Util.srcEventElement(ev); var menu_item = Roku.Util.parentClassElement(element, this.menuEntryClassName); var hilight = !Roku.Util.CompareNoCase(ev.type, "mouseout"); this.hilightMenuItem(menu_item, hilight); } Roku.LanguageMenu.hilightMenuItem = function(menu_item, hilight) { var icon = Roku.Util.childClassElement(menu_item, this.menuIconClassName); if(icon) { icon.style.opacity = hilight ? 1.00 : 0.70; icon.style.filter = hilight ? "" : "alpha(opacity=70)"; } var text = Roku.Util.childClassElement(menu_item, this.menuTextClassName); if(text) { text.style.color = hilight ? "#FFFFFF" : "#C0C0C0"; text.style.textDecoration = hilight ? "underline" : "none"; } } Roku.LanguageMenu.on_menu_entry = function(ev) { var element = Roku.Util.srcEventElement(ev); var menu_item = Roku.Util.parentClassElement(element, this.menuEntryClassName); var language_id = menu_item ? menu_item.id : ""; if(0 < language_id) { if(this.drop_lang_icon) this.drop_lang_icon.src = "flags/" + language_id + ".gif"; if(this.query_key && this.query_value) Roku.Query.invoke(this.query_key + "=" + this.query_value + "&value=" + language_id, function() { window.location = "index.php"; }); } this.show_menu(false); } Roku.LanguageMenu.initialize = function() { this.menu = document.getElementById(this.menu_id); var menu_items = Roku.Util.childrenClassElements(this.menu, this.menuEntryClassName) for(var index in menu_items) { var menu_item = menu_items[index]; Roku.Util.eventHandler(menu_item, "mouseover", function(ev) { Roku.LanguageMenu.on_mouse_entry(ev); } ); Roku.Util.eventHandler(menu_item, "mouseout", function(ev) { Roku.LanguageMenu.on_mouse_entry(ev); }); } this.drop = document.getElementById(this.drop_id); Roku.Util.eventHandler(this.drop, "mousedown", function(ev) { Roku.LanguageMenu.on_click_drop(); }); this.drop_lang_icon = Roku.Util.childIdElement(this.drop, this.dropLanguageIconId); this.query_key = this.menu ? this.menu.getAttribute(this.queryKeyAttribName) : ""; this.query_value = this.menu ? this.menu.getAttribute(this.queryValueAttribName) : ""; this.menu_visible = false; } /* Roku.Tab */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Tab = { tabClassName : "tab", tabItemsListClassName : "tab_items_list", tabItemClassName : "tab_item", tabItemFooterClassName : "tab_items_footer", tabItemHeaderClassName : "tab_items_header", tabPagesListClassName : "tab_pages_list", tabPageClassName : "tab_page", tabOffsetAttributeName : "tab_offset", tabItemSelAttribName : "selected", selChangedEventName : "selection_changed", dropStationTabItem : null, dragStation : null, dragStationOpacity : null, dragStationTimeoutId : null, dragStationAnimTimeout : 15, dragStationAnimStep : 2, dragStationInitAnim : { stationDropOpacity : 0.30, stationDropFilter : "alpha(opacity=30)" } }; Roku.classes.push(Roku.Tab); Roku.Tab.select = function(tab, id) { var tab_items_list = Roku.Util.childClassElement(tab, this.tabItemsListClassName); var sel_item = Roku.Util.childIdElement(tab_items_list, id); this.selectTabItem(tab, sel_item); } Roku.Tab.selected = function(tab) { var tab_item = this.selectedTabItem(tab); return tab_item ? tab_item.id : ""; } Roku.Tab.item = function(tab, index) { var tab_items_list = Roku.Util.childClassElement(tab, this.tabItemsListClassName); var tab_items = Roku.Util.childrenClassElements(tab_items_list, this.tabItemClassName); return (tab_items && (0 <= index) && (index < tab_items.length)) ? tab_items[index].id : ""; } Roku.Tab.item_index = function(tab, tab_item) { var tab_item_id = tab_item ? tab_item.id : ""; var tab_items_list = Roku.Util.childClassElement(tab, this.tabItemsListClassName); var tab_items = Roku.Util.childrenClassElements(tab_items_list, this.tabItemClassName); var tab_items_count = tab_items.length; for(var index = 0; index < tab_items_count; index++) if(tab_items[index].id == tab_item_id) return index; return -1; } Roku.Tab.on_select = function(ev) { var element = Roku.Util.srcEventElement(ev); var tab_item = Roku.Util.parentClassElement(element, this.tabItemClassName); var tab = Roku.Util.parentClassElement(element, this.tabClassName); this.selectTabItem(tab, tab_item); if(tab && (typeof(tab[this.selChangedEventName]) == "function")) tab[this.selChangedEventName](tab, tab_item); } Roku.Tab.selectTabItem = function(tab, sel_item) { if(!tab) return; var tab_items_list = Roku.Util.childClassElement(tab, this.tabItemsListClassName); var tab_items = Roku.Util.childrenClassElements(tab_items_list, this.tabItemClassName); var tab_items_count = tab_items.length; var tab_pages_list = Roku.Util.childClassElement(tab, this.tabPagesListClassName); var zIndex = tab_items.length - 1; for(var index = 0; index < tab_items_count; index++) { var tab_item = tab_items[index]; var tab_page = Roku.Util.childIdElement(tab_pages_list, tab_item.id); if(tab_item == sel_item) { tab_item.style.zIndex = tab_items.length; //tab_item.style.borderBottomStyle = "none"; //tab_item.style.height = "22px"; tab_item.style.borderBottomColor = "#FFFFFF"; tab_item.setAttribute(this.tabItemSelAttribName, "true"); if(tab_page) tab_page.style.display = "block"; } else { tab_item.style.zIndex = zIndex; zIndex--; //tab_item.style.borderBottomStyle = "solid"; //tab_item.style.height = "20px"; tab_item.style.borderBottomColor = "#6E6E6E"; tab_item.removeAttribute(this.tabItemSelAttribName); if(tab_page) tab_page.style.display = "none"; } } } Roku.Tab.isTabItemSelected = function(tab_item) { //return (tab_item.style.borderBottomStyle == "none"); //return Roku.Util.CompareNoCase(tab_item.style.borderBottomColor, "#FFFFFF"); //return Roku.Util.CompareNoCase(tab_item.getAttribute(this.tabItemSelAttribName), "true"); return tab_item.getAttribute(this.tabItemSelAttribName); } Roku.Tab.selectedTabItem = function(tab) { if(!tab) return null; var tab_items_list = Roku.Util.childClassElement(tab, this.tabItemsListClassName); var tab_items = Roku.Util.childrenClassElements(tab_items_list, this.tabItemClassName); var tab_items_count = tab_items.length; for(var index = 0; index < tab_items_count; index++) { var tab_item = tab_items[index]; if(this.isTabItemSelected(tab_item)) return tab_item; } return null; } Roku.Tab.onStationDragEnter = function(target, station) { if(this.isTabItemSelected(target)) return false; this.dropStationTabItem = target; this.dragStation = station; this.dragStationOpacity = Math.ceil(this.dragStationInitAnim.stationDropOpacity * 100); this.dragStationTimeoutId = window.setTimeout("Roku.Tab.animateTimeout()", this.dragStationAnimTimeout); return this.dragStationInitAnim; } Roku.Tab.animateTimeout = function() { this.dragStationTimeoutId = null; if(!this.dragStation) return; this.dragStationOpacity = Math.min(100, this.dragStationOpacity + this.dragStationAnimStep); this.dragStation.style.opacity = this.dragStationOpacity / 100.0; this.dragStation.style.filter = "alpha(opacity=" + this.dragStationOpacity +")"; if(this.dragStationOpacity < 100) this.dragStationTimeoutId = window.setTimeout("Roku.Tab.animateTimeout()", this.dragStationAnimTimeout); else { var tab = Roku.Util.parentClassElement(this.dropStationTabItem, this.tabClassName); this.selectTabItem(tab, this.dropStationTabItem); Roku.Station.setDropTarget(null); this.clearDragData(); } } Roku.Tab.onStationDragLeave = function(target, station) { this.clearDragData(); } Roku.Tab.onStationDrop = function(target, station) { this.clearDragData(); } Roku.Tab.clearDragData = function() { if(this.dragStationTimeoutId != null) window.clearTimeout(this.dragStationTimeoutId); this.dropStationTabItem = null; this.dragStation = null; this.dragStationOpacity = null; this.dragStationTimeoutId = null; } Roku.Tab.selectHandler = function(ev) { return Roku.Tab.on_select(ev); }; Roku.Tab.initialize = function() { var tabs = Roku.Body.all ? Roku.Body.all[this.tabClassName] : Roku.Util.childrenClassElements(document.body, this.tabClassName); var tabs_count = tabs ? tabs.length : 0; for(var iTab = 0; iTab < tabs_count; iTab++) { var tab = tabs[iTab]; var tab_items_list = Roku.Util.childClassElement(tab, this.tabItemsListClassName); var tab_items = Roku.Util.childrenClassElements(tab_items_list, this.tabItemClassName); var tab_items_count = tab_items.length; var tab_pages_list = Roku.Util.childClassElement(tab, this.tabPagesListClassName); var left = 0; var zIndex = tab_items_count; var offsetX = parseInt(tab.getAttribute(this.tabOffsetAttributeName)); if(isNaN(offsetX)) offsetX = 5; for(var iTabItem = 0; iTabItem < tab_items_count; iTabItem++) { var tab_item = tab_items[iTabItem]; tab_item.style.left = left + "px"; left -= offsetX; tab_item.style.zIndex = zIndex; zIndex -= 1; Roku.Util.eventHandler(tab_item, "click", Roku.Tab.selectHandler); tab_item.onstationdragenter = function(target, station) { return Roku.Tab.onStationDragEnter(target, station); }; tab_item.onstationdragleave = function(target, station) { return Roku.Tab.onStationDragLeave(target, station); }; tab_item.onstationdrop = function(target, station) { return Roku.Tab.onStationDrop(target, station); }; var tab_page = Roku.Util.childIdElement(tab_pages_list, tab_item.id); if(tab_page) tab_page.style.display = "none"; } var tab_footer = Roku.Util.childClassElement(tab, this.tabItemFooterClassName); if(tab_footer) { tab_footer.style.left = (left + offsetX) + "px"; } //tab.style.width = (tab.offsetWidth + left) + "px"; } } /* Roku.Button */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Button = { buttonClassName : "button", buttonLeftClassName : "button_left", buttonContentClassName : "button_content", buttonRightClassName : "button_right", buttonClickPropName : "on_click", buttonDisabledAttribName : "button_disabled", hilightElement : null, hilightElementColor : null, hilightElementDecor : null }; Roku.classes.push(Roku.Button); Roku.Button.on_mouse_over = function(ev) { var element = Roku.Util.srcEventElement(ev); var button = Roku.Util.parentClassElement(element, this.buttonClassName); if(button && this.enabled(button)) { if(this.hilightElement && (this.hilightElement != button)) { this.hilightElement.style.color = this.hilightElementColor; this.hilightElement.style.textDecoration = this.hilightElementDecor; } this.hilightElement = button; this.hilightElementColor = button.style.color; this.hilightElementDecor = button.style.textDecoration; button.style.color = "#765CF0"; button.style.textDecoration = "underline"; } } Roku.Button.on_mouse_out = function() { if(this.hilightElement) { this.hilightElement.style.color = this.hilightElementColor; this.hilightElement.style.textDecoration = this.hilightElementDecor; this.hilightElement = null; } } Roku.Button.on_mouse_click = function(ev) { var element = Roku.Util.srcEventElement(ev); var button = Roku.Util.parentClassElement(element, this.buttonClassName); if(button && this.enabled(button)) { var on_click_value = button.getAttribute(this.buttonClickPropName); if(!on_click_value) on_click_value = button[this.buttonClickPropName]; if(typeof(on_click_value) == "string") window.eval(on_click_value); else if(typeof(on_click_value) == "function") on_click_value(button, ev); } } Roku.Button.set_disabled = function(button, disabled) { if(!button) return; var left = Roku.Util.childClassElement(button, this.buttonLeftClassName); if(left) left.style.backgroundImage = disabled ? "url('images/button-left-disabled.gif')" : ""; var center = Roku.Util.childClassElement(button, this.buttonContentClassName); if(center) center.style.backgroundImage = disabled ? "url('images/button-center-disabled.png')" : ""; var right = Roku.Util.childClassElement(button, this.buttonRightClassName); if(right) right.style.backgroundImage = disabled ? "url('images/button-right-disabled.gif')" : ""; button.disabled = disabled; button.style.cursor = disabled ? "default" : ""; if(disabled) button.setAttribute(this.buttonDisabledAttribName, "true"); else button.removeAttribute(this.buttonDisabledAttribName); } Roku.Button.disabled = function(button) { return button ? (button.getAttribute(this.buttonDisabledAttribName) == "true") : true; } Roku.Button.disable = function(button, disabled) { if(typeof(disabled) == "undefined") disabled = true; if(this.disabled(button) != disabled) this.set_disabled(button, disabled ? true : false); } Roku.Button.enabled = function(button) { return button ? (button.getAttribute(this.buttonDisabledAttribName) != "true") : false; } Roku.Button.enable = function(button, enabled) { if(typeof(enabled) == "undefined") enabled = true; if(this.enabled(button) != enabled) this.set_disabled(button, enabled ? false : true); } Roku.Button.get_text = function(button) { var center = Roku.Util.childClassElement(button, this.buttonContentClassName); return center ? center.innerHTML : ""; } Roku.Button.set_text = function(button, text) { var center = Roku.Util.childClassElement(button, this.buttonContentClassName); if(center) center.innerHTML = text; } Roku.Button.initialize = function() { var mouseOverHandler = function() { return Roku.Button.on_mouse_over((0 < arguments.length) ? arguments[0] : null); }; var mouseOutHandler = function() { return Roku.Button.on_mouse_out((0 < arguments.length) ? arguments[0] : null); }; var mouseClickHandler = function() { return Roku.Button.on_mouse_click((0 < arguments.length) ? arguments[0] : null); }; var buttons = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.buttonClassName] : Roku.Util.childrenClassElements(document.body, this.buttonClassName); var buttons_count = buttons ? buttons.length : 0; for(var index = 0; index < buttons_count; index++) { var button = buttons[index]; Roku.Util.eventHandler(button, "mouseover", mouseOverHandler); Roku.Util.eventHandler(button, "mouseout", mouseOutHandler); Roku.Util.eventHandler(button, "click", mouseClickHandler); if(this.disabled(button)) this.set_disabled(button, true); } } /* Roku.Rank */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Rank = { panelClassName : "rank_panel", values : [ "images/stars-00-drk.gif", "images/stars-01-drk.gif", "images/stars-02-drk.gif", "images/stars-03-drk.gif", "images/stars-04-drk.gif", "images/stars-05-drk.gif", "images/stars-06-drk.gif", "images/stars-07-drk.gif", "images/stars-08-drk.gif", "images/stars-09-drk.gif", "images/stars-10-drk.gif" ] }; Roku.classes.push(Roku.Rank); Roku.Rank.get_value = function(rank) { var value = rank ? rank.style.backgroundImage : ""; var length = this.values.length; for(var index = 0; index < length; index++) if(0 <= value.indexOf(this.values[index])) return (index/(length - 1)); return -1; } Roku.Rank.set_value = function(rank, value) { var index = value; if((0 <= value) && (value <= 1)) index = Math.round(value * (this.values.length - 1)); else if(value < 0) index = 0; else if(this.values.length <= value) index = this.values.length - 1; if(rank) rank.style.backgroundImage ="url(" + this.values[index] + ")"; } Roku.Rank.set_visible = function(rank, value) { if(rank) rank.style.visibility = value ? "visible" : "hidden"; } Roku.Rank.is_visible = function(rank) { return (rank && (rank.style.visibility != "hidden")); } /* Roku.Slider */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Slider = { sliderClassName : "slider", sliderHandleClassName : "slider_handle", disabledAttribName : "slider_disabled", dragHandle : null, dragSlider : null, dragPointX : 0, dragHandleX : 0, dragMaxX : 0 }; Roku.classes.push(Roku.Slider); Roku.Slider.getPos = function(slider) { var handle = Roku.Util.childClassElement(slider, this.sliderHandleClassName); if(!handle) return 0; var width = slider.offsetWidth - handle.offsetWidth; if(width <= 0) return 0; var pos = (handle.offsetLeft / width); pos = Math.max(0, pos); pos = Math.min(1, pos); return pos; } Roku.Slider.setPos = function(slider, value) { var handle = Roku.Util.childClassElement(slider, this.sliderHandleClassName); if(!handle) return; value = Math.max(0, value); value = Math.min(1, value); handle.style.left = Math.ceil((slider.offsetWidth - handle.offsetWidth) * value) + "px"; if (handle.style.left == "63px") handle.style.left = "64px" //Roku.Util.Trace("debug_out", handle.style.left); } Roku.Slider.on_mouse_down = function(ev) { var element = Roku.Util.srcEventElement(ev); var handle = Roku.Util.parentClassElement(element, this.sliderHandleClassName); var slider = Roku.Util.parentClassElement(handle, this.sliderClassName); if(this.dragHandle || !ev || !handle || !slider || slider.getAttribute(this.disabledAttribName)) return; this.dragHandle = element; this.dragSlider = slider; this.dragPointX = ev.clientX; this.dragHandleX = element.offsetLeft; this.dragMaxX = slider.offsetWidth - handle.offsetWidth if(this.dragHandle.setCapture) this.dragHandle.setCapture(); } Roku.Slider.on_mouse_move = function(ev) { if(!this.dragHandle || !ev) return; var x = (this.dragHandleX + ev.clientX - this.dragPointX); x = Math.max(0, x); x = Math.min(this.dragMaxX, x); this.dragHandle.style.left = x + "px"; if(this.dragSlider && (typeof(this.dragSlider.changing_handler) == "function")) this.dragSlider.changing_handler(this.dragSlider); } Roku.Slider.sliding = function() { return (this.dragHandle); } Roku.Slider.need_mouse_move = function() { return this.sliding(); } Roku.Slider.on_mouse_up = function(ev) { if(!this.dragHandle) return; if(this.dragSlider && (typeof(this.dragSlider.changed_handler) == "function")) this.dragSlider.changed_handler(this.dragSlider); if(this.dragHandle.releaseCapture) this.dragHandle.releaseCapture(); this.dragHandle = null; this.dragSlider = null; } Roku.Slider.click = function(ev) { if(this.dragHandle) return; var element = Roku.Util.srcEventElement(ev); var slider = Roku.Util.parentClassElement(element, this.sliderClassName); var handle = Roku.Util.childClassElement(slider, this.sliderHandleClassName); if(!ev || !slider || !handle || slider.getAttribute(this.disabledAttribName)) return; var x; if(ev.offsetX) x = ev.offsetX; // IE else if(ev.pageX) x = ev.pageX - Roku.Util.elementRect(slider).left; // Mozilla else return; if((handle.offsetLeft <= x) && (x < (handle.offsetLeft + handle.offsetWidth))) return; x -= handle.offsetWidth / 2; x = Math.max(0, x); x = Math.min(slider.offsetWidth - handle.offsetWidth, x); handle.style.left = x + "px"; if(typeof(slider.changed_handler) == "function") slider.changed_handler(slider); this.dragHandle = handle; this.dragSlider = slider; this.dragPointX = ev.clientX; this.dragHandleX = handle.offsetLeft; this.dragMaxX = slider.offsetWidth - handle.offsetWidth if(this.dragHandle.setCapture) this.dragHandle.setCapture(); } Roku.Slider.need_mouse_up = function() { return (this.dragHandle); } Roku.Slider.get_handle = function(slider) { return Roku.Util.childClassElement(slider, this.sliderHandleClassName); } Roku.Slider.show_handle = function(slider, show) { var handle = Roku.Util.childClassElement(slider, this.sliderHandleClassName); if(handle) handle.style.visibility = show ? "visible" : "hidden"; } Roku.Slider.initialize = function() { var mouseDownHandler = function() { return Roku.Slider.on_mouse_down((0 < arguments.length) ? arguments[0] : null); }; var mouseMoveHandler = function() { return Roku.Slider.on_mouse_move((0 < arguments.length) ? arguments[0] : null); }; var mouseUpHandler = function() { return Roku.Slider.on_mouse_up((0 < arguments.length) ? arguments[0] : null); }; var clickHandler = function() { return Roku.Slider.click((0 < arguments.length) ? arguments[0] : null); }; var sliders = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.sliderClassName] : Roku.Util.childrenClassElements(document.body, this.sliderClassName); var sliders_count = sliders ? sliders.length : 0; for(var iSlider = 0; iSlider < sliders_count; iSlider++) { var slider = sliders[iSlider]; Roku.Util.eventHandler(slider, "mousedown", clickHandler); var slider_handle = Roku.Util.childClassElement(slider, this.sliderHandleClassName); if(slider_handle) { Roku.Util.eventHandler(slider_handle, "mousedown", mouseDownHandler); //Roku.Util.eventHandler(slider_handle, "mousemove", mouseMoveHandler); //Roku.Util.eventHandler(slider_handle, "mouseup", mouseUpHandler); } } } /* Roku.Station */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; /////////////////////////////// // Roku.Station Roku.Station = { stationClassName : "station", stationDragPadding : 2, stationDragBorder : 1, stationDragOpacity : 0.30, stationDragFilter : "alpha(opacity=30)", stationDropOpacity : 1.00, stationDropFilter : "alpha(opacity=100)", stationAttrId : "station_id", stationAttrTitle : "station_title", stationAttrUrl : "station_url", stationAttrPopup : "station_popup", stationAttrLive : "station_live", droppedEventName : "station_dropped", dragElement : null, dragOffsetX : 0, dragOffsetY : 0, dragScrollX : 0, dragScrollY : 0, dropTargetClients : [], dropTargets : null, dropTarget : null, mouseDownData : null, mouseDownTimeout : 500, mouseDownOffset : 3, mouseMoveData : null, mouseMoveTimeout : 1000, mouseOutData : null, mouseOutTimeout : 200, scrollX : 0, scrollY : 0, scrollIntervalId : null, scrollOffset : 15, scrollStep : 5, scrollTimeout : 10 }; Roku.classes.push(Roku.Station); Roku.Station.on_mouse_down = function(ev) { if(this.mouseMoveData && this.mouseMoveData.timeoutId) window.clearTimeout(this.mouseMoveData.timeoutId); var element = Roku.Util.srcEventElement(ev); if(this.dragElement || !element || !ev) return; var stationElement = Roku.Util.parentClassElement(element, this.stationClassName); if(!stationElement) return; if(!this.getTitle(stationElement)) return; // ignore this station: no title means nothing to drag this.mouseDownData = { element : element, offsetX : ev.offsetX, offsetY : ev.offsetY, clientX : ev.clientX, clientY : ev.clientY, pageX : ev.pageX, pageY : ev.pageY }; window.setTimeout("Roku.Station.do_mouse_down()", this.mouseDownTimeout); //this.do_mouse_down(); Roku.Util.eventCancel(ev); } Roku.Station.do_mouse_down = function() { if(!this.mouseDownData) return; var ev = this.mouseDownData; this.mouseDownData = null; var element = ev.element; if(this.dragElement || !element) return; var stationElement = Roku.Util.parentClassElement(element, this.stationClassName); if(!stationElement) return; var dropTargets = []; for(var index in this.dropTargetClients) this.scanDropTargets(dropTargets, this.dropTargetClients[index]); if(dropTargets.length == 0) return; var dragElement = stationElement.cloneNode(true); if(!dragElement) return; this.dropTargets = dropTargets; this.dragElement = dragElement; this.dragElement.srcElement = stationElement; var elementRect = Roku.Util.elementRect(element); var parentRect = Roku.Util.elementRect(element.offsetParent); var stationRect = Roku.Util.elementRect(stationElement); if(ev.offsetX && ev.offsetY) { // IE if(Roku.Util.CompareNoCase(element.tagName, "span")) { this.dragOffsetX = ev.offsetX - (stationRect.left - parentRect.left) + this.stationDragPadding + this.stationDragBorder; this.dragOffsetY = ev.offsetY - (stationRect.top - parentRect.top) + this.stationDragPadding + this.stationDragBorder + 2; // 2 is margin-top, can't find a way to retrieve it from stationElement this.dragScrollX = parentRect.left - (ev.clientX - ev.offsetX); this.dragScrollY = parentRect.top - (ev.clientY - ev.offsetY); } else { this.dragOffsetX = ev.offsetX + this.stationDragPadding + this.stationDragBorder; this.dragOffsetY = ev.offsetY + this.stationDragPadding + this.stationDragBorder + 2; // 2 is margin-top, can't find a way to retrieve it from stationElement this.dragScrollX = elementRect.left - (ev.clientX - ev.offsetX); this.dragScrollY = elementRect.top - (ev.clientY - ev.offsetY); } } else if(ev.pageX && ev.pageY) { // Mozilla this.dragScrollX = ev.pageX - ev.clientX; this.dragScrollY = ev.pageY - ev.clientY; this.dragOffsetX = ev.clientX + this.dragScrollX - stationRect.left + this.stationDragPadding + this.stationDragBorder;; this.dragOffsetY = ev.clientY + this.dragScrollY - stationRect.top + this.stationDragPadding + this.stationDragBorder + 2; } this.dragElement.style.left = (this.dragScrollX + ev.clientX - this.dragOffsetX) + "px"; this.dragElement.style.top = (this.dragScrollY + ev.clientY - this.dragOffsetY) + "px"; this.dragElement.style.width = (stationRect.width + 2*this.stationDragPadding + 2*this.stationDragBorder)+ "px"; this.dragElement.style.height = (stationRect.height + 2*this.stationDragPadding + 2*this.stationDragBorder) + "px"; this.dragElement.style.position = "absolute"; this.dragElement.style.zIndex = 999; this.dragElement.style.color = "#5524DE"; this.dragElement.style.border = this.stationDragBorder + "px solid #000000"; this.dragElement.style.backgroundColor = "#FFFFFF"; this.dragElement.style.cursor = "default"; this.dragElement.style.padding = this.stationDragPadding + "px"; this.dragElement.style.opacity = this.stationDragOpacity; this.dragElement.style.filter = this.stationDragFilter; document.body.appendChild(this.dragElement); this.dragElement.focus(); if(this.dragElement.setCapture) this.dragElement.setCapture(); if(document.selection) document.selection.empty(); for(var index in this.dropTargets) { var target = this.dropTargets[index]; if(target && (typeof(target.onstationdragbegin) == "function")) target.onstationdragbegin(target, this.dragElement); } this.scrollX = 0; this.scrollY = 0; return true; } Roku.Station.on_mouse_move = function(ev) { if(!ev) return; if(this.mouseDownData) { if((this.mouseDownOffset < Math.abs(this.mouseDownData.clientX - ev.clientX)) || (this.mouseDownOffset < Math.abs(this.mouseDownData.clientY - ev.clientY))) this.do_mouse_down(); else Roku.Util.eventCancel(ev); } if(!this.dragElement) { /* no station tips for now if(this.mouseMoveData && this.mouseMoveData.timeoutId) window.clearTimeout(this.mouseMoveData.timeoutId); var element = Roku.Util.srcEventElement(ev); var station = Roku.Util.parentClassElement(element, this.stationClassName); if(!this.getId(station)) return; // ignore this station: no id means nothing to display in tip this.mouseMoveData = { srcElement : element, offsetX : ev.offsetX, offsetY : ev.offsetY, clientX : ev.clientX, clientY : ev.clientY, pageX : ev.pageX, pageY : ev.pageY }; if(this.mouseOutData) { if(this.mouseOutData.timeoutId) window.clearTimeout(this.mouseOutData.timeoutId); this.mouseOutData = null; if(Roku.TipStation.currentStation() == station) this.mouseMoveData = null; // moving round the same station - just keep the tip visible else if(!Roku.TipStation.auto_poped()) this.show_tip(); // show tip (now) else { // hide the this and shedule new one Roku.TipStation.hide(); this.mouseMoveData.timeoutId = window.setTimeout("Roku.TipStation.visible()", this.mouseMoveTimeout); } } else if(!Roku.TipStation.visible()) { this.mouseMoveData.timeoutId = window.setTimeout("Roku.Station.show_tip()", this.mouseMoveTimeout); // shedule tip } else if(!Roku.TipStation.auto_poped()) { Roku.TipStation.refresh_auto_pop(); // refresh_autopop } */ return; } var x = this.dragScrollX + ev.clientX - this.dragOffsetX; var y = this.dragScrollY + ev.clientY - this.dragOffsetY; this.dragElement.style.left = x + "px"; this.dragElement.style.top = y + "px"; var dropTarget = this.findDropTarget(x + this.dragOffsetX, y + this.dragOffsetY); this.setDropTarget(dropTarget); if(this.dropTarget && (typeof(this.dropTarget.onstationdragover) == "function")) this.dropTarget.onstationdragover(this.dropTarget, this.dragElement, x + this.dragElement.offsetWidth/2, y + this.dragElement.offsetHeight/2); var right = Roku.Util.clientWidth(); var bottom = Roku.Util.clientHeight(); if(ev.clientX < this.scrollOffset) this.scrollX = -this.scrollStep; else if((right - this.scrollOffset) < ev.clientX) this.scrollX = this.scrollStep; else this.scrollX = 0; if(ev.clientY < this.scrollOffset) this.scrollY = -this.scrollStep; else if((bottom - this.scrollOffset) < ev.clientY) this.scrollY = this.scrollStep; else this.scrollY = 0; var doScroll = ((this.scrollX != 0) || (this.scrollY != 0)); if(doScroll && !this.scrollIntervalId) { this.scrollIntervalId = window.setInterval("Roku.Station.on_scroll()", this.scrollTimeout); } else if(!doScroll && this.scrollIntervalId) { window.clearInterval(this.scrollIntervalId); this.scrollIntervalId = null; } if(document.selection) document.selection.empty(); return; } Roku.Station.need_mouse_move = function() { return (this.dragElement || this.mouseDownData); } Roku.Station.on_scroll = function() { var content_table = Roku.Util.childClassElement(document.body, Roku.Widget.contentTableClassName); var content_rect = Roku.Util.elementRect(content_table); var drag_rect = Roku.Util.elementRect(this.dragElement); if(this.scrollX < 0) this.scrollX = Math.max(this.scrollX, -this.dragScrollX); if(0 < this.scrollX) { var content_right = content_rect.left + content_rect.width; var window_right = this.dragScrollX; if(window.innerWidth) window_right += window.innerWidth; else if(0 < document.documentElement.clientWidth) window_right += document.documentElement.clientWidth; else window_right += document.body.clientWidth; this.scrollX = Math.min(this.scrollX, content_right - window_right); } if(this.scrollY < 0) this.scrollY = Math.max(this.scrollY, -this.dragScrollY); if(0 < this.scrollY) { var content_bottom = content_rect.top + content_rect.height; var window_bottom = this.dragScrollY; if(window.innerHeight) window_bottom += window.innerHeight; else if(0 < document.documentElement.clientHeight) window_bottom += document.documentElement.clientHeight; else window_bottom += document.body.clientHeight; this.scrollY = Math.min(this.scrollY, content_bottom - window_bottom); } if((this.scrollY != 0) || (this.scrollX != 0)) { this.dragScrollX += this.scrollX; this.dragScrollY += this.scrollY; this.dragElement.style.left = (drag_rect.left + this.scrollX) + "px"; this.dragElement.style.top = (drag_rect.top + this.scrollY) + "px"; window.scrollBy(this.scrollX, this.scrollY); } else { window.clearInterval(this.scrollIntervalId); this.scrollIntervalId = null; } } Roku.Station.on_mouse_up = function(ev) { if(this.mouseDownData) { var mouseDownData = this.mouseDownData; this.mouseDownData = null; var stationElement = Roku.Util.parentClassElement(mouseDownData.element, this.stationClassName); if(stationElement && (typeof(stationElement.on_clicked) == "function")) { Roku.Util.eventCancel(ev); stationElement.on_clicked(ev); } return; } if(!this.dragElement) return; document.body.removeChild(this.dragElement); for(var index in this.dropTargets) { var target = this.dropTargets[index]; if(target && (target != this.dropTarget) && (typeof(target.onstationdragend) == "function")) target.onstationdragend(target, this.dragElement); } if(typeof(this.dragElement[this.droppedEventName]) == "function") this.dragElement[this.droppedEventName](this.dragElement, this.dropTarget); if(this.dropTarget && (typeof(this.dropTarget.onstationdrop) == "function")) this.dropTarget.onstationdrop(this.dropTarget, this.dragElement); this.dragElement = null; this.dropTargets = null; this.dropTarget = null; } Roku.Station.need_mouse_up = function() { return (this.dragElement || this.mouseDownData); } Roku.Station.on_mouse_out = function(ev) { if(this.mouseMoveData) { if(this.mouseMoveData.timeoutId) window.clearTimeout(this.mouseMoveData.timeoutId); this.mouseMoveData = null; } if(this.mouseOutData) { if(this.mouseOutData.timeoutId) window.clearTimeout(this.mouseOutData.timeoutId); this.mouseOutData = null; } /* no station tips for now if(Roku.TipStation.visible()) { this.mouseOutData = []; this.mouseOutData.timeoutId = window.setTimeout("Roku.Station.hide_tip()", this.mouseOutTimeout); } */ } /* no station tips for now Roku.Station.show_tip = function() { Roku.TipStation.show(this.mouseMoveData); this.mouseMoveData = null; } Roku.Station.hide_tip = function() { Roku.TipStation.hide(); this.mouseOutData = null; } */ Roku.Station.scanDropTargets = function(targets, element) { if(!element) return; if(typeof(element.onstationdrop) == "function") targets.push(element); var children = element.childNodes; var length = children.length; for(var index = 0; index < length; index++) { var child = children[index]; if(child && child.tagName) this.scanDropTargets(targets, child); } } Roku.Station.findDropTarget = function(x, y) { if(!this.dropTargets) return null; var dragElementRect = Roku.Util.elementRect(this.dragElement); var length = this.dropTargets.length; for(var index = 0; index < length; index++) { var target = this.dropTargets[index]; var rect = Roku.Util.elementRect(target); if((rect.left < x) && (x < (rect.left + rect.width)) && (rect.top < y) && (y < (rect.top + rect.height))) return target; } return null; } Roku.Station.setDropTarget = function(dropTarget) { if(dropTarget == this.dropTarget) return; if(this.dropTarget && (typeof(this.dropTarget.onstationdragleave) == "function")) { this.dropTarget.onstationdragleave(this.dropTarget, this.dragElement); this.dropTarget = null; } var dragData = null; if(dropTarget && (typeof(dropTarget.onstationdragenter) == "function")) { dragData = dropTarget.onstationdragenter(dropTarget, this.dragElement); if(!dragData) dropTarget = null; } this.dropTarget = dropTarget; if(this.dropTarget) { this.dragElement.style.opacity = (dragData && (typeof(dragData.stationDropOpacity) != "undefined")) ? dragData.stationDropOpacity : this.stationDropOpacity; this.dragElement.style.filter = (dragData && (typeof(dragData.stationDropFilter) != "undefined")) ? dragData.stationDropFilter: this.stationDropFilter; } else { this.dragElement.style.opacity = this.stationDragOpacity; this.dragElement.style.filter = this.stationDragFilter; } } Roku.Station.getAttribute = function(station, attribute) { if(station) if(typeof(station.getAttribute) == "function") value = station.getAttribute(attribute); else value = station[attribute]; if(!value) value = ""; return value; } Roku.Station.getId = function(station) { return Roku.Util.Shared.getAttribute(station, this.stationAttrId); } Roku.Station.getTitle = function(station) { return Roku.Util.Shared.getAttribute(station, this.stationAttrTitle); } Roku.Station.getUrl = function(station) { return Roku.Util.Shared.getAttribute(station, this.stationAttrUrl); } Roku.Station.getPopupType = function(station) { return Roku.Util.Shared.getAttribute(station, this.stationAttrPopup); } Roku.Station.getLive = function(station) { return Roku.Util.Shared.getAttribute(station, this.stationAttrLive); } Roku.Station.refresh = function(root) { var mouseDownHandler = function() { return Roku.Station.on_mouse_down((0 < arguments.length) ? arguments[0] : null); }; var mouseMoveHandler = function() { return Roku.Station.on_mouse_move((0 < arguments.length) ? arguments[0] : null); }; var mouseUpHandler = function() { return Roku.Station.on_mouse_up((0 < arguments.length) ? arguments[0] : null); }; var dragStartHandler = function() { return Roku.Util.eventCancel((0 < arguments.length) ? arguments[0] : null); } var clickHandler = function() { return Roku.Util.eventCancel((0 < arguments.length) ? arguments[0] : null); } var stations = (Roku.Body && Roku.Body.all && !root) ? Roku.Body.all[this.stationClassName] : Roku.Util.childrenClassElements(root ? root : document.body, this.stationClassName); var stations_count = stations ? stations.length : null; for(var index = 0; index < stations_count; index++) { var station = stations[index]; Roku.Util.eventHandler(station, "mousedown", mouseDownHandler); Roku.Util.eventHandler(station, "mousemove", mouseMoveHandler); Roku.Util.eventHandler(station, "mouseup", mouseUpHandler); Roku.Util.eventHandler(station, "dragstart", dragStartHandler); Roku.Util.eventHandler(station, "click", clickHandler); station.on_clicked = function(ev) { return Roku.PopupStation.show(ev); }; Roku.Util.eventHandler(station, "mouseout", function(ev) { return Roku.Station.on_mouse_out(ev); }); } } Roku.Station.initialize = function() { Roku.Station.refresh(); } /* Roku.StationList */ Roku.StationList = { stationListClassName : "station_list", stationClassName : "station", stationIndexClassName : "station_index", stationTitleClassName : "station_title", stationDropAttributeName : "stationDrop", stationDropReplace : "replace", stationDropReorder : "reorder", stationIndexesAttributeName : "stationIndexes", stationCrAttributeName : "stationCR", stationIdAttributeName : "stationId", changedEventName : "on_changed", dropTargetSrc : null, dropTargetStation : null, dropTargetStationIndex : -1, dropTargetStationReplace : null, dragStationSource : null, dropTargetIndexed : null, dropTargetModeReplace : null, dropTargetModeReorder : null, dragStationReorder : { stationDropOpacity : 0.3, stationDropFilter : "alpha(opacity=30)" } }; Roku.classes.push(Roku.StationList); Roku.StationList.onStationDragEnter = function(target, station) { var stationDropMode = target.getAttribute(this.stationDropAttributeName); if(stationDropMode == null) return false; var reorder = false; if(Roku.Util.parentClassElement(station.srcElement, this.stationListClassName) == target) { if((typeof(stationDropMode) != "string") || (stationDropMode.indexOf(this.stationDropReorder) < 0)) return false; reorder = true; } if(!reorder) { station.style.visibility = "hidden"; target.style.backgroundColor = "#F0F0F0"; } this.dropTargetModeReorder = reorder; this.dropTargetModeReplace = (typeof(stationDropMode) == "string") && (0 <= stationDropMode.indexOf(this.stationDropReplace)); var indexes = (target.getAttribute(this.stationIndexesAttributeName) != null) ? true : false;; var crs = (target.getAttribute(this.stationCrAttributeName) != null) ? true : false; this.dropTargetSrc = document.createElement("div"); this.dropTargetSrc.style.backgroundColor = "#FFFFFF"; //this.dropTargetSrc.style.border = "1px solid #000000"; //this.dropTargetSrc.style.padding = "1px"; var dropTargetStationSrc = station.srcElement.cloneNode(true); var station_title = Roku.Util.childClassElement(dropTargetStationSrc, this.stationTitleClassName); //process indexes var station_index = Roku.Util.childClassElement(dropTargetStationSrc, this.stationIndexClassName); if(!indexes && station_index) { station_index.parentNode.removeChild(station_index); station_index = null; } else if(indexes && !station_index && station_title) { station_index = document.createElement("span"); station_index.className = this.stationIndexClassName; station_title.parentNode.insertBefore(station_index, station_title); } this.dropTargetIndexed = station_index ? true : false; //process carriage returns var station_cr = Roku.Util.childTagElement(dropTargetStationSrc, "br"); if(!crs && station_cr) { station_cr.parentNode.removeChild(station_cr); station_cr = null; } else if(crs && !station_cr) { station_cr = document.createElement("br"); dropTargetStationSrc.appendChild(station_cr); } this.dropTargetSrc.appendChild(dropTargetStationSrc); return reorder ? this.dragStationReorder : true; } Roku.StationList.onStationDragOver = function(target, station, x, y) { var station_list = Roku.Util.childrenClassElements(target, this.stationClassName); var stations_count = station_list.length; for(var index = 0; index < stations_count; index++) { var station_entry = station_list[index]; var station_entry_rect = Roku.Util.elementRect(station_entry); var top = station_entry_rect.top; var bottom = top + station_entry_rect.height; if((top <= y) && (y <= bottom)) { if(this.dropTargetStation == station_entry) break; // over our dropTargetStation if(this.dropTargetModeReorder) { if(station.srcElement == station_entry) break; // still over dragged element - do nothing target.style.backgroundColor = "#F0F0F0"; station.style.visibility = "hidden"; station.srcElement.style.display = "none"; if((0 < index) && (this.dropTargetStation == station_list[index-1])) index++; this.insertDropTargetStation(target, station_list, index); } else if(this.dropTargetModeReplace) { this.insertDropTargetStation(target, station_list, index); } else if(y < ((top + bottom) / 2)) { // insert before this element if((0 < index) && (this.dropTargetStation == station_list[index-1])) break; // the previous element is our dropTargetStation this.insertDropTargetStation(target, station_list, index); } else { // insert after this element var next_element = ((index + 1) < stations_count) ? station_list[index+1] : null; if(next_element && (this.dropTargetStation == next_element)) break; // the next element is our dropTargetStation this.insertDropTargetStation(target, station_list, index + 1); } break; } } } Roku.StationList.insertDropTargetStation = function(target, station_list, index) { var elementBefore = ((0 <= index) && (index < station_list.length)) ? station_list[index] : 0; if(this.dropTargetStation) { target.removeChild(this.dropTargetStation.parentNode); station_list.splice(this.dropTargetStationIndex, 1); if(this.dropTargetStationIndex <= index) index--; } var dropTargetElement = this.dropTargetSrc.cloneNode(true); this.dropTargetStation = Roku.Util.childClassElement(dropTargetElement, this.stationClassName); this.dropTargetStationIndex = index; if(this.dropTargetIndexed) { var station_index = Roku.Util.childClassElement(this.dropTargetStation, this.stationIndexClassName); if(station_index) station_index.innerHTML = (index + 1) + " ."; } if(this.dropTargetModeReplace && !this.dropTargetModeReorder) { if(this.dropTargetStationReplace) this.dropTargetStationReplace.style.display = "block"; this.dropTargetStationReplace = elementBefore; if(this.dropTargetStationReplace) elementBefore.style.display = "none"; } if(elementBefore) { target.insertBefore(dropTargetElement, elementBefore); station_list.splice(this.dropTargetStationIndex, 0, this.dropTargetStation); } else { target.appendChild(dropTargetElement); station_list.push(this.dropTargetStation); } this.updateListIndexes(target, station_list); } Roku.StationList.updateListIndexes = function(target, station_list) { if(!this.dropTargetIndexed || (this.dropTargetModeReplace && !this.dropTargetModeReorder)) return; if(!station_list && target) station_list = Roku.Util.childrenClassElements(target, this.stationClassName); if(!station_list) return; var index_counter = 0; var stations_count = station_list.length; for(var index = 0; index < stations_count; index++) { var station_entry = station_list[index]; var station_index = Roku.Util.childClassElement(station_entry, this.stationIndexClassName) if(station_index && (0 < station_index.offsetHeight)) station_index.innerHTML = (++index_counter) + ". "; } } Roku.StationList.clearDropData = function(target, station) { this.dropTargetSrc = null; this.dropTargetStation = null; this.dropTargetStationIndex = null; this.dropTargetStationReplace = null; this.dropTargetModeReorder = null; this.dropTargetIndexed = null; this.dropTargetModeReplace = null; target.style.backgroundColor = ""; station.style.visibility = "visible"; } Roku.StationList.onStationDragLeave = function(target, station) { if(this.dropTargetStation) target.removeChild(this.dropTargetStation.parentNode); if(this.dropTargetStationReplace) this.dropTargetStationReplace.style.display = "block"; if(this.dropTargetModeReorder) station.srcElement.style.display = "block"; this.updateListIndexes(target); this.clearDropData(target, station); } Roku.StationList.onStationDrop = function(target, station) { if(this.dropTargetStation) { var dropTargetStation = this.dropTargetStation.cloneNode(true); target.insertBefore(dropTargetStation, this.dropTargetStation.parentNode); target.removeChild(this.dropTargetStation.parentNode); if(typeof(target[this.changedEventName]) == "function") target[this.changedEventName](dropTargetStation); if(this.dropTargetModeReorder) { if(typeof(target[this.changedEventName]) == "function") target[this.changedEventName](station.srcElement); target.removeChild(station.srcElement); } else if(this.dropTargetStationReplace) this.dropTargetStationReplace.parentNode.removeChild(this.dropTargetStationReplace); } this.clearDropData(target, station); } Roku.StationList.refresh = function(root) { var station_list = (Roku.Body && Roku.Body.all && !root) ? Roku.Body.all[this.stationListClassName] : Roku.Util.childrenClassElements(root ? root : document.body, this.stationListClassName); var station_list_count = station_list ? station_list.length : 0; for(var index = 0; index < station_list_count; index++) { var station_list_entry = station_list[index]; station_list_entry.onstationdragenter = function(target, station) { return Roku.StationList.onStationDragEnter(target, station); }; station_list_entry.onstationdragover = function(target, station, x, y) { return Roku.StationList.onStationDragOver(target, station, x, y); }; station_list_entry.onstationdragleave = function(target, station) { return Roku.StationList.onStationDragLeave(target, station); }; station_list_entry.onstationdrop = function(target, station) { return Roku.StationList.onStationDrop(target, station); }; } } Roku.StationList.initialize = function() { Roku.StationList.refresh(); } /* Roku.Popup */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Popup = { popupClassName : "popup", closeClassName : "close", currentPopup : null }; Roku.classes.push(Roku.Popup); Roku.Popup.show = function(popup, element, x, y, arrowOffsetX) { if(!popup || !element) return; this.hidePopup(popup); this.currentPopup = popup; popup.currentElement = element; popup.style.left = x + "px"; popup.style.top = y + "px"; var widget = this.parentWidget(element); if(widget) Roku.Widget.enable(widget, false); popup.style.visibility = "visible"; popup.style.display = "block"; this.setArrowsOffset(popup, arrowOffsetX); popup.focus(); } Roku.Popup.on_clicked_popup_close = function(ev) { var element = Roku.Util.srcEventElement(ev); var popup = Roku.Util.parentClassElement(element, this.popupClassName); this.hidePopup(popup); } Roku.Popup.setArrowsOffset = function(popup, offset) { this.clearFillWidths(popup, "ftl", "ftr", "fbl", "fbr"); this.setArrowOffset(popup, offset, "tl", "ftl", "ta", "ftr", "tr"); this.setArrowOffset(popup, offset, "bl", "fbl", "ba", "fbr", "br"); } Roku.Popup.setArrowOffset = function(popup, offset, l, fl, a, fr, r) { var fill_left = Roku.Util.childIdElement(popup, fl); if(fill_left) fill_left.width = 1; var fill_right = Roku.Util.childIdElement(popup, fr); if(fill_right) fill_right.width = 1; var currentWidth = popup.offsetWidth; var left_edge = Roku.Util.childIdElement(popup, l); if(left_edge) { currentWidth -= left_edge.offsetWidth; offset -= left_edge.offsetWidth; } var right_edge = Roku.Util.childIdElement(popup, r); currentWidth -= right_edge ? right_edge.offsetWidth : 0; var arrow = Roku.Util.childIdElement(popup, a); if(arrow) { currentWidth -= arrow.offsetWidth; offset -= arrow.offsetWidth / 2; } if(fill_left) { fill_left.width = Math.max(offset, 1); currentWidth -= Math.max(offset, 1); } if(fill_right) { fill_right.width = Math.max(currentWidth, 1); } } Roku.Popup.clearFillWidths = function(popup, fills) { for(var index in fills) { var fill = Roku.Util.childIdElement(popup, fills[index]); if(fill) fill.width = 1; } } Roku.Popup.showArrow = function(popup, a, show) { var arrow = Roku.Util.childIdElement(popup, a); if(arrow) arrow.style.display = show ? "block" : "none"; } Roku.Popup.hidePopup = function(popup) { if(!popup) popup = this.currentPopup; if(popup) { popup.style.display = "none"; popup.style.visibility = "hidden"; var widget = this.parentWidget(popup.currentElement); if(widget) Roku.Widget.enable(widget, true); popup.currentElement = null; } } Roku.Popup.need_mouse_down = function() { return Roku.Popup.currentPopup; } Roku.Popup.on_mouse_down = function(ev) { var element = Roku.Util.srcEventElement(ev); if(!element) return; if(Roku.Util.parentClassElement(element, Roku.Popup.popupClassName)) return; var widget = this.parentWidget(element); if(widget && Roku.Widget.disabled(widget)) return; Roku.Popup.hidePopup(); } Roku.Popup.parentWidget = function(element) { return Roku.Widget ? Roku.Util.parentClassElement(element, Roku.Widget.widgetClassName) : null; } Roku.Popup.initialize = function() { var popups = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.popupClassName] : Roku.Util.childrenClassElements(document.body, this.popupClassName); var popups_count = popups ? popups.length : 0; for(var iPopup = 0; iPopup < popups_count; iPopup++) this.initialize_popup(popups[iPopup]) } Roku.Popup.initialize_popup = function(popup) { var closeHandler = function() { return Roku.Popup.on_clicked_popup_close((0 < arguments.length) ? arguments[0] : null); }; var close_list = Roku.Util.childrenClassElements(popup, this.closeClassName); var close_list_count = close_list.length; for(var iClose = 0; iClose < close_list_count; iClose++) { var close = close_list[iClose]; Roku.Util.eventHandler(close, "click", closeHandler); } } /* Roku.PopupStation */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.PopupStation = { popupId : "popup_station", contentClassName : "content", queryKeyAttribName : "query_key", entryClassName : "entry", iconClassName : "icon", textClassName : "text", cmdIdPlayPC : "cmdPlayPC", cmdIdPlaySoundbridge: "cmdPlaySoundbridge", cmdIdSaveAsPreset : "cmdSaveAsPreset", cmdIdSaveAsFavorite : "cmdSaveAsFavorite", cmdIdRemoveFavorite : "cmdRemoveFavorite", cmdIdEdit : "cmdEdit", cmdIdApprove : "cmdApprove", cmdIdUnApprove : "cmdUnApprove", cmdIdShowURLs : "cmdShowURLs", cmdIdShowPlays : "cmdShowPlays", cmdIdShowDetail : "cmdShowDetail", popup : null, content : null, queryKey : "" }; Roku.classes.push(Roku.PopupStation); Roku.PopupStation.show = function(ev) { var element = Roku.Util.srcEventElement(ev); var station = Roku.Util.parentClassElement(element, Roku.Station.stationClassName); if(!this.popup || !this.content || !station) return; var offsetX = 0; var stationRect = Roku.Util.elementRect(station); if(ev.offsetX && ev.offsetY) { // IE if(Roku.Util.CompareNoCase(element.tagName, "span")) { var parentRect = Roku.Util.elementRect(element.offsetParent); offsetX = ev.offsetX - (stationRect.left - parentRect.left); } else { offsetX = ev.offsetX; } } else if(ev.pageX && ev.pageY) { // Mozilla offsetX = ev.clientX + ev.pageX - ev.clientX - stationRect.left; } var clientPoint = { x : ev.clientX, y : ev.clientY }; this.show1(station, stationRect, clientPoint, offsetX); } Roku.PopupStation.show1 = function(station, stationRect, clientPoint, offsetX) { var custom_data = { station : station, stationRect : stationRect, clientPoint : clientPoint, offsetX : offsetX }; var popup_type = Roku.Station.getPopupType(station); var id = Roku.Station.getId(station); var queryParam = this.queryKey + "=" + popup_type + "&id=" + id; Roku.Query.invoke(queryParam, function (content, custom_data) { Roku.PopupStation.fill_content(content, custom_data); }, custom_data); } Roku.PopupStation.fill_content = function(content, custom_data) { if(!content) return; this.content.innerHTML = content; Roku.Popup.initialize_popup(this.popup); this.initialize_content(); // prepare calculations Roku.Popup.showArrow(this.popup, "ta", false); Roku.Popup.showArrow(this.popup, "ba", false); Roku.Popup.setArrowsOffset(this.popup, 0); this.popup.style.visibility = "hidden"; this.popup.style.display = "block"; var offsetX = custom_data.offsetX; var x = custom_data.stationRect.left; if(Roku.Util.clientWidth() < (custom_data.clientPoint.x - offsetX + this.popup.offsetWidth)) { var popupWidth = this.popup.offsetWidth; offsetX += popupWidth - custom_data.stationRect.width; x += custom_data.stationRect.width - popupWidth; } var y = custom_data.stationRect.top; if( (this.popup.offsetHeight < y) && (Roku.Util.clientHeight() < (custom_data.clientPoint.y + custom_data.stationRect.height + this.popup.offsetHeight))) { y -= this.popup.offsetHeight; Roku.Popup.showArrow(this.popup, "ba", true); } else { y += custom_data.stationRect.height; Roku.Popup.showArrow(this.popup, "ta", true); } Roku.Popup.show(this.popup, custom_data.station, x, y, offsetX); } Roku.PopupStation.on_mouse_entry = function(ev) { if(ev) { var element = Roku.Util.srcEventElement(ev); var hilight = !Roku.Util.CompareNoCase(ev.type, "mouseout"); this.hilightEntry(element, hilight); } } Roku.PopupStation.hilightEntry = function(element, hilight) { var entry = Roku.Util.parentClassElement(element, this.entryClassName); var text = Roku.Util.childClassElement(entry, this.textClassName); if(text) { text.style.textDecoration = hilight ? "underline" : ""; } } Roku.PopupStation.on_click_entry = function(ev) { var element = Roku.Util.srcEventElement(ev); var entry = Roku.Util.parentClassElement(element, this.entryClassName); if(entry) this.on_command(entry.id, ev); } Roku.PopupStation.on_command = function(cmd, ev) { var station = this.popup ? this.popup.currentElement : null; Roku.Popup.hidePopup(this.popup); this.do_command(cmd, station, ev); } Roku.PopupStation.do_command = function(cmd, station, ev) { if(!station) return; if(cmd == this.cmdIdPlayPC) { Roku.Util.Shared.playStation(ev, station); } else if(cmd == this.cmdIdPlaySoundbridge) { if(Roku.MySB && Roku.MySB.Radio && Roku.MySB.Radio.can_play()) { Roku.MySB.Radio.play_station(station); } } else if(cmd == this.cmdIdSaveAsPreset) { Roku.DialogSavePreset.do_modal(station, ev); } else if(cmd == this.cmdIdSaveAsFavorite) { if(Roku.Util && Roku.Util.Shared && !Roku.Util.Shared.checkConfirmed(ev)) return; Roku.Query.invoke("station_favorite=1&id=" + Roku.Station.getId(station), function(response) { if(Roku.Favorites) Roku.Favorites.update(); } ); } else if(cmd == this.cmdIdRemoveFavorite) { Roku.Query.invoke("station_favorite=0&id=" + Roku.Station.getId(station), function(response) { if(Roku.Favorites) Roku.Favorites.update(); }); } else if(cmd == this.cmdIdEdit) { if(Roku.Util && Roku.Util.Shared && !Roku.Util.Shared.checkConfirmed(ev)) return; var edit_url = Roku.Util.Shared.getAttribute(station, "station_edit"); if(!edit_url) edit_url = "addstream.php"; window.location = edit_url + '?id=' + Roku.Station.getId(station); } else if(cmd == this.cmdIdApprove) { //if (confirm("Are you sure you want to approve this station?") == true) Roku.Query.invoke("approve_stream=1&id=" + Roku.Station.getId(station), function() { /*Roku.Body.doRefreshContent(null, station, Roku.PopupStation.cmdIdApprove); */}); } else if(cmd == this.cmdIdUnApprove) { if (confirm("Are you sure you want to unapprove this station?") == true) Roku.Query.invoke("approve_stream=0&id=" + Roku.Station.getId(station), function() { Roku.Body.doRefreshContent(null, station, Roku.PopupStation.cmdIdUnApprove); }); } else if(cmd == this.cmdIdShowURLs) { //if(Roku.Util && Roku.Util.Shared && !Roku.Util.Shared.checkConfirmed(ev)) // return; var showStreams_url = "streamurls.php"; window.location = showStreams_url + '?id=' + Roku.Station.getId(station); } else if(cmd == this.cmdIdShowPlays) { //if(Roku.Util && Roku.Util.Shared && !Roku.Util.Shared.checkConfirmed(ev)) // return; var showPlays_url = "streamsplaystation.php"; window.location = showPlays_url + '?id=' + Roku.Station.getId(station); } else if(cmd == this.cmdIdShowDetail) { //if(Roku.Util && Roku.Util.Shared && !Roku.Util.Shared.checkConfirmed(ev)) // return; var showPlays_url = "stationdetail.php"; window.location = showPlays_url + '?sid=' + Roku.Station.getId(station); } } Roku.PopupStation.initialize = function() { this.popup = document.getElementById(this.popupId); this.content = Roku.Util.childClassElement(this.popup, this.contentClassName); this.queryKey = this.popup ? this.popup.getAttribute(this.queryKeyAttribName) : ""; } Roku.PopupStation.initialize_content = function() { if(!this.content) return; var hilightEntryHandler = function(ev) { return Roku.PopupStation.on_mouse_entry(ev); }; var clickEntryHandler = function(ev) { return Roku.PopupStation.on_click_entry(ev); }; var entries = Roku.Util.childrenClassElements(this.content, this.entryClassName); var entries_count = entries.length; for(var iEntry = 0; iEntry < entries_count; iEntry++) { var entry = entries[iEntry]; Roku.Util.eventHandler(entry, "click", clickEntryHandler); Roku.Util.eventHandler(entry, "mouseover", hilightEntryHandler); Roku.Util.eventHandler(entry, "mouseout", hilightEntryHandler); } } /* Roku.Combo */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Combo = { comboClassName : "combo", displayClassName : "display", dropDownClassName : "drop", contentClassName : "content", leftClassName : "left", rightClassName : "right", contentTextAttribName : "content_text", selChangedEventName : "on_selection_changed", dropDownEventName : "drop_down", displayHilightHandler : "display_hilight_handler", dropHilightHandler : "drop_hilight_handler", currentDropDown : null, currentHilight : null }; Roku.classes.push(Roku.Combo); Roku.Combo.selected = function(combo) { var display = Roku.Util.childClassElement(combo, this.displayClassName); var display_entry = Roku.Util.childClassElement(display, this.contentClassName); return display_entry ? display_entry.id : null; } Roku.Combo.selected_entry = function(combo) { var selected_id = this.selected(combo); return selected_id ? this.contains(combo, selected_id) : null; } Roku.Combo.select = function(combo, id) { var drop_down = Roku.Util.childClassElement(combo, this.dropDownClassName); var selItem = Roku.Util.childIdElement(drop_down, id); this.selectItem(combo, selItem); } Roku.Combo.contains = function(combo, id) { var drop_down = Roku.Util.childClassElement(combo, this.dropDownClassName); var selItem = Roku.Util.childIdElement(drop_down, id); return selItem; } Roku.Combo.on_click_display = function(ev) { var element = Roku.Util.srcEventElement(ev); var combo = Roku.Util.parentClassElement(element, this.comboClassName); this.showDropDown(combo); } Roku.Combo.on_hilight_display = function(ev) { var element = Roku.Util.srcEventElement(ev); var display = Roku.Util.parentClassElement(element, this.displayClassName); this.hilightDisplay(display, ev && !Roku.Util.CompareNoCase(ev.type, "mouseout")); } Roku.Combo.hilightDisplay = function(display, hilight) { var combo = Roku.Util.parentClassElement(display, this.comboClassName); var drop_down = Roku.Util.childClassElement(combo, this.dropDownClassName); if(this.currentDropDown && (drop_down == this.currentDropDown)) hilight = false; if(combo && (typeof(combo[this.displayHilightHandler]) == "function")) { combo[this.displayHilightHandler](display, hilight); } else if(display) { var left = Roku.Util.childClassElement(display, this.leftClassName); var right = Roku.Util.childClassElement(display, this.rightClassName); var content = Roku.Util.childClassElement(display, this.contentClassName); if(left && right && content) { left.style.backgroundImage = hilight ? "url(images/combo-left-hilight.gif)" : ""; right.style.backgroundImage = hilight ? "url(images/combo-right-hilight.gif)" : ""; content.style.backgroundImage = hilight ? "url(images/combo-center-hilight.png)" : ""; display.style.color = hilight ? "#0000E0" : ""; // #0000FF #9279D0 #9882E2 } } } Roku.Combo.showDropDown = function(combo) { var display = Roku.Util.childClassElement(combo, this.displayClassName); var display_entry = Roku.Util.childClassElement(display, this.contentClassName); var drop_down = Roku.Util.childClassElement(combo, this.dropDownClassName); if(!display || !drop_down || !display_entry) return; if(this.currentDropDown && (Roku.Util.parentClassElement(this.currentDropDown, this.comboClassName) != combo)) { this.currentDropDown.style.display = "none"; this.currentDropDown = null; this.currentHilight = null; } if(this.currentDropDown == drop_down) { drop_down.style.display = "none"; this.currentDropDown = null; this.currentHilight = null; } else { drop_down.style.visibility = "hidden"; drop_down.style.display = "block"; var displayRect = Roku.Util.elementRect(display); drop_down.style.left = (displayRect.left + (displayRect.width - drop_down.offsetWidth) / 2) + "px"; drop_down.style.top = (displayRect.top + displayRect.height) + "px"; if(combo[this.dropDownEventName]) combo[this.dropDownEventName](combo); this.currentDropDown = drop_down; drop_down.style.visibility = "visible"; this.hilightDropList(this.currentDropDown, display_entry.id); this.hilightDisplay(display, false); } } Roku.Combo.hilightDropList = function(drop_down, hilight_id) { var drop_entries = Roku.Util.childrenClassElements(drop_down, this.contentClassName); var drop_entries_count = drop_entries.length; for(var index = 0; index < drop_entries_count; index++) { var drop_entry = drop_entries[index]; this.hilightDropEntry(drop_entry, drop_entry.id == hilight_id); } } Roku.Combo.hilightDropEntry = function(drop_entry, hilight) { var combo = Roku.Util.parentClassElement(drop_entry, this.comboClassName); var dropHilightHandler = (typeof(combo[this.dropHilightHandler]) == "function") ? combo[this.dropHilightHandler] : null; if(hilight && (this.currentHilight != drop_entry)) { if(dropHilightHandler) dropHilightHandler(this.currentHilight, false); else if(this.currentHilight) { this.currentHilight.style.backgroundImage = ""; this.currentHilight.style.color = ""; } this.currentHilight = drop_entry; } if(dropHilightHandler) dropHilightHandler(drop_entry, hilight); else if(drop_entry) { drop_entry.style.backgroundImage = hilight ? "url(images/combo-drop-center-hilight.png)" : ""; drop_entry.style.color = hilight ? "#6F51C2" : ""; } } Roku.Combo.on_hilight_drop_entry = function(ev) { if(!ev) return; var element = Roku.Util.srcEventElement(ev); var entry = Roku.Util.parentClassElement(element, this.contentClassName); var hilight = !Roku.Util.CompareNoCase(ev.type, "mouseout"); this.hilightDropEntry(entry, hilight); } Roku.Combo.on_click_drop_entry = function(ev) { if(!ev) return; var element = Roku.Util.srcEventElement(ev); var drop_entry = Roku.Util.parentClassElement(element, this.contentClassName); var combo = Roku.Util.parentClassElement(drop_entry, this.comboClassName); this.selectItem(combo, drop_entry); this.showDropDown(combo); if(combo) { if(typeof(combo[this.selChangedEventName]) == "function") combo[this.selChangedEventName](combo, drop_entry); } } Roku.Combo.selectItem = function(combo, drop_item) { var display = Roku.Util.childClassElement(combo, this.displayClassName); var display_entry = Roku.Util.childClassElement(display, this.contentClassName); if(display_entry && drop_item) { display_entry.id = drop_item.id; var text_content = drop_item.getAttribute(this.contentTextAttribName); display_entry.innerHTML = (text_content) ? text_content : drop_item.innerHTML; } } Roku.Combo.need_mouse_down = function() { return Roku.Combo.currentDropDown; } Roku.Combo.on_mouse_down = function(ev) { var element = Roku.Util.srcEventElement(ev); if(!element) return; if(Roku.Util.parentClassElement(element, Roku.Combo.comboClassName)) return; var combo = Roku.Util.parentClassElement(Roku.Combo.currentDropDown, this.comboClassName); this.showDropDown(combo); } Roku.Combo.initialize = function() { var displayClickHandler = function() { return Roku.Combo.on_click_display((0 < arguments.length) ? arguments[0] : null); }; var displayHilightHandler = function() { return Roku.Combo.on_hilight_display((0 < arguments.length) ? arguments[0] : null); }; var dropEntryHilightHandler = function() { return Roku.Combo.on_hilight_drop_entry((0 < arguments.length) ? arguments[0] : null); }; var dropEntryClickHandler = function() { return Roku.Combo.on_click_drop_entry((0 < arguments.length) ? arguments[0] : null); }; var combos = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.comboClassName] : Roku.Util.childrenClassElements(document.body, this.comboClassName); var combos_count = combos ? combos.length : 0; for(var iCombo = 0; iCombo < combos_count; iCombo++) { var combo = combos[iCombo]; var display = Roku.Util.childClassElement(combo, this.displayClassName); Roku.Util.eventHandler(display, "click", displayClickHandler); Roku.Util.eventHandler(display, "mouseover", displayHilightHandler); Roku.Util.eventHandler(display, "mouseout", displayHilightHandler); var drop_down = Roku.Util.childClassElement(combo, this.dropDownClassName); var drop_entries = Roku.Util.childrenClassElements(drop_down, this.contentClassName); var drop_entries_count = drop_entries.length; for(var index = 0; index < drop_entries_count; index++) { var drop_entry = drop_entries[index]; Roku.Util.eventHandler(drop_entry, "click", dropEntryClickHandler); Roku.Util.eventHandler(drop_entry, "mouseover", dropEntryHilightHandler); Roku.Util.eventHandler(drop_entry, "mouseout", dropEntryHilightHandler); } } } /* Roku.AudioBrowser */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.AudioBrowser = { audioBrowserId : "wdgAudioBrowser", pageListClassName : "pages_list", pageClassName : "page", titleClassName : "title", playClassName : "play", entryClassName : "entry", imageClassName : "image", responseContentClassName: "response_content", currentEntryAttribName : "current_entry", queryKeyAttribName : "query_key", queryValueAttribName : "query_value", browseTypeAttribName : "browse_type", pageSelectComboId : "page_select", responseElementId : "query_response", namePageId : "audio_name", audioBrowser : null, pages : [] }; Roku.classes.push(Roku.AudioBrowser); Roku.AudioBrowser.on_hilight_sub_combo_display = function(display, hilight) {} Roku.AudioBrowser.on_hilight_sub_combo_drop = function(drop, hilight) { if(drop) { drop.style.textDecoration = hilight ? "underline" : ""; drop.style.color = hilight ? "#FFFF80" : ""; //drop.style.color = hilight ? "#938AC4" : ""; //drop.style.opacity = hilight ? 0.80 : 1.0;; //drop.style.filter = hilight ? "alpha(opacity=80)" : ""; } } Roku.AudioBrowser.on_sub_combo_sel_chnaged = function(combo, entry) { this.select_drop_entry(combo, entry ? entry.id : ""); this.on_select_entry(entry); } Roku.AudioBrowser.on_sub_combo_drop_down = function(combo) { var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName); if(drop_down) { var master_combo = Roku.Util.childIdElement(this.audioBrowser, this.pageSelectComboId); var display = Roku.Util.childClassElement(master_combo, Roku.Combo.displayClassName); var displayRect = Roku.Util.elementRect(display); drop_down.style.left = (displayRect.left + (displayRect.width - drop_down.offsetWidth) / 2) + "px"; drop_down.style.top = (displayRect.top + displayRect.height) + "px"; //var page = Roku.Util.parentClassElement(combo, this.pageClassName); //var sel_id = page.getAttribute(this.currentEntryAttribName); //this.select_drop_entry(combo, sel_id); } } Roku.AudioBrowser.select_drop_entry = function(combo, id) { var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName); var entries = Roku.Util.childrenClassElements(drop_down, Roku.Combo.contentClassName); var entries_count = entries.length; for(var index = 0; index < entries_count; index++) { var entry = entries[index]; entry.style.backgroundColor = (id && (entry.id == id)) ? "#9E96CA" : ""; } } Roku.AudioBrowser.get_default_entry = function(combo) { var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName); var entries = Roku.Util.childrenClassElements(drop_down, Roku.Combo.contentClassName); var entries_count = entries.length; for(var index = 0; index < entries_count; index++) { var entry = entries[index]; if(entry.getAttribute("default_entry")) return entry; } return null; } Roku.AudioBrowser.on_select_entry = function(entry) { var page = Roku.Util.parentClassElement(entry, this.pageClassName); this.select_page_entry(page, entry); } Roku.AudioBrowser.select_page_entry = function(page, entry) { if(!page) return; var entry_id = entry ? entry.id : ""; page.setAttribute(this.currentEntryAttribName, entry_id); this.fill_page(page, entry_id); } Roku.AudioBrowser.fill_page = function(page, entry_id) { if(!page) return; if(!entry_id) entry_id = page.getAttribute(this.currentEntryAttribName); if(!entry_id) return; var queryKey = page.getAttribute(this.queryKeyAttribName); var queryValue = entry_id; var queryParam = queryKey + "=" + queryValue; Roku.Query.invoke(queryParam, function (content, custom_data) { Roku.AudioBrowser.fill_page_content(content, custom_data); }, page); } Roku.AudioBrowser.fill_page_content = function(response, page) { if(!page) return; var content = Roku.Util.childClassElement(page, this.responseContentClassName); if(content) { content.innerHTML = response; Roku.Body.doRefresh(content); } } Roku.AudioBrowser.on_page_combo_sel_changed = function(combo, drop_entry) { this.select_page(drop_entry ? drop_entry.id : ""); // notify server for changed state var browse_type = drop_entry ? drop_entry.getAttribute(this.browseTypeAttribName) : ""; var query_key = combo ? combo.getAttribute(this.queryKeyAttribName) : ""; var query_value = combo ? combo.getAttribute(this.queryValueAttribName) : ""; if(query_key && query_value && browse_type) Roku.Query.invoke(query_key + "=" + query_value + "&value=" + browse_type); } Roku.AudioBrowser.select_page = function(id) { var page_count = this.pages.length; for(var index = 0; index < page_count; index++) { var page = this.pages[index]; page.style.display = (page.id == id) ? "block" : "none"; } } Roku.AudioBrowser.get_page = function(id) { var page_count = this.pages.length; for(var index = 0; index < page_count; index++) { var page = this.pages[index]; if(page.id == id) return page; } return null; } Roku.AudioBrowser.on_click_play = function(ev) { var element = Roku.Util.srcEventElement(ev); var entry = Roku.Util.parentClassElement(element, this.entryClassName); var station = Roku.Util.childClassElement(entry, Roku.Station.stationClassName); Roku.Util.Shared.playStation(ev, station); } Roku.AudioBrowser.refresh = function(root) { var clickPlayHandler = function() { return Roku.AudioBrowser.on_click_play((0 < arguments.length) ? arguments[0] : null); }; var play_cmd_list = Roku.Util.childrenClassElements(root ? root : this.audioBrowser, this.playClassName); var play_cmd_count = play_cmd_list.length; for(var index = 0; index < play_cmd_count; index++) { var play_cmd = play_cmd_list[index]; Roku.Util.eventHandler(play_cmd, "click", clickPlayHandler); } } Roku.AudioBrowser.initialize = function() { this.audioBrowser = document.getElementById(this.audioBrowserId); var page_list = Roku.Util.childClassElement(this.audioBrowser, this.pageListClassName); this.pages = Roku.Util.childrenClassElements(page_list, this.pageClassName); var pages_count = this.pages.length; for(var index = 0; index < pages_count; index++) { var page = this.pages[index]; var sub_combo = Roku.Util.childIdElement(page, "sub_category_combo"); if(sub_combo) { sub_combo[Roku.Combo.displayHilightHandler] = function(display, hilight) { Roku.AudioBrowser.on_hilight_sub_combo_display(display, hilight); } sub_combo[Roku.Combo.dropHilightHandler] = function(drop, hilight) { Roku.AudioBrowser.on_hilight_sub_combo_drop(drop, hilight); } sub_combo[Roku.Combo.selChangedEventName] = function(combo, entry) { Roku.AudioBrowser.on_sub_combo_sel_chnaged(combo, entry); } sub_combo[Roku.Combo.dropDownEventName] = function(combo) { Roku.AudioBrowser.on_sub_combo_drop_down(combo); } var entry = this.get_default_entry(sub_combo); var entry_id = entry ? entry.id : ""; page.setAttribute(this.currentEntryAttribName, entry_id); this.select_drop_entry(sub_combo, entry_id); Roku.Combo.select(sub_combo, entry_id); } } var combo = Roku.Util.childIdElement(this.audioBrowser, this.pageSelectComboId); if(combo) { combo[Roku.Combo.selChangedEventName] = function(combo, drop_entry) { return Roku.AudioBrowser.on_page_combo_sel_changed(combo, drop_entry); } this.select_page(Roku.Combo.selected(combo)); } this.refresh(this.audioBrowser); } Roku.AudioBrowser.refresh_content = function(root, source, reason) { var source_page = Roku.Util.parentClassElement(source, this.pageClassName); var page_combo = Roku.Util.childIdElement(this.topStations, this.pageSelectComboId); var sel_page_id = Roku.Combo.selected(page_combo); var sel_page = this.get_page(sel_page_id); if(sel_page == source_page) this.fill_page(sel_page); // do it now else window.setTimeout("Roku.AudioBrowser.refresh_selected_content()", 1000); window.setTimeout("Roku.AudioBrowser.refresh_entire_content()", 3000); } Roku.AudioBrowser.refresh_selected_content = function() { // immidiately update selected page, delay update other pages var page_combo = Roku.Util.childIdElement(this.topStations, this.pageSelectComboId); var sel_page_id = Roku.Combo.selected(page_combo); for(var index in this.pages) if(sel_page_id == this.pages.id) this.fill_page(this.pages[index]); } Roku.AudioBrowser.refresh_entire_content = function() { for(var index in this.pages) this.fill_page(this.pages[index]); } /* Roku.TopStations */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.TopStations = { topStationsId : "wdgTopStations", pageListClassName : "pages_list", pageClassName : "page", titleClassName : "title", playClassName : "play", entryClassName : "entry", imageClassName : "image", responseContentClassName: "response_content", currentEntryAttribName : "current_entry", queryKeyAttribName : "query_key", queryValueAttribName : "query_value", browseTypeAttribName : "browse_type", pageSelectComboId : "page_select", responseElementId : "query_response", topStations : null, pages : [] }; Roku.classes.push(Roku.TopStations); Roku.TopStations.on_hilight_sub_combo_display = function(display, hilight) {} Roku.TopStations.on_hilight_sub_combo_drop = function(drop, hilight) { if(drop) { drop.style.textDecoration = hilight ? "underline" : ""; drop.style.color = hilight ? "#FFFF80" : ""; //drop.style.color = hilight ? "#938AC4" : ""; //drop.style.opacity = hilight ? 0.80 : 1.0;; //drop.style.filter = hilight ? "alpha(opacity=80)" : ""; } } Roku.TopStations.on_sub_combo_sel_chnaged = function(combo, entry) { this.select_drop_entry(combo, entry ? entry.id : ""); this.on_select_entry(entry); } Roku.TopStations.on_sub_combo_drop_down = function(combo) { var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName); if(drop_down) { var master_combo = Roku.Util.childIdElement(this.topStations, this.pageSelectComboId); var display = Roku.Util.childClassElement(master_combo, Roku.Combo.displayClassName); var displayRect = Roku.Util.elementRect(display); drop_down.style.left = (displayRect.left + (displayRect.width - drop_down.offsetWidth) / 2) + "px"; drop_down.style.top = (displayRect.top + displayRect.height) + "px"; //var page = Roku.Util.parentClassElement(combo, this.pageClassName); //var sel_id = page.getAttribute(this.currentEntryAttribName); //this.select_drop_entry(combo, sel_id); } } Roku.TopStations.select_drop_entry = function(combo, id) { var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName); var entries = Roku.Util.childrenClassElements(drop_down, Roku.Combo.contentClassName); var entries_count = entries.length; for(var index = 0; index < entries_count; index++) { var entry = entries[index]; entry.style.backgroundColor = (id && (entry.id == id)) ? "#9E96CA" : ""; } } Roku.TopStations.get_default_entry = function(combo) { var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName); var entries = Roku.Util.childrenClassElements(drop_down, Roku.Combo.contentClassName); var entries_count = entries.length; for(var index = 0; index < entries_count; index++) { var entry = entries[index]; if(entry.getAttribute("default_entry")) return entry; } return null; } Roku.TopStations.on_select_entry = function(entry) { var page = Roku.Util.parentClassElement(entry, this.pageClassName); this.select_page_entry(page, entry); } Roku.TopStations.select_page_entry = function(page, entry) { if(!page) return; var entry_id = entry ? entry.id : ""; page.setAttribute(this.currentEntryAttribName, entry_id); this.fill_page(page, entry_id); } Roku.TopStations.fill_page = function(page, entry_id) { if(!page) return; if(!entry_id) entry_id = page.getAttribute(this.currentEntryAttribName); if(!entry_id) return; var queryKey = page.getAttribute(this.queryKeyAttribName); var queryValue = entry_id; var queryParam = queryKey + "=" + queryValue + "&top=true"; Roku.Query.invoke(queryParam, function (content, custom_data) { Roku.TopStations.fill_page_content(content, custom_data); }, page); } Roku.TopStations.fill_page_content = function(response, page) { if(!page) return; var content = Roku.Util.childClassElement(page, this.responseContentClassName); if(content) { content.innerHTML = response; Roku.Body.doRefresh(content); } } Roku.TopStations.on_page_combo_sel_changed = function(combo, drop_entry) { this.select_page(drop_entry ? drop_entry.id : ""); // notify server for changed state var browse_type = drop_entry ? drop_entry.getAttribute(this.browseTypeAttribName) : ""; var query_key = combo ? combo.getAttribute(this.queryKeyAttribName) : ""; var query_value = combo ? combo.getAttribute(this.queryValueAttribName) : ""; if(query_key && query_value && browse_type) Roku.Query.invoke(query_key + "=" + query_value + "&value=" + browse_type); } Roku.TopStations.select_page = function(id) { var page_count = this.pages.length; for(var index = 0; index < page_count; index++) { var page = this.pages[index]; page.style.display = (page.id == id) ? "block" : "none"; } } Roku.TopStations.get_page = function(id) { var page_count = this.pages.length; for(var index = 0; index < page_count; index++) { var page = this.pages[index]; if(page.id == id) return page; } return null; } Roku.TopStations.on_click_play = function(ev) { var element = Roku.Util.srcEventElement(ev); var entry = Roku.Util.parentClassElement(element, this.entryClassName); var station = Roku.Util.childClassElement(entry, Roku.Station.stationClassName); Roku.Util.Shared.playStation(ev, station); } Roku.TopStations.refresh = function(root) { var clickPlayHandler = function() { return Roku.TopStations.on_click_play((0 < arguments.length) ? arguments[0] : null); }; var play_cmd_list = Roku.Util.childrenClassElements(root ? root : this.topStations, this.playClassName); var play_cmd_count = play_cmd_list.length; for(var index = 0; index < play_cmd_count; index++) { var play_cmd = play_cmd_list[index]; Roku.Util.eventHandler(play_cmd, "click", clickPlayHandler); } } Roku.TopStations.initialize = function() { this.topStations = document.getElementById(this.topStationsId); var page_list = Roku.Util.childClassElement(this.topStations, this.pageListClassName); this.pages = Roku.Util.childrenClassElements(page_list, this.pageClassName); var pages_count = this.pages.length; for(var index = 0; index < pages_count; index++) { var page = this.pages[index]; var sub_combo = Roku.Util.childIdElement(page, "sub_category_combo"); if(sub_combo) { sub_combo[Roku.Combo.displayHilightHandler] = function(display, hilight) { Roku.TopStations.on_hilight_sub_combo_display(display, hilight); } sub_combo[Roku.Combo.dropHilightHandler] = function(drop, hilight) { Roku.TopStations.on_hilight_sub_combo_drop(drop, hilight); } sub_combo[Roku.Combo.selChangedEventName] = function(combo, entry) { Roku.TopStations.on_sub_combo_sel_chnaged(combo, entry); } sub_combo[Roku.Combo.dropDownEventName] = function(combo) { Roku.TopStations.on_sub_combo_drop_down(combo); } var entry = this.get_default_entry(sub_combo); var entry_id = entry ? entry.id : ""; page.setAttribute(this.currentEntryAttribName, entry_id); this.select_drop_entry(sub_combo, entry_id); Roku.Combo.select(sub_combo, entry_id); } } var combo = Roku.Util.childIdElement(this.topStations, this.pageSelectComboId); if(combo) { combo[Roku.Combo.selChangedEventName] = function(combo, drop_entry) { return Roku.TopStations.on_page_combo_sel_changed(combo, drop_entry); } var sel_page_id = Roku.Combo.selected(combo); Roku.TopStations.select_page(sel_page_id); } this.refresh(this.topStations); } Roku.TopStations.refresh_content = function(root, source, reason) { var source_page = Roku.Util.parentClassElement(source, this.pageClassName); var page_combo = Roku.Util.childIdElement(this.topStations, this.pageSelectComboId); var sel_page_id = Roku.Combo.selected(page_combo); var sel_page = this.get_page(sel_page_id); if(sel_page == source_page) this.fill_page(sel_page); // do it now else window.setTimeout("Roku.TopStations.refresh_selected_content()", 1000); window.setTimeout("Roku.TopStations.refresh_entire_content()", 3000); } Roku.TopStations.refresh_selected_content = function() { // immidiately update selected page, delay update other pages var page_combo = Roku.Util.childIdElement(this.topStations, this.pageSelectComboId); var sel_page_id = Roku.Combo.selected(page_combo); for(var index in this.pages) if(sel_page_id == this.pages.id) this.fill_page(this.pages[index]); } Roku.TopStations.refresh_entire_content = function() { for(var index in this.pages) this.fill_page(this.pages[index]); } /* Roku.AlertBox */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.AlertBox = { className : "alert_box", closeClassName : "close", popupDropClassName : "popup_drop", popupIdAttribName : "popup_id" } Roku.classes.push(Roku.AlertBox); Roku.AlertBox.on_close = function(ev) { var element = Roku.Util.srcEventElement(ev); var alert_box = Roku.Util.parentClassElement(element, this.className); if(alert_box) alert_box.style.display = "none"; //alert_box.style.visibility = "hidden"; } Roku.AlertBox.on_drop_popup = function(ev) { var element = Roku.Util.srcEventElement(ev); var popup_drop = Roku.Util.parentClassElement(element, this.popupDropClassName); if(!popup_drop) return; var popup_id = popup_drop.getAttribute(this.popupIdAttribName); var popup = document.getElementById(popup_id); if(!popup) return; var alert_box = Roku.Util.parentClassElement(element, this.className); var alert_box_body = Roku.Util.childTagElement(alert_box, "tbody"); var popup_drop_rect = Roku.Util.elementRect(popup_drop); var alert_box_rect = Roku.Util.elementRect(alert_box_body); popup.style.visibility = "hidden"; popup.style.display = "block"; var popupWidth = popup.offsetWidth; popup.style.display = ""; popup.style.visibility = ""; var offsetX = 0; if(ev.offsetX && ev.offsetY) { //IE if(Roku.Util.CompareNoCase(element.tagName, "a")) { var parentRect = Roku.Util.elementRect(element.offsetParent); offsetX = ev.offsetX - (popup_drop_rect.left - parentRect.left); } else { offsetX = ev.offsetX; } } else if(ev.pageX && ev.pageY) { // Mozilla offsetX = ev.clientX + ev.pageX - ev.clientX - popup_drop_rect.left; } var popup_left = alert_box_rect.left + alert_box_rect.width - popupWidth; offsetX += (popup_drop_rect.left - popup_left); Roku.Popup.show(popup, popup_drop, popup_left, popup_drop_rect.top + popup_drop_rect.height, offsetX); Roku.Util.eventCancel(ev); } Roku.AlertBox.initialize = function() { var closeHandler = function(ev) { return Roku.AlertBox.on_close(ev); }; var dropPopupHandler = function(ev) { return Roku.AlertBox.on_drop_popup(ev); }; var alert_boxes = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.className] : Roku.Util.childrenClassElements(document.body, this.className); var alert_boxes_count = alert_boxes ? alert_boxes.length : 0; for(var iBox = 0; iBox < alert_boxes_count; iBox++) { var alert_box = alert_boxes[iBox]; var close = Roku.Util.childClassElement(alert_box, this.closeClassName); Roku.Util.eventHandler(close, "click", closeHandler); var popup_drops = Roku.Util.childrenClassElements(alert_box, this.popupDropClassName); var popup_drops_count = popup_drops.length; for(var iDrop = 0; iDrop < popup_drops_count; iDrop++) { var popup_drop = popup_drops[iDrop]; Roku.Util.eventHandler(popup_drop, "click", dropPopupHandler); } } } /* Roku.Util */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; if(typeof(Roku.Util) == "undefined") Roku.Util = {}; Roku.Util.Point = function() { this.x = 0; this.y = 0; }; Roku.Util.Rect = function() { this.left = 0; this.top = 0; this.width = 0; this.height = 0; }; Roku.Util.isParent = function(parent, child) { var el = child; while(el && (el != parent)) el = el.parentNode; return el; } Roku.Util.parentClassElement = function(child, className) { var el = child; while(el && (el.className != className)) el = el.parentNode; return el; }; Roku.Util.parentIdElement = function(child, id) { if(!id) return null; var el = child; while(el && (el.id != id)) el = el.parentNode; return el; }; Roku.Util.parentAttribElement = function(child, attrib_name) { if(!attrib_name) return null; var el = child; while(el && el.getAttribute && (el.getAttribute(attrib_name) == null)) el = el.parentNode; return el; }; Roku.Util.parentTagElement = function(child, tagName) { var el = child; while(el && !this.CompareNoCase(el.tagName, tagName)) el = el.parentNode; return el; }; Roku.Util.childClassElement = function(parent, className) { if(!parent) return null; var elements = parent.childNodes; var length = elements.length; for(var index = 0; index < length; index++) { var element = elements[index]; if(element && element.className == className) return element; var child = this.childClassElement(element, className) if(child) return child; } return null; } Roku.Util.childIdElement = function(parent, id) { if(!parent || !id) return null; var elements = parent.childNodes; var length = elements ? elements.length : 0; for(var index = 0; index < length; index++) { var element = elements[index]; if(element && element.id == id) return element; var child = this.childIdElement(element, id) if(child) return child; } return null; } Roku.Util.childrenClassElements = function(element, className, result) { if(!result) { result = []; this.childrenClassElements(element, className, result); return result; } else if(element) { if(element.className == className) result.push(element); else { var children = element.childNodes; var length = children ? children.length : 0; for(var index = 0; index < length; index++) this.childrenClassElements(children[index], className, result); } } } Roku.Util.childrenIdElements = function(element, id, result) { if(!result) { result = []; this.childrenIdElements(element, id, result); return result; } else if(element) { if(element.id == id) result.push(element); else { var children = element.childNodes; var length = children ? children.length : 0; for(var index = 0; index < length; index++) this.childrenIdElements(children[index], id, result); } } } Roku.Util.childrenAttribElements = function(element, attrib_name, result) { if(!result) { result = []; this.childrenAttribElements(element, attrib_name, result); return result; } else if(element) { if(element.getAttribute && (element.getAttribute(attrib_name) != null)) result.push(element); else { var children = element.childNodes; var length = children ? children.length : 0; for(var index = 0; index < length; index++) this.childrenAttribElements(children[index], attrib_name, result); } } } Roku.Util.indexTagElement = function(children, tagName, index) { if(!children) return null; if(!index) index = 0; var length = children.length; for(var i = 0; i < length; i++) { var element = children[i]; if(element && Roku.Util.CompareNoCase(element.tagName, tagName)) { if(index == 0) return element; else index--; } } return null; } Roku.Util.childTagElement = function() { try { var parent = arguments[0]; var arg_count = arguments.length; for(var iArg = 1; iArg < arg_count; iArg++) { var tagName = arguments[iArg]; var children = parent.childNodes; var tagChild = null; var children_count = children.length; for(var iChild = 0; iChild < children_count; iChild++) { var child = children[iChild]; if(child && Roku.Util.CompareNoCase(child.tagName, tagName)) { tagChild = child; break; } } if(tagChild) parent = tagChild; else return null; } return parent; } catch (e) { } return null; } Roku.Util.childrenTagElements = function(element, tagName, result) { if(!result) { result = []; this.childrenTagElements(element, tagName, result); return result; } else if(element) { if(Roku.Util.CompareNoCase(element.tagName, tagName)) result.push(element); else { var children = element.childNodes; var length = children ? children.length : 0; for(var index = 0; index < length; index++) this.childrenTagElements(children[index], tagName, result); } } } Roku.Util.elementRect = function(el) { var rect = new Roku.Util.Rect(); rect.left = 0; rect.top = 0; rect.width = (el) ? el.offsetWidth : 0; rect.height = (el) ? el.offsetHeight : 0; while(el != null) { rect.left += el.offsetLeft - el.scrollLeft; rect.top += el.offsetTop - el.scrollTop; var parent = el.offsetParent; el = parent; } rect.left += document.body.scrollLeft; rect.top += document.body.scrollTop; return rect; } Roku.Util.clientWidth = function() { var width = 0; if(window.innerWidth) width = window.innerWidth; else if(0 < document.documentElement.clientWidth) width = document.documentElement.clientWidth; else width = document.body.clientWidth; return width; } Roku.Util.clientHeight = function() { var height = 0; if(window.innerHeight) height = window.innerHeight; else if(0 < document.documentElement.clientHeight) height = document.documentElement.clientHeight; else height = document.body.clientHeight; return height; } Roku.Util.CompareNoCase = function(text1, text2) { return text1 && (typeof(text1.toUpperCase) == "function") && text2 && (typeof(text2.toUpperCase) == "function") && (text1.toUpperCase() == text2.toUpperCase()); } Roku.Util.TruncateText = function(text, maxLength) { if(!text) return ""; if(text.length <= maxLength) return text; var last = maxLength; while((0 <= last) && (text.charAt(last) != ' ')) last--; if(last <= 0) last = maxLength; return text.substring(0, last) + " ..."; } Roku.Util.Trim = function(text) { if(!text) return ""; var first = 0, last = text.length - 1; while((first <= last) && (text.charCodeAt(first) < 33)) first++; while((first <= last) && (text.charCodeAt(last) < 33)) last--; return (first <= last) ? text.substr(first, last - first + 1) : ""; } Roku.Util.eventHandler = function(element, event_name, event_handler) { if(!element) return; if(element.attachEvent) { element.attachEvent("on" + event_name, event_handler); // IE } else if(element.addEventListener) { element.addEventListener(event_name, event_handler, true); //Mozilla } } Roku.Util.eventHandlerDetach = function(element, event_name, event_handler) { if(!element) return; if(element.detachEvent) { element.detachEvent("on" + event_name, event_handler); // IE } else if(element.removeEventListener) { element.removeEventListener(event_name, event_handler, true); //Mozilla } } Roku.Util.eventCancel = function(ev) { if(ev) { if(ev.preventDefault) ev.preventDefault(); //Mozilla ev.returnValue = false; //IE } } Roku.Util.eventCancelBuble = function(ev) { if(ev) { if(ev.stopPropagation) ev.stopPropagation(); //Mozilla ev.cancelBubble = true; //IE } } Roku.Util.srcEventElement = function(ev) { var element = null; if(ev) { element = ev.srcElement; if(!element) element = ev.target; } return element; } Roku.Util.getCookie = function(name, file_name) { if(!file_name) { var split = Roku.Util.splitUrl(window.location.href); file_name = split['file']; } var cookie_name = name + file_name; var cookies = (document.cookie != null) ? document.cookie.split(";") : []; var cookies_count = cookies.length; for(var iCookie = 0; iCookie < cookies_count; iCookie++) { var cookie = cookies[iCookie].split("="); if((cookie.length == 2) && (0 <= cookie[0].indexOf(cookie_name))) { return unescape(cookie[1]); } } return ""; } Roku.Util.setCookie = function(name, value, file_name, exp) { if(!file_name) { var split = Roku.Util.splitUrl(window.location.href); file_name = split['file']; } var cookie_name = name + file_name; if(!exp) exp = 6; var expdate = new Date(); expdate.setMonth(expdate.getMonth() + exp); var sCookie = cookie_name + "=" + escape(value) + "; expires=" + expdate.toGMTString(); document.cookie = sCookie; } Roku.Util.parseCookie = function(cookie, entry_delimiter, value_delimiter) { if(!entry_delimiter) entry_delimiter = ";"; if(!value_delimiter) value_delimiter = "="; var result = []; var entries = cookie.split(entry_delimiter); var entries_count = entries.length; for(var iEntry = 0; iEntry < entries_count; iEntry++) { var entry = entries[iEntry].split(value_delimiter); if(entry && (entry.length == 2)) result[entry[0]] = entry[1]; } return result; } Roku.Util.Encode = function(s) { var result = ""; var zero_str = "0"; var zero_code = zero_str.charCodeAt(0); var A_str = "A"; var A_code = A_str.charCodeAt(0); var length = s.length; for(var index = 0; index < length; index++) { var ch_code = s.charCodeAt(index); var high = ch_code / 16; result += String.fromCharCode(((high < 10) ? zero_code : A_code) + high); var low = ch_code % 16; result += String.fromCharCode(((low < 10) ? zero_code : A_code) + low); } return result; } Roku.Util.Decode = function(s) { var result = ""; var zero_str = "0"; var zero_code = zero_str.charCodeAt(0); var A_str = "A"; var A_code = A_str.charCodeAt(0); var length = s.length; for(var index = 0; index < length; index++) { var ch_code = 0; var high_code = s.charCodeAt(index++); ch_code += (high_code - ((A_code <= high_code) ? A_code : zero_code)) * 16 var low_code = (index < length) ? s.charCodeAt(index) : zero_code; ch_code += (low_code - ((A_code <= low_code) ? A_code : zero_code)); result += String.fromCharCode(ch_code); } return result; } Roku.Util.splitUrl = function(url) { var result = { path : "", file : "", extention : "", extra : ""}; if(!url) return result; var length = url.length; var posExtra = url.indexOf("?"); if(0 <= posExtra) { result.extra = url.substr(posExtra + 1, length - posExtra - 1); length = posExtra; } for(var index = length - 1; 0 <= index; index--) { var ch = url.charAt(index); if(!result.extention && (ch == '.')) { result.extention = url.substr(index, length - index); length = index; } if((ch == '\\') || (ch == '/')) { result.file = url.substr(index + 1, length - index - 1); result.path = url.substr(0, index + 1); break; } } if(!result.file) { if(result.extention) result.file = url.substr(0, length); else result.path = url.substr(0, length); } return result; } Roku.Util.Trace = function() { var statusEl, statusText; var append = false; if(1 == arguments.length) { statusEl = document.getElementById("status"); statusText = arguments[0]; window.status = statusText; } else if(2 <= arguments.length) { statusEl = document.getElementById(arguments[0]); statusText = arguments[1]; append = (2 < arguments.length) && arguments[2]; } if(statusEl) if(append) statusEl.innerHTML = statusEl.innerHTML + statusText + "
"; else statusEl.innerHTML = statusText; } /* Roku.Util.Shared */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; if(typeof(Roku.Util) == "undefined") Roku.Util = {}; Roku.Util.Shared = { pcPlayerTarget : "pcplayer", pcPlayerUrl : "", pcPlayerWindow : null }; Roku.Util.Shared.getAttribute = function(station, attribute) { var value = ""; if(station) if(typeof(station.getAttribute) == "function") value = station.getAttribute(attribute); else value = station[attribute]; if(!value) value = ""; return value; } Roku.Util.Shared.playStation = function(ev, stationElement, table, field, id, station_title, station_url) { if(!id) id = this.getAttribute(stationElement, "station_id"); if(id && !table) table = this.getAttribute(stationElement, "station_table"); if(id && !table) table = "stations"; if(id && !field) field = this.getAttribute(stationElement, "station_field"); if(id && !field) field = "id"; if(!station_title) station_title = this.getAttribute(stationElement, "station_title"); if(!station_url) station_url = this.getAttribute(stationElement, "station_url"); if(!id && !station_url) return; // can't play anything var scrollX = 0, scrollY = 0; if(ev && ev.offsetX && ev.offsetY) { // IE var element = Roku.Util.srcEventElement(ev); var rectElement = (Roku.Util.CompareNoCase(element.tagName, "span") || Roku.Util.CompareNoCase(element.tagName, "a")) ? element.offsetParent : element; var rect = Roku.Util.elementRect(rectElement); scrollX = rect.left - (ev.clientX - ev.offsetX); scrollY = rect.top - (ev.clientY - ev.offsetY); } else if(ev && ev.pageX && ev.pageY) { // Mozilla scrollX = ev.pageX - ev.clientX; scrollY = ev.pageY - ev.clientY; } var alignRect = Roku.Util.elementRect(stationElement); var x = alignRect.left - scrollX + (ev ? (ev.screenX - ev.clientX) : 0); var y = alignRect.top + alignRect.height - scrollY + (ev ? (ev.screenY - ev.clientY) : 0); var w = 250; var h = 240; if(!this.pcPlayerUrl) this.pcPlayerUrl = this.pcPlayerTarget + ".php"; var url = this.pcPlayerUrl; var url_params = "" if(table) { if(0 < url_params.length) url_params += "&" url_params += "table=" + table; } if(field) { if(0 < url_params.length) url_params += "&" url_params += "field=" + field; } if(id) { if(0 < url_params.length) url_params += "&" url_params += "id=" + id; } if(station_title) { if(0 < url_params.length) url_params += "&" url_params += "title=" + encodeURI(station_title); } if(station_url) { if(0 < url_params.length) url_params += "&" url_params += "url=" + encodeURIComponent(station_url); } if(this.getAttribute(stationElement, "single_url")) { if(0 < url_params.length) url_params += "&" url_params += "single_url=1"; } if(Roku.Util.CompareNoCase(window.navigator.appName, "Microsoft Internet Explorer")) { h += 20; // IE normally does not hide statusbar. } else { if(0 < url_params.length) url_params += "&" url_params += "embed=true"; } if(0 < url_params.length) url += ("?" + url_params); //try { this.pcPlayerWindow.close(); } catch(e) {} this.pcPlayerWindow = window.open(url, this.pcPlayerTarget, "width=250, height=" + h + ", menubar=no, toolbar=no, location=no, directories=no, status=no, resizable=no, scrollbars=no"); //"left=" + x + ", top=" + y + this.pcPlayerWindow.focus(); } Roku.Util.Shared.checkConfirmed = function(ev) { var need_confirm = Roku.DialogRegistrationRequired ? document.getElementById(Roku.DialogRegistrationRequired.id) : null; if(!need_confirm) return true; if(ev) Roku.Util.eventCancel(ev); Roku.DialogRegistrationRequired.do_modal(ev); return false; } /* Roku.Query */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Query = { url : "query.php" }; Roku.classes.push(Roku.Query); Roku.Query.createRequest = function() { var request; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); if (!request) request = null; } /* var request; if(window.ActiveXObject) { request = new ActiveXObject("Msxml2.XMLHTTP"); if(!request) request = new ActiveXObject("Microsoft.XMLHTTP") } else if(window.XMLHttpRequest) request = new XMLHttpRequest; */ return request; } Roku.Query.invoke = function(param, result_handler, custom_data) { var request = this.createRequest(); if(!request) return; try { request.onreadystatechange = function(ev) { if((request.readyState == 4) && result_handler) { result_handler(request.responseText, custom_data); } } request.open("POST", this.url, true); request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestHeader("Content-length", param.length); request.setRequestHeader("Connection", "close"); request.send(param); } catch(e) { } }; Roku.Query.invoke_sync = function(param) { var request = this.createRequest(); if(!request) return ""; try { request.open("POST", this.url, false); request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestHeader("Content-length", param.length); request.setRequestHeader("Connection", "close"); request.send(param); return request.responseText; } catch(e) { } return ""; }; /* Roku.MySB */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.MySB = { className : "my_sb", id : "my_sb", comboId : "sb_select", dev_pane_class_name : "device_pane", dev_controls_class_name : "device_controls", station_drop_target_id : "station_drop_target", playing_titles_id : [ "station_title0", "station_title1", "station_title2", "station_title3" ], btn_class_name : "button", btn_command_id : "command", btn_info_id : "button_info", playButtonSrc : "images/sb-ctrl-play.png", pauseButtonSrc : "images/sb-ctrl-pause.png", powerButtonSrc : "images/sb-ctrl-power.png", powerOffButtonSrc : "images/sb-ctrl-power-disabled.png", sliderBgSrc : "images/sb-ctrl-slide.png", sliderBgDisabledSrc : "images/sb-ctrl-slide-disabled.png", sliderHandleSrc : "images/sb-ctrl-slide-handle.png", sliderHandleDisabledSrc : "images/sb-ctrl-slide-handle-disabled.png", cmd_show_presets_id : "show_presets", cmd_hide_presets_id : "hide_presets", cmd_save_as_preset_id : "save_as_preset", cmd_reload_presets_id : "reload_presets", volume_slider_id : "sb_slider", tab_presets_id : "presets", mac_attrib_name : "id", dip_attrib_name : "dip", updateTimeout : 1000, me : null, device_pane : null, sb_combo : null, cur_sb_mac : "", volume_slider : null, volume_slider_handle : null, slider_changing : false, playing_titles : [], btn_command : null, btn_info : null, tab_presets : null, checked_sb_list : [], device_state : "", now_playing_state : "", now_playing_song : "", now_playing_artist : "", now_playing_title1 : "", now_playing_title2 : "", now_playing_url : "", now_playing_id : "", interval_ID : null }; Roku.classes.push(Roku.MySB); Roku.MySB.on_sb_combo_sel_changed = function(combo) { this.clear_sb_states(); var selected_entry = Roku.Combo.selected_entry(combo); this.init_current_sb_entry(selected_entry); this.update_presets(); } Roku.MySB.init_current_sb_entry = function(entry) { this.cur_sb_mac = entry ? entry.getAttribute(this.mac_attrib_name) : ""; Roku.MySB.Radio.set_ip(entry ? entry.getAttribute(this.dip_attrib_name) : ""); } Roku.MySB.on_sb_slider_sel_changing = function(slider) { this.slider_changing = true; } Roku.MySB.on_sb_slider_sel_changed = function(slider) { this.slider_changing = false; var volume = Math.ceil(Roku.Slider.getPos(slider) * 100); Roku.MySB.Radio.do_sb_command("SetVolume " + volume, null, null, true); } Roku.MySB.handle_error = function(exception_value) { //Roku.Util.Trace("debug_out", "Error: " + exception_value, true); try { if (this.interval_ID != null) window.clearInterval(this.interval_ID); this.interval_ID = null; //Roku.Util.Trace("debug_out", "Stop timer", true); } catch(e) {} //{ Roku.Util.Trace(e); } this.device_state = "GenericError"; this.init_playing_titles(); //this.playing_titles[0].innerHTML = exception_value; this.playing_titles[0].className = "text_entry_hilight_1"; } Roku.MySB.on_timeout_update = function() { if(!this.slider_changing) this.update_volume(); this.update_playing(); this.update_transport_state(); //Roku.Util.Trace("debug_out", "Timer", true); } Roku.MySB.init_volume = function(response) { var key = "GetVolume: "; response = Roku.Util.Trim(response); var volume = (response && response.indexOf(key) == 0) ? parseInt(response.substr(key.length, response.length - key.length)) : NaN; if(!isNaN(volume)) { if(this.volume_slider && (0 <= this.volume_slider.style.backgroundImage.indexOf(this.sliderBgSrc))) { Roku.Slider.setPos(this.volume_slider, volume / 100.0); if(this.volume_slider_handle) this.volume_slider_handle.style.visibility = ""; } } } Roku.MySB.update_volume = function(response) { Roku.MySB.Radio.do_sb_command("GetVolume", function(response) { Roku.MySB.init_volume(response); }); } Roku.MySB.init_playing = function(response) { // 1. Parse entrie response. var entry_key = "GetCurrentSongInfo: "; var entry_delim = ": "; var song_delim = " - "; var playing_info = []; var isNormal = true; if (response) { response = response.replace(" +++", " - "); response = response.replace("\\'", "'"); //Roku.Util.Trace("debug_out", response, true); if (response.indexOf("remoteStream: 1") > 0) { if (response.indexOf("remoteRhapsody") > 0) isNormal = false; } else isNormal = false; } var entries = response ? response.split('\n') : []; var entries_count = entries.length; for(var iEntry = 0; iEntry < entries_count; iEntry++) { var entry = Roku.Util.Trim(entries[iEntry]); //Roku.Util.Trace("debug_out", entry, true); if(entry.indexOf(entry_key) == 0) { entry = entry.substr(entry_key.length, entry.length - entry_key.length); var delim_pos = entry.indexOf(entry_delim) if(0 <= delim_pos) { var key = entry.substr(0, delim_pos); var value = entry.substr(delim_pos + entry_delim.length, entry.length - delim_pos - entry_delim.length); playing_info[key] = value; } } } // 2. Try to retrieve what we can from parsed response var now_playing_url = this.now_playing_url; this.now_playing_song = ""; this.now_playing_artist = ""; this.now_playing_title1 = ""; this.now_playing_title2 = ""; this.now_playing_url = ""; if (isNormal == false) { this.now_playing_id = ""; this.now_playing_song = playing_info['title']; this.now_playing_artist = playing_info['artist']; this.now_playing_title1 = playing_info['album']; return; } // GetCurrentSongInfo: title: Kenny G - Gettin' On The Step if(playing_info['title']) { var song_info = playing_info['title']; // Roku.Util.Trace("debug_out", song_info, true); var song_pos = song_info.indexOf(song_delim); if(0 <= song_pos) { this.now_playing_song = song_info.substr(song_pos + song_delim.length, song_info.length - song_pos - song_delim.length); this.now_playing_artist = song_info.substr(0, song_pos); } } // GetCurrentSongInfo: artist: http://www.radioparadise.com if(playing_info['artist']) this.now_playing_title1 = playing_info['artist']; // GetCurrentSongInfo: album: Radio Paradise if(playing_info['album']) this.now_playing_title2 = playing_info['album']; // GetCurrentSongInfo: playlistURL: http://207.173.203.149/musiclinks/rp_128a.m3u if(playing_info['playlistURL']) this.now_playing_url = playing_info['playlistURL']; // fixes: // GetCurrentSongInfo: artist: SomaFM // GetCurrentSongInfo: album: if(!this.now_playing_title2 && this.now_playing_title1) { this.now_playing_title2 = this.now_playing_title1; this.now_playing_title1 = ""; } // GetCurrentSongInfo: title: Quake Radio // GetCurrentSongInfo: artist: // GetCurrentSongInfo: album: if(!this.now_playing_title2 && !this.now_playing_title1 && !this.now_playing_song && !this.now_playing_artist && playing_info['title']) { this.now_playing_title2 = playing_info['title']; } // 3. try to retrieve station id from now_playing_url if(this.now_playing_url != now_playing_url) { if(this.now_playing_url) Roku.Query.invoke("station_id=" + encodeURIComponent(this.now_playing_url), function(response) { Roku.MySB.now_playing_id = Roku.Util.Trim(response); Roku.MySB.init_playing_titles(); }); else this.now_playing_id = ""; } // 4. Initialize retrieved values to now_playing titles this.init_playing_titles(); } Roku.MySB.init_playing_titles = function() { var data = [{}, {}, {}, {}]; switch(this.device_state) { case "Play": case "Pause": data[0].text = this.now_playing_song; data[1].text = (this.now_playing_artist) ? ("By " + this.now_playing_artist) : ""; data[2].text = this.now_playing_title1; data[3].text = this.now_playing_title2 ? (this.now_playing_state + ": " + this.now_playing_title2) : this.now_playing_state; break; case "Next": case "Prev": case "Buffering": break; case "Stop": case "Disconnected": case "Standby": var now = new Date(); data[0].text = now.toLocaleTimeString(); data[1].text = now.toLocaleDateString(); break; case "Uninitialized": break; case "GenericError": default: data[0].text = ""; data[0].class_name = "text_entry_1"; data[1].text = "Not Detected on Local Network"; data[1].class_name = "text_entry_hilight_1"; data[2].text = "Try Again"; data[2].class_name = "text_entry_1"; data[2].click_handler = function() { Roku.MySB.clear_sb_states(); Roku.MySB.refresh_sb_states(); }; break; } for(var index in this.playing_titles) { this.playing_titles[index].innerHTML = data[index].text ? data[index].text : ""; this.playing_titles[index].className = data[index].class_name ? data[index].class_name : ((0 == index) ? "text_entry_hilight" : "text_entry"); if(data[index].click_handler) { this.playing_titles[index]["click_handled"] = data[index].click_handler; Roku.Util.eventHandler(this.playing_titles[index], "click", data[index].click_handler); } else if(typeof(this.playing_titles[index]["click_handled"]) == "function") { Roku.Util.eventHandlerDetach(this.playing_titles[index], "click", this.playing_titles[index]["click_handled"]); this.playing_titles[index]["click_handled"] = null; } } if(this.btn_info) this.btn_info.style.display = this.now_playing_id ? "block" : ""; } Roku.MySB.update_playing = function() { Roku.MySB.Radio.do_sb_command("GetCurrentSongInfo", function(response) { Roku.MySB.init_playing(response); }); //Test: Roku.MySB.init_playing("GetCurrentSongInfo: title: Kenny G - Gettin' On The Step\nGetCurrentSongInfo: artist: Air America Radio\nGetCurrentSongInfo: album: Liberal Talk Radio\nGetCurrentSongInfo: playlistURL: http://vruk.ic.llnwd.net/stream/vruk_vr_hi"); } Roku.MySB.init_transport_state = function(response) { var key = "GetTransportState: "; response = Roku.Util.Trim(response); this.device_state = (response && response.indexOf(key) == 0) ? response.substr(key.length, response.length - key.length) : ""; this.now_playing_state = ""; switch(this.device_state) { case "Play": this.now_playing_state = "Playing"; break; case "Pause": this.now_playing_state = "Paused"; break; case "Next": this.now_playing_state = "Next"; break; case "Prev": this.now_playing_state = "Previous"; break; case "Stop": this.now_playing_state = "Stopped"; break; case "Buffering": this.now_playing_state = "Buffering"; break; case "Disconnected": this.now_playing_state = "Disconnected"; break; case "Standby": this.now_playing_state = "Standby"; break; case "GenericError": default: this.now_playing_state = ""; break; } this.process_transport_state(); } Roku.MySB.process_transport_state = function() { var btn_src = ""; var btn_cursor = "pointer"; var slider_src = this.sliderBgSrc; var slider_handle_src = this.sliderHandleSrc; var slider_cursor = "pointer"; var slider_pos = Roku.Slider.getPos(this.volume_slider); var slider_disabled = ""; //Roku.Util.Trace("debug_out", this.device_state, true); switch(this.device_state) { case "Buffering": case "Play": btn_src = this.pauseButtonSrc; break; case "Uninitialized": case "Stop": case "Pause": btn_src = this.playButtonSrc; break; case "Standby": case "Disconnected": btn_src = this.powerButtonSrc; break; default: btn_src = this.powerOffButtonSrc; btn_cursor = "default"; slider_src = this.sliderBgDisabledSrc; slider_handle_src = this.sliderHandleDisabledSrc; slider_cursor = "default"; slider_pos = 0.5; slider_disabled = "true"; break; } if(this.btn_command) { this.btn_command.src = btn_src; this.btn_command.style.cursor = btn_cursor; } if(this.volume_slider && this.volume_slider_handle) { this.volume_slider.style.backgroundImage = "url('" + slider_src + "')"; this.volume_slider.style.cursor = slider_cursor; this.volume_slider_handle.style.backgroundImage = "url('" + slider_handle_src + "')"; this.volume_slider_handle.style.cursor = slider_cursor; Roku.Slider.setPos(this.volume_slider, slider_pos); if(slider_disabled) this.volume_slider.setAttribute(Roku.Slider.disabledAttribName, slider_disabled); else this.volume_slider.removeAttribute(Roku.Slider.disabledAttribName); } this.init_playing_titles(); } Roku.MySB.update_transport_state = function() { Roku.MySB.Radio.do_sb_command("GetTransportState", function(response) { Roku.MySB.init_transport_state(response); }); //Test: Roku.MySB.init_transport_state("GetTransportState: Play"); } Roku.MySB.clear_sb_states = function() { this.now_playing_state = ""; this.now_playing_song = ""; this.now_playing_artist = ""; this.now_playing_title1 = ""; this.now_playing_title2 = ""; this.now_playing_url = ""; this.now_playing_id = ""; this.device_state = "Uninitialized"; this.process_transport_state(); //this.device_state = ""; } Roku.MySB.refresh_sb_states = function() { /* this.update_volume(); this.update_playing(); this.update_transport_state(); this.device_state = ""; window.setTimeout("Roku.MySB.process_transport_state();", this.updateTimeout * 3); */ if (this.interval_ID == null) this.interval_ID = window.setInterval("Roku.MySB.on_timeout_update()", this.updateTimeout); } Roku.MySB.on_command_button = function(ev) { var element = Roku.Util.srcEventElement(ev); var button = Roku.Util.parentClassElement(element, this.btn_class_name); var src = button ? button.src : ""; if(0 <= src.indexOf(this.pauseButtonSrc)) Roku.MySB.Radio.do_sb_command("Pause", function() { Roku.MySB.update_transport_state(); Roku.MySB.update_playing(); }, null, null, true ); else if(0 <= src.indexOf(this.playButtonSrc)) Roku.MySB.Radio.do_sb_command("Play", function() { Roku.MySB.update_transport_state(); Roku.MySB.update_playing(); }, null, null, true ); else if (0 <= src.indexOf(this.powerButtonSrc)) Roku.MySB.Radio.do_sb_command("SetPowerState on yes", function() { Roku.MySB.update_transport_state(); Roku.MySB.update_playing(); }, null, null, true ); //Roku.MySB.Radio.do_sb_command("Stop", function() { Roku.MySB.update_transport_state(); Roku.MySB.update_playing(); }, null, null, true ); } Roku.MySB.on_info_button = function(ev) { var station = { station_popup : 1, station_id : this.now_playing_id }; var offsetX = 140; var info_rect = Roku.Util.elementRect(this.btn_info); var stationRect = {}; stationRect.left = info_rect.left + info_rect.width / 2 - offsetX; stationRect.width = 2 * offsetX; stationRect.top = info_rect.top; stationRect.height = info_rect.height; var clientPoint = { x : ev.clientX, y : ev.clientY }; Roku.PopupStation.show1(station, stationRect, clientPoint, offsetX); } Roku.MySB.on_station_drag_enter = function(target, station) { if(!Roku.MySB.Radio.can_play() || !this.device_state) return false; this.set_station_drop_state(true); return true; } Roku.MySB.on_station_drag_leave = function(target, station) { this.set_station_drop_state(false); } Roku.MySB.on_station_drop = function(target, station) { this.set_station_drop_state(false); // emulate immediate playing this.device_state = "Play"; this.now_playing_state = "Playing"; this.now_playing_song = ""; this.now_playing_artist = ""; this.now_playing_title1 = ""; this.now_playing_title2 = Roku.Station.getTitle(station); this.now_playing_url = ""; this.now_playing_id = Roku.Station.getId(station); this.init_playing_titles(); Roku.MySB.Radio.play_station(station); } Roku.MySB.set_station_drop_state = function(active) { if(this.device_pane) { this.device_pane.style.opacity = active ? 0.70 : 1.0; this.device_pane.style.filter = active ? "alpha(opacity=70)" : ""; } for(var index in this.playing_titles) this.playing_titles[index].style.visibility = active ? "hidden" : ""; } Roku.MySB.update_presets = function() { var queryParam = "gather_presets=" + this.cur_sb_mac; Roku.Query.invoke(queryParam, function (content) { Roku.MySB.fill_presets(content, false); } ); this.refresh_sb_states(); } Roku.MySB.fill_presets = function(content, force) { var sel_page_id = Roku.Tab.selected(this.tab_presets); var tab_pages_list = Roku.Util.childClassElement(this.tab_presets, Roku.Tab.tabPagesListClassName); if(tab_pages_list) { tab_pages_list.innerHTML = content; Roku.Station.refresh(tab_pages_list); Roku.StationList.refresh(tab_pages_list); this.handle_presets_change(); } Roku.Tab.select(this.tab_presets, sel_page_id); this.update_reload_presets_visibility(); this.process_sb_refresh_presets(force); } Roku.MySB.process_sb_refresh_presets = function(force) { // is there a device at all? if(!this.cur_sb_mac) return; // does current SoundBridge device need refresh (i.e. all presets are empty)? var tab_pages_list = Roku.Util.childClassElement(this.tab_presets, Roku.Tab.tabPagesListClassName); var stations_list = Roku.Util.childrenClassElements(tab_pages_list, Roku.Station.stationClassName); var stations_count = stations_list.length; if (!force) { for(var index = 0; index < stations_count; index++) if(Roku.Station.getUrl(stations_list[index])) return; // have we already checked current SoundBridge device? var checked_count = this.checked_sb_list.length; for(var index = 0; index < checked_count; index++) if(this.checked_sb_list[index] == this.cur_sb_mac) return; } else { // if all 18 have data // return; } // invoke the refresh this.checked_sb_list.push(this.cur_sb_mac); // remember this device, do not refresh it more than once Roku.MySB.Radio.do_sb_command("UploadAllPresetsToRokuRadioServer"); // command SoundBridge device to contact server and send its presets window.setTimeout("Roku.MySB.update_presets();", 10000); // schedule request to the server to fill presets that the device has uploaded there } Roku.MySB.handle_presets_change = function() { var lists = Roku.Util.childrenClassElements(this.tab_presets, Roku.StationList.stationListClassName); var lists_count = lists.length; for(var index = 0; index < lists_count; index++) { var list = lists[index]; list[Roku.StationList.changedEventName] = function(arg) { Roku.MySB.on_presets_changed(arg); } } } Roku.MySB.on_presets_changed = function(station) { var station_index_element = Roku.Util.childClassElement(station, Roku.StationList.stationIndexClassName); if(!station_index_element) return; var tab_page = Roku.Util.parentClassElement(station, Roku.Tab.tabPageClassName); if(!tab_page) return; var preset_index = parseInt(station_index_element.innerHTML); var preset_offset = 0; switch(tab_page.id) { case "preset_A": preset_offset = 0; break; case "preset_B": preset_offset = 1; break; case "preset_C": preset_offset = 2; break; } var preset_id = preset_offset*6 + Math.max(preset_index - 1, 0) + 1; var queryParam; var station_set = (0 < station.offsetHeight); if(station_set) { var station_title = Roku.Station.getTitle(station); var station_url = Roku.Station.getUrl(station); var station_id = Roku.Station.getId(station); queryParam = "update_preset=" + this.cur_sb_mac + "&id=" + preset_id + "&station_title=" + station_title + "&station_url=" + encodeURIComponent(station_url) + "&station_id=" + station_id; } else { queryParam = "clear_preset=" + this.cur_sb_mac + "&id=" + preset_id; } //alert(queryParam); Roku.Query.invoke(queryParam); Roku.MySB.Radio.do_sb_command("UpdateFromRokuRadioServer"); window.setTimeout("Roku.MySB.update_reload_presets_visibility();", 100); } Roku.MySB.shown_presets = function(show) { return this.tab_presets ? (this.tab_presets.style.display != "none") : false; } Roku.MySB.show_presets = function(show) { if(this.tab_presets) this.tab_presets.style.display = show ? "block" : "none"; var cmd_hide = Roku.Util.childIdElement(this.me, this.cmd_hide_presets_id); if(cmd_hide) cmd_hide.style.display = show ? "block" : "none"; var cmd_show = Roku.Util.childIdElement(this.me, this.cmd_show_presets_id); if(cmd_show) cmd_show.style.display = show ? "none" : "block"; this.update_reload_presets_visibility(); } Roku.MySB.on_command_hide_presets = function(ev) { var element = Roku.Util.srcEventElement(ev); var cmd = Roku.Util.parentTagElement(element, "a"); var show; if(cmd && (cmd.id == this.cmd_show_presets_id)) show = true; if(cmd && (cmd.id == this.cmd_hide_presets_id)) show = false; if(typeof(show) == "boolean") { this.show_presets(show); Roku.Query.invoke("update_user_setting=device_presets_visible&value=" + (show ? "1" : "0")); } } Roku.MySB.on_min_restore = function() { var widget = Roku.Util.parentClassElement(this.me, Roku.Widget.widgetClassName); var content = Roku.Util.childClassElement(widget, Roku.Widget.widgetContentBarClassName); var content_display = content ? content.style.display : ""; var widget_hd_url = ""; var widget_c_url = ""; if(content_display != "none") { widget_hd_url = "url(images/tl-black.gif)"; widget_c_url = "url(images/tr-black.gif)"; } else { widget_hd_url = "url(images/tl.gif)"; widget_c_url = "url(images/tr.gif)"; } var widget_hd = Roku.Util.childClassElement(widget, "hd"); if(widget_hd) widget_hd.style.backgroundImage = widget_hd_url; var widget_c = Roku.Util.childClassElement(widget, "c"); if(widget_c) widget_c.style.backgroundImage = widget_c_url; } Roku.MySB.on_tab_page_changed = function(tab, tab_item) { Roku.Query.invoke("update_user_setting=device_presets_tab&value=" + Roku.Tab.item_index(tab, tab_item)); } Roku.MySB.can_reload_presets = function() { var tab_pages_list = Roku.Util.childClassElement(this.tab_presets, Roku.Tab.tabPagesListClassName); var stations_list = Roku.Util.childrenClassElements(tab_pages_list, Roku.Station.stationClassName); for(var index in stations_list) if(!Roku.Station.getTitle(stations_list[index])) return true; return false; } Roku.MySB.update_reload_presets_visibility = function() { var cmd_reload = Roku.Util.childIdElement(this.me, this.cmd_reload_presets_id); if(cmd_reload) { cmd_reload.style.display = (this.shown_presets() && this.can_reload_presets()) ? "block" : "none"; } } Roku.MySB.on_command_reload_presets = function(ev) { this.update_presets(); window.focus(); } Roku.MySB.initialize = function() { this.me = document.getElementById(this.id); var widget = Roku.Util.parentClassElement(this.me, Roku.Widget.widgetClassName); this.sb_combo = Roku.Util.childIdElement(this.me, this.comboId); if(this.sb_combo) { this.sb_combo[Roku.Combo.selChangedEventName] = function(combo) { return Roku.MySB.on_sb_combo_sel_changed(combo); } var selected_entry = Roku.Combo.selected_entry(this.sb_combo); this.init_current_sb_entry(selected_entry); } var station_drop_target = Roku.Util.childIdElement(this.me, this.station_drop_target_id); if(station_drop_target) { station_drop_target.onstationdragenter = function(target, station) { return Roku.MySB.on_station_drag_enter(target, station); }; station_drop_target.onstationdragleave = function(target, station) { return Roku.MySB.on_station_drag_leave(target, station); }; station_drop_target.onstationdrop = function(target, station) { return Roku.MySB.on_station_drop(target, station); }; Roku.Station.dropTargetClients.push(widget); } var device_controls = Roku.Util.childClassElement(this.me, this.dev_controls_class_name); this.btn_command = Roku.Util.childIdElement(device_controls, this.btn_command_id); Roku.Util.eventHandler(this.btn_command, "click", function(ev) {Roku.MySB.on_command_button(ev); } ) this.volume_slider = Roku.Util.childIdElement(device_controls, this.volume_slider_id); this.volume_slider_handle = Roku.Util.childClassElement(this.volume_slider, Roku.Slider.sliderHandleClassName); if(this.volume_slider) { this.volume_slider.changing_handler = function(slider) { Roku.MySB.on_sb_slider_sel_changing(slider); } this.volume_slider.changed_handler = function(slider) { Roku.MySB.on_sb_slider_sel_changed(slider); } } this.device_pane = Roku.Util.childClassElement(this.me, this.dev_pane_class_name); var playing_titles_count = this.playing_titles_id.length; for(var index = 0; index < playing_titles_count; index++) { var playing_title = Roku.Util.childIdElement(this.device_pane, this.playing_titles_id[index]); if(playing_title) this.playing_titles.push(playing_title); } this.btn_info = Roku.Util.childIdElement(this.device_pane, this.btn_info_id); Roku.Util.eventHandler(this.btn_info, "click", function(ev) {Roku.MySB.on_info_button(ev); } ) var cmd_hide_presets = Roku.Util.childIdElement(this.me, this.cmd_hide_presets_id); Roku.Util.eventHandler(cmd_hide_presets, "click", function(ev) {Roku.MySB.on_command_hide_presets(ev); } ) var cmd_show_presets = Roku.Util.childIdElement(this.me, this.cmd_show_presets_id); Roku.Util.eventHandler(cmd_show_presets, "click", function(ev) {Roku.MySB.on_command_hide_presets(ev); } ) var cmd_save_as_preset = Roku.Util.childIdElement(this.me, this.cmd_save_as_preset_id); Roku.Util.eventHandler(cmd_save_as_preset, "click", function(ev) {Roku.MySB.on_command_save_as_preset(ev); } ) var cmd_reload_presets = Roku.Util.childIdElement(this.me, this.cmd_reload_presets_id); Roku.Util.eventHandler(cmd_reload_presets, "click", function(ev) {Roku.MySB.on_command_reload_presets(ev); } ) this.tab_presets = Roku.Util.childIdElement(this.me, this.tab_presets_id); if(this.tab_presets) { this.tab_presets[Roku.Tab.selChangedEventName] = function(tab, tab_item) { Roku.MySB.on_tab_page_changed(tab, tab_item); } Roku.Tab.selectTabItem(this.tab_presets, Roku.Tab.selectedTabItem(this.tab_presets)); this.handle_presets_change(); this.update_reload_presets_visibility(); } if(widget) { widget[Roku.Widget.min_restoreEventName] = function() { Roku.MySB.on_min_restore(); } } if(widget && (!this.cur_sb_mac)) // || !this.cur_sb_ip { widget.style.display = "none"; widget.setAttribute(Roku.Widget.disabledAttribName, "true"); } } Roku.MySB.onBodyLoad = function() { Roku.MySB.Radio.set_error_handler( function(exception_value) { Roku.MySB.handle_error(exception_value); } ); if(Roku.MySB.Radio.can_play()) { this.update_presets(); } } /* Roku.MySB.Mutex */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; if(typeof(Roku.MySB) == "undefined") Roku.MySB = { }; Roku.MySB.Mutex = { list : new Object(), nextId : 1 }; Roku.MySB.Mutex.execute = function(handler, custom_data) { new MutexData(this.nextId++, handler, custom_data); } Roku.MySB.Mutex.add = function(key, data) { this.list[key] = data; } Roku.MySB.Mutex.remove = function( key ) { delete this.list[key]; } Roku.MySB.Mutex.get = function( key ) { return key==null ? null : this.list[key]; } Roku.MySB.Mutex.first = function() { return this.get(this.nextKey()); } Roku.MySB.Mutex.next = function( key ) { return this.get( this.nextKey(key) ); } Roku.MySB.Mutex.nextKey = function( key ) { for (entry in this.list) { if (!key) return entry; if (key==entry) key=null; /*tricky*/ } return null; } Roku.MySB.Mutex.SLICE = function( cmdID, startID ) { //Roku.Util.Trace("debug_out", "In SLICE: " + cmdID, true); this.get(cmdID).attempt( this.get(startID) ); } function MutexData( cmdID, handler, custom_data ) { this.attempt = function( start ) { for (var entry=start; entry; entry=Roku.MySB.Mutex.next(entry.id)) { if (entry.stamp && (entry.stamp < this.stamp || (entry.stamp == this.stamp && entry.id < this.id) ) ) return setTimeout("Roku.MySB.Mutex.SLICE("+this.id+","+entry.id+")", 5); } this.handler(this.custom_data); // Run this.stamp = 0; //release Roku.MySB.Mutex.remove( this.id ); } // constructor logic this.id = cmdID; this.handler = handler; this.custom_data = custom_data; Roku.MySB.Mutex.add( this.id, this ); // stamp is “false” this.stamp = (new Date()).getTime(); var entry = Roku.MySB.Mutex.first(); this.attempt( Roku.MySB.Mutex.first() ); } /* Roku.MySB.Radio */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; if(typeof(Roku.MySB) == "undefined") Roku.MySB = { }; Roku.MySB.Radio = { cur_sb_ip : "", entry : null, commands : new Array(), error_handler : null }; Roku.classes.push(Roku.MySB.Radio); Roku.MySB.Radio.do_sb_command_done = function() { if (Roku.MySB.Radio.check_exception()) return; if(typeof(this.entry.result_handler) == "function") { var result = document.RokuRadio.getResponse() + ""; this.entry.result_handler(result, this.entry.custom_data); } this.entry = null; Roku.MySB.Radio.next_sb_command(); // get next } function RCPDone() { Roku.MySB.Radio.do_sb_command_done(); } Roku.MySB.Radio.do_sb_command_opened = function() { var request = document.RokuRadio; if(!request) return; if (Roku.MySB.Radio.check_exception()) return; try { var command_data = ""; if (this.entry.cmd.length > 0) { request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); command_data = "command=" + request.encode(this.entry.cmd, "UTF-8"); } request.setRequestHeader("Connection", "keep-alive"); request.send(command_data, "RCPDone"); } catch(e) {} //{ Roku.Util.Trace(e); } } function RCPOpen() { Roku.MySB.Radio.do_sb_command_opened(); } Roku.MySB.Radio.next_sb_command = function() { if (!this.entry) { this.entry = this.commands.shift(); try { document.RokuRadio.open(this.entry.url, "RCPOpen"); } catch(e) {} //{ Roku.Util.Trace(e); } } } Roku.MySB.Radio.add_sb_command = function(data) { if (data.priority) this.commands.unshift(data); // Do not check high priority commands else { // Check command not already in the queue for (entry in this.commands) { if (entry.cmd == data.cmd) return false; } this.commands.push(data); } if (!this.entry) Roku.MySB.Radio.next_sb_command(); return true; } Roku.MySB.Radio.do_sb_command = function(cmd, result_handler, custom_data, priority) { if(!this.cur_sb_ip) return; if(!document.RokuRadio) return; var url = "http://" + this.cur_sb_ip + "/RCP"; //Roku.Util.Trace("debug_out", url + " -> Do Command: " + cmd, true); Roku.MySB.Mutex.execute(function(data) { Roku.MySB.Radio.add_sb_command( { url : url, cmd : cmd, result_handler : result_handler, custom_data : custom_data, priority: priority } ) }); } Roku.MySB.Radio.play_station = function(station) { var title = Roku.Station.getTitle(station); var url = Roku.Station.getUrl(station); var id = Roku.Station.getId(station); var live = Roku.Station.getLive(station); //alert("type0"); if (Roku.MySB.Radio.IsNumeric(id) == false) { //alert("type0"); /*if (id.substring(0, 3) == "Url") { //Roku.Util.Trace("debug_out", "type1 " + id, true); alert("type1"); Roku.MySB.Radio.do_sb_command("PlayStation " + url + " " + title, null, null, true); } else {*/ var pos = id.indexOf('='); var pid = id.substring(pos+1); //Roku.Util.Trace("debug_out", "type2", true); //alert("type2"); Roku.MySB.Radio.do_sb_command("PlayPreset " + pid, null, null, true); //} } else { var byId = false; if (live) { //alert(live); if (live == 'true') byId = true; } //else // alert('unknown'); if (url) { //Roku.Util.Trace("debug_out", "type3", true); //alert("type3 " + id); if (byId != false) Roku.MySB.Radio.do_sb_command("PlayStationWithID " + url + " " + id + " " + title, null, null, true); else Roku.MySB.Radio.do_sb_command("PlayStation " + url + " " + title, null, null, true); } else { if(id && Roku.Query) { //Roku.Util.Trace("debug_out", "type4", true); //alert("type4"); if (byId != false) { Roku.Query.invoke("station_url=" + id, function (response, title) { Roku.MySB.Radio.do_sb_command("PlayStationWithID " + Roku.Util.Trim(response) + " " + id + " " + title, null, null, true); }, title); } else { Roku.Query.invoke("station_url=" + id, function (response, title) { Roku.MySB.Radio.do_sb_command("PlayStation " + Roku.Util.Trim(response) + " " + title, null, null, true); }, title); } } } } } Roku.MySB.Radio.check_exception = function() { try { var exception = document.RokuRadio.getException() + ""; if (exception != "") { //Roku.Util.Trace("debug_out", "Check Error: " + exception, true); Roku.MySB.Radio.clear(); this.entry = null if(this.error_handler != null && typeof(this.error_handler) == "function") this.error_handler(exception); return true; } } catch(e) {} //{ Roku.Util.Trace(e); } return false; } Roku.MySB.Radio.can_play = function() { return this.cur_sb_ip; } Roku.MySB.Radio.clear = function() { this.commands = new Array(); } Roku.MySB.Radio.get_ip = function() { return this.cur_sb_ip; } Roku.MySB.Radio.set_ip = function(new_ip) { if(this.cur_sb_ip != new_ip) { this.cur_sb_ip = new_ip; Roku.MySB.Mutex.execute(function(data) { Roku.MySB.Radio.clear(); }); } } Roku.MySB.Radio.set_error_handler = function(new_error_handler) { this.error_handler = new_error_handler; } Roku.MySB.Radio.IsNumeric = function(sText) { var ValidChars = "0123456789"; var IsNumber = true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } /* Roku.Dialog */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Dialog = { className : "dialog", closeClassName : "close", captionClassName : "caption", closeEventName : "on_closed", modalDialog : null, disableOverlap : null, dragDialog : null, dragStartPos : null, dragStartMouse : null }; Roku.classes.push(Roku.Dialog); Roku.Dialog.on_close = function() { this.hide(); } Roku.Dialog.show = function(dialog, ev) { if(!dialog || this.modalDialog) return; var content_rect = { left : 0, top : 0, width : document.body.clientWidth, height : document.body.clientHeight }; this.disableOverlap = document.createElement("div"); this.disableOverlap.style.position = "absolute"; this.disableOverlap.style.zIndex = "99"; this.disableOverlap.style.left = "0px"; this.disableOverlap.style.top = "0px"; this.disableOverlap.style.width = (content_rect.left + content_rect.width + 20) + "px"; this.disableOverlap.style.height = (content_rect.top + content_rect.height) + "px"; this.disableOverlap.style.backgroundColor = "#ABABAB"; this.disableOverlap.style.filter = "alpha(opacity=80)"; this.disableOverlap.style.opacity = 0.8; document.body.appendChild(this.disableOverlap); dialog.style.visibility = "hidden"; dialog.style.display = "block"; var scrollX = 0, scrollY = 0; if(ev) { var element = Roku.Util.srcEventElement(ev); var elementRect = Roku.Util.elementRect(element); var parentRect = Roku.Util.elementRect(element ? element.offsetParent : null); if(ev.offsetX && ev.offsetY) { // IE if(Roku.Util.CompareNoCase(element.tagName, "span")) { scrollX = parentRect.left - (ev.clientX - ev.offsetX); scrollY = parentRect.top - (ev.clientY - ev.offsetY); } else { scrollX = elementRect.left - (ev.clientX - ev.offsetX); scrollY = elementRect.top - (ev.clientY - ev.offsetY); } } else if(ev.pageX && ev.pageY) { // Mozilla scrollX = ev.pageX - ev.clientX; scrollY = ev.pageY - ev.clientY; } } var windowWidth = Roku.Util.clientWidth(); var windowHeight = Roku.Util.clientHeight(); dialog.style.left = (scrollX + (windowWidth - dialog.offsetWidth) / 2) + "px"; dialog.style.top = (scrollY + (windowHeight - dialog.offsetHeight) / 2) + "px"; dialog.style.visibility = "visible"; dialog.focus(); this.modalDialog = dialog; } Roku.Dialog.hide = function() { if(!this.modalDialog) return; if(this.disableOverlap) { document.body.removeChild(this.disableOverlap); this.disableOverlap = null; } if(this.modalDialog) { this.modalDialog.style.display = "none"; if(typeof(this.modalDialog[this.closeEventName]) == "function") this.modalDialog[this.closeEventName](this.modalDialog); this.modalDialog = null; } } Roku.Dialog.on_mouse_down = function(ev) { var element = Roku.Util.srcEventElement(ev); var dialog = Roku.Util.parentClassElement(element, this.className); if(this.dragDialog || !dialog || !ev) return; this.dragDialog = dialog; this.dragStartPos = { X : dialog.offsetLeft, Y : dialog.offsetTop }; this.dragStartMouse = { X : ev.clientX, Y : ev.clientY }; if(dialog.setCapture) dialog.setCapture(); } Roku.Dialog.on_mouse_move = function(ev) { if(!this.dragDialog || !ev) return; this.dragDialog.style.left = (this.dragStartPos.X + ev.clientX - this.dragStartMouse.X) + "px"; this.dragDialog.style.top = (this.dragStartPos.Y + ev.clientY - this.dragStartMouse.Y) + "px"; } Roku.Dialog.need_mouse_move = function() { return this.dragDialog; } Roku.Dialog.on_mouse_up = function(ev) { if(this.dragDialog && this.dragDialog.releaseCapture) this.dragDialog.releaseCapture(); this.dragDialog = null; this.dragStartPos = null; this.dragStartMouse = null; } Roku.Dialog.need_mouse_up = function() { return this.dragDialog; } Roku.Dialog.on_key_down = function(ev) { if(ev && (ev.keyCode == 27)) //VK_ESC this.hide(); } Roku.Dialog.initialize = function() { var dialogs = Roku.Body.all ? Roku.Body.all[this.className] : Roku.Util.childrenClassElements(document.body, this.className); var dialogs_count = dialogs ? dialogs.length : 0; for(var iDialog = 0; iDialog < dialogs_count; iDialog++) { var dialog = dialogs[iDialog]; Roku.Util.eventHandler(dialog, "keydown", function(ev) { Roku.Dialog.on_key_down(ev); }) var close = Roku.Util.childClassElement(dialog, this.closeClassName); Roku.Util.eventHandler(close, "click", function(ev) { Roku.Dialog.on_close(ev); }) var caption = Roku.Util.childClassElement(dialog, this.captionClassName); Roku.Util.eventHandler(caption, "mousedown", function(ev) { Roku.Dialog.on_mouse_down(ev); }) } } /* Roku.DialogSavePreset */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.DialogSavePreset = { id : "dlgSavePreset", devicesId : "devices", tab_presets_id : "presets", presetNameId : "preset_name", presetEntryId : "preset_", presetClassName : "preset", presetTitleClassName : "name", presetRadioClassName : "radio", presetRadioName : "preset_radio", fullEntryClassName : "entry", okId : "ok", cancelId : "cancel", me : null, dialog : null, station : null, combo_devices : null, devices : null, tab_presets : null, sel_preset_data : null }; Roku.classes.push(Roku.DialogSavePreset); Roku.DialogSavePreset.can_display = function() { return (0 < this.devices.length); } Roku.DialogSavePreset.do_modal = function(station, ev) { if(Roku.MySB) this.select_device(Roku.MySB.cur_sb_mac); var sel_device = this.selected_device(); if(!sel_device) return; var name = Roku.Util.childIdElement(this.me, this.presetNameId); name.value = Roku.Station.getTitle(station); this.station = station; this.sel_preset_data = null; this.on_device_changed(); Roku.Dialog.show(this.dialog, ev); } Roku.DialogSavePreset.select_device = function(mac) { var option = Roku.Util.childIdElement(this.combo_devices, mac); if(option) option.selected = true; } Roku.DialogSavePreset.selected_device = function() { var devices_count = this.devices.length; for(var index = 0; index < devices_count; index++) { var device = this.devices[index]; if(device.selected) return device.id; } } Roku.DialogSavePreset.on_device_changed = function() { var cur_mac = this.selected_device(); var queryParam = "gather_dlg_presets=" + cur_mac; Roku.Query.invoke(queryParam, function (content) { Roku.DialogSavePreset.fill_presets(content); } ); } Roku.DialogSavePreset.fill_presets = function(content) { this.sel_preset_data = null; var sel_page_id = Roku.Tab.selected(this.tab_presets); var tab_pages_list = Roku.Util.childClassElement(this.tab_presets, Roku.Tab.tabPagesListClassName); if(tab_pages_list) { tab_pages_list.innerHTML = content; this.handle_presets_change(); } Roku.Tab.select(this.tab_presets, sel_page_id); } Roku.DialogSavePreset.on_ok = function() { if(!this.sel_preset_data) { alert("Please select a preset."); return; } var sel_device = this.selected_device(); var sel_preset_data = this.sel_preset_data; var station = this.station; Roku.Dialog.hide(); var element = sel_preset_data.element; var element_id = element ? element.id : ""; var pos = element_id.indexOf(this.presetEntryId); var preset_id = (0 <= pos) ? parseInt(element_id.substr(pos + this.presetEntryId.length, element_id.length - this.presetEntryId.length)) : 0; var station_id = Roku.Station.getId(station); var queryParam = "update_preset=" + sel_device + "&id=" + preset_id + "&station_id=" + station_id; Roku.Query.invoke(queryParam, function() { if(Roku.MySB) { Roku.MySB.update_presets(); if(Roku.MySB.Radio) Roku.MySB.Radio.do_sb_command("UpdateFromRokuRadioServer"); } } ); } Roku.DialogSavePreset.on_cancel = function() { Roku.Dialog.hide(); } Roku.DialogSavePreset.on_dialog_closed = function() { this.station = null; this.sel_preset_data = null; } Roku.DialogSavePreset.on_preset_radio_clicked = function(ev) { var element = Roku.Util.srcEventElement(ev); var preset_element = Roku.Util.parentClassElement(element, this.presetClassName); if(this.sel_preset_data) { var preset_title_entry = Roku.Util.childClassElement(this.sel_preset_data.element, this.presetTitleClassName); preset_title_entry.innerHTML = this.sel_preset_data.innerHTML; var preset_title_parent = Roku.Util.parentTagElement(preset_title_entry, "td"); preset_title_parent.className = this.sel_preset_data.className; } var preset_title_entry = Roku.Util.childClassElement(preset_element, this.presetTitleClassName); var preset_title_parent = Roku.Util.parentTagElement(preset_title_entry, "td"); if(this.station) { this.sel_preset_data = { element : preset_element, innerHTML : preset_title_entry.innerHTML, className : preset_title_parent.className }; var preset_title = Roku.Station.getTitle(this.station); preset_title_parent.className = preset_title ? this.fullEntryClassName : ""; preset_title_entry.innerHTML = preset_title ? preset_title : ""; } this.me.focus(); } Roku.DialogSavePreset.handle_presets_change = function() { var presets = Roku.Util.childrenClassElements(this.tab_presets, this.presetClassName); var presets_count = presets.length; for(var iPreset = 0; iPreset < presets_count; iPreset++) { var preset = presets[iPreset]; var preset_radio = Roku.Util.childClassElement(preset, this.presetRadioClassName); Roku.Util.eventHandler(preset_radio, "click", function(ev) { Roku.DialogSavePreset.on_preset_radio_clicked(ev); } ); } } Roku.DialogSavePreset.initialize = function() { this.me = document.getElementById(this.id); this.dialog = Roku.Util.parentClassElement(this.me, Roku.Dialog.className); if(this.dialog) this.dialog[Roku.Dialog.closeEventName] = function() { Roku.DialogSavePreset.on_dialog_closed(); }; this.combo_devices = Roku.Util.childIdElement(this.me, this.devicesId); this.devices = Roku.Util.childrenTagElements(this.combo_devices, "option"); if(1 < this.devices.length) Roku.Util.eventHandler(this.combo_devices, "change", function(ev) { Roku.DialogSavePreset.on_device_changed(ev);}); else this.combo_devices.parentNode.parentNode.style.display = "none"; this.tab_presets = Roku.Util.childIdElement(this.me, this.tab_presets_id); this.handle_presets_change(); var cancel = Roku.Util.childIdElement(this.me, this.cancelId); if(cancel) cancel[Roku.Button.buttonClickPropName] = function() { Roku.DialogSavePreset.on_cancel(); }; var ok = Roku.Util.childIdElement(this.me, this.okId); if(ok) ok[Roku.Button.buttonClickPropName] = function() { Roku.DialogSavePreset.on_ok(); }; } Roku.DialogSavePreset.onBodyLoad = function() { var tab = Roku.Util.childClassElement(this.me, Roku.Tab.tabClassName); Roku.Tab.select(tab, Roku.Tab.item(tab, 0)); } /* Roku.DialogRegistrationRequired */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.DialogRegistrationRequired = { id : "dialog_registration_required", okId : "ok", cancelId : "cancel", registrationUrlAttribName : "registration_url" }; Roku.classes.push(Roku.DialogRegistrationRequired); Roku.DialogRegistrationRequired.do_modal = function(ev) { var me = document.getElementById(this.id); var dialog = Roku.Util.parentClassElement(me, Roku.Dialog.className); var cancel = Roku.Util.childIdElement(me, this.cancelId); if(cancel) cancel[Roku.Button.buttonClickPropName] = function() { Roku.DialogRegistrationRequired.on_cancel(); }; var ok = Roku.Util.childIdElement(me, this.okId); if(ok) ok[Roku.Button.buttonClickPropName] = function() { Roku.DialogRegistrationRequired.on_ok(); }; Roku.Dialog.show(dialog, ev); } Roku.DialogRegistrationRequired.on_ok = function() { //Roku.Dialog.hide(); var me = document.getElementById(this.id); var url = me ? me.getAttribute(this.registrationUrlAttribName) : ""; if(url) window.location = url; } Roku.DialogRegistrationRequired.on_cancel = function() { Roku.Dialog.hide(); } /* Roku.Favorites */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.Favorites = { favoritesId : "wdgFavorites", favoritesContentId : "contentBarFavorites", responseContentId : "response_content", queryKeyAttribName : "query_key", favoritesIconId : "icon", titleClassName : "title", playClassName : "play", entryClassName : "entry", favorites : null, favoritesIcon : null, content : null, queryKey : "" }; Roku.classes.push(Roku.Favorites); Roku.Favorites.on_click_play = function(ev) { var element = Roku.Util.srcEventElement(ev); var entry = Roku.Util.parentClassElement(element, this.entryClassName); var station = Roku.Util.childClassElement(entry, Roku.Station.stationClassName); Roku.Util.Shared.playStation(ev, station); } Roku.Favorites.update = function() { if(this.queryKey) Roku.Query.invoke(this.queryKey + "=y", function(response) { Roku.Favorites.fill_content(response); }); } Roku.Favorites.fill_content = function(content) { if(this.content && content) { this.content.innerHTML = content; Roku.Body.doRefresh(this.content); } } Roku.Favorites.on_station_drag_enter = function(target, station) { if(!Roku.Station.getId(station)) return false; if(Roku.Util.parentIdElement(station.srcElement, this.favoritesId) == this.favorites) return { stationDropOpacity : Roku.Station.stationDragOpacity, stationDropFilter : Roku.Station.stationDragFilter }; this.set_station_drop_state(true); return true; } Roku.Favorites.on_station_drag_leave = function(target, station) { if(Roku.Util.parentIdElement(station.srcElement, this.favoritesId) != this.favorites) this.set_station_drop_state(false); } Roku.Favorites.on_station_drop = function(target, station) { if(Roku.Util.parentIdElement(station.srcElement, this.favoritesId) != this.favorites) { this.set_station_drop_state(false); if(Roku.Util && Roku.Util.Shared && Roku.Util.Shared.checkConfirmed()) { Roku.Query.invoke("station_favorite=1&id=" + Roku.Station.getId(station), function(response) { Roku.Favorites.update(); } ); } } } Roku.Favorites.set_station_drop_state = function(active) { if(this.favoritesIcon) { this.favoritesIcon.style.opacity = active ? 0.70 : 1.0; this.favoritesIcon.style.filter = active ? "alpha(opacity=70)" : ""; } } Roku.Favorites.on_favorite_station_drop = function(station, target) { //Do not remove favorites when dropped nowhere //if(!target) // Roku.Query.invoke("station_favorite=0&id=" + Roku.Station.getId(station), function(response) { Roku.Favorites.update(); } ); } Roku.Favorites.initialize = function() { this.favorites = document.getElementById(this.favoritesId); this.favoritesIcon = Roku.Util.childIdElement(this.favorites, this.favoritesIconId); this.content = Roku.Util.childIdElement(this.favorites, this.responseContentId); this.queryKey = this.content ? this.content.getAttribute(this.queryKeyAttribName) : ""; var station_drop_target = Roku.Util.childIdElement(this.favorites, this.favoritesContentId); if(station_drop_target) { station_drop_target.onstationdragenter = function(target, station) { return Roku.Favorites.on_station_drag_enter(target, station); }; station_drop_target.onstationdragleave = function(target, station) { return Roku.Favorites.on_station_drag_leave(target, station); }; station_drop_target.onstationdrop = function(target, station) { return Roku.Favorites.on_station_drop(target, station); }; Roku.Station.dropTargetClients.push(this.favorites); } this.refresh(); } Roku.Favorites.refresh = function() { var play_cmd_list = Roku.Util.childrenClassElements(this.content, this.playClassName); var play_cmd_count = play_cmd_list.length; for(var index = 0; index < play_cmd_count; index++) Roku.Util.eventHandler(play_cmd_list[index], "click", function(ev) { return Roku.Favorites.on_click_play(ev); }); var station_list = Roku.Util.childrenClassElements(this.content, Roku.Station.stationClassName); var station_count = station_list.length; for(var index = 0; index < station_count; index++) station_list[index][Roku.Station.droppedEventName] = function(station, target) { Roku.Favorites.on_favorite_station_drop(station, target); } } Roku.Favorites.refresh_content = function(root, source, reason) { if(Roku.Util.isParent(this.favorites, source)) this.update(); // do it now else window.setTimeout("Roku.Favorites.update()", 1000); }/* Roku.SearchAudioStreams */ if(typeof(Roku) == "undefined") Roku = { classes : [] }; Roku.SearchAudioStreams = { className : "search_audio_streams", contentId : "response_content", findEditId : "find", findButtonId : "cmdFind", queryKeyAttribName : "query_key", refreshIntervalAttribName : "refresh_interval", playClassName : "play", entryClassName : "entry" }; Roku.classes.push(Roku.SearchAudioStreams); Roku.SearchAudioStreams.on_click_play = function(ev) { var element = Roku.Util.srcEventElement(ev); var entry = Roku.Util.parentClassElement(element, this.entryClassName); var station = Roku.Util.childClassElement(entry, Roku.Station.stationClassName); Roku.Util.Shared.playStation(ev, station); } Roku.SearchAudioStreams.update = function(search) { var findEdit = Roku.Util.childIdElement(search, this.findEditId); if(findEdit) this.query_content(search, encodeURI(findEdit.value)); } Roku.SearchAudioStreams.query_content = function(search, findText) { var queryKey = search ? search.getAttribute(this.queryKeyAttribName) : ""; if(!queryKey) return; //Roku.Util.Trace("debug_out", queryKey + "=" + findText, true); this.kill_refresh_interval(search); Roku.Query.invoke( queryKey + "=" + encodeURI(findText), function(response, custom_data) { Roku.SearchAudioStreams.fill_content(response, custom_data); }, { search : search, findText : findText }); } Roku.SearchAudioStreams.fill_content = function(content, param) { var search = param.search; var content_element = Roku.Util.childIdElement(search, this.contentId); if(content_element && content) { content_element.innerHTML = content; Roku.Body.doRefresh(content_element); this.set_refresh_interval(search, param.findText); } } Roku.SearchAudioStreams.refresh_search_content = function(searchId, findText) { var search = document.getElementById(searchId); if(Roku.Popup && Roku.Popup.currentPopup && Roku.Util.isParent(search, Roku.Popup.currentPopup.currentElement)) return; // not now this.query_content(search, findText); } Roku.SearchAudioStreams.set_refresh_interval = function(search, findText) { this.kill_refresh_interval(search); var refreshInterval = search.getAttribute(this.refreshIntervalAttribName); var interval = refreshInterval ? parseInt(refreshInterval) : NaN; if(!isNaN(interval) && search.id) { var eval = "Roku.SearchAudioStreams.refresh_search_content('" + search.id + "', '" + findText + "');"; search.refreshIntervalId = window.setInterval(eval, interval); } } Roku.SearchAudioStreams.kill_refresh_interval = function(search) { if(search && (typeof(search.refreshIntervalId) == "number")) { window.clearInterval(search.refreshIntervalId); search.refreshIntervalId = null; } } Roku.SearchAudioStreams.on_find_key_press = function(ev) { var keyCode = 0; if(ev.keyCode) keyCode = ev.keyCode; else if(ev.which) keyCode = ev.which; if(keyCode == 13) this.on_find_button_press(ev); } Roku.SearchAudioStreams.on_find_button_press = function(ev) { var element = Roku.Util.srcEventElement(ev); var search = Roku.Util.parentClassElement(element, this.className); this.update(search); } Roku.SearchAudioStreams.initialize = function() { var searches = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.className] : Roku.Util.childrenClassElements(document.body, this.className); for(var iSearch in searches) { var search = searches[iSearch] var findEdit = Roku.Util.childIdElement(search, this.findEditId); if(findEdit) Roku.Util.eventHandler(findEdit, "keypress", function(ev) { Roku.SearchAudioStreams.on_find_key_press(ev); } ); var btnFind = Roku.Util.childIdElement(search, this.findButtonId); if(btnFind) btnFind[Roku.Button.buttonClickPropName] = function(button, ev) { Roku.SearchAudioStreams.on_find_button_press(ev); } this.refresh_content(Roku.Util.childIdElement(search, this.contentId)); this.set_refresh_interval(search, ""); } } Roku.SearchAudioStreams.refresh = function(root) { if(root) this.refresh_content(root); else { var searches = (Roku.Body && Roku.Body.all) ? Roku.Body.all[this.className] : Roku.Util.childrenClassElements(document.body, this.className); for(var iSearch in searches) refresh_content(Roku.Util.childIdElement(searches[iSearch], this.contentId)); } } Roku.SearchAudioStreams.refresh_content = function(content) { var play_cmd_list = Roku.Util.childrenClassElements(content, this.playClassName); for(var iPlayCmd in play_cmd_list) Roku.Util.eventHandler(play_cmd_list[iPlayCmd], "click", function(ev) { return Roku.SearchAudioStreams.on_click_play(ev); }); }
//
//
var cols_count = cols.length; for(var iCol = 0; iCol < cols_count; iCol++) { var col = cols[iCol]; if(col && Roku.Util.CompareNoCase(col.tagName, "td")) { var currentRow = 0; var rows = Roku.Util.childTagElement(col, "table", "tbody").childNodes; var rows_count = rows.length; for(var iRow = 0; iRow < rows_count; iRow++) { var row = rows[iRow]; if(row && Roku.Util.CompareNoCase(row.tagName, "tr")) { var widget = Roku.Util.childClassElement(row, this.widgetClassName); if(widget) { var widgetData = widget.id; widgetData += "=" + currentCol + "|" + currentRow + "|"; if(!widget.getAttribute(this.disabledAttribName) && (widget.style.display == "none")) widgetData += "c"; var widgetContent = Roku.Util.childClassElement(widget, this.widgetContentBarClassName); if(widgetContent && (widgetContent.style.display == "none")) widgetData += "m"; if(0 < placement.length) placement += ";"; placement += widgetData; } currentRow++; } } currentCol++; } } } return placement; } Roku.Widget.setCurrentWidgetsPlacement = function(placement) { // get access to content table var contentTable = Roku.Util.childClassElement(document.body, this.contentTableClassName); if(!contentTable) { return; } // collect exisiting widgets in widgetElements var current_placement = "", current_col = 0, current_row = 0; var widgetElements = []; var cols = Roku.Util.childTagElement(contentTable, "tbody", "tr").childNodes; // array of var cols_count = cols.length; for(var iCol = 0; iCol < cols_count; iCol++) { var col = cols[iCol]; if(col && Roku.Util.CompareNoCase(col.tagName, "td")) { var rows = Roku.Util.childTagElement(col, "table", "tbody").childNodes; // array of