谁能解释下这段代码?

liusahara 2011-08-08 08:53:37
CC.extendx(CTab.prototype, CContainerBase);

CC.extend(CTab.prototype, {

type: 'CTab',

//默认TabItem长度.
defItemLen: 130,

//该面板存放当前显示的TabItem中的面板,TabItem中的面板将放入该面板内,即Tab显示主体.
ctxPanel: null,

selected: null,

initialize: function(opt) {
this._super(opt); if (!this.ctxPanel) {
this.ctxPanel = CC. $C('DIV');
}

//重写容器类的add方法.
this.override('add', function(it) {
//selected event.
it.view.onclick = this.select.bind(this, it);
//close event.
it.view.ondblclick = this.show.bind(this, it, false); it.setOnclose(this.show.bind(this, it, false)); this._ajust(); it.parent = this;
}
);
}
,

//设置Tab控件显示主板面板.
setCtxPanel: function(v) {
this.ctxPanel = v;
}
,

_ajust: function() {
var sty = this.view.style; var w = this.view.clientWidth; var ch = this.children; var tcnt = this.children.length; var vcnt = 0; for (var i = 0; i < tcnt; i++) {
if (ch[i].isVisible()) {
vcnt++
}
}

var perw = Math.floor(w / vcnt);

if (perw > this.defItemLen) {
perw = this.defItemLen;
}

for (var i = 0; i < tcnt; i++) {
ch[i].setWidth(perw);
}
}
,

//是否显示指定的TabItem,
//参数a可为TabItem实例也可为TabItem的id,b为true或false.
show: function(a, b) {
//only one,can't set it.
if (!b && this.getDisc() == 1) {
return ;
}
a = this. $(a);

//Cann't change this attribute.
if (!a.closeable && !b) {
return false;
}

var isv = a.isVisible();

if (isv != b) {
this._ajust();
}

a.setVisible(b);

if (!b && this.selected == a) {
var idx = this.indexOf(a); var tmp = idx - 1; var chs = this.children;
while (tmp >= 0 && !chs[tmp].isVisible()) {
tmp--;
}
if (tmp >= 0) {
this.select(chs[tmp]);
if(!b){
this.remove(a);
}
return ;

}

tmp = chs.length; idx += 1;
while (idx < tmp && !chs[idx].isVisible()) {
idx++;
}
if (idx < tmp) {
this.select(chs[idx]);
}
}
}
,

//选择某个TabItem,
//参数a可为TabItem实例也可为id.
select: function(a) {

if (a == '' || a == null) {
var sel = this.selected; if (sel) {
sel.setViewAttr('className', ''); this.ctxPanel.removeChild(sel.panel);
}
this.selected = ''; return ;
}

if (a == this.selected) {
return ;
}

a = this.get(a); if (a == null) {
return ;
}

this.show(a, true);

var sel = this.selected; if (sel) {
sel.setViewAttr('className', ''); this.ctxPanel.removeChild(sel.panel);
}

this.selected = a; a.setViewAttr('className', 'on'); this.ctxPanel.appendChild(a.panel); if (this.onselect) {
this.onselect(a);
}
}
,
//返回显示的TabItem个数.
getDisc: function() {
var cnt = 0; var chs = this.children; for (var i = 0, len = chs.length; i < len; i++) {
if (chs[i].isVisible()) {
cnt++;
}
}
return cnt;
}
});

谁能解释下上面的代码?看不懂,望赐教!
...全文
76 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
豆虫 2011-08-08
  • 打赏
  • 举报
回复
先自己试着研究下 毕竟这只是截取了一段 还是你本人最了解 给你打打气~~

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧