]>
git.proxmox.com Git - pve-xtermjs.git/blob - xterm.js/src/util.js
1 function urlEncode(object
) {
2 var i
,value
, params
= [];
5 if (object
.hasOwnProperty(i
)) {
7 if (value
=== undefined) value
= '';
8 params
.push(encodeURIComponent(i
) + '=' + encodeURIComponent(String(value
)));
12 return params
.join('&');
22 function showMsg(message
, timeout
, severity
) {
23 var status_bar
= document
.getElementById('status_bar');
24 clearTimeout(msgtimeout
);
26 status_bar
.classList
.remove('normal');
27 status_bar
.classList
.remove('warning');
28 status_bar
.classList
.remove('error');
30 status_bar
.textContent
= message
;
32 severity
= severity
|| severities
.normal
;
35 case severities
.normal
:
36 status_bar
.classList
.add('normal');
38 case severities
.warning
:
39 status_bar
.classList
.add('warning');
41 case severities
.error
:
42 status_bar
.classList
.add('error');
45 throw "unknown severity";
48 status_bar
.classList
.add('open');
51 msgtimeout
= setTimeout(hideMsg
, timeout
|| 1500);
56 clearTimeout(msgtimeout
);
57 status_bar
.classList
.remove('open');
60 function getQueryParameter(name
) {
61 var params
= location
.search
.slice(1).split('&');
63 params
.forEach(function(param
) {
64 var components
= param
.split('=');
65 if (components
[0] === name
) {
66 result
= components
.slice(1).join('=');
72 function API2Request(reqOpts
) {
75 reqOpts
.method
= reqOpts
.method
|| 'GET';
77 var xhr
= new XMLHttpRequest();
79 xhr
.onload = function() {
80 var scope
= reqOpts
.scope
|| this;
84 if (xhr
.readyState
=== 4) {
85 var ctype
= xhr
.getResponseHeader('Content-Type');
86 if (xhr
.status
=== 200) {
87 if (ctype
.match(/application\/json;/)) {
88 result
= JSON
.parse(xhr
.responseText
);
90 errmsg
= 'got unexpected content type ' + ctype
;
93 errmsg
= 'Error ' + xhr
.status
+ ': ' + xhr
.statusText
;
96 errmsg
= 'Connection error - server offline?';
99 if (errmsg
!== undefined) {
100 if (reqOpts
.failure
) {
101 reqOpts
.failure
.call(scope
, errmsg
);
104 if (reqOpts
.success
) {
105 reqOpts
.success
.call(scope
, result
);
108 if (reqOpts
.callback
) {
109 reqOpts
.callback
.call(scope
, errmsg
=== undefined);
113 var data
= urlEncode(reqOpts
.params
|| {});
115 if (reqOpts
.method
=== 'GET') {
116 xhr
.open(reqOpts
.method
, "/api2/json" + reqOpts
.url
+ '?' + data
);
118 xhr
.open(reqOpts
.method
, "/api2/json" + reqOpts
.url
);
120 xhr
.setRequestHeader('Cache-Control', 'no-cache');
121 if (reqOpts
.method
=== 'POST' || reqOpts
.method
=== 'PUT') {
122 xhr
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
123 xhr
.setRequestHeader('CSRFPreventionToken', PVE
.CSRFPreventionToken
);
125 } else if (reqOpts
.method
=== 'GET') {
128 throw "unknown method";
132 function getTerminalSettings() {
134 var settings
= ['fontSize', 'fontFamily', 'letterSpacing', 'lineHeight'];
136 settings
.forEach(function(setting
) {
137 var val
= localStorage
.getItem('pve-xterm-' + setting
);
138 if (val
!== undefined && val
!== null) {