2 * This section around grayOut came from here:
3 * http://www.codingforums.com/archive/index.php/t-151720.html
4 * Assumed public domain
6 * Init like this in your main html script, this also reapplies the gray
8 * lws_gray_out(true,{'zindex':'499'});
12 * lws_gray_out(false);
16 function lws_gray_out(vis, options) {
17 var options = options || {};
18 var zindex = options.zindex || 50;
19 var opacity = options.opacity || 70;
20 var opaque = (opacity / 100);
21 var bgcolor = options.bgcolor || '#000000';
22 var dark = document.getElementById('darkenScreenObject');
25 var tbody = document.getElementsByTagName("body")[0];
26 var tnode = document.createElement('div');
27 tnode.style.position = 'absolute';
28 tnode.style.top = '0px';
29 tnode.style.left = '0px';
30 tnode.style.overflow = 'hidden';
31 tnode.style.display ='none';
32 tnode.id = 'darkenScreenObject';
33 tbody.appendChild(tnode);
34 dark = document.getElementById('darkenScreenObject');
37 dark.style.opacity = opaque;
38 dark.style.MozOpacity = opaque;
39 dark.style.filter ='alpha(opacity='+opacity+')';
40 dark.style.zIndex = zindex;
41 dark.style.backgroundColor = bgcolor;
42 dark.style.width = gsize(1);
43 dark.style.height = gsize(0);
44 dark.style.display ='block';
45 addEvent(window, "resize",
47 dark.style.height = gsize(0);
48 dark.style.width = gsize(1);
52 dark.style.display = 'none';
53 removeEvent(window, "resize",
55 dark.style.height = gsize(0);
56 dark.style.width = gsize(1);
64 var h = document.compatMode == 'CSS1Compat' &&
66 document.documentElement.clientHeight :
67 document.body.clientHeight;
68 var w = document.compatMode == 'CSS1Compat' &&
70 document.documentElement.clientWidth :
71 document.body.clientWidth;
73 (document.body.scrollWidth || document.body.scrollHeight)) {
74 var pageWidth = (w > (t = document.body.scrollWidth)) ?
75 ("" + w + "px") : ("" + (t) + "px");
76 var pageHeight = (h > (t = document.body.scrollHeight)) ?
77 ("" + h + "px") : ("" + (t) + "px");
78 } else if (document.body.offsetWidth) {
79 var pageWidth = (w > (t = document.body.offsetWidth)) ?
80 ("" + w + "px") : ("" + (t) + "px");
81 var pageHeight =(h > (t = document.body.offsetHeight)) ?
82 ("" + h + "px") : ("" + (t) + "px");
84 var pageWidth = '100%';
85 var pageHeight = '100%';
87 return (ptype == 1) ? pageWidth : pageHeight;
90 function addEvent( obj, type, fn ) {
91 if ( obj.attachEvent ) {
92 obj['e' + type + fn] = fn;
93 obj[type+fn] = function() { obj['e' + type+fn]( window.event );}
94 obj.attachEvent('on' + type, obj[type + fn]);
96 obj.addEventListener(type, fn, false);
99 function removeEvent( obj, type, fn ) {
100 if ( obj.detachEvent ) {
101 obj.detachEvent('on' + type, obj[type + fn]);
102 obj[type + fn] = null;
104 obj.removeEventListener(type, fn, false);
108 * end of grayOut related stuff
116 OPEN_SUBCHANNEL: 0x41,
117 /**< Client requests to open new subchannel
120 /**< Result of client request to open new subchannel */
123 /**< client requests to close a subchannel */
125 /**< connection writes something to specific channel index */
129 function new_ws(urlpath, protocol)
131 if (typeof MozWebSocket != "undefined")
132 return new MozWebSocket(urlpath, protocol);
134 return new WebSocket(urlpath, protocol);
137 function lws_meta_ws() {
140 var channel_id_to_child;
141 var pending_children;
145 function lws_meta_ws_child() {
161 lws_meta_ws_child.prototype.send = function(data)
164 if (typeof data == "string") {
165 data = String.fromCharCode(lws_meta_cmd.WRITE) +
166 String.fromCharCode(this.channel_id) +
169 return this.parent.real.send(data);
174 var ab = new Uint8Array(data.length + 2);
176 ab[0] = lws_meta_cmd.WRITE;
177 ab[1] = this.channel_id;
180 return this.parent.real.send(ab);
184 lws_meta_ws_child.prototype.close = function(close_code, close_string)
186 var pkt = new Uint8Array(129), m = 0, pkt1;
188 pkt[m++] = lws_meta_cmd.CLOSE_RQ;
189 pkt[m++] = this.channel_id;
191 pkt[m++] = close_string.length + 0x20;
193 pkt[m++] = close_code / 256;
194 pkt[m++] = close_code % 256;
196 for (i = 0; i < close_string.length; i++)
197 pkt[m++] = close_string.charCodeAt(i);
199 pkt1 = new Uint8Array(m);
200 for (n = 0; n < m; n++)
203 this.parent.real.send(pkt1.buffer);
206 /* make a real ws connection using lws_meta*/
207 lws_meta_ws.prototype.new_parent = function(urlpath)
209 var n, i, m = 0, pkt1;
212 this.pending_children = [];
213 this.active_children = [];
214 this.real = new_ws(urlpath, "lws-meta");
216 this.real.binaryType = 'arraybuffer';
217 this.real.myparent = this;
219 this.real.onopen = function() {
220 pkt = new Uint8Array(1024);
221 var n, i, m = 0, pkt1;
222 console.log("real open - pending children " + this.myparent.pending_children.length);
223 for (n = 0; n < this.myparent.pending_children.length; n++) {
225 var p = this.myparent.pending_children[n];
227 pkt[m++] = lws_meta_cmd.OPEN_SUBCHANNEL;
228 for (i = 0; i < p.subprotocol.length; i++)
229 pkt[m++] = p.subprotocol.charCodeAt(i);
231 for (i = 0; i < p.suburl.length; i++)
232 pkt[m++] = p.suburl.charCodeAt(i);
234 for (i = 0; i < p.cookie.length; i++)
235 pkt[m++] = p.cookie.charCodeAt(i);
239 pkt1 = new Uint8Array(m);
240 for (n = 0; n < m; n++)
243 console.log(this.myparent.pending_children[0].subprotocol);
246 this.send(pkt1.buffer);
250 this.real.onmessage = function(msg) {
252 if (typeof msg.data != "string") {
253 var ba = new Uint8Array(msg.data), n = 0;
255 while (n < ba.length) {
258 case lws_meta_cmd.OPEN_RESULT:
260 var m = 0, cookie = "", protocol = "", ch = 0;
261 var ws = this.myparent;
263 * channel index + 0x20
267 cookie = cookie + String.fromCharCode(ba[n++]);
272 protocol = protocol + String.fromCharCode(ba[n++]);
274 console.log("open result " + cookie + " " + protocol + " " + ch + " pending len " + ws.pending_children.length);
276 for (m = 0; m < ws.pending_children.length; m++) {
277 if (ws.pending_children[m].cookie == cookie) {
278 var newchild = ws.pending_children[m];
281 ws.pending_children[m].channel_id = ch;
282 /* add to active children array */
283 ws.active_children.push(ws.pending_children[m]);
284 /* remove from pending children array */
285 ws.pending_children.splice(m, 1);
287 newchild.parent = ws;
288 newchild.extensions = this.extensions;
292 console.log("made active " + cookie);
299 case lws_meta_cmd.CLOSE_NOT:
301 var code = 0, str = "", ch = 0, m, le;
302 var ba = new Uint8Array(msg.data);
305 * BYTE: MSB status code
306 * BYTE: LSB status code
307 * BYTES: rest of message is close status string
312 code = ba[n++] * 256;
316 str += String.fromCharCode(ba[n++]);
318 console.log("channel id " + ch + " code " + code + " str " + str + " len " + str.length);
320 for (m = 0; m < this.myparent.active_children.length; m++)
321 if (this.myparent.active_children[m].channel_id == ch) {
322 var child = this.myparent.active_children[m];
323 var ms = new CloseEvent("close", { code:code, reason:str } );
325 /* reply with close ack */
331 this.myparent.active_children.splice(m, 1);
339 if (msg.data.charCodeAt(0) == lws_meta_cmd.WRITE ) {
340 var ch = msg.data.charCodeAt(1), m, ms;
341 var ws = this.myparent, ms;
343 for (m = 0; m < ws.active_children.length; m++) {
344 if (ws.active_children[m].channel_id == ch) {
345 ms = new MessageEvent("WebSocket", { data: msg.data.substr(2, msg.data.length - 2) } );
346 if (ws.active_children[m].onmessage)
347 ws.active_children[m].onmessage(ms);
354 this.real.onclose = function() {
355 var ws = this.myparent, m;
356 for (m = 0; m < ws.active_children.length; m++) {
357 var child = ws.active_children[m];
358 var ms = new CloseEvent("close", { code:1000, reason:"parent closed" } );
369 /* make a child connection using existing lws_meta real ws connection */
370 lws_meta_ws.prototype.new_ws = function(suburl, protocol)
372 var ch = new lws_meta_ws_child();
375 ch.subprotocol = protocol;
376 ch.cookie = "C" + this.ordinal++;
378 this.pending_children.push(ch);
380 if (this.real.readyState == 1)
388 * end of lws-meta helpers
393 if (s.search("<") != -1)
394 return "invalid string";