function lwsgt_get_appropriate_ws_url() { var pcol; var u = document.URL; if (u.substring(0, 5) === "https") { pcol = "wss://"; u = u.substr(8); } else { pcol = "ws://"; if (u.substring(0, 4) === "http") u = u.substr(7); } return pcol + u; } function lwsgt_app_hdr(j, bc, ws) { var s = "", n, m = 0; ws.bcq = 0; for (n = 0; n < j.cols.length; n++) if (!j.cols[n].hide) m++; s = "" + ws.lwsgt_title + ""; if (!!bc) { s += ""; for (n = 0; n < bc.length; n++) { s += " / "; if (!bc[n].url && bc[n].url !== "") s += " " + lws_san(bc[n].name) + " "; else { s += "" + lws_san(bc[n].name) + " "; ws.bcq++; } } s += ""; } s += ""; for (n = 0; n < j.cols.length; n++) if (!j.cols[n].hide) s = s + "" + lws_san(j.cols[n].name) + ""; s += ""; return s; } function lwsgt_click_callthru() { window[this.getAttribute("h")](this.getAttribute("p"), this.getAttribute("aa"), this.getAttribute("m"), this.getAttribute("n")); event.preventDefault(); } function lwsgt_initial(title, pcol, divname, cb, gname) { this.divname = divname; lws_gray_out(true,{"zindex":"499"}); this.lwsgt_ws = new WebSocket(lwsgt_get_appropriate_ws_url(), pcol); this.lwsgt_ws.divname = divname; this.lwsgt_ws.lwsgt_cb = cb; this.lwsgt_ws.lwsgt_parent = gname; this.lwsgt_ws.lwsgt_title = title; try { this.lwsgt_ws.onopen = function() { lws_gray_out(false); // document.getElementById("debug").textContent = // "ws opened " + lwsgt_get_appropriate_ws_url(); }; this.lwsgt_ws.onmessage = function got_packet(msg) { var s, m, n, j = JSON.parse(msg.data); document.getElementById("debug").textContent = msg.data; if (j.cols) { this.hdr = j; } if (j.breadcrumbs) this.breadcrumbs = j.breadcrumbs; if (j.data) { var q = 0; s = "" + lwsgt_app_hdr(this.hdr, this.breadcrumbs, this); for (m = 0; m < j.data.length; m++) { s = s + ""; for (n = 0; n < this.hdr.cols.length; n++) { if (!this.hdr.cols[n].hide) { if (!this.hdr.cols[n].align) s = s + ""; } } s = s + ""; } s = s + "
"; else s = s + ""; if (this.hdr.cols[n].href && !!j.data[m][this.hdr.cols[n].href]) { s = s + "" + lws_san(j.data[m][this.hdr.cols[n].name]) + ""; q++; } else s = s + lws_san(j.data[m][this.hdr.cols[n].name]); s = s + "
"; document.getElementById(this.divname).innerHTML = s; for (n = 0; n < q; n++) document.getElementById(this.divname + n).onclick = lwsgt_click_callthru; for (n = 0; n < this.bcq; n++) document.getElementById("bc_" + this.divname + n).onclick = lwsgt_click_callthru; } }; this.lwsgt_ws.onclose = function(){ lws_gray_out(true,{"zindex":"499"}); }; } catch(exception) { alert("

Error" + exception); } }