]>
git.proxmox.com Git - mirror_novnc.git/blob - include/webutil.js
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2010 Joel Martin
4 * Licensed under LGPL-3 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
10 /*jslint bitwise: false, white: false */
11 /*global window, document */
13 // Globals defined here
17 * Simple DOM selector by ID
21 if (document
.getElementById
) {
22 return document
.getElementById(id
);
23 } else if (document
.all
) {
24 return document
.all
[id
];
25 } else if (document
.layers
) {
26 return document
.layers
[id
];
34 * ------------------------------------------------------
35 * Namespaced in WebUtil
36 * ------------------------------------------------------
39 // init log level reading the logging HTTP param
40 WebUtil
.init_logging = function() {
41 Util
._log_level
= (document
.location
.href
.match(
42 /logging=([A-Za-z0-9\._\-]*)/) ||
43 ['', Util
._log_level
])[1];
47 WebUtil
.init_logging();
50 WebUtil
.dirObj = function (obj
, depth
, parent
) {
51 var i
, msg
= "", val
= "";
52 if (! depth
) { depth
=2; }
53 if (! parent
) { parent
= ""; }
55 // Print the properties of the passed-in object
57 if ((depth
> 1) && (typeof obj
[i
] === "object")) {
58 // Recurse attributes that are objects
59 msg
+= WebUtil
.dirObj(obj
[i
], depth
-1, parent
+ "." + i
);
61 //val = new String(obj[i]).replace("\n", " ");
62 val
= obj
[i
].toString().replace("\n", " ");
63 if (val
.length
> 30) {
64 val
= val
.substr(0,30) + "...";
66 msg
+= parent
+ "." + i
+ ": " + val
+ "\n";
72 // Read a query string variable
73 WebUtil
.getQueryVar = function(name
, defVal
) {
74 var re
= new RegExp('[?][^#]*' + name
+ '=([^&#]*)');
75 if (typeof defVal
=== 'undefined') { defVal
= null; }
76 return (document
.location
.href
.match(re
) || ['',defVal
])[1];
81 * Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
84 // No days means only for this browser session
85 WebUtil
.createCookie = function(name
,value
,days
) {
89 date
.setTime(date
.getTime()+(days
*24*60*60*1000));
90 expires
= "; expires="+date
.toGMTString();
95 document
.cookie
= name
+"="+value
+expires
+"; path=/";
98 WebUtil
.readCookie = function(name
, defaultValue
) {
99 var i
, c
, nameEQ
= name
+ "=", ca
= document
.cookie
.split(';');
100 for(i
=0; i
< ca
.length
; i
+= 1) {
102 while (c
.charAt(0) === ' ') { c
= c
.substring(1,c
.length
); }
103 if (c
.indexOf(nameEQ
) === 0) { return c
.substring(nameEQ
.length
,c
.length
); }
105 return (typeof defaultValue
!== 'undefined') ? defaultValue
: null;
108 WebUtil
.eraseCookie = function(name
) {
109 WebUtil
.createCookie(name
,"",-1);
113 * Alternate stylesheet selection
115 WebUtil
.getStylesheets = function() { var i
, links
, sheets
= [];
116 links
= document
.getElementsByTagName("link");
117 for (i
= 0; i
< links
.length
; i
+= 1) {
118 if (links
[i
].title
&&
119 links
[i
].rel
.toUpperCase().indexOf("STYLESHEET") > -1) {
120 sheets
.push(links
[i
]);
126 // No sheet means try and use value from cookie, null sheet used to
127 // clear all alternates.
128 WebUtil
.selectStylesheet = function(sheet
) {
129 var i
, link
, sheets
= WebUtil
.getStylesheets();
130 if (typeof sheet
=== 'undefined') {
133 for (i
=0; i
< sheets
.length
; i
+= 1) {
135 if (link
.title
=== sheet
) {
136 Util
.Debug("Using stylesheet " + sheet
);
137 link
.disabled
= false;
139 //Util.Debug("Skipping stylesheet " + link.title);
140 link
.disabled
= true;