File: lws-common.js

package info (click to toggle)
libwebsockets 4.0.20-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 22,960 kB
  • sloc: ansic: 122,378; javascript: 3,099; sh: 1,571; java: 461; perl: 405; cpp: 217; xml: 118; makefile: 79; awk: 5
file content (125 lines) | stat: -rw-r--r-- 3,221 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * This section around grayOut came from here:
 * http://www.codingforums.com/archive/index.php/t-151720.html
 * Assumed public domain
 *
 * Init like this in your main html script, this also reapplies the gray
 *
 *    lws_gray_out(true,{'zindex':'499'});
 *
 * To remove the gray
 *
 *    lws_gray_out(false);
 *
 */

function gsize(ptype)
{
	var h = document.compatMode === "CSS1Compat" &&
		!window.opera ?
			document.documentElement.clientHeight :
						document.body.clientHeight;
	var w = document.compatMode === "CSS1Compat" &&
		!window.opera ? 
			document.documentElement.clientWidth :
						document.body.clientWidth;
	var pageWidth, pageHeight, t;

	if (document.body && 
		    (document.body.scrollWidth || document.body.scrollHeight)) {
		t = document.body.scrollWidth;
		pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
		t = document.body.scrollHeight;
		pageHeight = (h > t) ? ("" + h + "px") : ("" + (t) + "px");
	} else if (document.body.offsetWidth) {
		t = document.body.offsetWidth;
		pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
		t = document.body.offsetHeight;
		pageHeight =(h > t) ? ("" + h + "px") : ("" + (t) + "px");
	} else {
		pageWidth = "100%";
		pageHeight = "100%";
	}
	return (ptype === 1) ? pageWidth : pageHeight;
}

function addEvent( obj, type, fn ) {
	if ( obj.attachEvent ) {
		obj["e" + type + fn] = fn;
		obj[type+fn] = function() { obj["e" + type + fn]( window.event );};
		obj.attachEvent("on" + type, obj[type + fn]);
	} else
		obj.addEventListener(type, fn, false);
}

function removeEvent( obj, type, fn ) {
	if ( obj.detachEvent ) {
		obj.detachEvent("on" + type, obj[type + fn]);
		obj[type + fn] = null;
	} else
		obj.removeEventListener(type, fn, false);
}

function lws_gray_out(vis, _options) {

	var options = _options || {};
	var zindex = options.zindex || 50;
	var opacity = options.opacity || 70;
	var opaque = (opacity / 100);
	var bgcolor = options.bgcolor || "#000000";
	var dark = document.getElementById("darkenScreenObject");

	if (!dark) {
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement("div");
		tnode.style.position = "absolute";
		tnode.style.top = "0px";
		tnode.style.left = "0px";
		tnode.style.overflow = "hidden";
		tnode.style.display ="none";
		tnode.id = "darkenScreenObject";
		tbody.appendChild(tnode);
		dark = document.getElementById("darkenScreenObject");
	}
	if (vis) {
		dark.style.opacity = opaque;
		dark.style.MozOpacity = opaque;
		// dark.style.filter ='alpha(opacity='+opacity+')';
		dark.style.zIndex = zindex;
		dark.style.backgroundColor = bgcolor;
		dark.style.width = gsize(1);
		dark.style.height = gsize(0);
		dark.style.display = "block";
		addEvent(window, "resize",
			function() {
				dark.style.height = gsize(0);
				dark.style.width = gsize(1);
			}
		);
	} else {
		dark.style.display = "none";
		removeEvent(window, "resize",
			function() {
				dark.style.height = gsize(0);
				dark.style.width = gsize(1);
			}
		);
	}
}

/*
 * end of grayOut related stuff
 */

function new_ws(urlpath, protocol)
{
	return new WebSocket(urlpath, protocol);
}
 
function lws_san(s)
{
	if (s.search("<") !== -1)
		return "invalid string";
	
	return s;
}