UU跑腿标准版

ligerDialog.js 37KB

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