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-4*(_defaultButtonSize+_defaultButtonLeftMargin);
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 if(_winfrmHolder.childNodes.length > 1)
91 _winfrmHolder.removeChild(
92 document.getElementById(
"DesktopWindowFrameLoadingDiv-"+_id));
105 this.getWindowName =
function() {
return _name; }
106 this.getWindowSubName =
function() {
return _subname; }
107 this.getWindowUrl =
function() {
return _url; }
108 this.getWindowId =
function() {
return _id; }
109 this.getWindowX =
function() {
return _x; }
110 this.getWindowY =
function() {
return _y; }
111 this.getWindowZ =
function() {
return parseInt(this.windiv.style.zIndex);}
112 this.getWindowWidth =
function() {
return _w; }
113 this.getWindowHeight =
function() {
return _h; }
114 this.getWindowHeaderHeight =
function() {
return _defaultHeaderHeight; }
115 this.isMaximized =
function() {
return _isMaximized && !_isMinimized;}
116 this.isMinimized =
function() {
return _isMinimized;}
118 this.setWindowZ =
function(z) {
120 _z = z; this.windiv.style.zIndex = _z;
123 this.showFrame =
function() { _winfrm.style.display =
"inline"; }
124 this.hideFrame =
function() { _winfrm.style.display =
"none"; }
128 this.setWindowNameAndSubName =
function(name,subname) {
129 _name = name; _subname = subname;
131 Debug.log(
"Desktop Window name=" + name +
" and subname=" + subname,Debug.LOW_PRIORITY);
136 this.setWindowSizeAndPosition =
function(x,y,w,h) {
143 _w = _isMaximized?Desktop.desktop.getDesktopContentWidth():(w < _defaultWindowMinWidth?_defaultWindowMinWidth:w);
144 _h = _isMaximized?Desktop.desktop.getDesktopContentHeight():(h < _defaultWindowMinHeight?_defaultWindowMinHeight:h);
145 _x = _isMaximized?Desktop.desktop.getDesktopContentX():x;
146 _y = _isMaximized?Desktop.desktop.getDesktopContentY():y;
149 if(_x + _w > Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth())
150 _x = Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth() - _w;
151 if(_y + _h > Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight())
152 _y = Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight() - _h;
154 this.windiv.style.width = _w +
"px";
155 this.windiv.style.height = _h+
"px";
156 this.windiv.style.left = _x+
"px";
157 this.windiv.style.top = _y+
"px";
161 _winfrm.style.width = (_w-2*_defaultFrameBorder-2)+
"px";
162 _winfrm.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+
"px";
163 _winfrmHolder.style.width = (_w-2*_defaultFrameBorder-2)+
"px";
164 _winfrmHolder.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+
"px";
170 _winfrm.style.position =
"absolute";
171 _winfrm.style.zIndex = _z + 1;
172 _winfrm.style.width = _w +
"px";
173 _winfrm.style.height = _h +
"px";
174 _winfrm.style.left =
"-1px";
175 _winfrm.style.top =
"-1px";
176 _winfrmHolder.style.position =
"absolute";
177 _winfrmHolder.style.width = (_w)+
"px";
178 _winfrmHolder.style.height = (_h)+
"px";
179 _winfrmHolder.style.left =(-_defaultFrameBorder-2) +
"px";
180 _winfrmHolder.style.top =
"-1px";
183 _w = w < _defaultWindowMinWidth?_defaultWindowMinWidth:w;
184 _h = h < _defaultWindowMinHeight?_defaultWindowMinHeight:h;
189 var hdrs = this.windiv.getElementsByClassName(
"DesktopWindowButton");
190 for(var h=0;hdrs && h<hdrs.length;++h)
191 hdrs[h].style.display =
"none";
192 hdrs =
this.windiv.getElementsByClassName(
"DesktopWindowHeader");
193 for(var h=0;hdrs && h<hdrs.length;++h)
194 hdrs[h].style.display =
"none";
197 _winfrm.style.zIndex = _z;
198 _winfrm.style.position =
"static";
199 _winfrmHolder.style.position =
"static";
202 var hdrs = this.windiv.getElementsByClassName(
"DesktopWindowButton");
203 for(var h=0;hdrs && h<hdrs.length;++h)
204 hdrs[h].style.display =
"block";
205 hdrs =
this.windiv.getElementsByClassName(
"DesktopWindowHeader");
206 for(var h=0;hdrs && h<hdrs.length;++h)
207 hdrs[h].style.display =
"block";
210 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
214 this.moveWindowByOffset =
function(dx,dy) {
218 if(_y < Desktop.desktop.getDesktopContentY()) _y = Desktop.desktop.getDesktopContentY();
219 this.windiv.style.left = _x+
"px";
220 this.windiv.style.top = _y+
"px";
226 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
231 this.resizeAndPositionWindow =
function(x,y,w,h) {
232 if((w <= _defaultWindowMinWidth && x > _x) ||
233 (h <= _defaultWindowMinHeight && y > _y))
return;
234 if(x < Desktop.desktop.getDesktopContentX()) x = Desktop.desktop.getDesktopContentX();
235 if(y < Desktop.desktop.getDesktopContentY()) y = Desktop.desktop.getDesktopContentY();
236 this.setWindowSizeAndPosition(x,y,w,h);
241 this.maximize =
function() {
243 if(_isMinimized) this.unminimize();
246 this.windiv.style.display =
"inline";
247 this.setWindowSizeAndPosition(_x+10,_y,_w,_h);
248 window.parent.document.title= _name;
249 console.log(document.title, _name,
"Maximize()");
253 this.unmaximize =
function() {
255 _isMaximized =
false;
257 this.windiv.style.display =
"inline";
258 this.setWindowSizeAndPosition(_x,_y,_w,_h);
259 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
264 this.minimize =
function() {
267 window.parent.document.title = _name;
269 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
272 this.windiv.style.display =
"none";
273 Debug.log(
"-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
276 this.unminimize =
function() {
279 window.parent.document.title = _name;
281 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
283 _isMinimized =
false;
284 this.windiv.style.display =
"inline";
285 Debug.log(
"-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
293 this.windiv = document.createElement(
"div");
294 this.windiv.setAttribute(
"class",
"DesktopWindow");
295 this.windiv.setAttribute(
"id",
"DesktopWindow-" + _id);
296 this.windiv.style.backgroundColor = Desktop.desktop.defaultWindowFrameColor;
297 this.windiv.style.position =
"absolute";
298 this.windiv.style.zIndex = _z;
301 _winhdr = document.createElement(
"div");
302 _winhdr.setAttribute(
"class",
"DesktopWindowHeader");
303 _winhdr.setAttribute(
"id",
"DesktopWindowHeader-" + _id);
304 _winhdr.style.height = _defaultHeaderHeight+
"px";
305 _winhdr.style.marginLeft = _defaultHeaderLeftMargin+
"px";
306 _winhdr.style.fontSize = _defaultHeaderFontSize+
"px";
307 this.setWindowNameAndSubName(name, subname);
308 this.windiv.appendChild(_winhdr);
311 var tmpContainer = document.createElement(
"div");
312 tmpContainer.setAttribute(
"style",
"float:right;white-space:nowrap;");
313 var tmpBtn = document.createElement(
"div");
314 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
315 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonRefresh-" + _id);
316 tmpBtn.style.width = (_defaultButtonSize) +
"px";
317 tmpBtn.style.height = (_defaultButtonSize) +
"px";
318 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
319 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
320 tmpBtn.onmouseup = Desktop.handleWindowRefresh;
321 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
322 var tmpEl = document.createElement(
"div");
323 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicRefresh");
324 tmpEl.innerHTML =
"↻";
325 tmpBtn.appendChild(tmpEl);
326 tmpContainer.appendChild(tmpBtn);
328 var tmpBtn = document.createElement(
"div");
329 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
330 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonMin-" + _id);
331 tmpBtn.style.width = (_defaultButtonSize) +
"px";
332 tmpBtn.style.height = (_defaultButtonSize) +
"px";
333 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
334 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
335 tmpBtn.onmouseup = Desktop.handleWindowMinimize;
336 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
337 var tmpEl = document.createElement(
"div");
338 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicMin");
339 tmpBtn.appendChild(tmpEl);
340 tmpContainer.appendChild(tmpBtn);
342 tmpBtn = document.createElement(
"div");
343 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
344 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonMax-" + _id);
345 tmpBtn.style.width = (_defaultButtonSize) +
"px";
346 tmpBtn.style.height = (_defaultButtonSize) +
"px";
347 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
348 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
349 tmpBtn.onmouseup = Desktop.handleWindowMaximize;
350 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
351 var tmpEl = document.createElement(
"div");
352 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicMax");
353 tmpBtn.appendChild(tmpEl);
354 tmpContainer.appendChild(tmpBtn);
356 tmpBtn = document.createElement(
"div");
357 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
358 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonClose-" + _id);
359 tmpBtn.style.width = (_defaultButtonSize) +
"px";
360 tmpBtn.style.height = (_defaultButtonSize) +
"px";
361 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
362 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
363 tmpBtn.onmouseup = Desktop.handleWindowClose;
364 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
365 var tmpEl = document.createElement(
"div");
366 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicClose");
367 tmpEl.innerHTML =
"x";
368 tmpBtn.appendChild(tmpEl);
369 tmpContainer.appendChild(tmpBtn);
372 this.windiv.appendChild(tmpContainer);
375 _winfrmHolder = document.createElement(
"div");
376 _winfrmHolder.setAttribute(
"class",
"DesktopWindowFrameHolder");
377 _winfrmHolder.setAttribute(
"id",
"DesktopWindowFrameHolder-" + _id);
378 _winfrmHolder.style.marginLeft = _defaultFrameBorder+
"px";
379 _winfrmHolder.innerHTML =
380 "<div class='DesktopWindowHeader' id='DesktopWindowFrameLoadingDiv-"+
381 _id +
"' style='width:100px;height:50px;position:relative;top:50%;left:50%;margin-top:-25px;margin-left:-50px;text-align:center;margin-bottom:-50px;'>" +
382 "Loading..." +
"</div>";
385 _winfrm = document.createElement(
"iframe");
386 _winfrm.setAttribute(
"class",
"DesktopWindowFrame");
387 _winfrm.setAttribute(
"id",
"DesktopWindowFrame-" + _id);
388 _winfrm.setAttribute(
"name",
"DesktopWindowFrame-" + _id);
389 _winfrm.onload = _handleWindowContentLoading;
390 _winfrm.setAttribute(
"src", _url);
391 _winfrmHolder.appendChild(_winfrm);
392 this.windiv.appendChild(_winfrmHolder);
394 this.setWindowSizeAndPosition(x,y,w,h);
397 this.windiv.onmousedown = Desktop.handleWindowMouseDown;
398 this.windiv.onmouseup = Desktop.handleWindowMouseUp;
399 this.windiv.onmousemove = Desktop.handleWindowMouseMove;
400 this.windiv.ondblclick = Desktop.handleWindowMaximize;
403 this.windiv.addEventListener(
'touchstart',Desktop.handleTouchStart);
404 this.windiv.addEventListener(
'touchend',Desktop.handleTouchEnd);
405 this.windiv.addEventListener(
'touchmove',Desktop.handleTouchMove);
407 Debug.log(
"Desktop Window Created",Debug.LOW_PRIORITY);