ligerWindow.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. l.windowCount = 0;
  13. $.ligerWindow = function (options)
  14. {
  15. return l.run.call(null, "ligerWindow", arguments, { isStatic: true });
  16. };
  17. $.ligerWindow.show = function (p)
  18. {
  19. return $.ligerWindow(p);
  20. };
  21. $.ligerDefaults.Window = {
  22. showClose: true,
  23. showMax: true,
  24. showToggle: true,
  25. showMin: true,
  26. title: 'window',
  27. load: false,
  28. onLoaded: null,
  29. modal: false //是否模态窗口
  30. };
  31. $.ligerMethos.Window = {};
  32. l.controls.Window = function (options)
  33. {
  34. l.controls.Window.base.constructor.call(this, null, options);
  35. };
  36. l.controls.Window.ligerExtend(l.core.Win, {
  37. __getType: function ()
  38. {
  39. return 'Window';
  40. },
  41. __idPrev: function ()
  42. {
  43. return 'Window';
  44. },
  45. _extendMethods: function ()
  46. {
  47. return $.ligerMethos.Window;
  48. },
  49. _render: function ()
  50. {
  51. var g = this, p = this.options;
  52. g.window = $('<div class="l-window"><div class="l-window-header"><div class="l-window-header-buttons"><div class="l-window-toggle"></div><div class="l-window-max"></div><div class="l-window-close"></div><div class="l-clear"></div></div><div class="l-window-header-inner"></div></div><div class="l-window-content"></div></div>');
  53. g.element = g.window[0];
  54. g.window.content = $(".l-window-content", g.window);
  55. g.window.header = $(".l-window-header", g.window);
  56. g.window.buttons = $(".l-window-header-buttons:first", g.window);
  57. if (p.url)
  58. {
  59. if (p.load)
  60. {
  61. g.window.content.load(p.url, function ()
  62. {
  63. g.trigger('loaded');
  64. });
  65. g.window.content.addClass("l-window-content-scroll");
  66. }
  67. else
  68. {
  69. var iframe = $("<iframe frameborder='0' src='" + p.url + "'></iframe>");
  70. var framename = "ligeruiwindow" + l.windowCount++;
  71. if (p.name) framename = p.name;
  72. iframe.attr("name", framename).attr("id", framename);
  73. p.framename = framename;
  74. iframe.appendTo(g.window.content);
  75. g.iframe = iframe;
  76. }
  77. }
  78. else if (p.content)
  79. {
  80. var content = $("<div>" + p.content + "</div>");
  81. content.appendTo(g.window.content);
  82. }
  83. else if (p.target)
  84. {
  85. g.window.content.append(p.target);
  86. p.target.show();
  87. }
  88. this.mask();
  89. g.active();
  90. $('body').append(g.window);
  91. g.set({ width: p.width, height: p.height });
  92. //位置初始化
  93. var left = 0;
  94. var top = 0;
  95. if (p.left != null) left = p.left;
  96. else p.left = left = 0.5 * ($(window).width() - g.window.width());
  97. if (p.top != null) top = p.top;
  98. else p.top = top = 0.5 * ($(window).height() - g.window.height()) + $(window).scrollTop() - 10;
  99. if (left < 0) p.left = left = 0;
  100. if (top < 0) p.top = top = 0;
  101. g.set(p);
  102. p.framename && $(">iframe", g.window.content).attr('name', p.framename);
  103. if (!p.showToggle) $(".l-window-toggle", g.window).remove();
  104. if (!p.showMax) $(".l-window-max", g.window).remove();
  105. if (!p.showClose) $(".l-window-close", g.window).remove();
  106. g._saveStatus();
  107. //拖动支持
  108. if ($.fn.ligerDrag)
  109. {
  110. g.draggable = g.window.drag = g.window.ligerDrag({ handler: '.l-window-header-inner', onStartDrag: function ()
  111. {
  112. g.active();
  113. }, onStopDrag: function ()
  114. {
  115. g._saveStatus();
  116. }, animate: false
  117. });
  118. }
  119. //改变大小支持
  120. if ($.fn.ligerResizable)
  121. {
  122. g.resizeable = g.window.resizable = g.window.ligerResizable({
  123. onStartResize: function ()
  124. {
  125. g.active();
  126. $(".l-window-max", g.window).removeClass("l-window-regain");
  127. },
  128. onStopResize: function (current, e)
  129. {
  130. var top = 0;
  131. var left = 0;
  132. if (!isNaN(parseInt(g.window.css('top'))))
  133. top = parseInt(g.window.css('top'));
  134. if (!isNaN(parseInt(g.window.css('left'))))
  135. left = parseInt(g.window.css('left'));
  136. if (current.diffTop)
  137. g.window.css({ top: top + current.diffTop });
  138. if (current.diffLeft)
  139. g.window.css({ left: left + current.diffLeft });
  140. if (current.newWidth)
  141. g.window.width(current.newWidth);
  142. if (current.newHeight)
  143. g.window.content.height(current.newHeight - 28);
  144. g._saveStatus();
  145. return false;
  146. }
  147. });
  148. g.window.append("<div class='l-btn-nw-drop'></div>");
  149. }
  150. //设置事件
  151. $(".l-window-toggle", g.window).click(function ()
  152. {
  153. if ($(this).hasClass("l-window-toggle-close"))
  154. {
  155. g.collapsed = false;
  156. $(this).removeClass("l-window-toggle-close");
  157. } else
  158. {
  159. g.collapsed = true;
  160. $(this).addClass("l-window-toggle-close");
  161. }
  162. g.window.content.slideToggle();
  163. }).hover(function ()
  164. {
  165. if (g.window.drag)
  166. g.window.drag.set('disabled', true);
  167. }, function ()
  168. {
  169. if (g.window.drag)
  170. g.window.drag.set('disabled', false);
  171. });
  172. $(".l-window-close", g.window).click(function ()
  173. {
  174. if (g.trigger('close') == false) return false;
  175. g.window.hide();
  176. l.win.removeTask(g);
  177. }).hover(function ()
  178. {
  179. if (g.window.drag)
  180. g.window.drag.set('disabled', true);
  181. }, function ()
  182. {
  183. if (g.window.drag)
  184. g.window.drag.set('disabled', false);
  185. });
  186. $(".l-window-max", g.window).click(function ()
  187. {
  188. if ($(this).hasClass("l-window-regain"))
  189. {
  190. if (g.trigger('regain') == false) return false;
  191. g.window.width(g._width).css({ left: g._left, top: g._top });
  192. g.window.content.height(g._height - 28);
  193. $(this).removeClass("l-window-regain");
  194. }
  195. else
  196. {
  197. if (g.trigger('max') == false) return false;
  198. g.window.width($(window).width() - 2).css({ left: 0, top: 0 });
  199. g.window.content.height($(window).height() - 28).show();
  200. $(this).addClass("l-window-regain");
  201. }
  202. });
  203. },
  204. _saveStatus: function ()
  205. {
  206. var g = this;
  207. g._width = g.window.width();
  208. g._height = g.window.height();
  209. var top = 0;
  210. var left = 0;
  211. if (!isNaN(parseInt(g.window.css('top'))))
  212. top = parseInt(g.window.css('top'));
  213. if (!isNaN(parseInt(g.window.css('left'))))
  214. left = parseInt(g.window.css('left'));
  215. g._top = top;
  216. g._left = left;
  217. },
  218. min: function ()
  219. {
  220. this.window.hide();
  221. this.minimize = true;
  222. this.actived = false;
  223. },
  224. _setShowMin: function (value)
  225. {
  226. var g = this, p = this.options;
  227. if (value)
  228. {
  229. if (!g.winmin)
  230. {
  231. g.winmin = $('<div class="l-window-min"></div>').prependTo(g.window.buttons)
  232. .click(function ()
  233. {
  234. g.min();
  235. });
  236. l.win.addTask(g);
  237. }
  238. }
  239. else if (g.winmin)
  240. {
  241. g.winmin.remove();
  242. g.winmin = null;
  243. }
  244. },
  245. _setLeft: function (value)
  246. {
  247. if (value != null)
  248. this.window.css({ left: value });
  249. },
  250. _setTop: function (value)
  251. {
  252. if (value != null)
  253. this.window.css({ top: value });
  254. },
  255. _setWidth: function (value)
  256. {
  257. if (value > 0)
  258. this.window.width(value);
  259. },
  260. _setHeight: function (value)
  261. {
  262. if (value > 28)
  263. this.window.content.height(value - 28);
  264. },
  265. _setTitle: function (value)
  266. {
  267. if (value)
  268. $(".l-window-header-inner", this.window.header).html(value);
  269. },
  270. _setUrl: function (url)
  271. {
  272. var g = this, p = this.options;
  273. p.url = url;
  274. if (p.load)
  275. {
  276. g.window.content.html("").load(p.url, function ()
  277. {
  278. if (g.trigger('loaded') == false) return false;
  279. });
  280. }
  281. else if (g.jiframe)
  282. {
  283. g.jiframe.attr("src", p.url);
  284. }
  285. },
  286. hide: function ()
  287. {
  288. var g = this, p = this.options;
  289. this.unmask();
  290. this.window.hide();
  291. },
  292. show: function ()
  293. {
  294. var g = this, p = this.options;
  295. this.mask();
  296. this.window.show();
  297. },
  298. remove: function ()
  299. {
  300. var g = this, p = this.options;
  301. this.unmask();
  302. this.window.remove();
  303. },
  304. active: function ()
  305. {
  306. var g = this, p = this.options;
  307. if (g.minimize)
  308. {
  309. var width = g._width, height = g._height, left = g._left, top = g._top;
  310. if (g.maximum)
  311. {
  312. width = $(window).width();
  313. height = $(window).height();
  314. left = top = 0;
  315. if (l.win.taskbar)
  316. {
  317. height -= l.win.taskbar.outerHeight();
  318. if (l.win.top) top += l.win.taskbar.outerHeight();
  319. }
  320. }
  321. g.set({ width: width, height: height, left: left, top: top });
  322. }
  323. g.actived = true;
  324. g.minimize = false;
  325. l.win.setFront(g);
  326. g.show();
  327. l.win.setFront(this);
  328. },
  329. setUrl: function (url)
  330. {
  331. return _setUrl(url);
  332. }
  333. });
  334. })(jQuery);