Skip to content
Snippets Groups Projects
lws-common.js 3.23 KiB
Newer Older
  • Learn to ignore specific revisions
  • Andy Green's avatar
    Andy Green committed
    /*
     * 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);
     *
     */
    
    
    Andy Green's avatar
    Andy Green committed
    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;
    }
    
    Andy Green's avatar
    Andy Green committed
    
    
    Andy Green's avatar
    Andy Green committed
    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 || {};
    
    Andy Green's avatar
    Andy Green committed
    	var zindex = options.zindex || 50;
    	var opacity = options.opacity || 70;
    	var opaque = (opacity / 100);
    
    Andy Green's avatar
    Andy Green committed
    	var bgcolor = options.bgcolor || "#000000";
    	var dark = document.getElementById("darkenScreenObject");
    
    Andy Green's avatar
    Andy Green committed
    
    	if (!dark) {
    		var tbody = document.getElementsByTagName("body")[0];
    
    Andy Green's avatar
    Andy Green committed
    		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";
    
    Andy Green's avatar
    Andy Green committed
    		tbody.appendChild(tnode);
    
    Andy Green's avatar
    Andy Green committed
    		dark = document.getElementById("darkenScreenObject");
    
    Andy Green's avatar
    Andy Green committed
    	}
    	if (vis) {
    		dark.style.opacity = opaque;
    		dark.style.MozOpacity = opaque;
    
    Andy Green's avatar
    Andy Green committed
    		// dark.style.filter ='alpha(opacity='+opacity+')';
    
    Andy Green's avatar
    Andy Green committed
    		dark.style.zIndex = zindex;
    		dark.style.backgroundColor = bgcolor;
    		dark.style.width = gsize(1);
    		dark.style.height = gsize(0);
    
    Andy Green's avatar
    Andy Green committed
    		dark.style.display = "block";
    
    Andy Green's avatar
    Andy Green committed
    		addEvent(window, "resize",
    			function() {
    				dark.style.height = gsize(0);
    				dark.style.width = gsize(1);
    			}
    		);
    	} else {
    
    Andy Green's avatar
    Andy Green committed
    		dark.style.display = "none";
    
    Andy Green's avatar
    Andy Green committed
    		removeEvent(window, "resize",
    			function() {
    				dark.style.height = gsize(0);
    				dark.style.width = gsize(1);
    			}
    		);
    	}
    }
    
    /*
     * end of grayOut related stuff
     */
    
    Andy Green's avatar
    Andy Green committed
    
    function new_ws(urlpath, protocol)
    {
    	if (typeof MozWebSocket != "undefined")
    		return new MozWebSocket(urlpath, protocol);
    
    	return new WebSocket(urlpath, protocol);
    }
    
    Andy Green's avatar
    Andy Green committed
     
    function lws_san(s)
    {
    
    Andy Green's avatar
    Andy Green committed
    	if (s.search("<") !== -1)
    
    Andy Green's avatar
    Andy Green committed
    		return "invalid string";
    	
    	return s;
    }