jquery.window.js 8.0 KB

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