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) { _z = z; this.windiv.style.zIndex = _z; }
120 this.showFrame =
function() { _winfrm.style.display =
"inline"; }
121 this.hideFrame =
function() { _winfrm.style.display =
"none"; }
125 this.setWindowNameAndSubName =
function(name,subname) {
126 _name = name; _subname = subname;
128 Debug.log(
"Desktop Window name=" + name +
" and subname=" + subname,Debug.LOW_PRIORITY);
133 this.setWindowSizeAndPosition =
function(x,y,w,h) {
140 _w = _isMaximized?Desktop.desktop.getDesktopContentWidth():(w < _defaultWindowMinWidth?_defaultWindowMinWidth:w);
141 _h = _isMaximized?Desktop.desktop.getDesktopContentHeight():(h < _defaultWindowMinHeight?_defaultWindowMinHeight:h);
142 _x = _isMaximized?Desktop.desktop.getDesktopContentX():x;
143 _y = _isMaximized?Desktop.desktop.getDesktopContentY():y;
146 if(_x + _w > Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth())
147 _x = Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth() - _w;
148 if(_y + _h > Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight())
149 _y = Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight() - _h;
151 this.windiv.style.width = _w +
"px";
152 this.windiv.style.height = _h+
"px";
153 this.windiv.style.left = _x+
"px";
154 this.windiv.style.top = _y+
"px";
158 _winfrm.style.width = (_w-2*_defaultFrameBorder-2)+
"px";
159 _winfrm.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+
"px";
160 _winfrmHolder.style.width = (_w-2*_defaultFrameBorder-2)+
"px";
161 _winfrmHolder.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+
"px";
167 _winfrm.style.position =
"absolute";
168 _winfrm.style.zIndex = _z + 1;
169 _winfrm.style.width = _w +
"px";
170 _winfrm.style.height = _h +
"px";
171 _winfrm.style.left =
"-1px";
172 _winfrm.style.top =
"-1px";
173 _winfrmHolder.style.position =
"absolute";
174 _winfrmHolder.style.width = (_w)+
"px";
175 _winfrmHolder.style.height = (_h)+
"px";
176 _winfrmHolder.style.left =(-_defaultFrameBorder-2) +
"px";
177 _winfrmHolder.style.top =
"-1px";
180 _w = w < _defaultWindowMinWidth?_defaultWindowMinWidth:w;
181 _h = h < _defaultWindowMinHeight?_defaultWindowMinHeight:h;
186 var hdrs = this.windiv.getElementsByClassName(
"DesktopWindowButton");
187 for(var h=0;hdrs && h<hdrs.length;++h)
188 hdrs[h].style.display =
"none";
189 hdrs =
this.windiv.getElementsByClassName(
"DesktopWindowHeader");
190 for(var h=0;hdrs && h<hdrs.length;++h)
191 hdrs[h].style.display =
"none";
194 _winfrm.style.zIndex = _z;
195 _winfrm.style.position =
"static";
196 _winfrmHolder.style.position =
"static";
199 var hdrs = this.windiv.getElementsByClassName(
"DesktopWindowButton");
200 for(var h=0;hdrs && h<hdrs.length;++h)
201 hdrs[h].style.display =
"block";
202 hdrs =
this.windiv.getElementsByClassName(
"DesktopWindowHeader");
203 for(var h=0;hdrs && h<hdrs.length;++h)
204 hdrs[h].style.display =
"block";
207 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
211 this.moveWindowByOffset =
function(dx,dy) {
215 if(_y < Desktop.desktop.getDesktopContentY()) _y = Desktop.desktop.getDesktopContentY();
216 this.windiv.style.left = _x+
"px";
217 this.windiv.style.top = _y+
"px";
223 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
228 this.resizeAndPositionWindow =
function(x,y,w,h) {
229 if((w <= _defaultWindowMinWidth && x > _x) ||
230 (h <= _defaultWindowMinHeight && y > _y))
return;
231 if(x < Desktop.desktop.getDesktopContentX()) x = Desktop.desktop.getDesktopContentX();
232 if(y < Desktop.desktop.getDesktopContentY()) y = Desktop.desktop.getDesktopContentY();
233 this.setWindowSizeAndPosition(x,y,w,h);
238 this.maximize =
function() {
240 if(_isMinimized) this.unminimize();
243 this.windiv.style.display =
"inline";
244 this.setWindowSizeAndPosition(_x+10,_y,_w,_h);
245 window.parent.document.title= _name;
246 console.log(document.title, _name,
"Maximize()");
250 this.unmaximize =
function() {
252 _isMaximized =
false;
254 this.windiv.style.display =
"inline";
255 this.setWindowSizeAndPosition(_x,_y,_w,_h);
256 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
261 this.minimize =
function() {
264 window.parent.document.title = _name;
266 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
269 this.windiv.style.display =
"none";
270 Debug.log(
"-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
273 this.unminimize =
function() {
276 window.parent.document.title = _name;
278 window.parent.document.title = Desktop.isWizardMode()?
"ots wiz":
"ots";
280 _isMinimized =
false;
281 this.windiv.style.display =
"inline";
282 Debug.log(
"-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
290 this.windiv = document.createElement(
"div");
291 this.windiv.setAttribute(
"class",
"DesktopWindow");
292 this.windiv.setAttribute(
"id",
"DesktopWindow-" + _id);
293 this.windiv.style.backgroundColor = Desktop.desktop.defaultWindowFrameColor;
294 this.windiv.style.position =
"absolute";
295 this.windiv.style.zIndex = _z;
298 _winhdr = document.createElement(
"div");
299 _winhdr.setAttribute(
"class",
"DesktopWindowHeader");
300 _winhdr.setAttribute(
"id",
"DesktopWindowHeader-" + _id);
301 _winhdr.style.height = _defaultHeaderHeight+
"px";
302 _winhdr.style.marginLeft = _defaultHeaderLeftMargin+
"px";
303 _winhdr.style.fontSize = _defaultHeaderFontSize+
"px";
304 this.setWindowNameAndSubName(name, subname);
305 this.windiv.appendChild(_winhdr);
308 var tmpBtn = document.createElement(
"div");
309 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
310 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonRefresh-" + _id);
311 tmpBtn.style.width = (_defaultButtonSize) +
"px";
312 tmpBtn.style.height = (_defaultButtonSize) +
"px";
313 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
314 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
315 tmpBtn.onmouseup = Desktop.handleWindowRefresh;
316 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
317 var tmpEl = document.createElement(
"div");
318 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicRefresh");
319 tmpEl.innerHTML =
"↻";
320 tmpBtn.appendChild(tmpEl);
321 this.windiv.appendChild(tmpBtn);
323 var tmpBtn = document.createElement(
"div");
324 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
325 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonMin-" + _id);
326 tmpBtn.style.width = (_defaultButtonSize) +
"px";
327 tmpBtn.style.height = (_defaultButtonSize) +
"px";
328 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
329 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
330 tmpBtn.onmouseup = Desktop.handleWindowMinimize;
331 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
332 var tmpEl = document.createElement(
"div");
333 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicMin");
334 tmpBtn.appendChild(tmpEl);
335 this.windiv.appendChild(tmpBtn);
337 tmpBtn = document.createElement(
"div");
338 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
339 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonMax-" + _id);
340 tmpBtn.style.width = (_defaultButtonSize) +
"px";
341 tmpBtn.style.height = (_defaultButtonSize) +
"px";
342 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
343 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
344 tmpBtn.onmouseup = Desktop.handleWindowMaximize;
345 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
346 var tmpEl = document.createElement(
"div");
347 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicMax");
348 tmpBtn.appendChild(tmpEl);
349 this.windiv.appendChild(tmpBtn);
351 tmpBtn = document.createElement(
"div");
352 tmpBtn.setAttribute(
"class",
"DesktopWindowButton");
353 tmpBtn.setAttribute(
"id",
"DesktopWindowButtonClose-" + _id);
354 tmpBtn.style.width = (_defaultButtonSize) +
"px";
355 tmpBtn.style.height = (_defaultButtonSize) +
"px";
356 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +
"px";
357 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +
"px";
358 tmpBtn.onmouseup = Desktop.handleWindowClose;
359 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
360 var tmpEl = document.createElement(
"div");
361 tmpEl.setAttribute(
"class",
"DesktopWindowButtonGraphicClose");
362 tmpEl.innerHTML =
"x";
363 tmpBtn.appendChild(tmpEl);
364 this.windiv.appendChild(tmpBtn);
367 _winfrmHolder = document.createElement(
"div");
368 _winfrmHolder.setAttribute(
"class",
"DesktopWindowFrameHolder");
369 _winfrmHolder.setAttribute(
"id",
"DesktopWindowFrameHolder-" + _id);
370 _winfrmHolder.style.marginLeft = _defaultFrameBorder+
"px";
371 _winfrmHolder.innerHTML =
372 "<div class='DesktopWindowHeader' id='DesktopWindowFrameLoadingDiv-"+
373 _id +
"' style='width:100px;height:50px;position:relative;top:50%;left:50%;margin-top:-25px;margin-left:-50px;text-align:center;margin-bottom:-50px;'>" +
374 "Loading..." +
"</div>";
377 _winfrm = document.createElement(
"iframe");
378 _winfrm.setAttribute(
"class",
"DesktopWindowFrame");
379 _winfrm.setAttribute(
"id",
"DesktopWindowFrame-" + _id);
380 _winfrm.setAttribute(
"name",
"DesktopWindowFrame-" + _id);
381 _winfrm.onload = _handleWindowContentLoading;
382 _winfrm.setAttribute(
"src", _url);
383 _winfrmHolder.appendChild(_winfrm);
384 this.windiv.appendChild(_winfrmHolder);
386 this.setWindowSizeAndPosition(x,y,w,h);
389 this.windiv.onmousedown = Desktop.handleWindowMouseDown;
390 this.windiv.onmouseup = Desktop.handleWindowMouseUp;
391 this.windiv.onmousemove = Desktop.handleWindowMouseMove;
392 this.windiv.ondblclick = Desktop.handleWindowMaximize;
395 this.windiv.addEventListener(
'touchstart',Desktop.handleTouchStart);
396 this.windiv.addEventListener(
'touchend',Desktop.handleTouchEnd);
397 this.windiv.addEventListener(
'touchmove',Desktop.handleTouchMove);
399 Debug.log(
"Desktop Window Created",Debug.LOW_PRIORITY);