jquery.layout.js 12.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
/**
 * jQuery EasyUI 1.5
 * 
 * Copyright (c) 2009-2016 www.jeasyui.com. All rights reserved.
 *
 * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
 * To use it on other terms please contact us: info@jeasyui.com
 *
 */
(function($){
var _1=false;
function _2(_3,_4){
var _5=$.data(_3,"layout");
var _6=_5.options;
var _7=_5.panels;
var cc=$(_3);
if(_4){
$.extend(_6,{width:_4.width,height:_4.height});
}
if(_3.tagName.toLowerCase()=="body"){
cc._size("fit");
}else{
cc._size(_6);
}
var _8={top:0,left:0,width:cc.width(),height:cc.height()};
_9(_a(_7.expandNorth)?_7.expandNorth:_7.north,"n");
_9(_a(_7.expandSouth)?_7.expandSouth:_7.south,"s");
_b(_a(_7.expandEast)?_7.expandEast:_7.east,"e");
_b(_a(_7.expandWest)?_7.expandWest:_7.west,"w");
_7.center.panel("resize",_8);
function _9(pp,_c){
if(!pp.length||!_a(pp)){
return;
}
var _d=pp.panel("options");
pp.panel("resize",{width:cc.width(),height:_d.height});
var _e=pp.panel("panel").outerHeight();
pp.panel("move",{left:0,top:(_c=="n"?0:cc.height()-_e)});
_8.height-=_e;
if(_c=="n"){
_8.top+=_e;
if(!_d.split&&_d.border){
_8.top--;
}
}
if(!_d.split&&_d.border){
_8.height++;
}
};
function _b(pp,_f){
if(!pp.length||!_a(pp)){
return;
}
var _10=pp.panel("options");
pp.panel("resize",{width:_10.width,height:_8.height});
var _11=pp.panel("panel").outerWidth();
pp.panel("move",{left:(_f=="e"?cc.width()-_11:0),top:_8.top});
_8.width-=_11;
if(_f=="w"){
_8.left+=_11;
if(!_10.split&&_10.border){
_8.left--;
}
}
if(!_10.split&&_10.border){
_8.width++;
}
};
};
function _12(_13){
var cc=$(_13);
cc.addClass("layout");
function _14(el){
var _15=$.fn.layout.parsePanelOptions(el);
if("north,south,east,west,center".indexOf(_15.region)>=0){
_19(_13,_15,el);
}
};
var _16=cc.layout("options");
var _17=_16.onAdd;
_16.onAdd=function(){
};
cc.find(">div,>form>div").each(function(){
_14(this);
});
_16.onAdd=_17;
cc.append("<div class=\"layout-split-proxy-h\"></div><div class=\"layout-split-proxy-v\"></div>");
cc.bind("_resize",function(e,_18){
if($(this).hasClass("easyui-fluid")||_18){
_2(_13);
}
return false;
});
};
function _19(_1a,_1b,el){
_1b.region=_1b.region||"center";
var _1c=$.data(_1a,"layout").panels;
var cc=$(_1a);
var dir=_1b.region;
if(_1c[dir].length){
return;
}
var pp=$(el);
if(!pp.length){
pp=$("<div></div>").appendTo(cc);
}
var _1d=$.extend({},$.fn.layout.paneldefaults,{width:(pp.length?parseInt(pp[0].style.width)||pp.outerWidth():"auto"),height:(pp.length?parseInt(pp[0].style.height)||pp.outerHeight():"auto"),doSize:false,collapsible:true,onOpen:function(){
var _1e=$(this).panel("header").children("div.panel-tool");
_1e.children("a.panel-tool-collapse").hide();
var _1f={north:"up",south:"down",east:"right",west:"left"};
if(!_1f[dir]){
return;
}
var _20="layout-button-"+_1f[dir];
var t=_1e.children("a."+_20);
if(!t.length){
t=$("<a href=\"javascript:void(0)\"></a>").addClass(_20).appendTo(_1e);
t.bind("click",{dir:dir},function(e){
_2d(_1a,e.data.dir);
return false;
});
}
$(this).panel("options").collapsible?t.show():t.hide();
}},_1b,{cls:((_1b.cls||"")+" layout-panel layout-panel-"+dir),bodyCls:((_1b.bodyCls||"")+" layout-body")});
pp.panel(_1d);
_1c[dir]=pp;
var _21={north:"s",south:"n",east:"w",west:"e"};
var _22=pp.panel("panel");
if(pp.panel("options").split){
_22.addClass("layout-split-"+dir);
}
_22.resizable($.extend({},{handles:(_21[dir]||""),disabled:(!pp.panel("options").split),onStartResize:function(e){
_1=true;
if(dir=="north"||dir=="south"){
var _23=$(">div.layout-split-proxy-v",_1a);
}else{
var _23=$(">div.layout-split-proxy-h",_1a);
}
var top=0,_24=0,_25=0,_26=0;
var pos={display:"block"};
if(dir=="north"){
pos.top=parseInt(_22.css("top"))+_22.outerHeight()-_23.height();
pos.left=parseInt(_22.css("left"));
pos.width=_22.outerWidth();
pos.height=_23.height();
}else{
if(dir=="south"){
pos.top=parseInt(_22.css("top"));
pos.left=parseInt(_22.css("left"));
pos.width=_22.outerWidth();
pos.height=_23.height();
}else{
if(dir=="east"){
pos.top=parseInt(_22.css("top"))||0;
pos.left=parseInt(_22.css("left"))||0;
pos.width=_23.width();
pos.height=_22.outerHeight();
}else{
if(dir=="west"){
pos.top=parseInt(_22.css("top"))||0;
pos.left=_22.outerWidth()-_23.width();
pos.width=_23.width();
pos.height=_22.outerHeight();
}
}
}
}
_23.css(pos);
$("<div class=\"layout-mask\"></div>").css({left:0,top:0,width:cc.width(),height:cc.height()}).appendTo(cc);
},onResize:function(e){
if(dir=="north"||dir=="south"){
var _27=$(">div.layout-split-proxy-v",_1a);
_27.css("top",e.pageY-$(_1a).offset().top-_27.height()/2);
}else{
var _27=$(">div.layout-split-proxy-h",_1a);
_27.css("left",e.pageX-$(_1a).offset().left-_27.width()/2);
}
return false;
},onStopResize:function(e){
cc.children("div.layout-split-proxy-v,div.layout-split-proxy-h").hide();
pp.panel("resize",e.data);
_2(_1a);
_1=false;
cc.find(">div.layout-mask").remove();
}},_1b));
cc.layout("options").onAdd.call(_1a,dir);
};
function _28(_29,_2a){
var _2b=$.data(_29,"layout").panels;
if(_2b[_2a].length){
_2b[_2a].panel("destroy");
_2b[_2a]=$();
var _2c="expand"+_2a.substring(0,1).toUpperCase()+_2a.substring(1);
if(_2b[_2c]){
_2b[_2c].panel("destroy");
_2b[_2c]=undefined;
}
$(_29).layout("options").onRemove.call(_29,_2a);
}
};
function _2d(_2e,_2f,_30){
if(_30==undefined){
_30="normal";
}
var _31=$.data(_2e,"layout").panels;
var p=_31[_2f];
var _32=p.panel("options");
if(_32.onBeforeCollapse.call(p)==false){
return;
}
var _33="expand"+_2f.substring(0,1).toUpperCase()+_2f.substring(1);
if(!_31[_33]){
_31[_33]=_34(_2f);
var ep=_31[_33].panel("panel");
if(!_32.expandMode){
ep.css("cursor","default");
}else{
ep.bind("click",function(){
if(_32.expandMode=="dock"){
_41(_2e,_2f);
}else{
p.panel("expand",false).panel("open");
var _35=_36();
p.panel("resize",_35.collapse);
p.panel("panel").animate(_35.expand,function(){
$(this).unbind(".layout").bind("mouseleave.layout",{region:_2f},function(e){
if(_1==true){
return;
}
if($("body>div.combo-p>div.combo-panel:visible").length){
return;
}
_2d(_2e,e.data.region);
});
$(_2e).layout("options").onExpand.call(_2e,_2f);
});
}
return false;
});
}
}
var _37=_36();
if(!_a(_31[_33])){
_31.center.panel("resize",_37.resizeC);
}
p.panel("panel").animate(_37.collapse,_30,function(){
p.panel("collapse",false).panel("close");
_31[_33].panel("open").panel("resize",_37.expandP);
$(this).unbind(".layout");
$(_2e).layout("options").onCollapse.call(_2e,_2f);
});
function _34(dir){
var _38={"east":"left","west":"right","north":"down","south":"up"};
var _39=(_32.region=="north"||_32.region=="south");
var _3a="layout-button-"+_38[dir];
var p=$("<div></div>").appendTo(_2e);
p.panel($.extend({},$.fn.layout.paneldefaults,{cls:("layout-expand layout-expand-"+dir),title:"&nbsp;",iconCls:(_32.hideCollapsedContent?null:_32.iconCls),closed:true,minWidth:0,minHeight:0,doSize:false,region:_32.region,collapsedSize:_32.collapsedSize,noheader:(!_39&&_32.hideExpandTool),tools:((_39&&_32.hideExpandTool)?null:[{iconCls:_3a,handler:function(){
_41(_2e,_2f);
return false;
}}])}));
if(!_32.hideCollapsedContent){
var _3b=typeof _32.collapsedContent=="function"?_32.collapsedContent.call(p[0],_32.title):_32.collapsedContent;
_39?p.panel("setTitle",_3b):p.html(_3b);
}
p.panel("panel").hover(function(){
$(this).addClass("layout-expand-over");
},function(){
$(this).removeClass("layout-expand-over");
});
return p;
};
function _36(){
var cc=$(_2e);
var _3c=_31.center.panel("options");
var _3d=_32.collapsedSize;
if(_2f=="east"){
var _3e=p.panel("panel")._outerWidth();
var _3f=_3c.width+_3e-_3d;
if(_32.split||!_32.border){
_3f++;
}
return {resizeC:{width:_3f},expand:{left:cc.width()-_3e},expandP:{top:_3c.top,left:cc.width()-_3d,width:_3d,height:_3c.height},collapse:{left:cc.width(),top:_3c.top,height:_3c.height}};
}else{
if(_2f=="west"){
var _3e=p.panel("panel")._outerWidth();
var _3f=_3c.width+_3e-_3d;
if(_32.split||!_32.border){
_3f++;
}
return {resizeC:{width:_3f,left:_3d-1},expand:{left:0},expandP:{left:0,top:_3c.top,width:_3d,height:_3c.height},collapse:{left:-_3e,top:_3c.top,height:_3c.height}};
}else{
if(_2f=="north"){
var _40=p.panel("panel")._outerHeight();
var hh=_3c.height;
if(!_a(_31.expandNorth)){
hh+=_40-_3d+((_32.split||!_32.border)?1:0);
}
_31.east.add(_31.west).add(_31.expandEast).add(_31.expandWest).panel("resize",{top:_3d-1,height:hh});
return {resizeC:{top:_3d-1,height:hh},expand:{top:0},expandP:{top:0,left:0,width:cc.width(),height:_3d},collapse:{top:-_40,width:cc.width()}};
}else{
if(_2f=="south"){
var _40=p.panel("panel")._outerHeight();
var hh=_3c.height;
if(!_a(_31.expandSouth)){
hh+=_40-_3d+((_32.split||!_32.border)?1:0);
}
_31.east.add(_31.west).add(_31.expandEast).add(_31.expandWest).panel("resize",{height:hh});
return {resizeC:{height:hh},expand:{top:cc.height()-_40},expandP:{top:cc.height()-_3d,left:0,width:cc.width(),height:_3d},collapse:{top:cc.height(),width:cc.width()}};
}
}
}
}
};
};
function _41(_42,_43){
var _44=$.data(_42,"layout").panels;
var p=_44[_43];
var _45=p.panel("options");
if(_45.onBeforeExpand.call(p)==false){
return;
}
var _46="expand"+_43.substring(0,1).toUpperCase()+_43.substring(1);
if(_44[_46]){
_44[_46].panel("close");
p.panel("panel").stop(true,true);
p.panel("expand",false).panel("open");
var _47=_48();
p.panel("resize",_47.collapse);
p.panel("panel").animate(_47.expand,function(){
_2(_42);
$(_42).layout("options").onExpand.call(_42,_43);
});
}
function _48(){
var cc=$(_42);
var _49=_44.center.panel("options");
if(_43=="east"&&_44.expandEast){
return {collapse:{left:cc.width(),top:_49.top,height:_49.height},expand:{left:cc.width()-p.panel("panel")._outerWidth()}};
}else{
if(_43=="west"&&_44.expandWest){
return {collapse:{left:-p.panel("panel")._outerWidth(),top:_49.top,height:_49.height},expand:{left:0}};
}else{
if(_43=="north"&&_44.expandNorth){
return {collapse:{top:-p.panel("panel")._outerHeight(),width:cc.width()},expand:{top:0}};
}else{
if(_43=="south"&&_44.expandSouth){
return {collapse:{top:cc.height(),width:cc.width()},expand:{top:cc.height()-p.panel("panel")._outerHeight()}};
}
}
}
}
};
};
function _a(pp){
if(!pp){
return false;
}
if(pp.length){
return pp.panel("panel").is(":visible");
}else{
return false;
}
};
function _4a(_4b){
var _4c=$.data(_4b,"layout");
var _4d=_4c.options;
var _4e=_4c.panels;
var _4f=_4d.onCollapse;
_4d.onCollapse=function(){
};
_50("east");
_50("west");
_50("north");
_50("south");
_4d.onCollapse=_4f;
function _50(_51){
var p=_4e[_51];
if(p.length&&p.panel("options").collapsed){
_2d(_4b,_51,0);
}
};
};
function _52(_53,_54,_55){
var p=$(_53).layout("panel",_54);
p.panel("options").split=_55;
var cls="layout-split-"+_54;
var _56=p.panel("panel").removeClass(cls);
if(_55){
_56.addClass(cls);
}
_56.resizable({disabled:(!_55)});
_2(_53);
};
$.fn.layout=function(_57,_58){
if(typeof _57=="string"){
return $.fn.layout.methods[_57](this,_58);
}
_57=_57||{};
return this.each(function(){
var _59=$.data(this,"layout");
if(_59){
$.extend(_59.options,_57);
}else{
var _5a=$.extend({},$.fn.layout.defaults,$.fn.layout.parseOptions(this),_57);
$.data(this,"layout",{options:_5a,panels:{center:$(),north:$(),south:$(),east:$(),west:$()}});
_12(this);
}
_2(this);
_4a(this);
});
};
$.fn.layout.methods={options:function(jq){
return $.data(jq[0],"layout").options;
},resize:function(jq,_5b){
return jq.each(function(){
_2(this,_5b);
});
},panel:function(jq,_5c){
return $.data(jq[0],"layout").panels[_5c];
},collapse:function(jq,_5d){
return jq.each(function(){
_2d(this,_5d);
});
},expand:function(jq,_5e){
return jq.each(function(){
_41(this,_5e);
});
},add:function(jq,_5f){
return jq.each(function(){
_19(this,_5f);
_2(this);
if($(this).layout("panel",_5f.region).panel("options").collapsed){
_2d(this,_5f.region,0);
}
});
},remove:function(jq,_60){
return jq.each(function(){
_28(this,_60);
_2(this);
});
},split:function(jq,_61){
return jq.each(function(){
_52(this,_61,true);
});
},unsplit:function(jq,_62){
return jq.each(function(){
_52(this,_62,false);
});
}};
$.fn.layout.parseOptions=function(_63){
return $.extend({},$.parser.parseOptions(_63,[{fit:"boolean"}]));
};
$.fn.layout.defaults={fit:false,onExpand:function(_64){
},onCollapse:function(_65){
},onAdd:function(_66){
},onRemove:function(_67){
}};
$.fn.layout.parsePanelOptions=function(_68){
var t=$(_68);
return $.extend({},$.fn.panel.parseOptions(_68),$.parser.parseOptions(_68,["region",{split:"boolean",collpasedSize:"number",minWidth:"number",minHeight:"number",maxWidth:"number",maxHeight:"number"}]));
};
$.fn.layout.paneldefaults=$.extend({},$.fn.panel.defaults,{region:null,split:false,collapsedSize:28,expandMode:"float",hideExpandTool:false,hideCollapsedContent:true,collapsedContent:function(_69){
var p=$(this);
var _6a=p.panel("options");
if(_6a.region=="north"||_6a.region=="south"){
return _69;
}
var _6b=_6a.collapsedSize-2;
var _6c=(_6b-16)/2;
_6c=_6b-_6c;
var cc=[];
if(_6a.iconCls){
cc.push("<div class=\"panel-icon "+_6a.iconCls+"\"></div>");
}
cc.push("<div class=\"panel-title layout-expand-title");
cc.push(_6a.iconCls?" layout-expand-with-icon":"");
cc.push("\" style=\"left:"+_6c+"px\">");
cc.push(_69);
cc.push("</div>");
return cc.join("");
},minWidth:10,minHeight:10,maxWidth:10000,maxHeight:10000});
})(jQuery);