(
function
(undefined) {
var
cOnfig= {
useUixLayout:
true
,
isDebugger:
true
,
version:
"V201508171400"
,
filename:
"uix.layout.js"
,
timeout: 500
};
var
log =
function
() { }
if
(
typeof
console !=
"undefined"
&& console.log) {
log =
function
(context, checklog) {
if
(
typeof
checklog !=
"undefined"
|| config.isDebugger)
console.log(
"%c"
+
"[uix.layout]"
,
"color:green;"
, context);
}
}
log(
"加载中"
,
true
);
if
(!config.useUixLayout) { log(
"已停止加载[uix.layout 未启用]"
,
true
);
return
; }
if
(
typeof
$ ==
"undefined"
) { log(
"已停止加载[需要jQuery支持]"
,
true
);
return
; }
if
(
typeof
$.uix !=
"undefined"
) { log(
"已停止加载[已加载过]"
,
true
);
return
; }
log(
"日志状态["
+ (config.isDebugger ?
"启用"
:
"禁用"
) +
"]"
,
true
);
var
tool = {
selecter:
".uix_box"
,
setAutoBox:
function
(inputSelecter) {
var
sel = inputSelecter || tool.selecter;
$(sel).each(
function
() {
var
o = $(
this
);
var
p = o.parent();
var
s = tool.getEleSize(o);
o.height(p.height() - s.otherHeight - tool.getCV(o, [
"marginTop"
,
"marginBottom"
]));
o.width(p.width() - s.otherWidth - tool.getCV(o, [
"marginLeft"
,
"marginRight"
]));
})
},
getCV:
function
(ele, cn) {
var
s = 0;
if
(
typeof
cn ==
"string"
) cn = [cn];
$(cn).each(
function
(i, o) {
var
v;
s += isNaN(v = parseInt(ele.css(o))) ? 0 : v;
});
return
s;
},
getOtherHeight:
function
($obj) {
return
$obj.outerHeight() - $obj.height() },
getOtherWidth:
function
($obj) {
return
$obj.outerWidth() - $obj.width() },
getEleSize:
function
($objs) {
var
rev = { height: 0, width: 0, otherHeight: 0, otherWidth: 0, outerHeight: 0, outerWidth: 0, children: [] };
for
(
var
i = 0; i <$objs.length; i++) {
var
o = $($objs[i]);
var
h = o.height(), w = o.width(), oh = o.outerHeight(), ow = o.outerWidth();
var
c = { height: h, width: w, otherHeight: oh - h, otherWidth: ow - w, outerHeight: oh, outerWidth: ow, ele: o }
rev.height += c.height;
rev.width += c.width;
rev.otherHeight += c.otherHeight;
rev.otherWidth += c.otherWidth;
rev.outerHeight += c.outerHeight;
rev.outerWidth += c.outerWidth;
rev.children.push(c);
}
return
rev;
},
log: log
}
var
uixlayout = {
tool: tool,
layout:
function
(cssname) {
var
timeout =
function
() {
tool.log(
"开始布局["
+ window.__uixlayoutstate +
"]"
);
var
pares = $(
".uix-layout-container"
);
pares.each(
function
(obj, i) {
$.uix.initLayout($(
this
));
});
$.uix.setGrid($(
".uix_grid"
));
tool.log(
"布局完毕["
+ window.__uixlayoutstate +
"]"
);
window.__uixlayoutstate =
false
;
}
if
(
typeof
window.__uixlayoutstate ==
"number"
) {
tool.log(
"取消布局["
+ window.__uixlayoutstate +
"]"
);
window.clearTimeout(window.__uixlayoutstate);
}
window.__uixlayoutstate = setTimeout(timeout, config.timeout);
tool.log(
"等待布局["
+ window.__uixlayoutstate +
"] 等待"
+ config.timeout +
"ms"
);
return
;
},
initLayout:
function
(pare) {
var
parent;
if
(pare[0].tagName.toUpperCase() ==
"BODY"
) {
parent = { height: $(window).height(), width: $(window).width() };
var
marginHeight = tool.getCV($(pare), [
"marginTop"
,
"marginBottom"
]);
parent.height -= marginHeight;
}
else
{
parent = { height: $(pare[0]).height(), width: $(pare[0]).width() };
var
marginHeight = tool.getCV($(pare), [
"marginTop"
,
"marginBottom"
]);
parent.height -= marginHeight;
}
parent.element = pare;
if
(pare[0].tagName.toUpperCase() ==
"BODY"
) {
pare.height(parent.height);
}
var
eles = {
north: pare.children(
".uix-layout-north:visible"
),
south: pare.children(
".uix-layout-south:visible"
),
east: pare.children(
".uix-layout-east:visible"
),
west: pare.children(
".uix-layout-west:visible"
),
center: pare.children(
".uix-layout-center:visible"
)
}
var
s = {
parent: parent,
norths: tool.getEleSize(eles.north),
souths: tool.getEleSize(eles.south),
centers: tool.getEleSize(eles.center),
easts: tool.getEleSize(eles.east),
wests: tool.getEleSize(eles.west)
}
s.centers.outerHeight = s.parent.height - s.norths.outerHeight - s.souths.outerHeight;
s.centers.height = s.centers.outerHeight - s.centers.otherHeight;
s.centers.outerWidth = s.parent.width - s.wests.outerWidth - s.easts.outerWidth;
s.centers.width = s.centers.outerWidth - s.centers.otherWidth;
tool.log(s);
var
autoHeight = parent.height - s.norths.outerHeight - s.souths.outerHeight;
var
autoWidth = parent.width - s.wests.outerWidth - s.easts.outerWidth;
var
cheight = s.centers.height;
var
cwidth = s.centers.width;
eles.north.css({ margin:
"0px"
});
eles.south.css({ margin:
"0px"
});
var
left = 0;
var
top = s.norths.outerHeight;
for
(
var
i = 0; i <s.wests.children.length; i++)=
""
{=
""
var
=
""
item=
"s.wests.children[i];"
westheight=
"autoHeight"
-=
""
item.otherheight;=
""
item.ele.css({=
""
position:=
""
"absolute"
,=
""
left:=
""
left=
""
+=
""
"px"
,=
""
right:=
""
"auto"
,=
""
top:=
""
top=
""
bottom:=
""
height:=
""
display:=
""
"block"
,=
""
margin:=
""
"0px"
=
""
});=
""
}=
""
right=
"0;"
parentbordr.right;=
""
for
=
""
(
var
=
""
i=
"0;"
<s.easts.children.length;=
""
eastheight=
"autoHeight"
eles.center.css({=
""
cheight,=
""
"marginleft"
:=
""
s.wests.outerwidth,=
""
"marginright"
:=
""
s.easts.outerwidth=
""
tool.log(
"整体布局完成"
);=
""
tool.log(
"开始检测回调函数="
" 提示:可设置window.uixafterresize值[false:禁用回调|function:自定义回调|undefined(默认):自动检测]"
);=
""
this
.resizecontral(s);=
""
tool.log(
"回调函数处理完毕"
);=
""
$.uix.tool.setautobox();=
""
uix_box=
""
高宽自适应=
""
},=
""
resizecontral:=
""
function
=
""
(sizes)=
""
调整布局内常用版式=
""
检查用户设置的=
""
uixafterresize=
""
变量,=
""
boolean=
""
fale:不进行排盘,=
""
调用自定义函数,=
""
undefined=
""
自动检测所属版式=
""
if
=
""
(
typeof
=
""
window.uixafterresize=
"="
"boolean"
=
""
&&=
""
false
)=
""
tool.log(
"禁用自动解析回调[window.uixafterresize="
=
false
]");
" return;="
" "
function
")="
" tool.log("
调用自定义回调函数[window.uixafterresize=
"function]");"
window.uixafterresize(sizes);=
""
"undefined"
)=
""
tool.log(
"使用自动解析回调[window.uixafterresize="
undefined]");
" n="
sizes.norths.children.length;
" w="
sizes.wests.children.length;
" e="
sizes.easts.children.length;
" c="
sizes.centers.children.length;
" s="
sizes.souths.children.length;
" tool.log("
解析页面结构
"="
" "
=
""
north[
"="
" "
]=
""
west[
"="
" east["
=
""
south[
"="
" center["
=
""
"]"
);=
""
判断界面结构,选择合适的回调方法,=
""
(w=
"="
0=
""
1)=
""
$.uix.afterresize1(sizes);=
""
1=
""
$.uix.afterresize2(sizes);=
""
initpage:=
""
()=
""
log(
"等待页面加载完成后初始化"
,=
""
true
);=
""
$(window.document.body).ready(
function
=
""
($(
".uix-layout-container"
).length=
"="
0)=
""
log(
"已停止加载[未发现.uix-layout-container]"
,=
""
$.uix.tool.log(
"触发布局[window="
" onload]"
);=
""
$.uix.layout();=
""
$(window).bind(
"resize"
,=
""
onresize]
");="
" $("
.uix-layout-north,.uix-layout-south,.uix-layout-east,.uix-layout-west
").bind("
resize
",="
" $.uix.tool.log("
触发布局[uix-layout-
"="
" $(this).attr("
class
")="
" log("
初始化完毕
",="
" afterresize1:="
" (size)="
" 特定结构回调1="
" afterresize2:="
" 特定结构回调2="
" };="
" $.extend({="
" uix:="
" uixlayout="
" log("
加载完毕
",="
" $.uix.initpage();="
" })();<="
" pre="
">
</s.wests.children.length;>