Window.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. MWF.require("MWF.widget.Dialog", null, false);
  2. MWF.xDesktop.Window = new Class({
  3. Extends: MWF.widget.Dialog,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "title": "window",
  8. "width": "800",
  9. "height": "600",
  10. "top": "10",
  11. "left": "10",
  12. "fromTop": "0",
  13. "fromLeft": "0",
  14. "mark": false,
  15. "html": "",
  16. "text": "",
  17. "url": "",
  18. "content": null,
  19. "isMax": true,
  20. "isClose": true,
  21. "isResize": true,
  22. "isMove": true,
  23. "buttons": null,
  24. "buttonList": null
  25. },
  26. initialize: function(app, options){
  27. var position = layout.desktop.desktopNode.getPosition();
  28. // var size = layout.desktop.desktopNode.getSize();
  29. this.options.top = parseFloat(this.options.top)+position.y;
  30. this.options.fromTop = parseFloat(this.options.fromTop)+position.y;
  31. this.app = app;
  32. this.parent(options);
  33. this.isHide = false;
  34. this.isMax = false;
  35. },
  36. // _loadCss: function(){
  37. // if (this.app.windowCss){
  38. // this.css = this.app.windowCss;
  39. // }else{
  40. // var key = encodeURIComponent(this.cssPath);
  41. // if (!reload && MWF.widget.css[key]){
  42. // this.css = MWF.widget.css[key];
  43. // }else{
  44. // this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+COMMON.version : this.cssPath+"?v="+COMMON.version;
  45. // var r = new Request.JSON({
  46. // url: this.cssPath,
  47. // secure: false,
  48. // async: false,
  49. // method: "get",
  50. // noCache: false,
  51. // onSuccess: function(responseJSON, responseText){
  52. // this.css = responseJSON;
  53. // MWF.widget.css[key] = responseJSON;
  54. // }.bind(this),
  55. // onError: function(text, error){
  56. // alert(error + text);
  57. // }
  58. // });
  59. // }
  60. // }
  61. // },
  62. changeStyle: function(){
  63. var obj = this.getNodeStyleStatus();
  64. this.cssPath = MWF.defaultPath+"/widget/$Dialog/"+this.options.style+"/css.wcss";
  65. this._loadCss();
  66. this.getContentUrl();
  67. var request = new Request.HTML({
  68. url: this.contentUrl,
  69. method: "GET",
  70. async: false,
  71. onSuccess: function(responseTree){
  72. var node = responseTree[0];
  73. var title = node.getElement(".MWF_dialod_title");
  74. var titleCenter = node.getElement(".MWF_dialod_title_center");
  75. var titleRefresh = node.getElement(".MWF_dialod_title_refresh");
  76. var titleText = node.getElement(".MWF_dialod_title_text");
  77. var titleAction = node.getElement(".MWF_dialod_title_action");
  78. var under = node.getElement(".MWF_dialod_under");
  79. var content = node.getElement(".MWF_dialod_content");
  80. var bottom = node.getElement(".MWF_dialod_bottom");
  81. var resizeNode = node.getElement(".MWF_dialod_bottom_resize");
  82. var button = node.getElement(".MWF_dialod_button");
  83. if (this.title && title){
  84. this.title.clearStyles();
  85. this.title.set("style", title.get("style"));
  86. }
  87. if (this.titleCenter && titleCenter){
  88. this.titleCenter.clearStyles();
  89. this.titleCenter.set("style", titleCenter.get("style"));
  90. }
  91. if (this.titleRefresh && titleRefresh){
  92. this.titleRefresh.clearStyles();
  93. this.titleRefresh.set("style", titleRefresh.get("style"));
  94. }
  95. if (this.titleText && titleText){
  96. this.titleText.clearStyles();
  97. this.titleText.set("style", titleText.get("style"));
  98. }
  99. if (this.titleAction && titleAction){
  100. this.titleAction.clearStyles();
  101. this.titleAction.set("style", titleAction.get("style"));
  102. }
  103. if (this.under && under){
  104. this.under.clearStyles();
  105. this.under.set("style", under.get("style"));
  106. }
  107. if (this.content && content){
  108. this.content.clearStyles();
  109. this.content.set("style", content.get("style"));
  110. }
  111. if (this.bottom && bottom){
  112. this.bottom.clearStyles();
  113. this.bottom.set("style", bottom.get("style"));
  114. }
  115. if (this.resizeNode && resizeNode){
  116. this.resizeNode.clearStyles();
  117. this.resizeNode.set("style", resizeNode.get("style"));
  118. }
  119. if (this.button && button){
  120. this.button.clearStyles();
  121. this.button.set("style", button.get("style"));
  122. }
  123. this.setNodeStyleStatus(obj);
  124. this.node.setStyles(this.css.to);
  125. this.spacer.setStyles(this.css.spacerTo);
  126. if (this.closeActionNode) this.closeActionNode.setStyles(this.css.closeActionNode);
  127. if (this.maxActionNode) this.maxActionNode.setStyles(this.css.maxActionNode);
  128. if (this.minActionNode) this.minActionNode.setStyles(this.css.minActionNode);
  129. if (this.restoreActionNode) this.restoreActionNode.setStyles(this.css.restoreActionNode);
  130. if (this.app == this.app.desktop.currentApp){
  131. this.node.setStyles(this.css.current);
  132. this.spacer.setStyles(this.css.spacerCurrent);
  133. }else{
  134. this.node.setStyles(this.css.uncurrent);
  135. this.spacer.setStyles(this.css.spacerUncurrent);
  136. }
  137. this.setContentSize();
  138. }.bind(this)
  139. });
  140. request.send();
  141. },
  142. setNodeStyleStatus: function(obj){
  143. this.css.to.height = obj.nodeTo.height;
  144. this.css.to.width = obj.nodeTo.width;
  145. this.css.to.top = obj.nodeTo.top;
  146. this.css.to.left = obj.nodeTo.left;
  147. this.css.to["z-index"] = obj.nodeTo["z-index"];
  148. this.css.from.top = obj.nodeFrom.top;
  149. this.css.from.left = obj.nodeFrom.left;
  150. this.css.from["z-index"] = obj.nodeFrom["z-index"];
  151. this.css.spacerTo.height = obj.spacerTo.height;
  152. this.css.spacerTo.width = obj.spacerTo.width;
  153. this.css.spacerTo.top = obj.spacerTo.top;
  154. this.css.spacerTo.left = obj.spacerTo.left;
  155. this.css.spacerTo["z-index"] = obj.spacerTo["z-index"];
  156. this.css.spacerFrom.top = obj.spacerFrom.top;
  157. this.css.spacerFrom.left = obj.spacerFrom.left;
  158. this.css.spacerFrom["z-index"] = obj.spacerFrom["z-index"];
  159. },
  160. getNodeStyleStatus: function(){
  161. return {
  162. "nodeTo": {
  163. "height": this.css.to.height,
  164. "width": this.css.to.width,
  165. "top": this.css.to.top,
  166. "left": this.css.to.left,
  167. "z-index": this.css.to["z-index"]
  168. },
  169. "nodeFrom": {
  170. "top": this.css.from.top,
  171. "left": this.css.from.left,
  172. "z-index": this.css.from["z-index"]
  173. },
  174. "spacerTo": {
  175. "height": this.css.spacerTo.height,
  176. "width": this.css.spacerTo.width,
  177. "top": this.css.spacerTo.top,
  178. "left": this.css.spacerTo.left,
  179. "z-index": this.css.spacerTo["z-index"]
  180. },
  181. "spacerFrom": {
  182. "top": this.css.spacerFrom.top,
  183. "left": this.css.spacerFrom.left,
  184. "z-index": this.css.spacerFrom["z-index"]
  185. }
  186. };
  187. },
  188. reStyle: function(options){
  189. if (options) this.setOptions(options);
  190. var index = null;
  191. if (MWF.xDesktop.zIndexPool) index = MWF.xDesktop.zIndexPool.applyZindex();
  192. this.css.to.height = this.options.height+"px";
  193. this.css.to.width = this.options.width+"px";
  194. this.css.to.top = this.options.top+"px";
  195. this.css.to.left = this.options.left+"px";
  196. // this.css.to.top = this.options.top+"px";
  197. this.css.from.top = this.options.fromTop+"px";
  198. this.css.from.left = this.options.fromLeft+"px";
  199. if (index){
  200. this.css.from["z-index"] = index+1;
  201. this.css.to["z-index"] = index+1;
  202. }
  203. if (this.node) this.node.set("styles", this.css.from);
  204. this.css.spacerTo.height = this.options.height+"px";
  205. this.css.spacerTo.width = this.options.width+"px";
  206. this.css.spacerTo.top = this.options.top+"px";
  207. this.css.spacerTo.left = this.options.left+"px";
  208. // this.css.spacerTo.top = this.options.top+"px";
  209. this.css.spacerFrom.top = this.options.fromTop+"px";
  210. this.css.spacerFrom.left = this.options.fromLeft+"px";
  211. if (index){
  212. this.css.spacerFrom["z-index"] = index;
  213. this.css.spacerTo["z-index"] = index;
  214. }
  215. if (this.spacer) this.spacer.set("styles", this.css.spacerFrom);
  216. },
  217. setCurrent: function(){
  218. if (MWF.xDesktop.zIndexPool){
  219. var index = this.node.getStyle("z-index").toFloat()+1;
  220. if (index < MWF.xDesktop.zIndexPool.zIndex){
  221. var newIndex = MWF.xDesktop.zIndexPool.applyZindex();
  222. this.css.spacerTo["z-index"] = newIndex;
  223. this.css.spacerFrom["z-index"] = newIndex;
  224. // if(this.spacerMorph){
  225. // if (this.spacerMorph.isRunning()){
  226. // this.spacerMorph.chain(function(){
  227. // if (this.spacer) this.spacer.setStyle("z-index", newIndex);
  228. // }.bind(this));
  229. // }else{
  230. if (this.spacer) this.spacer.setStyle("z-index", newIndex);
  231. // }
  232. // }
  233. this.css.to["z-index"] = newIndex+1;
  234. this.css.from["z-index"] = newIndex+1;
  235. // if(this.morph){
  236. // if (this.morph.isRunning()){
  237. // this.morph.chain(function(){
  238. // this.node.setStyle("z-index", newIndex+1);
  239. // }.bind(this));
  240. // }else{
  241. this.node.setStyle("z-index", newIndex+1);
  242. // }
  243. // }
  244. }
  245. }
  246. this.node.setStyles(this.css.current);
  247. if (this.spacer) this.spacer.setStyles(this.css.spacerCurrent);
  248. },
  249. setUncurrent: function(){
  250. this.node.setStyles(this.css.uncurrent);
  251. if (this.spacer) this.spacer.setStyles(this.css.spacerUncurrent);
  252. },
  253. setTitleEvent: function(){
  254. this.node.addEvent("mousedown", function(){
  255. this.app.setCurrent();
  256. }.bind(this));
  257. this.containerDrag = new Drag(this.title, {
  258. "handle": this.title,
  259. "onStart": function(el, e){
  260. this.containerDrag.stop();
  261. var div = this.node.clone(false).inject($(document.body));
  262. var size = this.node.getSize();
  263. div.setStyles({
  264. "opacity": 0.7,
  265. "border": "2px dashed #999",
  266. "z-index": this.node.getStyle("z-index"),
  267. "width": size.x,
  268. "height": size.y,
  269. "background-color": "#CCC",
  270. "position": "absolute"
  271. });
  272. div.position({
  273. relativeTo: this.node,
  274. position: 'upperLeft',
  275. edge: 'upperLeft'
  276. });
  277. var drag = new Drag.Move(div, {
  278. "onStart": function(){
  279. //this.node.setStyle("display", "none");
  280. this.node.fade("out");
  281. this.spacer.fade("out");
  282. }.bind(this),
  283. "onDrop": function(dragging, inObj, e){
  284. this.node.fade("in");
  285. this.spacer.fade(this.css.spacerTo.opacity);
  286. this.node.position({
  287. relativeTo: dragging,
  288. position: 'upperLeft',
  289. edge: 'upperLeft'
  290. });
  291. var p = this.node.getPosition();
  292. this.spacer.setStyles({
  293. "top": p.y,
  294. "left": p.x
  295. });
  296. this.css.spacerTo.left = p.x;
  297. this.css.spacerTo.top = p.y;
  298. this.css.to.left = p.x;
  299. this.css.to.top = p.y;
  300. dragging.destroy();
  301. this.fireEvent("moveDrop", [e]);
  302. }.bind(this),
  303. "onCancel": function(dragging){
  304. dragging.destroy();
  305. drag = null;
  306. }
  307. });
  308. drag.start(e);
  309. }.bind(this)
  310. });
  311. //this.title.addEvent("mousedown", function(e){
  312. //}.bind(this));
  313. //this.containerDrag = new Drag.Move(this.node, {
  314. // "limit": {"x": [null, null], "y": [0, null]},
  315. // "handle": this.title,
  316. // "onDrag": function(){
  317. // var p = this.node.getPosition();
  318. // if (this.spacer){
  319. // this.spacer.setStyles({
  320. // "top": p.y,
  321. // "left": p.x
  322. // });
  323. // this.css.spacerTo.left = p.x;
  324. // this.css.spacerTo.top = p.y;
  325. // };
  326. // this.css.to.left = p.x;
  327. // this.css.to.top = p.y;
  328. // }.bind(this)
  329. //});
  330. if (this.options.isResize){
  331. this.node.makeResizable({
  332. "handle": this.resizeNode || this.bottom,
  333. "limit": {x:[200, null], y:[200, null]},
  334. "onDrag": function(){
  335. var size = this.node.getComputedSize();
  336. if (this.spacer){
  337. this.spacer.setStyles({
  338. "width": size.width,
  339. "height": size.height
  340. });
  341. this.css.spacerTo.width = size.width;
  342. this.css.spacerTo.height = size.height;
  343. }
  344. this.css.to.width = size.width;
  345. this.css.to.height = size.height;
  346. this.setContentSize(size.height, size.width);
  347. this.fireEvent("resize");
  348. }.bind(this),
  349. "onComplete": function(){
  350. this.fireEvent("resizeCompleted");
  351. }.bind(this)
  352. });
  353. }
  354. },
  355. getContentUrl: function(){
  356. if (layout.desktop.windowCss){
  357. this.contentUrl = MWF.defaultPath+"/xDesktop/$Window/desktop_default/dialog.html";
  358. }else{
  359. this.contentUrl = MWF.defaultPath+"/xDesktop/$Window/"+this.options.style+"/dialog.html";
  360. }
  361. },
  362. _loadCss: function(){
  363. if (this.app.desktop.windowCss){
  364. this.css = this.app.desktop.windowCss;
  365. }else{
  366. this.path = MWF.defaultPath+"/xDesktop/$Window/";
  367. this.cssPath = MWF.defaultPath+"/xDesktop/$Window/"+this.options.style+"/css.wcss";
  368. var r = new Request.JSON({
  369. url: this.cssPath,
  370. secure: false,
  371. async: false,
  372. method: "get",
  373. noCache: true,
  374. onSuccess: function(responseJSON, responseText){
  375. this.css = responseJSON;
  376. }.bind(this),
  377. onError: function(text, error){
  378. alert(text);
  379. }
  380. });
  381. r.send();
  382. }
  383. },
  384. getSpacer: function(){
  385. if (!this.spacer){
  386. this.spacer = new Element("div", {
  387. styles: this.css.spacerFrom
  388. }).inject(this.options.container || $(document.body));
  389. }
  390. },
  391. showNoAnimation: function(max, hide){
  392. if (max){
  393. this.showMaxIm();
  394. }else if (hide){
  395. this.showIm();
  396. this.hideIm();
  397. }else{
  398. this.showIm();
  399. }
  400. },
  401. showMaxIm: function(callback){
  402. this.querySetMaxStyle();
  403. this.getSpacer();
  404. this.spacer.setStyle("display", "block");
  405. this.node.setStyle("display", "block");
  406. var size = this.getMaxSize();
  407. var spacerTo = Object.clone(this.css.spacerTo);
  408. var to = Object.clone(this.css.to);
  409. var contentTo = {};
  410. spacerTo.top = size.position.y;
  411. spacerTo.left = size.position.x;
  412. spacerTo.width = size.spacer.x;
  413. spacerTo.height = size.spacer.y;
  414. to.top = size.position.y;
  415. to.left = size.position.x;
  416. to.width = size.node.x;
  417. to.height = size.node.y;
  418. contentTo = size.contentSize;
  419. if (this.fireEvent("queryShow")){
  420. this.fireEvent("queryMax");
  421. this.node.setStyles(to);
  422. this.spacer.setStyles(spacerTo);
  423. this.content.setStyles(contentTo);
  424. if (this.titleText) this.getTitle();
  425. this.isMax = true;
  426. this.isHide = false;
  427. if (this.containerDrag) this.containerDrag.detach();
  428. this.postSetMaxStyle();
  429. if (callback) callback();
  430. this.fireEvent("postShow");
  431. this.fireEvent("postMax");
  432. if (this.maxActionNode) this.maxActionNode.setStyles(this.css.restoreActionNode);
  433. }
  434. },
  435. showIm: function(){
  436. if (this.options.mark) this._markShow();
  437. this.getSpacer();
  438. this.spacer.setStyle("display", "block");
  439. this.node.setStyle("display", "block");
  440. var contentSize = this.getContentSize(this.css.to.height.toFloat(), this.css.to.width.toFloat());
  441. if (this.fireEvent("queryShow")){
  442. this.spacer.setStyles(this.css.spacerTo);
  443. if (this.app.desktop.currentApp!=this.app) this.spacer.setStyles(this.css.spacerUncurrent);
  444. this.content.setStyles(contentSize);
  445. this.node.setStyles(this.css.to);
  446. if (this.titleText) this.getTitle();
  447. this.isHide = false;
  448. if (this.containerDrag) this.containerDrag.attach();
  449. this.fireEvent("postShow");
  450. }
  451. },
  452. show: function(){
  453. if (this.options.mark) this._markShow();
  454. if (!this.morph){
  455. this.morph = new Fx.Morph(this.node, {duration: 100, link: "chain"});
  456. }
  457. this.morph.setOptions({duration: 50});
  458. debugger;
  459. this.getSpacer();
  460. if (!this.spacerMorph){
  461. this.spacerMorph = new Fx.Morph(this.spacer, {duration: 100, link: "chain"});
  462. }
  463. this.spacerMorph.setOptions({duration: 50});
  464. if (!this.contentMorph){
  465. this.contentMorph = new Fx.Morph(this.content, {duration: 50, link: "chain"});
  466. }
  467. this.contentMorph.setOptions({duration: 50});
  468. this.spacer.setStyle("display", "block");
  469. this.node.setStyle("display", "block");
  470. var contentSize = this.getContentSize(this.css.to.height.toFloat(), this.css.to.width.toFloat());
  471. if (this.fireEvent("queryShow")){
  472. var nodeFinish = false;
  473. var spacerFinish = false;
  474. var contentFinish = false;
  475. this.spacerMorph.start(this.css.spacerTo).chain(function(){
  476. if (this.app.desktop.currentApp!=this.app) this.spacer.setStyles(this.css.spacerUncurrent);
  477. spacerFinish = true;
  478. firePost();
  479. }.bind(this));
  480. this.contentMorph.start(contentSize).chain(function(){
  481. contentFinish = true;
  482. firePost();
  483. }.bind(this));
  484. this.morph.start(this.css.to).chain(function(){
  485. nodeFinish = true;
  486. firePost();
  487. }.bind(this));
  488. var firePost = function(){
  489. if (nodeFinish && spacerFinish && contentFinish){
  490. if (this.titleText) this.getTitle();
  491. this.isHide = false;
  492. if (this.containerDrag) this.containerDrag.attach();
  493. this.fireEvent("postShow");
  494. // if (this.isMax){
  495. // this.isMax = false;
  496. // this.app.maxSize();
  497. // }
  498. }
  499. }.bind(this);
  500. }
  501. },
  502. restore: function(callback){
  503. this.querySetRestoreStyle();
  504. if (this.options.mark) this._markShow();
  505. if (!this.morph){
  506. this.morph = new Fx.Morph(this.node, {duration: 100, link: "chain"});
  507. }
  508. this.morph.setOptions({duration: 50});
  509. this.getSpacer();
  510. if (!this.spacerMorph){
  511. this.spacerMorph = new Fx.Morph(this.spacer, {duration: 100, link: "chain"});
  512. }
  513. this.spacerMorph.setOptions({duration: 50});
  514. if (!this.contentMorph){
  515. this.contentMorph = new Fx.Morph(this.content, {duration: 50, link: "chain"});
  516. }
  517. this.contentMorph.setOptions({duration: 50});
  518. this.spacer.setStyle("display", "block");
  519. this.node.setStyle("display", "block");
  520. var contentSize = this.getContentSize(this.css.to.height.toFloat(), this.css.to.width.toFloat());
  521. if (this.fireEvent("queryRestore")){
  522. var nodeFinish = false;
  523. var spacerFinish = false;
  524. var contentFinish = false;
  525. this.spacerMorph.start(this.css.spacerTo).chain(function(){
  526. if (this.app.desktop.currentApp!=this.app) this.spacer.setStyles(this.css.spacerUncurrent);
  527. spacerFinish = true;
  528. firePost();
  529. }.bind(this));
  530. this.contentMorph.start(contentSize).chain(function(){
  531. contentFinish = true;
  532. firePost();
  533. }.bind(this));
  534. this.morph.start(this.css.to).chain(function(){
  535. if (this.app.desktop.currentApp!=this.app) this.node.setStyles(this.css.uncurrent);
  536. nodeFinish = true;
  537. firePost();
  538. }.bind(this));
  539. var firePost = function(){
  540. if (nodeFinish && spacerFinish && contentFinish){
  541. if (this.titleText) this.getTitle();
  542. this.isHide = false;
  543. this.isMax = false;
  544. if (this.containerDrag) this.containerDrag.attach();
  545. this.postSetRestoreStyle();
  546. if (callback) callback();
  547. this.fireEvent("resize");
  548. this.fireEvent("postRestore");
  549. }
  550. }.bind(this);
  551. if (this.maxActionNode) this.maxActionNode.setStyles(this.css.maxActionNode);
  552. }
  553. },
  554. querySetRestoreStyle: function(){
  555. if (this.css.windowTitleRestore) this.title.setStyles(this.css.windowTitleRestore);
  556. if (this.css.titleRefresh) this.titleRefresh.setStyles(this.css.titleRefresh);
  557. if (this.css.windowTitleTextRestore) this.titleText.setStyles(this.css.windowTitleTextRestore);
  558. if (this.css.windowTitleActionRestore) this.titleAction.setStyles(this.css.windowTitleActionRestore);
  559. if (this.closeActionNode){
  560. if (this.css.closeActionNode) this.closeActionNode.setStyles(this.css.closeActionNode);
  561. }
  562. if (this.maxActionNode){
  563. if (this.css.maxActionNode) this.maxActionNode.setStyles(this.css.maxActionNode);
  564. }
  565. if (this.minActionNode){
  566. if (this.css.minActionNode) this.minActionNode.setStyles(this.css.minActionNode);
  567. }
  568. },
  569. postSetRestoreStyle: function(){
  570. if (this.css.windowNodeRestore) this.node.setStyles(this.css.windowNodeRestore);
  571. },
  572. restoreIm: function(callback){
  573. this.querySetRestoreStyle();
  574. this.getSpacer();
  575. this.spacer.setStyle("display", "block");
  576. this.node.setStyle("display", "block");
  577. var contentSize = this.getContentSize(this.css.to.height.toFloat(), this.css.to.width.toFloat());
  578. if (this.fireEvent("queryRestore")){
  579. this.node.setStyles(this.css.to);
  580. this.spacer.setStyles(this.css.spacerTo);
  581. this.content.setStyles(contentSize);
  582. if (this.titleText) this.getTitle();
  583. this.isHide = false;
  584. this.isMax = false;
  585. if (this.containerDrag) this.containerDrag.attach();
  586. this.postSetRestoreStyle();
  587. if (callback) callback();
  588. this.fireEvent("resize");
  589. this.fireEvent("postRestore");
  590. if (this.maxActionNode) this.maxActionNode.setStyles(this.css.maxActionNode);
  591. }
  592. },
  593. hideIm: function(x, y, callback) {
  594. this.getSpacer();
  595. if (x){
  596. this.css.from.left = x;
  597. this.css.spacerFrom.left = x;
  598. }
  599. if (y){
  600. this.css.from.top = y;
  601. this.css.spacerFrom.top = y;
  602. }
  603. if (this.fireEvent("queryHide")){
  604. if (this.titleText) this.titleText.set("text", "");
  605. if (this.button) this.button.set("html", "");
  606. this.spacer.setStyles(this.css.spacerFrom);
  607. this.node.setStyles(this.css.from);
  608. this._markHide();
  609. this.isHide = true;
  610. this.node.setStyle("display", "none");
  611. this.spacer.setStyle("display", "none");
  612. if (callback) callback();
  613. this.fireEvent("postHide");
  614. }
  615. },
  616. hide: function(x, y, callback) {
  617. if (!this.morph){
  618. this.morph = new Fx.Morph(this.node, {duration: 100, link: "chain"});
  619. }
  620. this.morph.setOptions({duration: 100});
  621. this.getSpacer();
  622. if (!this.spacerMorph){
  623. this.spacerMorph = new Fx.Morph(this.spacer, {duration: 100, link: "chain"});
  624. }
  625. this.spacerMorph.setOptions({duration: 100});
  626. if (x){
  627. this.css.from.left = x;
  628. this.css.spacerFrom.left = x;
  629. }
  630. if (y){
  631. this.css.from.top = y;
  632. this.css.spacerFrom.top = y;
  633. }
  634. if (this.fireEvent("queryHide")){
  635. if (this.titleText) this.titleText.set("text", "");
  636. if (this.button) this.button.set("html", "");
  637. var nodeFinish = false;
  638. var spacerFinish = false;
  639. this.spacerMorph.start(this.css.spacerFrom).chain(function(){
  640. spacerFinish = true;
  641. firePost();
  642. }.bind(this));
  643. this.morph.start(this.css.from).chain(function(){
  644. nodeFinish = true;
  645. firePost();
  646. }.bind(this));
  647. var firePost = function(){
  648. if (nodeFinish && spacerFinish){
  649. this._markHide();
  650. this.isHide = true;
  651. this.node.setStyle("display", "none");
  652. this.spacer.setStyle("display", "none");
  653. if (callback) callback();
  654. this.fireEvent("postHide");
  655. }
  656. }.bind(this);
  657. }
  658. },
  659. _hideIm: function(){
  660. this.node.setStyle("display", "none");
  661. this.spacer.setStyle("display", "none");
  662. },
  663. _showIm: function(){
  664. this.node.setStyle("display", "block");
  665. this.spacer.setStyle("display", "block");
  666. },
  667. _fadeOut: function(){
  668. this.node.fade("out");
  669. this.spacer.fade("out");
  670. },
  671. _fadeIn: function(){
  672. this.node.fade("in");
  673. this.spacer.fade("in");
  674. },
  675. close: function(callback){
  676. if (!this.morph){
  677. this.morph = new Fx.Morph(this.node, {duration: 100, link: "chain"});
  678. }
  679. this.morph.setOptions({duration: 100});
  680. this.getSpacer();
  681. if (!this.spacerMorph){
  682. this.spacerMorph = new Fx.Morph(this.spacer, {duration: 100, link: "chain"});
  683. }
  684. this.spacerMorph.setOptions({duration: 100});
  685. if (this.fireEvent("queryClose")){
  686. //this.spacerMorph.start(this.css.spacerFrom).chain(function(){
  687. // this.spacer.destroy();
  688. // this.spacer = null;
  689. //}.bind(this));
  690. //
  691. //this.morph.start(this.css.from).chain(function(){
  692. // this._markHide();
  693. // this.node.destroy();
  694. // this.node = null;
  695. // if (callback) callback();
  696. // this.fireEvent("postClose");
  697. //}.bind(this));
  698. this.spacer.destroy();
  699. this.spacer = null;
  700. this._markHide();
  701. this.node.destroy();
  702. this.node = null;
  703. if (callback) callback();
  704. this.fireEvent("postClose");
  705. o2.release(this);
  706. }
  707. },
  708. getAction: function(){
  709. this.titleAction.setStyles(this.css.titleAction);
  710. var _self = this;
  711. this.closeActionNode = new Element("div", {
  712. "styles": this.css.closeActionNode,
  713. "events": {
  714. "mouseover": function(e){this.setStyles(_self.css.titleActionOver);e.stopPropagation();},
  715. "mouseout": function(e){this.setStyles(_self.css.titleActionOut);e.stopPropagation();},
  716. "mousedown": function(e){this.setStyles(_self.css.titleActionDown);e.stopPropagation();},
  717. "mouseup": function(e){this.setStyles(_self.css.titleActionOver);e.stopPropagation();},
  718. "click": function(e){
  719. this.app.close();
  720. e.stopPropagation();
  721. }.bind(this)
  722. }
  723. }).inject(this.titleAction);
  724. if (this.options.isMax!=false){
  725. this.maxActionNode = new Element("div", {
  726. "styles": this.css.maxActionNode,
  727. "events": {
  728. "mouseover": function(){this.setStyles(_self.css.titleActionOver);},
  729. "mouseout": function(){this.setStyles(_self.css.titleActionOut);},
  730. "mousedown": function(){this.setStyles(_self.css.titleActionDown);},
  731. "mouseup": function(){this.setStyles(_self.css.titleActionOver);},
  732. "click": function(){
  733. this.app.maxOrRestoreSize();
  734. }.bind(this)
  735. }
  736. }).inject(this.titleAction);
  737. }
  738. if (this.options.isResize){
  739. this.title.addEvent("dblclick", this.app.maxOrRestoreSize.bind(this.app));
  740. }
  741. this.minActionNode = new Element("div", {
  742. "styles": this.css.minActionNode,
  743. "events": {
  744. "mouseover": function(){this.setStyles(_self.css.titleActionOver);},
  745. "mouseout": function(){this.setStyles(_self.css.titleActionOut);},
  746. "mousedown": function(){this.setStyles(_self.css.titleActionDown);},
  747. "mouseup": function(){this.setStyles(_self.css.titleActionOver);},
  748. "click": function(){
  749. this.app.minSize();
  750. }.bind(this)
  751. }
  752. }).inject(this.titleAction);
  753. if (this.options.isRefresh!=false){
  754. this.titleRefresh.addEvents({
  755. "mouseover": function(){this.setStyles(_self.css.titleActionOver);},
  756. "mouseout": function(){this.setStyles(_self.css.titleActionOut);},
  757. "mousedown": function(){this.setStyles(_self.css.titleActionDown);},
  758. "mouseup": function(){this.setStyles(_self.css.titleActionOver);},
  759. "click": function(e){
  760. this.app.refresh();
  761. }.bind(this),
  762. "dblclick": function(e){
  763. e.stopPropagation();
  764. }.bind(this)
  765. });
  766. }
  767. },
  768. maxOrRestoreSize: function(callback){
  769. if (this.isMax){
  770. this.restoreSize(callback);
  771. }else{
  772. this.maxSize(callback);
  773. }
  774. },
  775. restoreSize: function(callback){
  776. this.restore(callback);
  777. },
  778. maxSize: function(callback){
  779. this.querySetMaxStyle();
  780. if (!this.morph){
  781. this.morph = new Fx.Morph(this.node, {duration: 50, link: "chain"});
  782. }
  783. this.morph.setOptions({duration: 50});
  784. this.getSpacer();
  785. if (!this.spacerMorph){
  786. this.spacerMorph = new Fx.Morph(this.spacer, {duration: 50, link: "chain"});
  787. }
  788. this.spacerMorph.setOptions({duration: 50});
  789. if (!this.contentMorph){
  790. this.contentMorph = new Fx.Morph(this.content, {duration: 50, link: "chain"});
  791. }
  792. this.contentMorph.setOptions({duration: 50});
  793. this.spacer.setStyle("display", "block");
  794. this.node.setStyle("display", "block");
  795. var size = this.getMaxSize();
  796. var spacerTo = Object.clone(this.css.spacerTo);
  797. var to = Object.clone(this.css.to);
  798. var contentTo = {};
  799. spacerTo.top = size.position.y;
  800. spacerTo.left = size.position.x;
  801. spacerTo.width = size.spacer.x;
  802. spacerTo.height = size.spacer.y;
  803. to.top = size.position.y;
  804. to.left = size.position.x;
  805. to.width = size.node.x;
  806. to.height = size.node.y;
  807. contentTo = size.contentSize;
  808. if (this.fireEvent("queryMax")){
  809. var nodeFinish = false;
  810. var spacerFinish = false;
  811. var contentFinish = false;
  812. this.spacerMorph.start(spacerTo).chain(function(){
  813. if (this.app.desktop.currentApp!=this.app) this.spacer.setStyles(this.css.spacerUncurrent);
  814. spacerFinish = true;
  815. firePost();
  816. }.bind(this));
  817. this.contentMorph.start(contentTo).chain(function(){
  818. contentFinish = true;
  819. firePost();
  820. }.bind(this));
  821. this.morph.start(to).chain(function(){
  822. if (this.app.desktop.currentApp!=this.app) this.node.setStyles(this.css.uncurrent);
  823. nodeFinish = true;
  824. firePost();
  825. }.bind(this));
  826. var firePost = function(){
  827. if (nodeFinish && spacerFinish && contentFinish){
  828. if (this.titleText) this.getTitle();
  829. this.isMax = true;
  830. this.isHide = false;
  831. if (this.containerDrag) this.containerDrag.detach();
  832. this.postSetMaxStyle();
  833. if (callback) callback();
  834. this.fireEvent("resize");
  835. this.fireEvent("postMax");
  836. }
  837. }.bind(this);
  838. if (this.maxActionNode) this.maxActionNode.setStyles(this.css.restoreActionNode);
  839. }
  840. },
  841. querySetMaxStyle: function(){
  842. if (this.css.windowTitleMax) this.title.setStyles(this.css.windowTitleMax);
  843. if (this.css.windowTitleRefreshMax) this.titleRefresh.setStyles(this.css.windowTitleRefreshMax);
  844. if (this.css.windowTitleTextMax) this.titleText.setStyles(this.css.windowTitleTextMax);
  845. if (this.css.windowTitleActionMax) this.titleAction.setStyles(this.css.windowTitleActionMax);
  846. if (this.closeActionNode){
  847. if (this.css.windowActionNodeMax) this.closeActionNode.setStyles(this.css.windowActionNodeMax);
  848. }
  849. if (this.maxActionNode){
  850. if (this.css.windowActionNodeMax) this.maxActionNode.setStyles(this.css.windowActionNodeMax);
  851. }
  852. if (this.minActionNode){
  853. if (this.css.windowActionNodeMax) this.minActionNode.setStyles(this.css.windowActionNodeMax);
  854. }
  855. },
  856. postSetMaxStyle: function(){
  857. if (this.css.windowNodeMax) this.node.setStyles(this.css.windowNodeMax);
  858. },
  859. maxSizeIm: function(callback){
  860. this.querySetMaxStyle();
  861. this.getSpacer();
  862. this.spacer.setStyle("display", "block");
  863. this.node.setStyle("display", "block");
  864. var size = this.getMaxSize();
  865. var spacerTo = Object.clone(this.css.spacerTo);
  866. var to = Object.clone(this.css.to);
  867. var contentTo = {};
  868. spacerTo.top = size.position.y;
  869. spacerTo.left = size.position.x;
  870. spacerTo.width = size.spacer.x;
  871. spacerTo.height = size.spacer.y;
  872. to.top = size.position.y;
  873. to.left = size.position.x;
  874. to.width = size.node.x;
  875. to.height = size.node.y;
  876. contentTo = size.contentSize;
  877. if (this.fireEvent("queryMax")){
  878. this.node.setStyles(to);
  879. this.spacer.setStyles(spacerTo);
  880. this.content.setStyles(contentTo);
  881. if (this.titleText) this.getTitle();
  882. this.isMax = true;
  883. this.isHide = false;
  884. if (this.containerDrag) this.containerDrag.detach();
  885. this.postSetMaxStyle();
  886. if (callback) callback();
  887. this.fireEvent("resize");
  888. this.fireEvent("postMax");
  889. if (this.maxActionNode) this.maxActionNode.setStyles(this.css.restoreActionNode);
  890. }
  891. },
  892. getMaxSize: function(){
  893. var size = layout.desktop.desktopNode.getSize();
  894. var position = layout.desktop.desktopNode.getPosition();
  895. var pt = this.spacer.getStyle("padding-top").toFloat();
  896. var pb = this.spacer.getStyle("padding-bottom").toFloat();
  897. var pl = this.spacer.getStyle("padding-left").toFloat();
  898. var pr = this.spacer.getStyle("padding-right").toFloat();
  899. spacerHeight = size.y-pt-pb;
  900. spacerWidth = size.x-pl-pr;
  901. pt = this.node.getStyle("padding-top").toFloat();
  902. pb = this.node.getStyle("padding-bottom").toFloat();
  903. pl = this.node.getStyle("padding-left").toFloat();
  904. pr = this.node.getStyle("padding-right").toFloat();
  905. nodeHeight = size.y-pt-pb;
  906. nodeWidth = size.x-pl-pr;
  907. var contentSize = this.getContentSize(nodeHeight, nodeWidth);
  908. return {"node": {"x": nodeWidth, "y": nodeHeight}, "spacer": {"x": spacerWidth, "y": spacerHeight}, "position": {"x": position.x, "y": position.y}, "contentSize": contentSize};
  909. }
  910. });
  911. MWF.xDesktop.WindowTransparent = new Class({
  912. Implements: [Options, Events],
  913. options: {
  914. "style": "default"
  915. },
  916. initialize: function(app, options){
  917. this.setOptions(options);
  918. var position = layout.desktop.desktopNode.getPosition();
  919. this.app = app;
  920. this.fireEvent("queryLoad");
  921. this.isMax = false;
  922. this.isHide = false;
  923. this.css = {
  924. "to": {"width": "0", "height": "0", "left": "0", "top": "0"}
  925. };
  926. var index = null;
  927. if (MWF.xDesktop.zIndexPool) index = MWF.xDesktop.zIndexPool.applyZindex();
  928. this.node = new Element("div", {
  929. "styles":{
  930. "width": "0px",
  931. "height": "0px",
  932. "top": "0px",
  933. "left": "0px",
  934. "position": "absolute",
  935. "z-index": (index)? index : 100
  936. }
  937. }).inject(this.options.container || $(document.body));
  938. this.content = new Element("div", {
  939. "styles": {"width": "100%", "height": "100%"}
  940. }).inject(this.node);
  941. this.fireEvent("postLoad");
  942. },
  943. show: function(){
  944. this.fireEvent("queryShow");
  945. this.node.setStyle("display", "block");
  946. this.isHide = false;
  947. this.fireEvent("postShow");
  948. },
  949. hide: function(){
  950. this.fireEvent("queryHide");
  951. this.node.setStyle("display", "none");
  952. this.isHide = true;
  953. this.fireEvent("postHide");
  954. },
  955. restore: function(callback) {
  956. this.fireEvent("queryRestore");
  957. this.node.setStyle("display", "block");
  958. this.isHide = false;
  959. this.fireEvent("postRestore");
  960. if (callback) callback();
  961. },
  962. restoreSize: function(callback){
  963. this.restore(callback);
  964. },
  965. close: function(callback){
  966. this.fireEvent("queryClose");
  967. this.node.destroy();
  968. this.node = null;
  969. this.content = null;
  970. delete this;
  971. if (callback) callback();
  972. this.fireEvent("postClose");
  973. },
  974. maxOrRestoreSize: function(callback){
  975. if (this.isMax){
  976. this.restoreSize(callback);
  977. }else{
  978. this.maxSize(callback);
  979. }
  980. },
  981. maxSize: function(callback){
  982. this.fireEvent("queryMax");
  983. this.node.setStyle("display", "block");
  984. this.isHide = false;
  985. this.fireEvent("resize");
  986. this.fireEvent("postMax");
  987. if (callback) callback();
  988. },
  989. restoreIm: function(){
  990. this.restore();
  991. },
  992. maxSizeIm: function(){
  993. this.maxSize();
  994. },
  995. setCurrent: function(){
  996. if (MWF.xDesktop.zIndexPool){
  997. var index = this.node.getStyle("z-index").toFloat()+1;
  998. if (index < MWF.xDesktop.zIndexPool.zIndex){
  999. var newIndex = MWF.xDesktop.zIndexPool.applyZindex();
  1000. this.node.setStyle("z-index", newIndex);
  1001. }
  1002. }
  1003. },
  1004. _fadeOut: function(){
  1005. this.node.fade("out");
  1006. if (this.spacer) this.spacer.fade("out");
  1007. },
  1008. _fadeIn: function(){
  1009. this.node.fade("in");
  1010. if (this.spacer) this.spacer.fade("in");
  1011. },
  1012. setUncurrent: function(){},
  1013. reStyle: function(){},
  1014. changeStyle: function(){}
  1015. });