Dialog.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. o2.require("MWF.widget.Dialog", null, false);
  2. o2.xDesktop.Dialog = o2.DDL = new Class({
  3. Extends: o2.widget.Dialog,
  4. options : {
  5. maxHeightPercent : "98%"
  6. },
  7. // _markShow: function(){
  8. //
  9. // if (this.options.mark){
  10. // if (!this.markNode){
  11. //
  12. // this.markNode = new Element("div", {
  13. // styles: this.css.mark
  14. // }).inject($(document.body));
  15. //
  16. // }
  17. //// if (this.options.markNode){
  18. //// var size = this.options.markNode.getComputedSize();
  19. //// var position = this.options.markNode.getPosition();
  20. //// alert(size.totalHeight);
  21. //// this.markNode.set("styles", {
  22. //// "height": size.totalHeight+"px",
  23. //// "width": size.totalWidth+"px",
  24. //// "top": position.y,
  25. //// "height": position.x
  26. //// });
  27. ////
  28. //// }else{
  29. // var size = MWF.getMarkSize();
  30. // this.markNode.set("styles", {
  31. // "height": size.y,
  32. // "width": size.x,
  33. // "top": "0xp",
  34. // "height": "0px"
  35. // });
  36. //// }
  37. //
  38. // this.markNode.setStyle("display", "block");
  39. // }
  40. // },
  41. _markShow: function(){
  42. if (this.options.mark){
  43. if (!this.markNode){
  44. var size = MWF.getMarkSize(this.options.maskNode);
  45. var topNode = this.options.container || $(document.body);
  46. this.markNode = new Element("iframe", {
  47. styles: this.css.mark
  48. }).inject(topNode);
  49. this.markNode.set("styles", {
  50. "height": size.y,
  51. "width": size.x
  52. });
  53. if (!this.markNode_up) this.markNode_up = new Element("div", { styles: this.css.mark }).inject(topNode);
  54. this.markNode_up.set("styles", {
  55. "height": size.y,
  56. "width": size.x
  57. });
  58. }
  59. this.markNode.setStyle("display", "block");
  60. }
  61. },
  62. getDialogNode: function(){
  63. this.width = this.options.width;
  64. this.height = this.options.height;
  65. this.node.set("styles", this.css.from);
  66. var topNode = this.options.container || $(document.body);
  67. this.node.inject(topNode);
  68. // this.node.addEvent("selectstart", function(e){
  69. // // e.preventDefault();
  70. // });
  71. this.title = this.node.getElement(".MWF_dialod_title");
  72. this.titleCenter = this.node.getElement(".MWF_dialod_title_center");
  73. this.titleText = this.node.getElement(".MWF_dialod_title_text");
  74. this.titleAction = this.node.getElement(".MWF_dialod_title_action");
  75. this.content = this.node.getElement(".MWF_dialod_content");
  76. this.bottom = this.node.getElement(".MWF_dialod_bottom");
  77. this.resizeNode = this.node.getElement(".MWF_dialod_bottom_resize");
  78. this.button = this.node.getElement(".MWF_dialod_button");
  79. if( (!this.options.buttonList || this.options.buttonList.length === 0) && ( !this.options.buttons ) ){
  80. this.button.setStyle("display","none");
  81. this.buttonDisable = true;
  82. }else{
  83. this.okButton = this.node.getElement(".MWF_dialod_ok_button");
  84. this.cancelButton = this.node.getElement(".MWF_dialod_cancel_button");
  85. }
  86. this.backAction = this.node.getElement(".MWF_dialod_Action_back");
  87. if (!this.options.isTitle) {
  88. this.title.destroy();
  89. this.title = null;
  90. this.titleCenter = null;
  91. this.titleRefresh = null;
  92. this.titleText = null;
  93. this.titleAction = null;
  94. }
  95. if (this.title) this.setTitleEvent();
  96. // if (this.titleText) this.getTitle();
  97. if (this.content) this.getContent();
  98. if (this.titleAction) this.getAction();
  99. if (this.resizeNode) this.setResizeNode();
  100. // if (this.button) this.getButton();
  101. if (this.content) this.setContentSize();
  102. if (this.backAction)this.backAction.addEvent("click", this.close.bind(this))
  103. },
  104. getButton: function(){
  105. for (i in this.options.buttons){
  106. var button = new Element("input", {
  107. "type": "button",
  108. "value": i,
  109. "styles": this.css.button,
  110. "events": {
  111. "click": this.options.buttons[i].bind(this)
  112. }
  113. }).inject(this.button);
  114. }
  115. if (this.options.buttonList){
  116. this.options.buttonList.each(function(bt){
  117. var styles = this.css.button;
  118. if( bt.type === "ok" && this.css.okButton )styles = this.css.okButton;
  119. if( bt.type === "cancel" && this.css.cancelButton )styles = this.css.cancelButton;
  120. if( bt.styles )styles = bt.styles;
  121. var button;
  122. if( bt.type === "ok" && this.okButton ){
  123. button = this.okButton;
  124. button.show();
  125. }else if( bt.type === "cancel" && this.cancelButton ){
  126. button = this.cancelButton;
  127. button.show();
  128. }else{
  129. button = new Element("input", {
  130. "type": "button"
  131. }).inject(this.button);
  132. }
  133. button.set({
  134. "value": bt.text,
  135. "styles": styles,
  136. "events": {
  137. "click": function(e){bt.action.call(this, this, e)}.bind(this)
  138. }
  139. })
  140. }.bind(this));
  141. }
  142. },
  143. setTitleEvent: function(){
  144. var content;
  145. if( this.options.isMove ){
  146. if (layout.app) content = layout.app.content;
  147. if (layout.desktop.currentApp) content = layout.desktop.currentApp.content;
  148. this.containerDrag = new Drag.Move(this.node, {
  149. "handle": this.title,
  150. "container": this.options.container || this.markNode || content,
  151. "snap": 5
  152. });
  153. }
  154. },
  155. getAction: function(){
  156. //未完成................................
  157. if (this.options.isClose){
  158. this.closeAction = new Element("div", {"styles": this.css.closeAction}).inject(this.titleAction);
  159. this.closeAction.addEvent("click", this.close.bind(this));
  160. }
  161. if (this.options.isMax){
  162. this.maxAction = new Element("div", {"styles": this.css.maxAction}).inject(this.titleAction);
  163. this.maxAction.addEvent("click", this.maxSize.bind(this));
  164. this.restoreAction = new Element("div", {"styles": this.css.restoreAction}).inject(this.titleAction);
  165. this.restoreAction.hide();
  166. this.restoreAction.addEvent("click", this.restoreSize.bind(this));
  167. if (this.title){
  168. this.title.addEvent("dblclick", function(){
  169. this.switchMax();
  170. }.bind(this));
  171. }
  172. }
  173. },
  174. switchMax : function(){
  175. if( !this.isMax ){
  176. this.maxSize();
  177. }else{
  178. this.restoreSize();
  179. }
  180. },
  181. maxSize: function(){
  182. //if(!this.oldCoordinate)this.oldCoordinate = {
  183. // height : this.options.height,
  184. // width : this.options.width,
  185. // top : this.options.top,
  186. // left : this.options.left,
  187. // fromTop : this.options.fromTop,
  188. // fromLeft : this.options.fromLeft,
  189. // contentHeight : this.options.contentHeight,
  190. // contentWidth : this.options.contentWidth,
  191. // maxHeightPercent : this.options.maxHeightPercent,
  192. // maxHeight : this.options.maxHeight,
  193. // maxWidth : this.options.maxWidth
  194. //};
  195. //if( !this.oldSize ){
  196. // this.oldSize = {
  197. // "width" : this.width,
  198. // "height" : this.height
  199. // }
  200. //}
  201. if( !this.oldNodeSize ){
  202. this.oldNodeSize = {
  203. "width" : this.nodeWidth,
  204. "height" : this.nodeHeight
  205. }
  206. }
  207. if( !this.oldContentSize ){
  208. this.oldContentSize = {
  209. "width" : this.contentWidth,
  210. "height" : this.contentHeight
  211. }
  212. }
  213. //this.options.top = 0;
  214. //this.options.left = 0;
  215. //this.options.fromTop = 0;
  216. //this.options.fromLeft = 0;
  217. //this.options.contentHeight = 0;
  218. //this.options.contentWidth = 0;
  219. //this.options.maxHeightPercent = null;
  220. //this.options.maxHeight = null;
  221. //this.options.maxWidth = null;
  222. //this.height = null;
  223. //this.width = null;
  224. var container = $(document.body);
  225. if (layout.desktop.currentApp){
  226. container = layout.desktop.currentApp.content;
  227. }else if (this.options.container){
  228. if (this.options.container.getSize().y<$(document.body).getSize().y){
  229. container = this.options.container;
  230. }
  231. }
  232. var containerSize = container.getSize();
  233. this.options.width = containerSize.x;
  234. this.options.height = containerSize.y;
  235. this.setContentSize( containerSize.y, containerSize.x );
  236. this.node.setStyles({
  237. width : containerSize.x + "px",
  238. height : containerSize.y + "px",
  239. top : "0px",
  240. left : "0px"
  241. });
  242. this.maxAction.setStyle("display","none");
  243. this.restoreAction.setStyle("display","");
  244. this.isMax = true;
  245. this.fireEvent("max");
  246. },
  247. restoreSize : function(){
  248. //if( this.oldCoordinate){
  249. // this.options.height = this.oldCoordinate.height;
  250. // this.options.width = this.oldCoordinate.width;
  251. // this.options.top = this.oldCoordinate.top;
  252. // this.options.left = this.oldCoordinate.left;
  253. // this.options.fromTop = this.oldCoordinate.fromTop;
  254. // this.options.fromLeft = this.oldCoordinate.fromLeft;
  255. // this.options.contentHeight = this.oldCoordinate.contentHeight;
  256. // this.options.contentWidth = this.oldCoordinate.contentWidth;
  257. // this.options.maxHeightPercent = this.oldCoordinate.maxHeightPercent;
  258. // this.options.maxHeight = this.oldCoordinate.maxHeight;
  259. // this.options.maxWidth = this.oldCoordinate.maxWidth;
  260. //}
  261. //
  262. //if( this.oldSize ){
  263. // this.width = this.oldSize.width;
  264. // this.height = this.oldSize.height;
  265. //}
  266. //this.setContentSize( this.oldNodeSize.height, this.oldNodeSize.width );
  267. //this.node.setStyles( this.getNodeSize() );
  268. this.contentHeight = this.oldContentSize.height;
  269. this.contentWidth = this.oldContentSize.width;
  270. this.nodeHeight = this.oldNodeSize.height;
  271. this.nodeWidth = this.oldNodeSize.width;
  272. this.content.setStyles( this.oldContentSize );
  273. this.node.setStyles( this.oldNodeSize );
  274. this.reCenter();
  275. this.maxAction.setStyle("display","");
  276. this.restoreAction.setStyle("display","none");
  277. this.isMax = false;
  278. this.fireEvent("restore");
  279. },
  280. reCenter: function(){
  281. var size = this.node.getSize();
  282. if( this.options.positionWidth ){
  283. size.x = parseInt(this.options.positionWidth);
  284. }
  285. if( this.options.positionHeight ){
  286. size.y = parseInt(this.options.positionHeight);
  287. }
  288. var container = $(document.body);
  289. if( this.options.positionNode && this.options.positionNode.getSize().y<$(document.body).getSize().y ){
  290. container = this.options.positionNode;
  291. }else if (layout.desktop.currentApp){
  292. container = layout.desktop.currentApp.content;
  293. }else{
  294. if (this.options.container){
  295. if (this.options.container.getSize().y<$(document.body).getSize().y){
  296. container = this.options.container;
  297. }
  298. }
  299. }
  300. var p = o2.getCenter(size, container, container);
  301. if (p.y< ( this.options.minTop || 0 ) ) p.y = this.options.minTop || 0;
  302. this.options.top = p.y;
  303. this.options.left = p.x;
  304. this.css.to.top = this.options.top+"px";
  305. this.css.to.left = this.options.left+"px";
  306. this.node.setStyles({
  307. "top": this.css.to.top,
  308. "left": this.css.to.left
  309. });
  310. },
  311. getOffsetY : function(node){
  312. return (node.getStyle("margin-top").toInt() || 0 ) +
  313. (node.getStyle("margin-bottom").toInt() || 0 ) +
  314. (node.getStyle("padding-top").toInt() || 0 ) +
  315. (node.getStyle("padding-bottom").toInt() || 0 )+
  316. (node.getStyle("border-top-width").toInt() || 0 ) +
  317. (node.getStyle("border-bottom-width").toInt() || 0 );
  318. },
  319. getOffsetX : function(node){
  320. return (node.getStyle("margin-left").toInt() || 0 ) +
  321. (node.getStyle("margin-right").toInt() || 0 ) +
  322. (node.getStyle("padding-left").toInt() || 0 ) +
  323. (node.getStyle("padding-right").toInt() || 0 )+
  324. (node.getStyle("border-left-width").toInt() || 0 ) +
  325. (node.getStyle("border-right-width").toInt() || 0 );
  326. },
  327. setContentHeightAuto : function(){
  328. var maxHeight = this.getMaxHeight();
  329. var offsetY = 0;
  330. var y = 0;
  331. //y = y + getOffsetY( this.title ) + this.title.getSize().y; //this.titleNode.getStyle("height").toInt();
  332. if( this.title )offsetY = offsetY + this.getOffsetY( this.title ) + this.title.getSize().y;
  333. if( this.bottom )offsetY = offsetY + this.getOffsetY( this.bottom ) + this.bottom.getSize().y;
  334. if( this.button && !this.buttonDisable )offsetY = offsetY + this.getOffsetY( this.button ) + this.button.getSize().y;
  335. if( this.content ){
  336. offsetY = offsetY + this.getOffsetY( this.content );
  337. y = offsetY + this.content.getSize().y;
  338. }else{
  339. y = offsetY;
  340. }
  341. if ( typeOf(maxHeight) === "number" && y > maxHeight) {
  342. this.options.height = maxHeight;
  343. this.options.contentHeight = null;
  344. this.options.fromTop = this.options.fromTop.toFloat() - offsetY / 2;
  345. this.options.top = this.options.top.toFloat() - offsetY / 2;
  346. this.css.to.height = maxHeight + "px";
  347. this.css.to.top = this.options.top + "px";
  348. this.css.from.top = this.options.fromTop + "px";
  349. this.node.setStyles({
  350. "height": maxHeight
  351. });
  352. this.contentHeight = maxHeight - offsetY;
  353. if (this.content) {
  354. this.content.setStyles({
  355. "height" : maxHeight - offsetY,
  356. "overflow-y": "auto"
  357. })
  358. }
  359. }else{
  360. this.options.height = y;
  361. this.options.contentHeight = null;
  362. this.options.fromTop = this.options.fromTop.toFloat() - offsetY / 2;
  363. this.options.top = this.options.top.toFloat() - offsetY / 2;
  364. this.css.to.height = y + "px";
  365. this.css.to.top = this.options.top + "px";
  366. this.css.from.top = this.options.fromTop + "px";
  367. this.node.setStyles({
  368. "height": y
  369. });
  370. this.contentHeight = y - offsetY;
  371. if (this.content) {
  372. this.content.setStyles({
  373. "height" : y - offsetY,
  374. "overflow-y": "hidden"
  375. })
  376. }
  377. }
  378. },
  379. getMaxHeight : function(){
  380. var maxHeightPercent;
  381. if( this.options.maxHeightPercent ){
  382. maxHeightPercent = this.options.maxHeightPercent;
  383. if( typeOf(maxHeightPercent) === "string" && maxHeightPercent.substr(maxHeightPercent.length - 1, 1) === "%" ) {
  384. var containerHeight = ( this.options.positionNode || this.options.container || $(document.body)).getSize().y;
  385. maxHeightPercent = parseInt(containerHeight * parseInt(maxHeightPercent) / 100);
  386. }
  387. }
  388. var maxHeight;
  389. if( this.options.maxHeight && parseFloat( this.options.maxHeight ).toString() !== "NaN" ){
  390. maxHeight = parseFloat( this.options.maxHeight );
  391. if( typeOf(maxHeightPercent) === "number" ){
  392. maxHeight = Math.min( maxHeight, maxHeightPercent )
  393. }
  394. }else if( typeOf(maxHeightPercent) === "number" ){
  395. maxHeight = maxHeightPercent;
  396. }
  397. return maxHeight;
  398. },
  399. getNodeSize: function(){
  400. return {
  401. "height": this.nodeHeight+"px",
  402. "width": this.nodeWidth+"px"
  403. };
  404. },
  405. getContentSize: function(height, width){
  406. var nodeHeight, nodeWidth;
  407. if (!height){
  408. if (this.options.contentHeight){
  409. nodeHeight = height = this.options.contentHeight.toFloat();
  410. this.contentHeight = height;
  411. }else{
  412. height = this.options.height.toFloat();
  413. var maxHeight = this.getMaxHeight();
  414. if( typeOf(maxHeight) === "number" && maxHeight < height ){
  415. height = maxHeight;
  416. }
  417. this.nodeHeight = height;
  418. }
  419. }else{
  420. this.nodeHeight = height;
  421. }
  422. if (!width){
  423. if (this.options.contentWidth){
  424. nodeWidth = width = this.options.contentWidth.toFloat();
  425. this.contentWidth = width;
  426. }else{
  427. width = this.options.width.toFloat();
  428. this.nodeWidth = width;
  429. }
  430. }else{
  431. this.nodeWidth = width;
  432. }
  433. var offsetHeight = 0;
  434. var offsetWidth = 0;
  435. if (this.title){
  436. var h1 = this.title.getSize().y;
  437. var ptop1 = this.title.getStyle("padding-top").toFloat();
  438. var pbottom1 = this.title.getStyle("padding-bottom").toFloat();
  439. var mtop1 = this.title.getStyle("margin-top").toFloat();
  440. var mbottom1 = this.title.getStyle("margin-bottom").toFloat();
  441. offsetHeight += h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
  442. }
  443. if (this.bottom){
  444. var h2 = this.bottom.getSize().y;
  445. var ptop2 = this.bottom.getStyle("padding-top").toFloat();
  446. var pbottom2 = this.bottom.getStyle("padding-bottom").toFloat();
  447. var mtop2 = this.bottom.getStyle("margin-top").toFloat();
  448. var mbottom2 = this.bottom.getStyle("margin-bottom").toFloat();
  449. offsetHeight += h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
  450. }
  451. if (this.button && !this.buttonDisable){
  452. var h3 = this.button.getSize().y;
  453. var ptop3 = this.button.getStyle("padding-top").toFloat();
  454. var pbottom3 = this.button.getStyle("padding-bottom").toFloat();
  455. var mtop3 = this.button.getStyle("margin-top").toFloat();
  456. var mbottom3 = this.button.getStyle("margin-bottom").toFloat();
  457. offsetHeight += h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
  458. }
  459. var ptop4 = this.content.getStyle("padding-top").toFloat();
  460. var pbottom4 = this.content.getStyle("padding-bottom").toFloat();
  461. var mtop4 = this.content.getStyle("margin-top").toFloat();
  462. var mbottom4 = this.content.getStyle("margin-bottom").toFloat();
  463. offsetHeight += ptop4 + pbottom4 + mtop4 + mbottom4;
  464. if (nodeHeight){
  465. nodeHeight = nodeHeight + offsetHeight+2;
  466. }else {
  467. height = height - offsetHeight;
  468. }
  469. //if (this.content.getParent().getStyle("overflow-x")!="hidden" ) height = height-18;
  470. var pleft = this.content.getStyle("padding-left").toFloat();
  471. var pright = this.content.getStyle("padding-right").toFloat();
  472. var mleft = this.content.getStyle("margin-left").toFloat();
  473. var mright = this.content.getStyle("margin-right").toFloat();
  474. offsetWidth = pleft+pright+mleft+mright;
  475. //width = width-pleft-pright-mleft-mright;
  476. //if (this.content.getParent().getStyle("overflow-y")!="hidden" ) width = width-18;
  477. if (nodeWidth){
  478. nodeWidth = nodeWidth+offsetWidth;
  479. }else{
  480. width = width-offsetWidth;
  481. }
  482. if (nodeHeight) {
  483. this.nodeHeight = nodeHeight;
  484. this.options.height = nodeHeight;
  485. this.options.contentHeight = null;
  486. this.options.fromTop = this.options.fromTop.toFloat()-offsetHeight/2;
  487. this.options.top = this.options.top.toFloat()-offsetHeight/2;
  488. this.css.to.height = nodeHeight+"px";
  489. this.css.to.top = this.options.top+"px";
  490. this.css.from.top = this.options.fromTop+"px";
  491. }else{
  492. this.contentHeight = height;
  493. }
  494. if (nodeWidth){
  495. this.nodeWidth = nodeWidth;
  496. this.options.width = nodeWidth;
  497. this.options.contentWidth = null;
  498. this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
  499. this.options.left = this.options.left.toFloat()-offsetWidth/2;
  500. this.css.to.width = nodeWidth+"px";
  501. this.css.to.left = this.options.left+"px";
  502. this.css.from.left = this.options.fromLeft+"px";
  503. }else{
  504. this.contentWidth = width;
  505. }
  506. if (!height || height<0){
  507. this.content.setStyles({"overflow": "hidden", "height": "auto", "width": ""+width+"px"});
  508. height = this.content.getSize().y;
  509. var h = height + h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
  510. h = h + h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
  511. h = h + h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
  512. h = h + ptop4 + pbottom4 + mtop4 + mbottom4;
  513. this.css.to.height = h;
  514. }
  515. // var ptop5 = this.node.getStyle("padding-top").toFloat();
  516. // var pbottom5 = this.node.getStyle("padding-bottom").toFloat();
  517. // height = height - ptop5 - pbottom5;
  518. return {"height": height+"px", "width": width+"px"};
  519. },
  520. setContentHeight: function(height){
  521. var nodeHeight;
  522. if (!height){
  523. if (this.options.contentHeight){
  524. nodeHeight = height = this.options.contentHeight.toFloat();
  525. this.contentHeight = height;
  526. }else{
  527. height = this.options.height.toFloat();
  528. var maxHeight = this.getMaxHeight();
  529. if( typeOf(maxHeight) === "number" && maxHeight < height ){
  530. height = maxHeight;
  531. }
  532. this.nodeHeight = height;
  533. }
  534. }else{
  535. this.nodeHeight = height;
  536. }
  537. var offsetHeight = 0;
  538. if (this.title){
  539. var h1 = this.title.getSize().y;
  540. //offsetHeight += h1 + this.getOffsetY(this.title);
  541. var ptop1 = this.title.getStyle("padding-top").toFloat();
  542. var pbottom1 = this.title.getStyle("padding-bottom").toFloat();
  543. var mtop1 = this.title.getStyle("margin-top").toFloat();
  544. var mbottom1 = this.title.getStyle("margin-bottom").toFloat();
  545. offsetHeight += h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
  546. }
  547. if (this.bottom){
  548. var h2 = this.bottom.getSize().y;
  549. //offsetHeight += h2 + this.getOffsetY(this.bottom);
  550. var ptop2 = this.bottom.getStyle("padding-top").toFloat();
  551. var pbottom2 = this.bottom.getStyle("padding-bottom").toFloat();
  552. var mtop2 = this.bottom.getStyle("margin-top").toFloat();
  553. var mbottom2 = this.bottom.getStyle("margin-bottom").toFloat();
  554. offsetHeight += h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
  555. }
  556. if (this.button && !this.buttonDisable){
  557. var h3 = this.button.getSize().y;
  558. //offsetHeight += h3 + this.getOffsetY(this.button);
  559. var ptop3 = this.button.getStyle("padding-top").toFloat();
  560. var pbottom3 = this.button.getStyle("padding-bottom").toFloat();
  561. var mtop3 = this.button.getStyle("margin-top").toFloat();
  562. var mbottom3 = this.button.getStyle("margin-bottom").toFloat();
  563. offsetHeight += h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
  564. }
  565. //offsetHeight += this.getOffsetY(this.content);
  566. var ptop4 = this.content.getStyle("padding-top").toFloat();
  567. var pbottom4 = this.content.getStyle("padding-bottom").toFloat();
  568. var mtop4 = this.content.getStyle("margin-top").toFloat();
  569. var mbottom4 = this.content.getStyle("margin-bottom").toFloat();
  570. offsetHeight += ptop4 + pbottom4 + mtop4 + mbottom4;
  571. if (nodeHeight){
  572. nodeHeight = nodeHeight + offsetHeight+2;
  573. }else {
  574. height = height - offsetHeight;
  575. }
  576. if (nodeHeight) {
  577. this.nodeHeight = nodeHeight;
  578. this.options.height = nodeHeight;
  579. this.options.contentHeight = null;
  580. this.options.fromTop = this.options.fromTop.toFloat()-offsetHeight/2;
  581. this.options.top = this.options.top.toFloat()-offsetHeight/2;
  582. this.css.to.height = nodeHeight+"px";
  583. this.css.to.top = this.options.top+"px";
  584. this.css.from.top = this.options.fromTop+"px";
  585. }else{
  586. this.contentHeight = height;
  587. }
  588. //if (nodeWidth){
  589. // this.nodeWidth = nodeWidth;
  590. // this.options.width = nodeWidth;
  591. // this.options.contentWidth = null;
  592. // this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
  593. // this.options.left = this.options.left.toFloat()-offsetWidth/2;
  594. // this.css.to.width = nodeWidth+"px";
  595. // this.css.to.left = this.options.left+"px";
  596. // this.css.from.left = this.options.fromLeft+"px";
  597. //}else{
  598. // this.contentWidth = width;
  599. //}
  600. if (!height || height<0){
  601. this.content.setStyles({"overflow": "hidden", "height": "auto"});
  602. height = this.content.getSize().y;
  603. var h = height + h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
  604. h = h + h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
  605. h = h + h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
  606. h = h + ptop4 + pbottom4 + mtop4 + mbottom4;
  607. this.css.to.height = h;
  608. }else{
  609. this.content.setStyles( {"height" : height} )
  610. }
  611. },
  612. setContentWidthAuto : function(){
  613. var maxWidth = this.options.maxWidth || "100%";
  614. if( typeOf(maxWidth) === "string" && maxWidth.substr(maxWidth.length - 1, 1) === "%" ) {
  615. var containerWidth = ( this.options.positionNode || this.options.container || $(document.body)).getSize().x;
  616. maxWidth = parseInt(containerWidth * parseInt(maxWidth) / 100);
  617. }
  618. var offsetX = 0;
  619. var x = 0;
  620. if( this.content ){
  621. offsetX = offsetX + this.getOffsetX( this.content );
  622. x = offsetX + this.content.getSize().x;
  623. }else{
  624. x = offsetX;
  625. }
  626. if ( x > maxWidth) {
  627. this.nodeWidth = maxWidth;
  628. this.options.width = maxWidth;
  629. this.options.contentWidth = null;
  630. this.options.fromLeft = this.options.fromLeft.toFloat() - offsetX / 2;
  631. this.options.left = this.options.left.toFloat() - offsetX / 2;
  632. this.css.to.width = maxWidth + "px";
  633. this.css.to.left = this.options.left + "px";
  634. this.css.from.left = this.options.fromLeft + "px";
  635. this.node.setStyles({
  636. "width": maxWidth
  637. });
  638. this.contentWidth = maxWidth - offsetX;
  639. if (this.content) {
  640. this.content.setStyles({
  641. "width" : maxWidth - offsetX,
  642. "overflow-x": "auto"
  643. })
  644. }
  645. }else{
  646. this.nodeWidth = x;
  647. this.options.width = x;
  648. this.options.contentHeight = null;
  649. this.options.fromLeft = this.options.fromLeft.toFloat() - offsetX / 2;
  650. this.options.left = this.options.left.toFloat() - offsetX / 2;
  651. this.css.to.width = x + "px";
  652. this.css.to.left = this.options.left + "px";
  653. this.css.from.left = this.options.fromLeft + "px";
  654. this.node.setStyles({
  655. "width": x
  656. });
  657. this.contentWidth = x - offsetX;
  658. if (this.content) {
  659. this.content.setStyles({
  660. "width" : x - offsetX,
  661. "overflow-x": "hidden"
  662. })
  663. }
  664. }
  665. },
  666. setContentWidth: function(width){
  667. var nodeWidth;
  668. if (!width){
  669. if (this.options.contentWidth){
  670. nodeWidth = width = this.options.contentWidth.toFloat();
  671. this.contentWidth = width;
  672. }else{
  673. width = this.options.width.toFloat();
  674. this.nodeWidth = width;
  675. }
  676. }else{
  677. this.nodeWidth = width;
  678. }
  679. var offsetWidth = 0;
  680. //if (this.content.getParent().getStyle("overflow-x")!="hidden" ) height = height-18;
  681. var pleft = this.content.getStyle("padding-left").toFloat();
  682. var pright = this.content.getStyle("padding-right").toFloat();
  683. var mleft = this.content.getStyle("margin-left").toFloat();
  684. var mright = this.content.getStyle("margin-right").toFloat();
  685. offsetWidth = pleft+pright+mleft+mright;
  686. //width = width-pleft-pright-mleft-mright;
  687. //if (this.content.getParent().getStyle("overflow-y")!="hidden" ) width = width-18;
  688. if (nodeWidth){
  689. nodeWidth = nodeWidth+offsetWidth;
  690. }else{
  691. var x = width;
  692. width = width-offsetWidth;
  693. }
  694. if (nodeWidth){
  695. this.nodeWidth = nodeWidth;
  696. this.options.width = nodeWidth;
  697. this.options.contentWidth = null;
  698. this.css.to.left = this.options.left+"px";
  699. this.css.from.left = this.options.fromLeft+"px";
  700. this.css.to.width = nodeWidth+"px";
  701. this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
  702. this.options.left = this.options.left.toFloat()-offsetWidth/2;
  703. this.node.setStyle("width", nodeWidth )
  704. }else{
  705. this.contentWidth = width;
  706. this.node.setStyle("width", x )
  707. }
  708. this.content.setStyles( {"width" : width} )
  709. },
  710. setContentSize: function(height, width){
  711. debugger;
  712. //this.content.setStyle("height", this.getContentSize(height));
  713. // if (!this.options.height && !height){
  714. // this.content.setStyle("height", "auto");
  715. // this.content.setStyle("overflow", "hidden");
  716. // this.content.setStyle("width", "auto");
  717. // }else{
  718. var y = height;
  719. if (!y){
  720. if (this.options.contentHeight){
  721. y = this.options.contentHeight;
  722. }else{
  723. y = this.height;
  724. }
  725. }
  726. var x = width;
  727. if (!x){
  728. if (this.options.contentWidth){
  729. x = this.options.contentWidth;
  730. }else{
  731. x = this.width;
  732. }
  733. }
  734. if( y === "auto" || x === "auto" ){
  735. if( y === "auto" ){
  736. this.setContentHeightAuto();
  737. }else{
  738. this.setContentHeight( height );
  739. }
  740. if( x === "auto" ){
  741. this.setContentWidthAuto();
  742. }else{
  743. this.setContentWidth( width );
  744. }
  745. }else{
  746. this.content.setStyles(this.getContentSize(height, width));
  747. this.content.setStyle("width", "auto");
  748. }
  749. }
  750. });
  751. o2.DL.open = function(options){
  752. if (!options) options = {};
  753. if (!options.style) options.style = "user";
  754. //if (!options.transition) options.transition = Fx.Transitions.Back.easeOut;
  755. if (!options.duration) options.duration = 200;
  756. if (options.isClose!==false) options.isClose = true;
  757. var size;
  758. if (!options.width && !options.contentWidth){
  759. if (options.content){
  760. options.content.show();
  761. size = options.content.getComputedSize();
  762. options.contentWidth = size.totalWidth.toFloat();
  763. }
  764. }
  765. if (!options.height && !options.contentHeight){
  766. if (options.content){
  767. if (!size){
  768. options.content.show();
  769. size = options.content.getComputedSize();
  770. }
  771. options.contentHeight = size.totalHeight.toFloat()+2;
  772. }
  773. }
  774. if (!options.width && !options.contentWidth) options.width = 300;
  775. if (!options.height && !options.contentHeight) options.height = 150;
  776. if (!options.container && layout){
  777. if (layout.desktop.currentApp){
  778. options.container = layout.desktop.currentApp.content;
  779. }
  780. }
  781. var container = (options.positionNode || options.container || $(document.body));
  782. if( options.width !== "auto" && options.height !== "auto" ){
  783. //如果是百分比
  784. if( "string" == typeOf(options.width) && (1 < options.width.length && "%" == options.width.substr(options.width.length - 1, 1)) ){
  785. options.width = parseInt( container.getSize().x * parseInt(options.width, 10) / 100, 10);
  786. }
  787. if( "string" == typeOf(options.height) && (1 < options.height.length && "%" == options.height.substr(options.height.length - 1, 1)) ){
  788. options.height = parseInt( container.getSize().y * parseInt(options.height, 10) / 100, 10);
  789. }
  790. if ((options.top===undefined ) && (options.left===undefined)){
  791. var p = o2.getCenter({"x":(options.width || options.contentWidth), "y": (options.height || options.contentHeight+120)}, container, container);
  792. options.top = (p.y<0) ? 0 : p.y;
  793. options.left = (p.x<0) ? 0 : p.x;
  794. }
  795. if ((options.fromTop===undefined ) && (options.fromLeft===undefined)){
  796. var p = o2.getCenter({"x":(options.width || options.contentWidth)*0, "y": (options.height || options.contentHeight+120)*0}, container, container);
  797. options.fromTop = (p.y<0) ? 0 : p.y;
  798. options.fromLeft = (p.x<0) ? 0 : p.x;
  799. }
  800. if (options.offset){
  801. if (options.offset.y){
  802. options.top = options.top+options.offset.y.toInt();
  803. options.fromTop = options.fromTop+options.offset.y.toInt();
  804. }
  805. if (options.offset.x){
  806. options.left = options.left+options.offset.x.toInt();
  807. options.fromLeft = options.fromLeft+options.offset.x.toInt();
  808. }
  809. }
  810. if (options.top<0) options.top = 0;
  811. if (options.left<0) options.left = 0;
  812. if (options.fromTop<0) options.fromTop = 0;
  813. if (options.fromLeft<0) options.fromLeft = 0;
  814. }else{
  815. if(options.top===undefined )options.top = 0;
  816. if(options.left===undefined)options.left = 0;
  817. if(options.fromTop===undefined)options.fromTop = 0;
  818. if(options.fromLeft===undefined)options.fromLeft = 0;
  819. }
  820. options.mark = !(options.mask===false);
  821. var dlg = new o2.DDL(options);
  822. if( options.width === "auto" || options.height === "auto" ){
  823. dlg.reCenter();
  824. }
  825. dlg.show();
  826. return dlg;
  827. };