Dialog.js 36 KB

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