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