UU跑腿标准版

ligerWindow.js 11KB

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