ligerDialog.js 42 KB

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