Dialog.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. o2.require("MWF.widget.Dialog", null, false);
  2. o2.xDesktop.Dialog = o2.DDL = new Class({
  3. Extends: o2.widget.Dialog,
  4. // _markShow: function(){
  5. //
  6. // if (this.options.mark){
  7. // if (!this.markNode){
  8. //
  9. // this.markNode = new Element("div", {
  10. // styles: this.css.mark
  11. // }).inject($(document.body));
  12. //
  13. // }
  14. //// if (this.options.markNode){
  15. //// var size = this.options.markNode.getComputedSize();
  16. //// var position = this.options.markNode.getPosition();
  17. //// alert(size.totalHeight);
  18. //// this.markNode.set("styles", {
  19. //// "height": size.totalHeight+"px",
  20. //// "width": size.totalWidth+"px",
  21. //// "top": position.y,
  22. //// "height": position.x
  23. //// });
  24. ////
  25. //// }else{
  26. // var size = MWF.getMarkSize();
  27. // this.markNode.set("styles", {
  28. // "height": size.y,
  29. // "width": size.x,
  30. // "top": "0xp",
  31. // "height": "0px"
  32. // });
  33. //// }
  34. //
  35. // this.markNode.setStyle("display", "block");
  36. // }
  37. // },
  38. _markShow: function(){
  39. if (this.options.mark){
  40. if (!this.markNode){
  41. var size = MWF.getMarkSize(this.options.maskNode);
  42. var topNode = this.options.container || $(document.body);
  43. this.markNode = new Element("iframe", {
  44. styles: this.css.mark
  45. }).inject(topNode);
  46. this.markNode.set("styles", {
  47. "height": size.y,
  48. "width": size.x
  49. });
  50. if (!this.markNode_up) this.markNode_up = new Element("div", { styles: this.css.mark }).inject(topNode);
  51. this.markNode_up.set("styles", {
  52. "height": size.y,
  53. "width": size.x
  54. });
  55. }
  56. this.markNode.setStyle("display", "block");
  57. }
  58. },
  59. getDialogNode: function(){
  60. this.width = this.options.width;
  61. this.height = this.options.height;
  62. this.node.set("styles", this.css.from);
  63. var topNode = this.options.container || $(document.body);
  64. this.node.inject(topNode);
  65. // this.node.addEvent("selectstart", function(e){
  66. // // e.preventDefault();
  67. // });
  68. this.title = this.node.getElement(".MWF_dialod_title");
  69. this.titleCenter = this.node.getElement(".MWF_dialod_title_center");
  70. this.titleText = this.node.getElement(".MWF_dialod_title_text");
  71. this.titleAction = this.node.getElement(".MWF_dialod_title_action");
  72. this.content = this.node.getElement(".MWF_dialod_content");
  73. this.bottom = this.node.getElement(".MWF_dialod_bottom");
  74. this.resizeNode = this.node.getElement(".MWF_dialod_bottom_resize");
  75. this.button = this.node.getElement(".MWF_dialod_button");
  76. if (!this.options.isTitle) {
  77. this.title.destroy();
  78. this.title = null;
  79. this.titleCenter = null;
  80. this.titleRefresh = null;
  81. this.titleText = null;
  82. this.titleAction = null;
  83. }
  84. if (this.title) this.setTitleEvent();
  85. // if (this.titleText) this.getTitle();
  86. if (this.content) this.getContent();
  87. if (this.titleAction) this.getAction();
  88. if (this.resizeNode) this.setResizeNode();
  89. // if (this.button) this.getButton();
  90. if (this.content) this.setContentSize();
  91. },
  92. reCenter: function(){
  93. var size = this.node.getSize();
  94. if( this.options.positionWidth ){
  95. size.x = parseInt(this.options.positionWidth);
  96. }
  97. if( this.options.positionHeight ){
  98. size.y = parseInt(this.options.positionHeight);
  99. }
  100. var container = $(document.body);
  101. if( this.options.positionNode && this.options.positionNode.getSize().y<$(document.body).getSize().y ){
  102. container = this.options.positionNode;
  103. }else if (layout.desktop.currentApp){
  104. container = layout.desktop.currentApp.content;
  105. }else{
  106. if (this.options.container){
  107. if (this.options.container.getSize().y<$(document.body).getSize().y){
  108. container = this.options.container;
  109. }
  110. }
  111. }
  112. var p = o2.getCenter(size, container, container);
  113. if (p.y< ( this.options.minTop || 0 ) ) p.y = this.options.minTop || 0;
  114. this.options.top = p.y;
  115. this.options.left = p.x;
  116. this.css.to.top = this.options.top+"px";
  117. this.css.to.left = this.options.left+"px";
  118. this.node.setStyles({
  119. "top": this.css.to.top,
  120. "left": this.css.to.left
  121. });
  122. },
  123. getOffsetY : function(node){
  124. return (node.getStyle("margin-top").toInt() || 0 ) +
  125. (node.getStyle("margin-bottom").toInt() || 0 ) +
  126. (node.getStyle("padding-top").toInt() || 0 ) +
  127. (node.getStyle("padding-bottom").toInt() || 0 )+
  128. (node.getStyle("border-top-width").toInt() || 0 ) +
  129. (node.getStyle("border-bottom-width").toInt() || 0 );
  130. },
  131. getOffsetX : function(node){
  132. return (node.getStyle("margin-left").toInt() || 0 ) +
  133. (node.getStyle("margin-right").toInt() || 0 ) +
  134. (node.getStyle("padding-left").toInt() || 0 ) +
  135. (node.getStyle("padding-right").toInt() || 0 )+
  136. (node.getStyle("border-left-width").toInt() || 0 ) +
  137. (node.getStyle("border-right-width").toInt() || 0 );
  138. },
  139. setContentHeightAuto : function(){
  140. var maxHeightPercent = this.options.maxHeightPercent || "98%";
  141. if( typeOf(maxHeightPercent) === "string" && maxHeightPercent.substr(maxHeightPercent.length - 1, 1) === "%" ) {
  142. var containerHeight = ( this.options.positionNode || this.options.container || $(document.body)).getSize().y;
  143. maxHeightPercent = parseInt(containerHeight * parseInt(maxHeightPercent) / 100);
  144. }
  145. var maxHeight;
  146. if( this.options.maxHeight && parseFloat( this.options.maxHeight ).toString() !== "NaN" ){
  147. maxHeight = parseFloat( this.options.maxHeight );
  148. if( typeOf(maxHeightPercent) === "number" ){
  149. maxHeight = Math.min( maxHeight, maxHeightPercent )
  150. }
  151. }else if( typeOf(maxHeightPercent) === "number" ){
  152. maxHeight = maxHeightPercent;
  153. }
  154. var offsetY = 0;
  155. var y = 0;
  156. //y = y + getOffsetY( this.title ) + this.title.getSize().y; //this.titleNode.getStyle("height").toInt();
  157. if( this.title )offsetY = offsetY + this.getOffsetY( this.title ) + this.title.getSize().y;
  158. if( this.bottom )offsetY = offsetY + this.getOffsetY( this.bottom ) + this.bottom.getSize().y;
  159. if( this.button )offsetY = offsetY + this.getOffsetY( this.button ) + this.button.getSize().y;
  160. if( this.content ){
  161. offsetY = offsetY + this.getOffsetY( this.content );
  162. y = offsetY + this.content.getSize().y;
  163. }else{
  164. y = offsetY;
  165. }
  166. if ( typeOf(maxHeight) === "number" && y > maxHeight) {
  167. this.options.height = maxHeight;
  168. this.options.contentHeight = null;
  169. this.options.fromTop = this.options.fromTop.toFloat() - offsetY / 2;
  170. this.options.top = this.options.top.toFloat() - offsetY / 2;
  171. this.css.to.height = maxHeight + "px";
  172. this.css.to.top = this.options.top + "px";
  173. this.css.from.top = this.options.fromTop + "px";
  174. this.node.setStyles({
  175. "height": maxHeight
  176. });
  177. if (this.content) {
  178. this.content.setStyles({
  179. "height" : maxHeight - offsetY,
  180. "overflow-y": "auto"
  181. })
  182. }
  183. }else{
  184. this.options.height = y;
  185. this.options.contentHeight = null;
  186. this.options.fromTop = this.options.fromTop.toFloat() - offsetY / 2;
  187. this.options.top = this.options.top.toFloat() - offsetY / 2;
  188. this.css.to.height = y + "px";
  189. this.css.to.top = this.options.top + "px";
  190. this.css.from.top = this.options.fromTop + "px";
  191. this.node.setStyles({
  192. "height": y
  193. });
  194. if (this.content) {
  195. this.content.setStyles({
  196. "height" : y - offsetY,
  197. "overflow-y": "hidden"
  198. })
  199. }
  200. }
  201. },
  202. setContentHeight: function(height){
  203. var nodeHeight;
  204. if (!height){
  205. if (this.options.contentHeight){
  206. nodeHeight = height = this.options.contentHeight.toFloat();
  207. }else{
  208. height = this.options.height.toFloat();
  209. }
  210. }
  211. var offsetHeight = 0;
  212. if (this.title){
  213. var h1 = this.title.getSize().y;
  214. var ptop1 = this.title.getStyle("padding-top").toFloat();
  215. var pbottom1 = this.title.getStyle("padding-bottom").toFloat();
  216. var mtop1 = this.title.getStyle("margin-top").toFloat();
  217. var mbottom1 = this.title.getStyle("margin-bottom").toFloat();
  218. offsetHeight += h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
  219. }
  220. if (this.bottom){
  221. var h2 = this.bottom.getSize().y;
  222. var ptop2 = this.bottom.getStyle("padding-top").toFloat();
  223. var pbottom2 = this.bottom.getStyle("padding-bottom").toFloat();
  224. var mtop2 = this.bottom.getStyle("margin-top").toFloat();
  225. var mbottom2 = this.bottom.getStyle("margin-bottom").toFloat();
  226. offsetHeight += h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
  227. }
  228. if (this.button){
  229. var h3 = this.button.getSize().y;
  230. var ptop3 = this.button.getStyle("padding-top").toFloat();
  231. var pbottom3 = this.button.getStyle("padding-bottom").toFloat();
  232. var mtop3 = this.button.getStyle("margin-top").toFloat();
  233. var mbottom3 = this.button.getStyle("margin-bottom").toFloat();
  234. offsetHeight += h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
  235. }
  236. var ptop4 = this.content.getStyle("padding-top").toFloat();
  237. var pbottom4 = this.content.getStyle("padding-bottom").toFloat();
  238. var mtop4 = this.content.getStyle("margin-top").toFloat();
  239. var mbottom4 = this.content.getStyle("margin-bottom").toFloat();
  240. offsetHeight += ptop4 + pbottom4 + mtop4 + mbottom4;
  241. if (nodeHeight){
  242. nodeHeight = nodeHeight + offsetHeight+2;
  243. }else {
  244. height = height - offsetHeight;
  245. }
  246. if (nodeHeight) {
  247. this.options.height = nodeHeight;
  248. this.options.contentHeight = null;
  249. this.options.fromTop = this.options.fromTop.toFloat()-offsetHeight/2;
  250. this.options.top = this.options.top.toFloat()-offsetHeight/2;
  251. this.css.to.height = nodeHeight+"px";
  252. this.css.to.top = this.options.top+"px";
  253. this.css.from.top = this.options.fromTop+"px";
  254. }
  255. if (nodeWidth){
  256. this.options.width = nodeWidth;
  257. this.options.contentWidth = null;
  258. this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
  259. this.options.left = this.options.left.toFloat()-offsetWidth/2;
  260. this.css.to.width = nodeWidth+"px";
  261. this.css.to.left = this.options.left+"px";
  262. this.css.from.left = this.options.fromLeft+"px";
  263. }
  264. if (!height || height<0){
  265. this.content.setStyles({"overflow": "hidden", "height": "auto"});
  266. height = this.content.getSize().y;
  267. var h = height + h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
  268. h = h + h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
  269. h = h + h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
  270. h = h + ptop4 + pbottom4 + mtop4 + mbottom4;
  271. this.css.to.height = h;
  272. }else{
  273. this.content.setStyles( {"height" : height} )
  274. }
  275. },
  276. setContentWidthAuto : function(){
  277. var maxWidth = this.options.maxWidth || "100%";
  278. if( typeOf(maxWidth) === "string" && maxWidth.substr(maxWidth.length - 1, 1) === "%" ) {
  279. var containerWidth = ( this.options.positionNode || this.options.container || $(document.body)).getSize().x;
  280. maxWidth = parseInt(containerWidth * parseInt(maxWidth) / 100);
  281. }
  282. var offsetX = 0;
  283. var x = 0;
  284. if( this.content ){
  285. offsetX = offsetX + this.getOffsetX( this.content );
  286. x = offsetX + this.content.getSize().x;
  287. }else{
  288. x = offsetX;
  289. }
  290. if ( x > maxWidth) {
  291. this.options.width = maxWidth;
  292. this.options.contentWidth = null;
  293. this.options.fromLeft = this.options.fromLeft.toFloat() - offsetX / 2;
  294. this.options.left = this.options.left.toFloat() - offsetX / 2;
  295. this.css.to.width = maxWidth + "px";
  296. this.css.to.left = this.options.left + "px";
  297. this.css.from.left = this.options.fromLeft + "px";
  298. this.node.setStyles({
  299. "width": maxWidth
  300. });
  301. if (this.content) {
  302. this.content.setStyles({
  303. "width" : maxWidth - offsetX,
  304. "overflow-x": "auto"
  305. })
  306. }
  307. }else{
  308. this.options.width = x;
  309. this.options.contentHeight = null;
  310. this.options.fromLeft = this.options.fromLeft.toFloat() - offsetX / 2;
  311. this.options.left = this.options.left.toFloat() - offsetX / 2;
  312. this.css.to.width = x + "px";
  313. this.css.to.left = this.options.left + "px";
  314. this.css.from.left = this.options.fromLeft + "px";
  315. this.node.setStyles({
  316. "width": x
  317. });
  318. if (this.content) {
  319. this.content.setStyles({
  320. "width" : x - offsetX,
  321. "overflow-x": "hidden"
  322. })
  323. }
  324. }
  325. },
  326. setContentWidth: function(width){
  327. var nodeWidth;
  328. if (!width){
  329. if (this.options.contentWidth){
  330. nodeWidth = width = this.options.contentWidth.toFloat();
  331. }else{
  332. width = this.options.width.toFloat();
  333. }
  334. }
  335. var offsetWidth = 0;
  336. //if (this.content.getParent().getStyle("overflow-x")!="hidden" ) height = height-18;
  337. var pleft = this.content.getStyle("padding-left").toFloat();
  338. var pright = this.content.getStyle("padding-right").toFloat();
  339. var mleft = this.content.getStyle("margin-left").toFloat();
  340. var mright = this.content.getStyle("margin-right").toFloat();
  341. offsetWidth = pleft+pright+mleft+mright;
  342. //width = width-pleft-pright-mleft-mright;
  343. //if (this.content.getParent().getStyle("overflow-y")!="hidden" ) width = width-18;
  344. if (nodeWidth){
  345. nodeWidth = nodeWidth+offsetWidth;
  346. }else{
  347. var x = width;
  348. width = width-offsetWidth;
  349. }
  350. if (nodeWidth){
  351. this.options.width = nodeWidth;
  352. this.options.contentWidth = null;
  353. this.css.to.left = this.options.left+"px";
  354. this.css.from.left = this.options.fromLeft+"px";
  355. this.css.to.width = nodeWidth+"px";
  356. this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
  357. this.options.left = this.options.left.toFloat()-offsetWidth/2;
  358. this.node.setStyle("width", nodeWidth )
  359. }else{
  360. this.node.setStyle("width", x )
  361. }
  362. this.content.setStyles( {"width" : width} )
  363. },
  364. setContentSize: function(height, width){
  365. //this.content.setStyle("height", this.getContentSize(height));
  366. // if (!this.options.height && !height){
  367. // this.content.setStyle("height", "auto");
  368. // this.content.setStyle("overflow", "hidden");
  369. // this.content.setStyle("width", "auto");
  370. // }else{
  371. var y = height;
  372. if (!y){
  373. if (this.options.contentHeight){
  374. y = this.options.contentHeight;
  375. }else{
  376. y = this.height;
  377. }
  378. }
  379. var x = width;
  380. if (!x){
  381. if (this.options.contentWidth){
  382. x = this.options.contentWidth;
  383. }else{
  384. x = this.width;
  385. }
  386. }
  387. if( y === "auto" || x === "auto" ){
  388. if( y === "auto" ){
  389. this.setContentHeightAuto();
  390. }else{
  391. this.setContentHeight( height );
  392. }
  393. if( x === "auto" ){
  394. this.setContentWidthAuto();
  395. }else{
  396. this.setContentWidth( width );
  397. }
  398. }else{
  399. this.content.setStyles(this.getContentSize(height, width));
  400. this.content.setStyle("width", "auto");
  401. }
  402. }
  403. });
  404. o2.DL.open = function(options){
  405. if (!options) options = {};
  406. if (!options.style) options.style = "user";
  407. //if (!options.transition) options.transition = Fx.Transitions.Back.easeOut;
  408. if (!options.duration) options.duration = 200;
  409. if (options.isClose!==false) options.isClose = true;
  410. var size;
  411. if (!options.width && !options.contentWidth){
  412. if (options.content){
  413. options.content.show();
  414. size = options.content.getComputedSize();
  415. options.contentWidth = size.totalWidth.toFloat();
  416. }
  417. }
  418. if (!options.height && !options.contentHeight){
  419. if (options.content){
  420. if (!size){
  421. options.content.show();
  422. size = options.content.getComputedSize();
  423. }
  424. options.contentHeight = size.totalHeight.toFloat()+2;
  425. }
  426. }
  427. if (!options.width && !options.contentWidth) options.width = 300;
  428. if (!options.height && !options.contentHeight) options.height = 150;
  429. if (!options.container && layout){
  430. if (layout.desktop.currentApp){
  431. options.container = layout.desktop.currentApp.content;
  432. }
  433. }
  434. var container = (options.positionNode || options.container || $(document.body));
  435. if( options.width !== "auto" && options.height !== "auto" ){
  436. if ((options.top===undefined ) && (options.left===undefined)){
  437. var p = o2.getCenter({"x":(options.width || options.contentWidth), "y": (options.height || options.contentHeight+120)}, container, container);
  438. options.top = (p.y<0) ? 0 : p.y;
  439. options.left = (p.x<0) ? 0 : p.x;
  440. }
  441. if ((options.fromTop===undefined ) && (options.fromLeft===undefined)){
  442. var p = o2.getCenter({"x":(options.width || options.contentWidth)*0, "y": (options.height || options.contentHeight+120)*0}, container, container);
  443. options.fromTop = (p.y<0) ? 0 : p.y;
  444. options.fromLeft = (p.x<0) ? 0 : p.x;
  445. }
  446. if (options.offset){
  447. if (options.offset.y){
  448. options.top = options.top+options.offset.y.toInt();
  449. options.fromTop = options.fromTop+options.offset.y.toInt();
  450. }
  451. if (options.offset.x){
  452. options.left = options.left+options.offset.x.toInt();
  453. options.fromLeft = options.fromLeft+options.offset.x.toInt();
  454. }
  455. }
  456. if (options.top<0) options.top = 0;
  457. if (options.left<0) options.left = 0;
  458. if (options.fromTop<0) options.fromTop = 0;
  459. if (options.fromLeft<0) options.fromLeft = 0;
  460. }else{
  461. if(options.top===undefined )options.top = 0;
  462. if(options.left===undefined)options.left = 0;
  463. if(options.fromTop===undefined)options.fromTop = 0;
  464. if(options.fromLeft===undefined)options.fromLeft = 0;
  465. }
  466. options.mark = !(options.mask===false);
  467. var dlg = new o2.DDL(options);
  468. if( options.width === "auto" || options.height === "auto" ){
  469. dlg.reCenter();
  470. }
  471. dlg.show();
  472. return dlg;
  473. };