ligerDialog.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. /**
  2. * jQuery ligerUI 1.1.9
  3. *
  4. * http://ligerui.com
  5. *
  6. * Author daomi 2012 [ gd_star@163.com ]
  7. *
  8. */
  9. (function ($)
  10. {
  11. var l = $.ligerui;
  12. //全局事件
  13. $(".l-dialog-btn").live('mouseover', function ()
  14. {
  15. $(this).addClass("l-dialog-btn-over");
  16. }).live('mouseout', function ()
  17. {
  18. $(this).removeClass("l-dialog-btn-over");
  19. });
  20. $(".l-dialog-tc .l-dialog-close").live('mouseover', function ()
  21. {
  22. $(this).addClass("l-dialog-close-over");
  23. }).live('mouseout', function ()
  24. {
  25. $(this).removeClass("l-dialog-close-over");
  26. });
  27. $.ligerDialog = function ()
  28. {
  29. return l.run.call(null, "ligerDialog", arguments, { isStatic: true });
  30. };
  31. //dialog 图片文件夹的路径 预加载
  32. $.ligerui.DialogImagePath = "../../lib/ligerUI/skins/Aqua/images/win/";
  33. function prevImage(paths)
  34. {
  35. for (var i in paths)
  36. {
  37. $('<img />').attr('src', l.DialogImagePath + paths[i]);
  38. }
  39. }
  40. //prevImage(['dialog.gif', 'dialog-winbtns.gif', 'dialog-bc.gif', 'dialog-tc.gif']);
  41. $.ligerDefaults.Dialog = {
  42. cls: null, //给dialog附加css class
  43. id: null, //给dialog附加id
  44. buttons: null, //按钮集合
  45. isDrag: true, //是否拖动
  46. width: 280, //宽度
  47. height: null, //高度,默认自适应
  48. content: '', //内容
  49. target: null, //目标对象,指定它将以appendTo()的方式载入
  50. url: null, //目标页url,默认以iframe的方式载入
  51. load: false, //是否以load()的方式加载目标页的内容
  52. onLoaded: null,
  53. type: 'none', //类型 warn、success、error、question
  54. left: null, //位置left
  55. top: null, //位置top
  56. modal: true, //是否模态对话框
  57. name: null, //创建iframe时 作为iframe的name和id
  58. isResize: false, // 是否调整大小
  59. allowClose: true, //允许关闭
  60. opener: null,
  61. timeParmName: null, //是否给URL后面加上值为new Date().getTime()的参数,如果需要指定一个参数名即可
  62. closeWhenEnter: null, //回车时是否关闭dialog
  63. isHidden: true, //关闭对话框时是否只是隐藏,还是销毁对话框
  64. show: true, //初始化时是否马上显示
  65. title: '提示', //头部
  66. showMax: false, //是否显示最大化按钮
  67. showToggle: false, //是否显示收缩窗口按钮
  68. showMin: false, //是否显示最小化按钮
  69. slide: $.browser.msie ? false : true, //是否以动画的形式显示
  70. fixedType: null, //在固定的位置显示, 可以设置的值有n, e, s, w, ne, se, sw, nw
  71. showType: null //显示类型,可以设置为slide(固定显示时有效)
  72. };
  73. $.ligerDefaults.DialogString = {
  74. titleMessage: '提示', //提示文本标题
  75. ok: '确定',
  76. yes: '是',
  77. no: '否',
  78. cancel: '取消',
  79. waittingMessage: '正在等待中,请稍候...'
  80. };
  81. $.ligerMethos.Dialog = $.ligerMethos.Dialog || {};
  82. l.controls.Dialog = function (options)
  83. {
  84. l.controls.Dialog.base.constructor.call(this, null, options);
  85. };
  86. l.controls.Dialog.ligerExtend(l.core.Win, {
  87. __getType: function ()
  88. {
  89. return 'Dialog';
  90. },
  91. __idPrev: function ()
  92. {
  93. return 'Dialog';
  94. },
  95. _extendMethods: function ()
  96. {
  97. return $.ligerMethos.Dialog;
  98. },
  99. _render: function ()
  100. {
  101. var g = this, p = this.options;
  102. g.set(p, true);
  103. var dialog = $('<div class="l-dialog"><table class="l-dialog-table" cellpadding="0" cellspacing="0" border="0"><tbody><tr><td class="l-dialog-tl"></td><td class="l-dialog-tc"><div class="l-dialog-tc-inner"><div class="l-dialog-icon"></div><div class="l-dialog-title"></div><div class="l-dialog-winbtns"><div class="l-dialog-winbtn l-dialog-close"></div></div></div></td><td class="l-dialog-tr"></td></tr><tr><td class="l-dialog-cl"></td><td class="l-dialog-cc"><div class="l-dialog-body"><div class="l-dialog-image"></div> <div class="l-dialog-content"></div><div class="l-dialog-buttons"><div class="l-dialog-buttons-inner"></div></td><td class="l-dialog-cr"></td></tr><tr><td class="l-dialog-bl"></td><td class="l-dialog-bc"></td><td class="l-dialog-br"></td></tr></tbody></table></div>');
  104. $('body').append(dialog);
  105. g.dialog = dialog;
  106. g.element = dialog[0];
  107. g.dialog.body = $(".l-dialog-body:first", g.dialog);
  108. g.dialog.header = $(".l-dialog-tc-inner:first", g.dialog);
  109. g.dialog.winbtns = $(".l-dialog-winbtns:first", g.dialog.header);
  110. g.dialog.buttons = $(".l-dialog-buttons:first", g.dialog);
  111. g.dialog.content = $(".l-dialog-content:first", g.dialog);
  112. g.set(p, false);
  113. if (p.allowClose == false) $(".l-dialog-close", g.dialog).remove();
  114. if (p.target || p.url || p.type == "none")
  115. {
  116. p.type = null;
  117. g.dialog.addClass("l-dialog-win");
  118. }
  119. if (p.cls) g.dialog.addClass(p.cls);
  120. if (p.id) g.dialog.attr("id", p.id);
  121. //设置锁定屏幕、拖动支持 和设置图片
  122. g.mask();
  123. if (p.isDrag)
  124. g._applyDrag();
  125. if (p.isResize)
  126. g._applyResize();
  127. if (p.type)
  128. g._setImage();
  129. else
  130. {
  131. $(".l-dialog-image", g.dialog).remove();
  132. g.dialog.content.addClass("l-dialog-content-noimage");
  133. }
  134. if (!p.show)
  135. {
  136. g.unmask();
  137. g.dialog.hide();
  138. }
  139. //设置主体内容
  140. if (p.target)
  141. {
  142. g.dialog.content.prepend(p.target);
  143. $(p.target).show();
  144. }
  145. else if (p.url)
  146. {
  147. if (p.timeParmName)
  148. {
  149. p.url += p.url.indexOf('?') == -1 ? "?" : "&";
  150. p.url += p.timeParmName + "=" + new Date().getTime();
  151. }
  152. if (p.load)
  153. {
  154. g.dialog.body.load(p.url, function ()
  155. {
  156. g._saveStatus();
  157. g.trigger('loaded');
  158. });
  159. }
  160. else
  161. {
  162. g.jiframe = $("<iframe frameborder='0'></iframe>");
  163. var framename = p.name ? p.name : "ligerwindow" + new Date().getTime();
  164. g.jiframe.attr("name", framename);
  165. g.jiframe.attr("id", framename);
  166. g.dialog.content.prepend(g.jiframe);
  167. g.dialog.content.addClass("l-dialog-content-nopadding");
  168. setTimeout(function ()
  169. {
  170. g.jiframe.attr("src", p.url);
  171. g.frame = window.frames[g.jiframe.attr("name")];
  172. }, 0);
  173. }
  174. }
  175. if (p.opener) g.dialog.opener = p.opener;
  176. //设置按钮
  177. if (p.buttons)
  178. {
  179. $(p.buttons).each(function (i, item)
  180. {
  181. var btn = $('<div class="l-dialog-btn"><div class="l-dialog-btn-l"></div><div class="l-dialog-btn-r"></div><div class="l-dialog-btn-inner"></div></div>');
  182. $(".l-dialog-btn-inner", btn).html(item.text);
  183. $(".l-dialog-buttons-inner", g.dialog.buttons).prepend(btn);
  184. item.width && btn.width(item.width);
  185. item.onclick && btn.click(function () { item.onclick(item, g, i) });
  186. });
  187. } else
  188. {
  189. g.dialog.buttons.remove();
  190. }
  191. $(".l-dialog-buttons-inner", g.dialog.buttons).append("<div class='l-clear'></div>");
  192. $(".l-dialog-title", g.dialog)
  193. .bind("selectstart", function () { return false; });
  194. g.dialog.click(function ()
  195. {
  196. l.win.setFront(g);
  197. });
  198. //设置事件
  199. $(".l-dialog-tc .l-dialog-close", g.dialog).click(function ()
  200. {
  201. if (p.isHidden)
  202. g.hide();
  203. else
  204. g.close();
  205. });
  206. if (!p.fixedType)
  207. {
  208. //位置初始化
  209. var left = 0;
  210. var top = 0;
  211. var width = p.width || g.dialog.width();
  212. if (p.slide == true) p.slide = 'fast';
  213. if (p.left != null) left = p.left;
  214. else p.left = left = 0.5 * ($(window).width() - width);
  215. if (p.top != null) top = p.top;
  216. else p.top = top = 0.5 * ($(window).height() - g.dialog.height()) + $(window).scrollTop() - 10;
  217. if (left < 0) p.left = left = 0;
  218. if (top < 0) p.top = top = 0;
  219. g.dialog.css({ left: left, top: top });
  220. }
  221. g.show();
  222. $('body').bind('keydown.dialog', function (e)
  223. {
  224. var key = e.which;
  225. if (key == 13)
  226. {
  227. g.enter();
  228. }
  229. else if (key == 27)
  230. {
  231. g.esc();
  232. }
  233. });
  234. g._updateBtnsWidth();
  235. g._saveStatus();
  236. g._onReisze();
  237. },
  238. _borderX: 12,
  239. _borderY: 32,
  240. doMax: function (slide)
  241. {
  242. var g = this, p = this.options;
  243. var width = $(window).width(), height = $(window).height(), left = 0, top = 0;
  244. if (l.win.taskbar)
  245. {
  246. height -= l.win.taskbar.outerHeight();
  247. if (l.win.top) top += l.win.taskbar.outerHeight();
  248. }
  249. if (slide)
  250. {
  251. g.dialog.body.animate({ width: width - g._borderX }, p.slide);
  252. g.dialog.animate({ left: left, top: top }, p.slide);
  253. g.dialog.content.animate({ height: height - g._borderY - g.dialog.buttons.outerHeight() }, p.slide, function ()
  254. {
  255. g._onReisze();
  256. });
  257. }
  258. else
  259. {
  260. g.set({ width: width, height: height, left: left, top: top });
  261. g._onReisze();
  262. }
  263. },
  264. //最大化
  265. max: function ()
  266. {
  267. var g = this, p = this.options;
  268. if (g.winmax)
  269. {
  270. g.winmax.addClass("l-dialog-recover");
  271. g.doMax(p.slide);
  272. if (g.wintoggle)
  273. {
  274. if (g.wintoggle.hasClass("l-dialog-extend"))
  275. g.wintoggle.addClass("l-dialog-toggle-disabled l-dialog-extend-disabled");
  276. else
  277. g.wintoggle.addClass("l-dialog-toggle-disabled l-dialog-collapse-disabled");
  278. }
  279. if (g.resizable) g.resizable.set({ disabled: true });
  280. if (g.draggable) g.draggable.set({ disabled: true });
  281. g.maximum = true;
  282. $(window).bind('resize.dialogmax', function ()
  283. {
  284. g.doMax(false);
  285. });
  286. }
  287. },
  288. //恢复
  289. recover: function ()
  290. {
  291. var g = this, p = this.options;
  292. if (g.winmax)
  293. {
  294. g.winmax.removeClass("l-dialog-recover");
  295. if (p.slide)
  296. {
  297. g.dialog.body.animate({ width: g._width - g._borderX }, p.slide);
  298. g.dialog.animate({ left: g._left, top: g._top }, p.slide);
  299. g.dialog.content.animate({ height: g._height - g._borderY - g.dialog.buttons.outerHeight() }, p.slide, function ()
  300. {
  301. g._onReisze();
  302. });
  303. }
  304. else
  305. {
  306. g.set({ width: g._width, height: g._height, left: g._left, top: g._top });
  307. g._onReisze();
  308. }
  309. if (g.wintoggle)
  310. {
  311. g.wintoggle.removeClass("l-dialog-toggle-disabled l-dialog-extend-disabled l-dialog-collapse-disabled");
  312. }
  313. $(window).unbind('resize.dialogmax');
  314. }
  315. if (this.resizable) this.resizable.set({ disabled: false });
  316. if (g.draggable) g.draggable.set({ disabled: false });
  317. g.maximum = false;
  318. },
  319. //最小化
  320. min: function ()
  321. {
  322. var g = this, p = this.options;
  323. var task = l.win.getTask(this);
  324. if (p.slide)
  325. {
  326. g.dialog.body.animate({ width: 1 }, p.slide);
  327. task.y = task.offset().top + task.height();
  328. task.x = task.offset().left + task.width() / 2;
  329. g.dialog.animate({ left: task.x, top: task.y }, p.slide, function ()
  330. {
  331. g.dialog.hide();
  332. });
  333. }
  334. else
  335. {
  336. g.dialog.hide();
  337. }
  338. g.unmask();
  339. g.minimize = true;
  340. g.actived = false;
  341. },
  342. active: function ()
  343. {
  344. var g = this, p = this.options;
  345. if (g.minimize)
  346. {
  347. var width = g._width, height = g._height, left = g._left, top = g._top;
  348. if (g.maximum)
  349. {
  350. width = $(window).width();
  351. height = $(window).height();
  352. left = top = 0;
  353. if (l.win.taskbar)
  354. {
  355. height -= l.win.taskbar.outerHeight();
  356. if (l.win.top) top += l.win.taskbar.outerHeight();
  357. }
  358. }
  359. if (p.slide)
  360. {
  361. g.dialog.body.animate({ width: width - g._borderX }, p.slide);
  362. g.dialog.animate({ left: left, top: top }, p.slide);
  363. }
  364. else
  365. {
  366. g.set({ width: width, height: height, left: left, top: top });
  367. }
  368. }
  369. g.actived = true;
  370. g.minimize = false;
  371. l.win.setFront(g);
  372. g.show();
  373. },
  374. //展开 收缩
  375. toggle: function ()
  376. {
  377. var g = this, p = this.options;
  378. if (!g.wintoggle) return;
  379. if (g.wintoggle.hasClass("l-dialog-extend"))
  380. g.extend();
  381. else
  382. g.collapse();
  383. },
  384. //收缩
  385. collapse: function ()
  386. {
  387. var g = this, p = this.options;
  388. if (!g.wintoggle) return;
  389. if (p.slide)
  390. g.dialog.content.animate({ height: 1 }, p.slide);
  391. else
  392. g.dialog.content.height(1);
  393. if (this.resizable) this.resizable.set({ disabled: true });
  394. },
  395. //展开
  396. extend: function ()
  397. {
  398. var g = this, p = this.options;
  399. if (!g.wintoggle) return;
  400. var contentHeight = g._height - g._borderY - g.dialog.buttons.outerHeight();
  401. if (p.slide)
  402. g.dialog.content.animate({ height: contentHeight }, p.slide);
  403. else
  404. g.dialog.content.height(contentHeight);
  405. if (this.resizable) this.resizable.set({ disabled: false });
  406. },
  407. _updateBtnsWidth: function ()
  408. {
  409. var g = this;
  410. var btnscount = $(">div", g.dialog.winbtns).length;
  411. g.dialog.winbtns.width(22 * btnscount);
  412. },
  413. _setLeft: function (value)
  414. {
  415. if (!this.dialog) return;
  416. if (value != null)
  417. this.dialog.css({ left: value });
  418. },
  419. _setTop: function (value)
  420. {
  421. if (!this.dialog) return;
  422. if (value != null)
  423. this.dialog.css({ top: value });
  424. },
  425. _setWidth: function (value)
  426. {
  427. if (!this.dialog) return;
  428. if (value >= this._borderX)
  429. {
  430. this.dialog.body.width(value - this._borderX);
  431. }
  432. },
  433. _setHeight: function (value)
  434. {
  435. var g = this, p = this.options;
  436. if (!this.dialog) return;
  437. if (value >= this._borderY)
  438. {
  439. var height = value - this._borderY - g.dialog.buttons.outerHeight();
  440. g.dialog.content.height(height);
  441. }
  442. },
  443. _setShowMax: function (value)
  444. {
  445. var g = this, p = this.options;
  446. if (value)
  447. {
  448. if (!g.winmax)
  449. {
  450. g.winmax = $('<div class="l-dialog-winbtn l-dialog-max"></div>').appendTo(g.dialog.winbtns)
  451. .hover(function ()
  452. {
  453. if ($(this).hasClass("l-dialog-recover"))
  454. $(this).addClass("l-dialog-recover-over");
  455. else
  456. $(this).addClass("l-dialog-max-over");
  457. }, function ()
  458. {
  459. $(this).removeClass("l-dialog-max-over l-dialog-recover-over");
  460. }).click(function ()
  461. {
  462. if ($(this).hasClass("l-dialog-recover"))
  463. g.recover();
  464. else
  465. g.max();
  466. });
  467. }
  468. }
  469. else if (g.winmax)
  470. {
  471. g.winmax.remove();
  472. g.winmax = null;
  473. }
  474. g._updateBtnsWidth();
  475. },
  476. _setShowMin: function (value)
  477. {
  478. var g = this, p = this.options;
  479. if (value)
  480. {
  481. if (!g.winmin)
  482. {
  483. g.winmin = $('<div class="l-dialog-winbtn l-dialog-min"></div>').appendTo(g.dialog.winbtns)
  484. .hover(function ()
  485. {
  486. $(this).addClass("l-dialog-min-over");
  487. }, function ()
  488. {
  489. $(this).removeClass("l-dialog-min-over");
  490. }).click(function ()
  491. {
  492. g.min();
  493. });
  494. l.win.addTask(g);
  495. }
  496. }
  497. else if (g.winmin)
  498. {
  499. g.winmin.remove();
  500. g.winmin = null;
  501. }
  502. g._updateBtnsWidth();
  503. },
  504. _setShowToggle: function (value)
  505. {
  506. var g = this, p = this.options;
  507. if (value)
  508. {
  509. if (!g.wintoggle)
  510. {
  511. g.wintoggle = $('<div class="l-dialog-winbtn l-dialog-collapse"></div>').appendTo(g.dialog.winbtns)
  512. .hover(function ()
  513. {
  514. if ($(this).hasClass("l-dialog-toggle-disabled")) return;
  515. if ($(this).hasClass("l-dialog-extend"))
  516. $(this).addClass("l-dialog-extend-over");
  517. else
  518. $(this).addClass("l-dialog-collapse-over");
  519. }, function ()
  520. {
  521. $(this).removeClass("l-dialog-extend-over l-dialog-collapse-over");
  522. }).click(function ()
  523. {
  524. if ($(this).hasClass("l-dialog-toggle-disabled")) return;
  525. if (g.wintoggle.hasClass("l-dialog-extend"))
  526. {
  527. if (g.trigger('extend') == false) return;
  528. g.wintoggle.removeClass("l-dialog-extend");
  529. g.extend();
  530. g.trigger('extended');
  531. }
  532. else
  533. {
  534. if (g.trigger('collapse') == false) return;
  535. g.wintoggle.addClass("l-dialog-extend");
  536. g.collapse();
  537. g.trigger('collapseed')
  538. }
  539. });
  540. }
  541. }
  542. else if (g.wintoggle)
  543. {
  544. g.wintoggle.remove();
  545. g.wintoggle = null;
  546. }
  547. },
  548. //按下回车
  549. enter: function ()
  550. {
  551. var g = this, p = this.options;
  552. var isClose;
  553. if (p.closeWhenEnter != undefined)
  554. {
  555. isClose = p.closeWhenEnter;
  556. }
  557. else if (p.type == "warn" || p.type == "error" || p.type == "success" || p.type == "question")
  558. {
  559. isClose = true;
  560. }
  561. if (isClose)
  562. {
  563. g.close();
  564. }
  565. },
  566. esc: function ()
  567. {
  568. },
  569. _removeDialog: function ()
  570. {
  571. var g = this, p = this.options;
  572. if (p.showType && p.fixedType)
  573. {
  574. g.dialog.animate({ bottom: -1 * p.height }, function ()
  575. {
  576. g.dialog.remove();
  577. });
  578. } else
  579. {
  580. g.dialog.remove();
  581. }
  582. },
  583. close: function ()
  584. {
  585. var g = this, p = this.options;
  586. l.win.removeTask(this);
  587. g.unmask();
  588. g._removeDialog();
  589. $('body').unbind('keydown.dialog');
  590. },
  591. _getVisible: function ()
  592. {
  593. return this.dialog.is(":visible");
  594. },
  595. _setUrl: function (url)
  596. {
  597. var g = this, p = this.options;
  598. p.url = url;
  599. if (p.load)
  600. {
  601. g.dialog.body.html("").load(p.url, function ()
  602. {
  603. g.trigger('loaded');
  604. });
  605. }
  606. else if (g.jiframe)
  607. {
  608. g.jiframe.attr("src", p.url);
  609. }
  610. },
  611. _setContent: function (content)
  612. {
  613. this.dialog.content.html(content);
  614. },
  615. _setTitle: function (value)
  616. {
  617. var g = this; var p = this.options;
  618. if (value)
  619. {
  620. $(".l-dialog-title", g.dialog).html(value);
  621. }
  622. },
  623. _hideDialog: function ()
  624. {
  625. var g = this, p = this.options;
  626. if (p.showType && p.fixedType)
  627. {
  628. g.dialog.animate({ bottom: -1 * p.height }, function ()
  629. {
  630. g.dialog.hide();
  631. });
  632. } else
  633. {
  634. g.dialog.hide();
  635. }
  636. },
  637. hidden: function ()
  638. {
  639. var g = this;
  640. l.win.removeTask(g);
  641. g.dialog.hide();
  642. g.unmask();
  643. },
  644. show: function ()
  645. {
  646. var g = this, p = this.options;
  647. g.mask();
  648. if (p.fixedType)
  649. {
  650. if (p.showType)
  651. {
  652. g.dialog.css({ bottom: -1 * p.height }).addClass("l-dialog-fixed");
  653. g.dialog.show().animate({ bottom: 0 });
  654. }
  655. else
  656. {
  657. g.dialog.show().css({ bottom: 0 });
  658. }
  659. }
  660. else
  661. {
  662. g.dialog.show();
  663. }
  664. //前端显示
  665. $.ligerui.win.setFront.ligerDefer($.ligerui.win, 100, [g]);
  666. },
  667. setUrl: function (url)
  668. {
  669. this._setUrl(url);
  670. },
  671. _saveStatus: function ()
  672. {
  673. var g = this;
  674. g._width = g.dialog.body.width();
  675. g._height = g.dialog.body.height();
  676. var top = 0;
  677. var left = 0;
  678. if (!isNaN(parseInt(g.dialog.css('top'))))
  679. top = parseInt(g.dialog.css('top'));
  680. if (!isNaN(parseInt(g.dialog.css('left'))))
  681. left = parseInt(g.dialog.css('left'));
  682. g._top = top;
  683. g._left = left;
  684. },
  685. _applyDrag: function ()
  686. {
  687. var g = this, p = this.options;
  688. if ($.fn.ligerDrag)
  689. g.draggable = g.dialog.ligerDrag({ handler: '.l-dialog-title', animate: false,
  690. onStartDrag: function ()
  691. {
  692. l.win.setFront(g);
  693. },
  694. onStopDrag: function ()
  695. {
  696. if (p.target)
  697. {
  698. var triggers1 = l.find($.ligerui.controls.DateEditor);
  699. var triggers2 = l.find($.ligerui.controls.ComboBox);
  700. //更新所有下拉选择框的位置
  701. $($.merge(triggers1, triggers2)).each(function ()
  702. {
  703. if (this.updateSelectBoxPosition)
  704. this.updateSelectBoxPosition();
  705. });
  706. }
  707. g._saveStatus();
  708. }
  709. });
  710. },
  711. _onReisze: function ()
  712. {
  713. var g = this, p = this.options;
  714. if (p.target)
  715. {
  716. var manager = $(p.target).liger();
  717. if (!manager) manager = $(p.target).find(":first").liger();
  718. if (!manager) return;
  719. var contentHeight = g.dialog.content.height();
  720. var contentWidth = g.dialog.content.width();
  721. manager.trigger('resize', [{ width: contentWidth, height: contentHeight}]);
  722. }
  723. },
  724. _applyResize: function ()
  725. {
  726. var g = this, p = this.options;
  727. if ($.fn.ligerResizable)
  728. {
  729. g.resizable = g.dialog.ligerResizable({
  730. onStopResize: function (current, e)
  731. {
  732. var top = 0;
  733. var left = 0;
  734. if (!isNaN(parseInt(g.dialog.css('top'))))
  735. top = parseInt(g.dialog.css('top'));
  736. if (!isNaN(parseInt(g.dialog.css('left'))))
  737. left = parseInt(g.dialog.css('left'));
  738. if (current.diffLeft)
  739. {
  740. g.set({ left: left + current.diffLeft });
  741. }
  742. if (current.diffTop)
  743. {
  744. g.set({ top: top + current.diffTop });
  745. }
  746. if (current.newWidth)
  747. {
  748. g.set({ width: current.newWidth });
  749. g.dialog.body.css({ width: current.newWidth - g._borderX });
  750. }
  751. if (current.newHeight)
  752. {
  753. g.set({ height: current.newHeight });
  754. }
  755. g._onReisze();
  756. g._saveStatus();
  757. return false;
  758. }, animate: false
  759. });
  760. }
  761. },
  762. _setImage: function ()
  763. {
  764. var g = this, p = this.options;
  765. if (p.type)
  766. {
  767. if (p.type == 'success' || p.type == 'donne' || p.type == 'ok')
  768. {
  769. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-donne").show();
  770. g.dialog.content.css({ paddingLeft: 64, paddingBottom: 30 });
  771. }
  772. else if (p.type == 'error')
  773. {
  774. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-error").show();
  775. g.dialog.content.css({ paddingLeft: 64, paddingBottom: 30 });
  776. }
  777. else if (p.type == 'warn')
  778. {
  779. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-warn").show();
  780. g.dialog.content.css({ paddingLeft: 64, paddingBottom: 30 });
  781. }
  782. else if (p.type == 'question')
  783. {
  784. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-question").show();
  785. g.dialog.content.css({ paddingLeft: 64, paddingBottom: 40 });
  786. }
  787. }
  788. }
  789. });
  790. l.controls.Dialog.prototype.hide = l.controls.Dialog.prototype.hidden;
  791. $.ligerDialog.open = function (p)
  792. {
  793. return $.ligerDialog(p);
  794. };
  795. $.ligerDialog.close = function ()
  796. {
  797. var dialogs = l.find(l.controls.Dialog.prototype.__getType());
  798. for (var i in dialogs)
  799. {
  800. var d = dialogs[i];
  801. d.destroy.ligerDefer(d, 5);
  802. }
  803. l.win.unmask();
  804. };
  805. $.ligerDialog.show = function (p)
  806. {
  807. var dialogs = l.find(l.controls.Dialog.prototype.__getType());
  808. if (dialogs.length)
  809. {
  810. for (var i in dialogs)
  811. {
  812. dialogs[i].show();
  813. return;
  814. }
  815. }
  816. return $.ligerDialog(p);
  817. };
  818. $.ligerDialog.hide = function ()
  819. {
  820. var dialogs = l.find(l.controls.Dialog.prototype.__getType());
  821. for (var i in dialogs)
  822. {
  823. var d = dialogs[i];
  824. d.hide();
  825. }
  826. };
  827. $.ligerDialog.tip = function (options)
  828. {
  829. options = $.extend({
  830. showType: 'slide',
  831. width: 240,
  832. modal: false,
  833. height: 100
  834. }, options || {});
  835. $.extend(options, {
  836. fixedType: 'se',
  837. type: 'none',
  838. isDrag: false,
  839. isResize: false,
  840. showMax: false,
  841. showToggle: false,
  842. showMin: false
  843. });
  844. return $.ligerDialog.open(options);
  845. };
  846. $.ligerDialog.alert = function (content, title, type, callback)
  847. {
  848. content = content || "";
  849. if (typeof (title) == "function")
  850. {
  851. callback = title;
  852. type = null;
  853. }
  854. else if (typeof (type) == "function")
  855. {
  856. callback = type;
  857. }
  858. var btnclick = function (item, Dialog, index)
  859. {
  860. Dialog.close();
  861. if (callback)
  862. callback(item, Dialog, index);
  863. };
  864. p = {
  865. content: content,
  866. buttons: [{ text: $.ligerDefaults.DialogString.ok, onclick: btnclick}]
  867. };
  868. if (typeof (title) == "string" && title != "") p.title = title;
  869. if (typeof (type) == "string" && type != "") p.type = type;
  870. $.extend(p, {
  871. showMax: false,
  872. showToggle: false,
  873. showMin: false
  874. });
  875. return $.ligerDialog(p);
  876. };
  877. $.ligerDialog.confirm = function (content, title, callback)
  878. {
  879. if (typeof (title) == "function")
  880. {
  881. callback = title;
  882. type = null;
  883. }
  884. var btnclick = function (item, Dialog)
  885. {
  886. Dialog.close();
  887. if (callback)
  888. {
  889. callback(item.type == 'ok');
  890. }
  891. };
  892. p = {
  893. type: 'question',
  894. content: content,
  895. buttons: [{ text: $.ligerDefaults.DialogString.yes, onclick: btnclick, type: 'ok' }, { text: $.ligerDefaults.DialogString.no, onclick: btnclick, type: 'no'}]
  896. };
  897. if (typeof (title) == "string" && title != "") p.title = title;
  898. $.extend(p, {
  899. showMax: false,
  900. showToggle: false,
  901. showMin: false
  902. });
  903. return $.ligerDialog(p);
  904. };
  905. $.ligerDialog.warning = function (content, title, callback)
  906. {
  907. if (typeof (title) == "function")
  908. {
  909. callback = title;
  910. type = null;
  911. }
  912. var btnclick = function (item, Dialog)
  913. {
  914. Dialog.close();
  915. if (callback)
  916. {
  917. callback(item.type);
  918. }
  919. };
  920. p = {
  921. type: 'question',
  922. content: content,
  923. buttons: [{ text: $.ligerDefaults.DialogString.yes, onclick: btnclick, type: 'yes' }, { text: $.ligerDefaults.DialogString.no, onclick: btnclick, type: 'no' }, { text: $.ligerDefaults.DialogString.cancel, onclick: btnclick, type: 'cancel'}]
  924. };
  925. if (typeof (title) == "string" && title != "") p.title = title;
  926. $.extend(p, {
  927. showMax: false,
  928. showToggle: false,
  929. showMin: false
  930. });
  931. return $.ligerDialog(p);
  932. };
  933. $.ligerDialog.waitting = function (title)
  934. {
  935. title = title || $.ligerDefaults.Dialog.waittingMessage;
  936. return $.ligerDialog.open({ cls: 'l-dialog-waittingdialog', type: 'none', content: '<div style="padding:4px">' + title + '</div>', allowClose: false });
  937. };
  938. $.ligerDialog.closeWaitting = function ()
  939. {
  940. var dialogs = l.find(l.controls.Dialog);
  941. for (var i in dialogs)
  942. {
  943. var d = dialogs[i];
  944. if (d.dialog.hasClass("l-dialog-waittingdialog"))
  945. d.close();
  946. }
  947. };
  948. $.ligerDialog.success = function (content, title, onBtnClick)
  949. {
  950. return $.ligerDialog.alert(content, title, 'success', onBtnClick);
  951. };
  952. $.ligerDialog.error = function (content, title, onBtnClick)
  953. {
  954. return $.ligerDialog.alert(content, title, 'error', onBtnClick);
  955. };
  956. $.ligerDialog.warn = function (content, title, onBtnClick)
  957. {
  958. return $.ligerDialog.alert(content, title, 'warn', onBtnClick);
  959. };
  960. $.ligerDialog.question = function (content, title)
  961. {
  962. return $.ligerDialog.alert(content, title, 'question');
  963. };
  964. $.ligerDialog.prompt = function (title, value, multi, callback)
  965. {
  966. var target = $('<input type="text" class="l-dialog-inputtext"/>');
  967. if (typeof (multi) == "function")
  968. {
  969. callback = multi;
  970. }
  971. if (typeof (value) == "function")
  972. {
  973. callback = value;
  974. }
  975. else if (typeof (value) == "boolean")
  976. {
  977. multi = value;
  978. }
  979. if (typeof (multi) == "boolean" && multi)
  980. {
  981. target = $('<textarea class="l-dialog-textarea"></textarea>');
  982. }
  983. if (typeof (value) == "string" || typeof (value) == "int")
  984. {
  985. target.val(value);
  986. }
  987. var btnclick = function (item, Dialog, index)
  988. {
  989. Dialog.close();
  990. if (callback)
  991. {
  992. callback(item.type == 'yes', target.val());
  993. }
  994. }
  995. p = {
  996. title: title,
  997. target: target,
  998. width: 320,
  999. buttons: [{ text: $.ligerDefaults.DialogString.ok, onclick: btnclick, type: 'yes' }, { text: $.ligerDefaults.DialogString.cancel, onclick: btnclick, type: 'cancel'}]
  1000. };
  1001. return $.ligerDialog(p);
  1002. };
  1003. })(jQuery);