Dialog.js 35 KB

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