📄 tabcontrolcommon.jsp
字号:
<!-------------------------------------------->
<!-- Common code for all types of Tab Pages -->
<!-------------------------------------------->
<script language="JavaScript1.2">
var gsTabControl="";
var gaDivs = new Array();
var gaTabs = new Array();
var goPersist = null;
var gsPageId = "";
//scrolling menu variables
var menuwidth = 800;
var scrollspeed = 6;
var actualwidth = 0;
var ns_scroll;
function CPersist(attachedTo, storePath){
if( oBD.doesPersistence ){
this._obj = attachedTo;
this._obj.addBehavior("#default#userData");
this._path = storePath;
this._loaded = false;
}
}
CPersist.prototype.Save = function(){
if( oBD.doesPersistence ){
if(this.IsLoaded()){
var enabled = true;
var code = "try{ this.GetAttached().save(this._path); } catch(e) {enabled = false;}";
eval(code);
}
}
}
CPersist.prototype.Load = function(){
if( oBD.doesPersistence ){
if(!this.IsLoaded()){
var enabled = true;
var code = "try{ this.GetAttached().load(this._path); } catch(e) {enabled = false;}";
eval(code);
if(!enabled) return;
this._loaded = true;
}
}
}
CPersist.prototype.GetAttached = function(){
if( oBD.doesPersistence ) return this._obj;
}
CPersist.prototype.IsLoaded = function(){
if( oBD.doesPersistence ) return this._loaded;
}
CPersist.prototype.SetAttribute = function(key, value){
if( oBD.doesPersistence ){
if( !this.IsLoaded() ) this.Load();
if( this.IsLoaded() ){ // confirm that the load actually happened. Cannot add data if load failed.
if( !gsPageId ) pageID = "unknown"; else pageID = gsPageId;
this.GetAttached().setAttribute(pageID + "." + key, value);
}
this.Save();
}
}
CPersist.prototype.GetAttribute = function(key){
if( oBD.doesPersistence ){
if( !this.IsLoaded() ) this.Load();
if( this.IsLoaded() ){ // confirm that the load actually happened. Cannot get data if load failed.
if( !gsPageId ) pageID = "unknown"; else pageID = gsPageId;
var value = this.GetAttached().getAttribute(pageID + "." + key);
}
if(key == "selectedTab"){
if(!value) value = 0;
} else if(key == "expanded"){
if(value == "true")
value = true;
else
value = false;
} else if(key == "scroll"){
if(!value) value = 0;
}
return value;
}
}
/*
* initilizes a new, logical tab for objectmembers. A "tab" consists of both
* the tab and the member content.
*/
function CTabber(newTab){
this._caption = ""; this._content = null; this._tab = null; this._targetURL=newTab.targetURL;
// only initialize of this is actually a tab. Tabs are identifed by a @tabName attribute.
if(newTab.tabName){
this._initializeComponent(newTab);
} else {
return null;
}
}
/*
* Returns the caption used for the tab.
*/
CTabber.prototype.GetCaption = function(){
return this._caption;
}
/*
* Sets the caption used for the tab. Also updates the tabbed title bar.
*/
CTabber.prototype.SetCaption = function(newCaption){
this._caption = newCaption;
if(this.IsActive){ // should only change title bar if currently active.
oMTitle.innerText = newCaption;
}
}
/*
* Returns the <div> that is attached to this tab object.
*/
CTabber.prototype.GetContent = function(){
return this._content;
}
/*
* Returns the rendered tab (<TD>) for this tab object.
*/
CTabber.prototype.GetTab = function(){
return this._tab;
}
/*
* Returns true if this tab object is currently being rendered (e.g. the <div> is displayed),
* otherwise returns false.
*/
CTabber.prototype.IsActive = function(){
return (this.GetTab().className == "oMTabOn" ? true : false);
}
/*
* Not used, ignore.
*/
CTabber.prototype._setColumnHeaders = function(){
var heads = this.GetContent().getElementsByTagName("TH");
for(var i=0; i<heads.length; i++){
var cn = heads[i].cloneNode(true);
oMHeadings.appendChild(cn);
heads[i].style.display = "none";
}
}
CTabber.prototype.GetActiveTab = function(){
for(var i=0; i<gaTabs.length; i++){
var tab = gaTabs[i];
if(tab.IsActive()) return tab;
}
}
/*
* Forces a an inactive tab to become active. That means that the
* tab itself changes state and the <div> is rendered.
*
* Any previously active tab is made inactive first.
*/
CTabber.prototype.MakeActive = function(){
var tab = this.GetActiveTab();
if(tab){
tab.MakeInActive();
}
this.GetTab().className = "oMTabOn";
this.GetTab().style.backgroundColor = "#FFFFFF";
this.GetTab().style.borderBottom = "0.02cm solid white";
oMTData.appendChild(this.GetContent());
this.GetContent().style.display = "block";
this.SetScrollPosition(0); // reset the scroll bar.
oMTData.scrollTop = this.GetScrollPosition();
if (this._targetURL){
document.all.oMIframe.style.visibility = "visible";
document.all.oMIframe.width="100%";
document.all.oMIframe.height="98%";
document.all.oMIframe.src = this._targetURL;
} else {
document.all.oMIframe.style.visibility = "hidden";
document.all.oMIframe.width="0";
document.all.oMIframe.height="0";
}
// save the state to a userData store.
goPersist.SetAttribute("selectedTab", this.GetCaption());
}
/*
* Forces an active tab to become inactive. Changes the state of the tab
* and removes the <div> from the screen.
*/
CTabber.prototype.MakeInActive = function(){
this.GetContent().style.display = "none";
this.GetTab().className = "oMTab";
this.GetTab().style.backgroundColor = "#C0C0C0";
this.GetTab().style.borderBottom = "0.02cm solid black";
}
/*
* Event for when the mouse moves over the tab button.
*/
CTabber.prototype.OnMouseHover = function(){
if(!this.IsActive())
this.GetTab().className = "oMTabHover";
}
/*
* Event for when the user clicks the tab button.
*/
CTabber.prototype.OnMouseClick = function(){
if(!this.IsActive()){ // should only run event if not already active.
this.MakeActive();
}
}
/*
* Event for when the user moves the mouse from within the tab button area.
*/
CTabber.prototype.OnMouseFlee = function(){
if(!this.IsActive()) // should only run event if not alreay active.
this.GetTab().className = "oMTab";
}
/*
* Returns the scroll position for the <div> associated with this tab object.
*/
CTabber.prototype.GetScrollPosition = function(){
this._scroll;
}
// Sets the scroll position for the <div> associated with this tab object.
CTabber.prototype.SetScrollPosition = function(newValue){
this._scroll = newValue;
if(this.IsActive()) oMTData.scrollTop = newValue;
goPersist.SetAttribute("scroll", newValue);
goPersist.Save();
}
// Initializes the state of the tab. This includes creating the physical tab as well as associated a <div> with it.
CTabber.prototype._initializeComponent = function(newTab){
this._caption = newTab.tabName;
this._content = newTab;
this._scroll = 0;
// prepare the tab for use. Create the necessary structure.
this._tab = document.createElement("TD");
this._tab.onmouseover = onMouseOverRedirect;
this._tab.onmouseout = onMouseOutRedirect;
this._tab.onmousedown = onMouseClickRedirect;
this._tab.onkeypress = onMouseClickRedirect;
this._tab.onclick = onMouseClickRedirect;
this._tab.title = this.GetCaption();
this._tab.className = "oMTab";
this._tab.tabIndex = "0";
this._tab.innerHTML = "<noBR><CENTER>" + this.GetCaption() + "</CENTER></noBR>";
// this._tab.setAttribute("width","20",0);
// this._tab.width = "20%";
// this._tab.width = (this._tab.title.length*5) + 20;
this._tab.vAlign = "middle";
this._tab.tab = this;
this.GetContent().tab = this;
}
/*
* functions that dispatch the event to the correct handler. This is done because
* when an event fires, there is no way for the system to know which user-defined
* object (CTabber) is being invoked. The <TD> has a reference to the owning tab object
* so that the event can be invoked on the correct object.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -