62,266
社区成员
发帖
与我相关
我的任务
分享
System.UI.tabPage = function()
{
this.classType = "System.UI.tabPage";
Class.initialize.apply(this,arguments);
}
System.UI.tabPage.prototype = {
initialize:function(_parent,o)
{
this.parent = _parent;
this.selected = false;
this.options = {
title:"New TAB",
width:80,
closeAble:false
};
Object.extend(this.options,o);
System.UI.elementInit.apply(this);
},
initElement:function()
{
this.field = $C("DIV");
this.tabObj = $C("li");
this.closeButton = this.tabObj.appendChild($C("div"));
this.bgRight = this.tabObj.appendChild($C("A"));
this.bgLeft = this.bgRight.appendChild($C("DIV"));
this.bgCenter = this.bgLeft.appendChild($C("DIV"));
this.titleObj = this.bgCenter.appendChild($C("span"));
this.parent.tabsField.appendChild(this.tabObj);
this.parent.pageField.appendChild(this.field);
},
scrollToView:function(){this.parent.scrollTo(this);},
setElement:function()
{
var css = System.UI.tabControl.css;
this.bgRight.href="javascript:;";
this.tabObj.className = css.TAB;
this.bgRight.className = css.TAB_BACKGROUND_RIGHT;
this.bgLeft.className = css.TAB_BACKGROUND_LEFT;
this.bgCenter.className = css.TAB_BACKGROUND;
this.closeButton.className = css.TAB_CLOSEBUTTON;
this.titleObj.className = css.TAB_TITLE;
this.field.className = css.TAB_PAGE;
this.field.style.display = "none";
this.title(this.options.title);
this.width(this.options.width);
this.closeAble(this.options.closeAble);
},
initEvent:function()
{
var self = this;
this.closeButton.onclick = function(){self.parent.removeTab(self);Browser.Event.cancelBubble(true);}
this.tabObj.onclick = function(){self.select();}
},
killEvent:function()
{
this.closeButton.onclick = this.bgRight.onclick = this.tabObj.onclick = null;
},
title:function(value)
{
if(typeof(value)=="string")
{
this.titleObj.textContent = this.titleObj.innerText =
this.options.title = value;
this.fireEvent("ontitlechange",value);
}
return this.options.title;
},
width:function(value)
{
if(value!=null)
{
value = parseInt(parseNum(value));
this.bgCenter.style.width = this.options.width = value?(value+"px"):"auto";
}
return this.options.width;
},
select:function(){this.parent.tabChange(this);},
focus:function()
{
this.selected = true;
this.scrollToView();
this.tabObj.className = System.UI.tabControl.css.TAB_SELECTED;
this.display(true);
this.fireEvent("onfocus");
},
blur:function()
{
this.selected = false;
this.tabObj.className = System.UI.tabControl.css.TAB;
this.display(false);
this.fireEvent("onblur");
},
display:function(value)
{
if(value!=null)
{
this._display = !!value;
this.field.style.display = this._display?"block":"none";
}
return this._display;
},
unload:function()
{
this.parent.tabs.Remove(this);
this.tabObj.parentNode.removeChild(this.tabObj);
this.field.parentNode.removeChild(this.field);
System.killInstance(this);
this.killEvent();
for(o in this)delete this[o];
},
closeAble:function(value)
{
if(value!=null)
{
this.options.closeAble = value = !!value;
this.bgLeft.style.paddingRight = value?"19px":"";
this.closeButton.style.display = value?"":"none";
}
return this.options.closeAble;
}
}System.StyleSheets.add("css/tabControl.css");
System.Scripts.add(System.Scripts.paths + "UIBase.js");
if(System==null)var System={};
if(System.UI==null)System.UI={};
System.UI.tabControl = function(){
this.classType = "System.UI.tabControl";
Class.initialize.apply(this,arguments);
}
System.UI.tabControl.css = {
TAB_CONTROL:"tabcontrol",
TAB_PANEL:"tab-panel",
TAB_HEAD:"tab-header",
TAB_SCROLL:"tab-scroll",
TAB_BUTTON:"tab-tab",
SCROLL_LEFT:"tab-sl",
SCROLL_RIGHT:"tab-sr",
TAB:"tab-tab",
TAB_SELECTED:"tab-tab1",
TAB_BACKGROUND:"tab-bg",
TAB_BACKGROUND_LEFT:"tab-bl",
TAB_BACKGROUND_RIGHT:"tab-br",
TAB_TITLE:"tab-bt",
TAB_PAGEFIELD:"tab-pagefield",
TAB_PAGE:"tab-page",
TAB_CLOSEBUTTON:"tab-bc"
}
System.UI.tabControl.prototype = {
initialize:function(_container,o)
{
this.container = _container;
this.tabs = [];
this.selectedTab = null;
this.options = Object.extend({
allowClose:false,
width:600,
height:400,
scrollSpeedLevel:3
},o)
if(this.container==null)return;
System.UI.elementInit.apply(this);
},
initElement:function()
{
this.mainObj = $C("DIV");
this.panel = $C("div");
this.header = $C("DIV");
this.tabsField = $C("ul");
this.pageField = $C("div");
this.leftButton = $C("div");
this.rightButton = $C("div");
with(this.mainObj)
{
appendChild(this.panel);
appendChild(this.pageField);
}
with(this.panel)
{
appendChild(this.leftButton);
appendChild(this.rightButton);
appendChild(this.header);
}
this.header.appendChild(this.tabsField);
this.container.appendChild(this.mainObj);
},
setElement:function()
{
var css = System.UI.tabControl.css;
this.pageField.className = css.TAB_PAGEFIELD;
this.panel.className = css.TAB_PANEL;
this.mainObj.className = css.TAB_CONTROL;
this.header.className = css.TAB_HEAD;
this.tabsField.className = css.TAB_SCROLL;
this.leftButton.className = css.SCROLL_LEFT;
this.rightButton.className = css.SCROLL_RIGHT;
this.width(this.options.width);
this.height(this.options.height);
this.resetScrollBar();
},
initEvent:function()
{
var self = this;
this.leftButton.onclick = function(){self.scrollLeft();}
this.rightButton.onclick = function(){self.scrollRight();}
this.panel.onselectstart = function(){return false;}
},
killEvent:function()
{
this.panel.onselectstart = this.leftButton.onclick = this.rightButton.onclick = null;
},
scrollLeft:function(step)
{
step = parseInt(parseNum(step)) || 1;
step--;
var leftlimit = this.header.scrollLeft;
var arr = [];
for(var i=this.tabs.length-1;i>=0;i--)
{
if(this.tabs[i].tabObj.offsetLeft<leftlimit)
arr[arr.length] = this.tabs[i];
}
step = step<arr.length?step:(arr.length-1);
this.scrollTo(arr[step]);
},
scrollRight:function(step)
{
step = parseInt(parseNum(step)) || 1;
step--;
var rightlimit = this.header.scrollLeft + this.header.clientWidth;
var arr = [];
for(var i=0,l=this.tabs.length;i<l;i++)
if(this.tabs[i].tabObj.offsetLeft + this.tabs[i].tabObj.offsetWidth > rightlimit)
arr[arr.length] = this.tabs[i];
step = step<arr.length?step:(arr.length-1);
this.scrollTo(arr[step]);
},
scrollTo:function(obj)
{
if(obj && obj.classType=="System.UI.tabPage")
{
obj = obj.tabObj;
if(obj.offsetLeft < this.header.scrollLeft)
this.scroll(obj.offsetLeft - 3);
else if(obj.offsetLeft + obj.offsetWidth > this.header.scrollLeft + this.header.clientWidth)
this.scroll(obj.offsetLeft + obj.offsetWidth - this.header.clientWidth + 3)
}
},
scroll:function(limit)
{
var self = this;
var direct = this.header.scrollLeft<limit?1:-1;
var ts;
var move = function(){
var left = self.header.scrollLeft + ((Math.abs(self.header.scrollLeft-limit)>>self.options.scrollSpeedLevel)*direct || direct);
if((left-limit)*direct<=0)
{
self.header.scrollLeft = left;
ts = setTimeout(move,10);
}
else
{
self.header.scrollLeft = limit;
self.fireEvent("onscroll");
}
}
move();
},
unload:function()
{
this.mainObj.parentNode.removeChild(this.mainObj);
System.killInstance(this);
this.killEvent();
for(var o in this)delete this[o];
},
addTab:function(o)
{
var os = {closeAble:this.options.allowClose}
var ss = this.tabs[this.tabs.length] = new System.UI.tabPage(this,Object.extend(os,o));
this.resetHeader();
if(this.selectedTab==null && this.tabs.length>0)this.tabs[0].select();
this.resetScrollBar();
this.fireEvent("onaddtab",ss);
return ss;
},
removeTab:function(o)
{
switch(typeof(o))
{
case "number":
o = this.tabs[parseInt(o)];
case "object":
var index = this.tabs.indexOf(o)
if(o && index>-1)
{
o.fireEvent("onclose");
this.fireEvent("onremovetab",o);
o.unload();
if(index>0)index--;
if(this.selectedTab==o)this.selectedTab = null;
if(this.selectedTab==null && this.tabs.length>0)this.tabs[index].select();
this.resetScrollBar();
}
break;
}
},
resetHeader:function()
{
var height = this.tabsField.firstChild?this.tabsField.firstChild.offsetHeight:2;
this.leftButton.style.height = this.rightButton.style.height = (height+1) + "px";
this.tabsField.style.height = height + "px";
},
resetScrollBar:function()
{
var last = this.tabs[this.tabs.length-1];
if(last && last.tabObj.offsetLeft + last.tabObj.offsetWidth > this.header.clientWidth)
{
this.leftButton.style.display = this.rightButton.style.display = "block";
this.header.style.marginLeft = this.header.style.marginRight = "";
}
else
{
this.header.scrollLeft = 0;
this.leftButton.style.display = this.rightButton.style.display = "none";
this.header.style.marginLeft = this.header.style.marginRight = "0px";
}
this.resetWidth();
},
tabChange:function(tab)
{
if(this.selectedTab!=tab)
{
if(this.selectedTab)this.selectedTab.blur();
tab.focus();
this.fireEvent("onchange",{oldTab:this.selectedTab,newTab:tab});
this.selectedTab = tab;
tab.fireEvent("onselected");
}
},
resetWidth:function()
{
this.panel.style.width = this.pageField.style.width = this.options.width + "px";
this.header.style.width = (this.options.width - this.leftButton.offsetWidth - this.rightButton.offsetWidth) + "px";
},
width:function(value)
{
if(value!=null)
{
value = parseInt(parseNum(value));
this.options.width = value<140?140:value;
this.resetWidth();
this.fireEvent("onresize");
}
return this.options.width;
},
height:function(value)
{
if(value!=null)
{
value = parseInt(parseNum(value));
this.options.height = value<60?60:value;
value = value - this.panel.offsetHeight;
this.pageField.style.height = value + "px";
this.fireEvent("onresize");
}
return this.options.height;
},
allowClose:function(value)
{
if(value!=null)
{
this.options.allowClose = value = !!value;
for(var i=0,l=this.tabs.length;i<l;i++)
this.tabs[i].closeAble(value);
}
return this.options.allowClose;
}
}
[Quote=引用 8 楼 hongqi162 的回复:]
// Method: loadToolbarSet()
// Description: Loads a toobar buttons set from an array inside the Toolbar holder.
// Author: FredCK
// Editor:fanliang11
function loadToolbarSet()
{
var sToolBarSet = URLParams["Toolbar"] == null ? "Default" : URLParams["Toolbar"] ;
var sCanUpload= ( URLParams['Upload'] == 'true' );//Editor:fanliang11
// FredCK: Toobar holder (DIV)
var oToolbarHolder = document.getElementById("divToolbar") ;
var oToolbar = new TBToolbar() ;
oToolbar.LoadButtonsSet( sToolBarSet ) ;
if(!sCanUpload)
{
var attachId= IndexArray(oToolbar.Bands.Array[1].Items.Array, "upload",0);//Editor:fanliang11
RemoveArray(oToolbar.Bands.Array[1].Items.Array,attachId);//Editor:fanliang11
}
oToolbarHolder.innerHTML = oToolbar.GetHTML() ;
}
//Method:Index
//Description:Add The name of Method is "Index" for Array Method
//Author:fanliang11
function IndexArray(arrayitem,item, i){ //判断Array的原型是否已作indexOf方法的扩展
i || (i = 0); //初始化起步查询的下标,比较奇特的写法。
var length = arrayitem.length;
if (i < 0) i = length + i; // 如i为负数,则从数组末端开始。
for (; i < length; i++)
if (arrayitem[i].Name === item) return i; // 使用全等于(===)判断符
return -1;
};
//Method:remove
////Description: Add The name of Method is "remove" for Array Method.
//Author:fanliang11
function RemoveArray(array,attachId)
{
for(var i=0,n=0;i<array.length;i++)
{
if(array[i]!=attachId)
{
array[n++]=array[i]
}
}
array.length -= 1;
}