jquery.window.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. * jQuery EasyUI 1.4.1
  3. *
  4. * Copyright (c) 2009-2014 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
  7. * To use it on other terms please contact us at info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. function _1(_2,_3){
  12. var _4=$.data(_2,"window");
  13. if(_3){
  14. if(_3.left!=null){
  15. _4.options.left=_3.left;
  16. }
  17. if(_3.top!=null){
  18. _4.options.top=_3.top;
  19. }
  20. }
  21. $(_2).panel("move",_4.options);
  22. if(_4.shadow){
  23. _4.shadow.css({left:_4.options.left,top:_4.options.top});
  24. }
  25. };
  26. function _5(_6,_7){
  27. var _8=$.data(_6,"window").options;
  28. var pp=$(_6).window("panel");
  29. var _9=pp._outerWidth();
  30. if(_8.inline){
  31. var _a=pp.parent();
  32. _8.left=Math.ceil((_a.width()-_9)/2+_a.scrollLeft());
  33. }else{
  34. _8.left=Math.ceil(($(window)._outerWidth()-_9)/2+$(document).scrollLeft());
  35. }
  36. if(_7){
  37. _1(_6);
  38. }
  39. };
  40. function _b(_c,_d){
  41. var _e=$.data(_c,"window").options;
  42. var pp=$(_c).window("panel");
  43. var _f=pp._outerHeight();
  44. if(_e.inline){
  45. var _10=pp.parent();
  46. _e.top=Math.ceil((_10.height()-_f)/2+_10.scrollTop());
  47. }else{
  48. _e.top=Math.ceil(($(window)._outerHeight()-_f)/2+$(document).scrollTop());
  49. }
  50. if(_d){
  51. _1(_c);
  52. }
  53. };
  54. function _11(_12){
  55. var _13=$.data(_12,"window");
  56. var _14=_13.options;
  57. var win=$(_12).panel($.extend({},_13.options,{border:false,doSize:true,closed:true,cls:"window",headerCls:"window-header",bodyCls:"window-body "+(_14.noheader?"window-body-noheader":""),onBeforeDestroy:function(){
  58. if(_14.onBeforeDestroy.call(_12)==false){
  59. return false;
  60. }
  61. if(_13.shadow){
  62. _13.shadow.remove();
  63. }
  64. if(_13.mask){
  65. _13.mask.remove();
  66. }
  67. },onClose:function(){
  68. if(_13.shadow){
  69. _13.shadow.hide();
  70. }
  71. if(_13.mask){
  72. _13.mask.hide();
  73. }
  74. _14.onClose.call(_12);
  75. },onOpen:function(){
  76. if(_13.mask){
  77. _13.mask.css({display:"block",zIndex:$.fn.window.defaults.zIndex++});
  78. }
  79. if(_13.shadow){
  80. _13.shadow.css({display:"block",zIndex:$.fn.window.defaults.zIndex++,left:_14.left,top:_14.top,width:_13.window._outerWidth(),height:_13.window._outerHeight()});
  81. }
  82. _13.window.css("z-index",$.fn.window.defaults.zIndex++);
  83. _14.onOpen.call(_12);
  84. },onResize:function(_15,_16){
  85. var _17=$(this).panel("options");
  86. $.extend(_14,{width:_17.width,height:_17.height,left:_17.left,top:_17.top});
  87. if(_13.shadow){
  88. _13.shadow.css({left:_14.left,top:_14.top,width:_13.window._outerWidth(),height:_13.window._outerHeight()});
  89. }
  90. _14.onResize.call(_12,_15,_16);
  91. },onMinimize:function(){
  92. if(_13.shadow){
  93. _13.shadow.hide();
  94. }
  95. if(_13.mask){
  96. _13.mask.hide();
  97. }
  98. _13.options.onMinimize.call(_12);
  99. },onBeforeCollapse:function(){
  100. if(_14.onBeforeCollapse.call(_12)==false){
  101. return false;
  102. }
  103. if(_13.shadow){
  104. _13.shadow.hide();
  105. }
  106. },onExpand:function(){
  107. if(_13.shadow){
  108. _13.shadow.show();
  109. }
  110. _14.onExpand.call(_12);
  111. }}));
  112. _13.window=win.panel("panel");
  113. if(_13.mask){
  114. _13.mask.remove();
  115. }
  116. if(_14.modal==true){
  117. _13.mask=$("<div class=\"window-mask\"></div>").insertAfter(_13.window);
  118. _13.mask.css({width:(_14.inline?_13.mask.parent().width():_18().width),height:(_14.inline?_13.mask.parent().height():_18().height),display:"none"});
  119. }
  120. if(_13.shadow){
  121. _13.shadow.remove();
  122. }
  123. if(_14.shadow==true){
  124. _13.shadow=$("<div class=\"window-shadow\"></div>").insertAfter(_13.window);
  125. _13.shadow.css({display:"none"});
  126. }
  127. if(_14.left==null){
  128. _5(_12);
  129. }
  130. if(_14.top==null){
  131. _b(_12);
  132. }
  133. _1(_12);
  134. if(!_14.closed){
  135. win.window("open");
  136. }
  137. };
  138. function _19(_1a){
  139. var _1b=$.data(_1a,"window");
  140. _1b.window.draggable({handle:">div.panel-header>div.panel-title",disabled:_1b.options.draggable==false,onStartDrag:function(e){
  141. if(_1b.mask){
  142. _1b.mask.css("z-index",$.fn.window.defaults.zIndex++);
  143. }
  144. if(_1b.shadow){
  145. _1b.shadow.css("z-index",$.fn.window.defaults.zIndex++);
  146. }
  147. _1b.window.css("z-index",$.fn.window.defaults.zIndex++);
  148. if(!_1b.proxy){
  149. _1b.proxy=$("<div class=\"window-proxy\"></div>").insertAfter(_1b.window);
  150. }
  151. _1b.proxy.css({display:"none",zIndex:$.fn.window.defaults.zIndex++,left:e.data.left,top:e.data.top});
  152. _1b.proxy._outerWidth(_1b.window._outerWidth());
  153. _1b.proxy._outerHeight(_1b.window._outerHeight());
  154. setTimeout(function(){
  155. if(_1b.proxy){
  156. _1b.proxy.show();
  157. }
  158. },500);
  159. },onDrag:function(e){
  160. _1b.proxy.css({display:"block",left:e.data.left,top:e.data.top});
  161. return false;
  162. },onStopDrag:function(e){
  163. _1b.options.left=e.data.left;
  164. _1b.options.top=e.data.top;
  165. $(_1a).window("move");
  166. _1b.proxy.remove();
  167. _1b.proxy=null;
  168. }});
  169. _1b.window.resizable({disabled:_1b.options.resizable==false,onStartResize:function(e){
  170. if(_1b.pmask){
  171. _1b.pmask.remove();
  172. }
  173. _1b.pmask=$("<div class=\"window-proxy-mask\"></div>").insertAfter(_1b.window);
  174. _1b.pmask.css({zIndex:$.fn.window.defaults.zIndex++,left:e.data.left,top:e.data.top,width:_1b.window._outerWidth(),height:_1b.window._outerHeight()});
  175. if(_1b.proxy){
  176. _1b.proxy.remove();
  177. }
  178. _1b.proxy=$("<div class=\"window-proxy\"></div>").insertAfter(_1b.window);
  179. _1b.proxy.css({zIndex:$.fn.window.defaults.zIndex++,left:e.data.left,top:e.data.top});
  180. _1b.proxy._outerWidth(e.data.width)._outerHeight(e.data.height);
  181. },onResize:function(e){
  182. _1b.proxy.css({left:e.data.left,top:e.data.top});
  183. _1b.proxy._outerWidth(e.data.width);
  184. _1b.proxy._outerHeight(e.data.height);
  185. return false;
  186. },onStopResize:function(e){
  187. $(_1a).window("resize",e.data);
  188. _1b.pmask.remove();
  189. _1b.pmask=null;
  190. _1b.proxy.remove();
  191. _1b.proxy=null;
  192. }});
  193. };
  194. function _18(){
  195. if(document.compatMode=="BackCompat"){
  196. return {width:Math.max(document.body.scrollWidth,document.body.clientWidth),height:Math.max(document.body.scrollHeight,document.body.clientHeight)};
  197. }else{
  198. return {width:Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth),height:Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight)};
  199. }
  200. };
  201. $(window).resize(function(){
  202. $("body>div.window-mask").css({width:$(window)._outerWidth(),height:$(window)._outerHeight()});
  203. setTimeout(function(){
  204. $("body>div.window-mask").css({width:_18().width,height:_18().height});
  205. },50);
  206. });
  207. $.fn.window=function(_1c,_1d){
  208. if(typeof _1c=="string"){
  209. var _1e=$.fn.window.methods[_1c];
  210. if(_1e){
  211. return _1e(this,_1d);
  212. }else{
  213. return this.panel(_1c,_1d);
  214. }
  215. }
  216. _1c=_1c||{};
  217. return this.each(function(){
  218. var _1f=$.data(this,"window");
  219. if(_1f){
  220. $.extend(_1f.options,_1c);
  221. }else{
  222. _1f=$.data(this,"window",{options:$.extend({},$.fn.window.defaults,$.fn.window.parseOptions(this),_1c)});
  223. if(!_1f.options.inline){
  224. document.body.appendChild(this);
  225. }
  226. }
  227. _11(this);
  228. _19(this);
  229. });
  230. };
  231. $.fn.window.methods={options:function(jq){
  232. var _20=jq.panel("options");
  233. var _21=$.data(jq[0],"window").options;
  234. return $.extend(_21,{closed:_20.closed,collapsed:_20.collapsed,minimized:_20.minimized,maximized:_20.maximized});
  235. },window:function(jq){
  236. return $.data(jq[0],"window").window;
  237. },move:function(jq,_22){
  238. return jq.each(function(){
  239. _1(this,_22);
  240. });
  241. },hcenter:function(jq){
  242. return jq.each(function(){
  243. _5(this,true);
  244. });
  245. },vcenter:function(jq){
  246. return jq.each(function(){
  247. _b(this,true);
  248. });
  249. },center:function(jq){
  250. return jq.each(function(){
  251. _5(this);
  252. _b(this);
  253. _1(this);
  254. });
  255. }};
  256. $.fn.window.parseOptions=function(_23){
  257. return $.extend({},$.fn.panel.parseOptions(_23),$.parser.parseOptions(_23,[{draggable:"boolean",resizable:"boolean",shadow:"boolean",modal:"boolean",inline:"boolean"}]));
  258. };
  259. $.fn.window.defaults=$.extend({},$.fn.panel.defaults,{zIndex:9000,draggable:true,resizable:true,shadow:true,modal:false,inline:false,title:"New Window",collapsible:true,minimizable:true,maximizable:true,closable:true,closed:false});
  260. })(jQuery);