15 if (typeof Debug ==
'undefined')
16 console.log(
'ERROR: Debug is undefined! Must include Debug.js before Desktop.js');
18 if (typeof Desktop ==
'undefined')
19 console.log(
'ERROR: Desktop is undefined! Must include Desktop.js before DesktopWindow.js');
28 Desktop.createWindow =
function(id,z,name,subname,url,w,h,x,y) {
30 if(
false === (
this instanceof Desktop.createWindow)) {
33 return new Desktop.createWindow(
id,z,name,subname,url,w,h,x,y);
43 var _defaultWindowMinWidth = 100;
44 var _defaultWindowMinHeight = 100;
46 var _defaultHeaderHeight = 30;
47 var _defaultHeaderLeftMargin = 10;
48 var _defaultHeaderFontSize = 16;
49 var _defaultButtonSize = 20;
50 var _defaultButtonLeftMargin = 2;
51 var _defaultButtonTopMargin = 1;
53 var _defaultFrameBorder = 6;
60 var _winhdr,_winfrm,_winfrmHolder;
63 var _isMaximized =
false;
64 var _isMinimized =
false;
80 var _refreshHeader =
function() {
81 var hdrW = _w-2*_defaultHeaderLeftMargin-5*(_defaultButtonSize+_defaultButtonLeftMargin)-1;
82 _winhdr.style.width = hdrW +
"px";
83 _winhdr.innerHTML = _name + (_subname==
""?
"":
" - ") + _subname;
84 while(_winhdr.scrollWidth > hdrW && _winhdr.innerHTML.length > 4)
85 _winhdr.innerHTML = _winhdr.innerHTML.substr(0,_winhdr.innerHTML.length-4)+
"...";
88 var _handleWindowContentLoading =
function() {
90 Debug.log(
"Server desktop sending first message to window: " + _id);
93 if(_winfrmHolder.childNodes.length > 1)
94 _winfrmHolder.removeChild(
95 document.getElementById(
"DesktopWindowFrameLoadingDiv-"+_id));
103 "gatewayURN": urnLid_,
104 "gatewayOrigin": serverOrigin_,
105 "cookieCode": Desktop.desktop.login.getCookieCode(),
106 "dashboardColor": Desktop.desktop.dashboard.getDefaultDashboardColor(),
107 "desktopColor": document.body.style.backgroundColor,
108 "windowFrameColor": Desktop.desktop.defaultWindowFrameColor
111 _winfrm.contentWindow.postMessage(
126 this.getWindowName =
function() {
return _name; }
127 this.getWindowSubName =
function() {
return _subname; }
128 this.getWindowUrl =
function() {
return _url; }
129 this.getWindowId =
function() {
return _id; }
130 this.getWindowX =
function() {
return _x; }
131 this.getWindowY =
function() {
return _y; }
132 this.getWindowZ =
function() {
return parseInt(this.windiv.style.zIndex);}
133 this.getWindowWidth =
function() {
return _w; }
134 this.getWindowHeight =
function() {
return _h; }
135 this.getWindowHeaderHeight =
function() {
return _defaultHeaderHeight; }
136 this.isMaximized =
function() {
return _isMaximized && !_isMinimized;}
137 this.isMinimized =
function() {
return _isMinimized;}
141 this.setWindowZ =
function(z) {
143 _z = z; this.windiv.style.zIndex = _z;
146 this.showFrame =
function() { _winfrm.style.display =
"inline"; }
147 this.hideFrame =
function() { _winfrm.style.display =
"none"; }
148 this.getFrame =
function() {
return _winfrm; }
152 this.setWindowNameAndSubName =
function(name,subname) {
153 _name = name; _subname = subname;
155 Debug.log(
"Desktop Window name=" + name +
" and subname=" + subname,Debug.LOW_PRIORITY);
160 this.setWindowSizeAndPosition =
function(x,y,w,h) {
167 _w = _isMaximized?Desktop.desktop.getDesktopContentWidth():(w < _defaultWindowMinWidth?_defaultWindowMinWidth:w);
168 _h = _isMaximized?Desktop.desktop.getDesktopContentHeight():(h < _defaultWindowMinHeight?_defaultWindowMinHeight:h);
169 _x = _isMaximized?Desktop.desktop.getDesktopContentX():x;
170 _y = _isMaximized?Desktop.desktop.getDesktopContentY():y;
173 if(_x + _w > Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth())
174 _x = Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth() - _w;
175 if(_y + _h > Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight())
176 _y = Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight() - _h;
178 this.windiv.style.width = _w +
"px";
179 this.windiv.style.height = _h+
"px";
180 this.windiv.style.left = _x+
"px";
181 this.windiv.style.top = _y+
"px";
185 _winfrm.style.width = (_w-2*_defaultFrameBorder-2)+
"px";
186 _winfrm.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+
"px";
187 _winfrmHolder.style.width = (_w-2*_defaultFrameBorder-2)+
"px";
188 _winfrmHolder.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+
"px";
194 _winfrm.style.position =
"absolute";
195 _winfrm.style.zIndex = _z + 1;
196 _winfrm.style.width = _w +
"px";
197 _winfrm.style.height = _h +
"px";
198 _winfrm.style.left =
"-1px";
199 _winfrm.style.top =
"-1px";
200 _winfrmHolder.style.position =
"absolute";
201 _winfrmHolder.style.width = (_w)+
"px";
202 _winfrmHolder.style.height = (_h)+
"px";
203 _winfrmHolder.style.left =(-_defaultFrameBorder-2) +
"px";
204 _winfrmHolder.style.top =
"-1px";
207 _w = w < _defaultWindowMinWidth?_defaultWindowMinWidth:w;
208 _h = h < _defaultWindowMinHeight?_defaultWindowMinHeight:h;
213 var hdrs = this.windiv.getElementsByClassName(
"DesktopWindowButton");
214 for(var h=0;hdrs && h<hdrs.length;++h)
215 hdrs[h].style.display =
"none";
216 hdrs =
this.windiv.getElementsByClassName(
"DesktopWindowHeader");
217 for(var h=0;hdrs && h<hdrs.length;++h)
218 hdrs[h].style.display =
"none";
221 _winfrm.style.zIndex = _z;
222 _winfrm.style.position =
"static";
223 _winfrmHolder.style.position =
"static";
226 var hdrs = this.windiv.getElementsByClassName(
"DesktopWindowButton");
227 for(var h=0;hdrs && h<hdrs.length;++h)
228 hdrs[h].style.display =
"block";
229 hdrs =
this.windiv.getElementsByClassName(
"DesktopWindowHeader");
230 for(var h=0;hdrs && h<hdrs.length;++h)
231 hdrs[h].style.display =
"block";
234 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
238 this.moveWindowByOffset =
function(dx,dy) {
242 if(_y < Desktop.desktop.getDesktopContentY()) _y = Desktop.desktop.getDesktopContentY();
243 this.windiv.style.left = _x+
"px";
244 this.windiv.style.top = _y+
"px";
250 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
255 this.resizeAndPositionWindow =
function(x,y,w,h) {
256 if((w <= _defaultWindowMinWidth && x > _x) ||
257 (h <= _defaultWindowMinHeight && y > _y))
return;
258 if(x < Desktop.desktop.getDesktopContentX()) x = Desktop.desktop.getDesktopContentX();
259 if(y < Desktop.desktop.getDesktopContentY()) y = Desktop.desktop.getDesktopContentY();
260 this.setWindowSizeAndPosition(x,y,w,h);
265 this.maximize =
function() {
267 if(_isMinimized) this.unminimize();
270 this.windiv.style.display =
"inline";
271 this.setWindowSizeAndPosition(_x+10,_y,_w,_h);
272 window.parent.document.title= _name;
273 console.log(document.title, _name,
"Maximize()");
277 this.unmaximize =
function() {
279 _isMaximized =
false;
281 this.windiv.style.display =
"inline";
282 this.setWindowSizeAndPosition(_x,_y,_w,_h);
283 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
288 this.minimize =
function() {
291 window.parent.document.title = _name;
293 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
296 this.windiv.style.display =
"none";
297 Debug.log(
"-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
300 this.unminimize =
function() {
303 window.parent.document.title = _name;
305 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
307 _isMinimized =
false;
308 this.windiv.style.display =
"inline";
309 Debug.log(
"-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
317 this.windiv = document.createElement(
"div");
318 this.windiv.setAttribute(
"class",
"DesktopWindow");
319 this.windiv.setAttribute(
"id",
"DesktopWindow-" + _id);
320 this.windiv.style.backgroundColor = Desktop.desktop.defaultWindowFrameColor;
321 this.windiv.style.position =
"absolute";
322 this.windiv.style.zIndex = _z;
325 _winhdr = document.createElement(
"div");
326 _winhdr.setAttribute(
"class",
"DesktopWindowHeader");
327 _winhdr.setAttribute(
"id",
"DesktopWindowHeader-" + _id);
328 _winhdr.style.height = _defaultHeaderHeight+
"px";
329 _winhdr.style.marginLeft = _defaultHeaderLeftMargin+
"px";
330 _winhdr.style.marginRight = (-100)+
"px";
331 _winhdr.style.fontSize = _defaultHeaderFontSize+
"px";
332 this.setWindowNameAndSubName(name, subname);
333 this.windiv.appendChild(_winhdr);
338 var tmpContainer = document.createElement(
"div");
339 tmpContainer.setAttribute(
"style",
"float:right;white-space:nowrap;height:" + _defaultHeaderHeight +
"px;overflow:auto;");
340 var tmpBtn = document.createElement(
"div");
341 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
342 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonRefresh-" + _id);
343 tmpBtn.style.width = (_defaultButtonSize) +
"px";
344 tmpBtn.style.height = (_defaultButtonSize) +
"px";
345 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
346 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
347 tmpBtn.onmouseup = Desktop.handleWindowRefresh;
348 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
349 var tmpEl = document.createElement(
"div");
350 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicRefresh");
351 if(Debug.BROWSER_TYPE == Debug.BROWSER_TYPE_FIREFOX)
355 "<div style='font-size:28px; margin: -4px 0 0 -1px; color:inherit;' "+
356 "title='Click to refresh onl this window'>↻</div>";
363 "<div style='font-size:16px; margin-left:1px; font-weight: 400; color:inherit;' "+
364 "title='Click to refresh onl this window'>↻</div>";
370 tmpBtn.appendChild(tmpEl);
371 tmpContainer.appendChild(tmpBtn);
374 var tmpBtn = document.createElement(
"div");
375 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
376 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonHelp-" + _id);
377 tmpBtn.style.width = (_defaultButtonSize) +
"px";
378 tmpBtn.style.height = (_defaultButtonSize) +
"px";
379 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
380 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
381 tmpBtn.onmouseup = Desktop.handleWindowHelp;
382 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
383 var tmpEl = document.createElement(
"div");
384 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicHelp");
385 tmpEl.innerHTML =
"?";
386 tmpBtn.appendChild(tmpEl);
387 tmpContainer.appendChild(tmpBtn);
390 var tmpBtn = document.createElement(
"div");
391 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
392 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonMin-" + _id);
393 tmpBtn.style.width = (_defaultButtonSize) +
"px";
394 tmpBtn.style.height = (_defaultButtonSize) +
"px";
395 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
396 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
397 tmpBtn.onmouseup = Desktop.handleWindowMinimize;
398 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
399 var tmpEl = document.createElement(
"div");
400 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicMin");
401 tmpBtn.appendChild(tmpEl);
402 tmpContainer.appendChild(tmpBtn);
404 tmpBtn = document.createElement(
"div");
405 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
406 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonMax-" + _id);
407 tmpBtn.style.width = (_defaultButtonSize) +
"px";
408 tmpBtn.style.height = (_defaultButtonSize) +
"px";
409 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
410 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
411 tmpBtn.onmouseup = Desktop.handleWindowMaximize;
412 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
413 var tmpEl = document.createElement(
"div");
414 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicMax");
415 tmpBtn.appendChild(tmpEl);
416 tmpContainer.appendChild(tmpBtn);
418 tmpBtn = document.createElement(
"div");
419 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
420 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonClose-" + _id);
421 tmpBtn.style.width = (_defaultButtonSize) +
"px";
422 tmpBtn.style.height = (_defaultButtonSize) +
"px";
423 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
424 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
425 tmpBtn.onmouseup = Desktop.handleWindowClose;
426 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
427 var tmpEl = document.createElement(
"div");
428 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicClose");
429 tmpEl.innerHTML =
"x";
430 tmpBtn.appendChild(tmpEl);
431 tmpContainer.appendChild(tmpBtn);
434 this.windiv.appendChild(tmpContainer);
437 _winfrmHolder = document.createElement(
"div");
438 _winfrmHolder.setAttribute(
"class",
"DesktopWindowFrameHolder");
439 _winfrmHolder.setAttribute(
"id",
"DesktopWindowFrameHolder-" + _id);
440 _winfrmHolder.style.marginLeft = _defaultFrameBorder+
"px";
441 _winfrmHolder.innerHTML =
442 "<div class='DesktopWindowHeader' id='DesktopWindowFrameLoadingDiv-"+
443 _id +
"' style='width:100px;height:50px;position:relative;top:50%;left:50%;margin-top:-25px;margin-left:-50px;text-align:center;margin-bottom:-50px;'>" +
444 "Loading..." +
"</div>";
447 _winfrm = document.createElement(
"iframe");
448 _winfrm.setAttribute(
"class",
"DesktopWindowFrame");
449 _winfrm.setAttribute(
"id",
"DesktopWindowFrame-" + _id);
450 _winfrm.setAttribute(
"name",
"DesktopWindowFrame-" + _id);
451 _winfrm.setAttribute(
"allow",
"autoplay");
452 _winfrm.onload = _handleWindowContentLoading;
453 _winfrm.setAttribute(
"src", _url);
454 _winfrmHolder.appendChild(_winfrm);
455 this.windiv.appendChild(_winfrmHolder);
457 this.setWindowSizeAndPosition(x,y,w,h);
460 this.windiv.onmousedown = Desktop.handleWindowMouseDown;
461 this.windiv.onmouseup = Desktop.handleWindowMouseUp;
462 this.windiv.onmousemove = Desktop.handleWindowMouseMove;
463 this.windiv.ondblclick = Desktop.handleWindowMaximize;
466 this.windiv.addEventListener(
'touchstart',Desktop.handleTouchStart);
467 this.windiv.addEventListener(
'touchend',Desktop.handleTouchEnd);
468 this.windiv.addEventListener(
'touchmove',Desktop.handleTouchMove);
471 Debug.log(
"Desktop Window Created",Debug.LOW_PRIORITY);