Dialog.js 35 KB

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