sync.tabpane.js
来自「echo3 很炫的ajax框架技术 js 演示demo ajax j2ee 里」· JavaScript 代码 · 共 1,019 行 · 第 1/3 页
JS
1,019 行
icon = icons.disabledIcon;
}
return icon ? icon : icons.defaultIcon || this._parent.client.getResourceUrl("Extras", "image/tabpane/Close.gif");
},
_getContentInsets: function() {
if (this._childComponent.pane) {
return Extras.Sync.TabPane._paneInsets;
} else {
return this._parent.component.render("defaultContentInsets",
Extras.Sync.TabPane._defaultTabContentInsets);
}
},
_getLeftImage: function(state) {
var propertyName = state ? "tabActiveLeftImage" : "tabInactiveLeftImage";
var image = this._parent.component.render(propertyName);
if (!image) {
return;
}
var fillImage = { url: (image.url ? image.url : image), repeat: "no-repeat", x: 0, y: 0 };
return { width: (image.width ? image.width : null), fillImage: fillImage };
},
_getRightImage: function(state) {
var propertyName = state ? "tabActiveRightImage" : "tabInactiveRightImage";
var image = this._parent.component.render(propertyName);
if (!image) {
return;
}
var fillImage = { url: (image.url ? image.url : image), repeat: "no-repeat", x: "100%", y: 0 };
return { width: (image.width ? image.width : null), fillImage: fillImage };
},
/**
* Renders the tab active or inactive, updating header state and showing/hiding tab content.
*/
_renderActiveState: function(state) {
var headerContentTable = this._headerContentTable;
var centerTd = this._centerTd;
var contentDiv = this._contentDiv;
var foreground;
var background;
var border;
if (state) {
foreground = this._parent.component.render("tabActiveForeground");
background = this._parent.component.render("tabActiveBackground");
border = this._parent._tabActiveBorder;
} else {
foreground = this._parent.component.render("tabInactiveForeground");
background = this._parent.component.render("tabInactiveBackground");
border = this._parent._tabInactiveBorder;
}
Echo.Sync.Color.renderClear(foreground, headerContentTable, "color");
Echo.Sync.Color.renderClear(background, headerContentTable, "backgroundColor");
headerContentTable.style.cursor = state ? "default" : "pointer";
var backgroundImage;
if (state) {
backgroundImage = this._parent.component.render("tabActiveBackgroundImage");
} else {
backgroundImage = this._parent.component.render("tabInactiveBackgroundImage");
}
Echo.Sync.FillImage.renderClear(backgroundImage, centerTd, null);
var activeBorderSize = Echo.Sync.Border.getPixelSize(this._parent._tabActiveBorder);
var inactiveBorderSize = Echo.Sync.Border.getPixelSize(this._parent._tabInactiveBorder);
if (this._parent._tabPosition == Extras.TabPane.TAB_POSITION_BOTTOM) {
headerContentTable.style.marginTop = state ? 0 : activeBorderSize + "px";
headerContentTable.style.marginBottom = state ? 0 : this._parent._tabActiveHeightIncreasePx + "px";
centerTd.style.paddingTop = state ? (inactiveBorderSize + this._parent._tabActiveHeightIncreasePx )+ "px" : 0;
Echo.Sync.Border.render(border, headerContentTable, "borderBottom");
} else {
headerContentTable.style.marginBottom = state ? 0 : activeBorderSize + "px";
headerContentTable.style.marginTop = state ? 0 : this._parent._tabActiveHeightIncreasePx + "px";
centerTd.style.paddingBottom = state ? (inactiveBorderSize + this._parent._tabActiveHeightIncreasePx )+ "px" : 0;
Echo.Sync.Border.render(border, headerContentTable, "borderTop");
}
Echo.Sync.Border.render(border, headerContentTable, "borderLeft");
Echo.Sync.Border.render(border, headerContentTable, "borderRight");
var font;
if (state) {
font = this._parent.component.render("tabActiveFont");
} else {
font = this._parent.component.render("tabInactiveFont");
}
Echo.Sync.Font.renderClear(font, headerContentTable);
if (this._leftTd) {
var leftImage = this._getLeftImage(state);
Echo.Sync.FillImage.renderClear(leftImage ? leftImage.fillImage : null, this._leftTd, null);
if (leftImage && leftImage.width) {
this._leftTd.style.width = leftImage.width.toString();
}
}
if (this._rightTd) {
var rightImage = this._getRightImage(state);
Echo.Sync.FillImage.renderClear(rightImage ? rightImage.fillImage : null, this._rightTd, null);
if (rightImage && rightImage.width) {
this._rightTd.style.width = rightImage.width.toString();
}
}
// show/hide content
if (Core.Web.Env.BROWSER_MOZILLA && !Core.Web.Env.BROWSER_FIREFOX) {
contentDiv.style.right = state ? "0" : "100%";
contentDiv.style.bottom = state ? "0" : "100%";
} else {
contentDiv.style.display = state ? "block" : "none";
}
if (state) {
// FIXME hack to notify the tab content component that it's size may have changed, this is
// required because any previous notifications could have taken place when this tab was hidden.
Echo.Render.renderComponentDisplay(this._childComponent);
}
},
/**
* Tab click handler.
*/
_processClick: function(e) {
if (!this._parent || !this._parent.client || !this._parent.client.verifyInput(this._parent.component)) {
return true;
}
if (this._closeImageTd && Core.Web.DOM.isAncestorOf(this._closeImageTd, e.target)) {
// close icon clicked
if (!this._tabCloseEnabled) {
return;
}
this._parent.component.doTabClose(this._childComponent);
} else {
// tab clicked
this._parent._selectTab(this._childComponent.renderId);
this._parent._setActiveTabId(this._childComponent.renderId);
this._parent.component.doTabSelect(this._childComponent);
}
},
/**
* Tab rollover enter handler.
*/
_processEnter: function(e) {
if (!this._parent || !this._parent.client || !this._parent.client.verifyInput(this._parent.component)) {
return true;
}
var rollover = Core.Web.DOM.isAncestorOf(this._closeImageTd, e.target);
this._closeImageTd.firstChild.src = Echo.Sync.ImageReference.getUrl(this._getCloseImage(rollover));
},
/**
* Tab rollover exit handler.
*/
_processExit: function(e) {
var rollover = Core.Web.DOM.isAncestorOf(this._closeImageTd, e.target);
this._closeImageTd.firstChild.src = Echo.Sync.ImageReference.getUrl(this._getCloseImage(false));
},
/**
* Renders the tab.
*/
_render: function(update) {
this._headerTd = this._renderHeader();
this._headerContentTable = this._headerTd.firstChild;
this._contentDiv = this._renderContent(update);
this._renderActiveState(this._childComponent.renderId == this._parent._activeTabId);
this._addEventListeners();
},
/**
* Renders the close icon.
*/
_renderCloseIcon: function() {
var td = document.createElement("td");
Echo.Sync.Alignment.render(this._parent.component.render("tabAlignment",
Extras.Sync.TabPane._defaultTabAlignment), td, true, this._parent.component);
td.style.padding = "0 0 0 " + this._parent.component.render("tabCloseIconTextMargin",
Extras.Sync.TabPane._defaultTabCloseIconTextMargin + "px");
td.style.cursor = "pointer";
var img = document.createElement("img");
img.src = Echo.Sync.ImageReference.getUrl(this._getCloseImage(false));
if (Core.Web.Env.BROWSER_INTERNET_EXPLORER) {
// remove auto-calculated width & height, to prevent problems with different image sizes
img.removeAttribute("width");
img.removeAttribute("height");
}
td.appendChild(img);
return td;
},
/**
* Renders the content of a tab.
*/
_renderContent: function(update) {
var div = document.createElement("div");
div.style.cssText = "position:absolute;top:0;left:0;overflow:auto;";
// hide content
if (Core.Web.Env.BROWSER_MOZILLA && !Core.Web.Env.BROWSER_FIREFOX) {
//FIXME doc or remove (and why no display=none?)
div.style.right = "100%";
div.style.bottom = "100%";
} else {
div.style.display = "none";
div.style.right = "0";
div.style.bottom = "0";
}
Echo.Sync.Insets.render(this._getContentInsets(), div, "padding");
Echo.Render.renderComponentAdd(update, this._childComponent, div);
return div;
},
/**
* Tab-specific renderDisplay() tasks.
*/
_renderDisplay: function() {
Core.Web.VirtualPosition.redraw(this._contentDiv);
},
/**
* Renders the "header" of a tab, i.e., the tab label at the top/bottom of the TabPane.
*/
_renderHeader: function() {
var layoutData = this._childComponent.render("layoutData");
var headerTd = document.createElement("td");
headerTd.style.padding = 0;
headerTd.style.border = "0px none";
headerTd.vAlign = this._parent._tabPosition == Extras.TabPane.TAB_POSITION_BOTTOM ? "top" : "bottom";
var tabTable = document.createElement("table");
tabTable.cellPadding = "0";
tabTable.cellSpacing = "0";
tabTable.style.padding = "0";
tabTable.style.marginRight = this._parent._tabSpacing.toString();
var width = this._parent.component.render("tabWidth");
if (width) {
tabTable.style.width = width.toString();
}
var tabTbody = document.createElement("tbody");
var tabTr = document.createElement("tr");
// Render TD element to contain left border image (if required).
if (this._getLeftImage(true) != null || this._getLeftImage(false) != null) {
this._leftTd = document.createElement("td");
this._leftTd.appendChild(document.createTextNode("\u00a0"));
tabTr.appendChild(this._leftTd);
}
// Render TD element to contain tab content.
var centerTd = document.createElement("td");
Echo.Sync.Insets.render(Extras.Sync.TabPane._defaultTabInsets, centerTd, "padding");
var labelDiv = document.createElement("div");
centerTd.appendChild(labelDiv);
var icon = layoutData ? layoutData.icon : null;
var title = layoutData ? (layoutData.title ? layoutData.title : "*") : "*";
var closeIcon = this._parent._tabCloseEnabled && (this._tabCloseEnabled || this._parent._icons.disabledIcon);
if (icon || closeIcon) {
// Render Text and Icon(s)
var table = document.createElement("table");
table.style.padding = "0";
table.cellPadding = "0";
table.cellSpacing = "0";
var tbody = document.createElement("tbody");
var tr = document.createElement("tr");
if (icon) {
tr.appendChild(this._renderIcon(icon));
}
var textTd = document.createElement("td");
textTd.style.whiteSpace = "nowrap";
Echo.Sync.Alignment.render(this._parent.component.render("tabAlignment",
Extras.Sync.TabPane._defaultTabAlignment), textTd, true, this._parent.component);
textTd.appendChild(document.createTextNode(title));
table.appendChild(tbody);
tbody.appendChild(tr);
tr.appendChild(textTd);
if (closeIcon) {
this._closeImageTd = this._renderCloseIcon();
tr.appendChild(this._closeImageTd);
}
labelDiv.appendChild(table);
} else {
// Render Text Only
labelDiv.style.whiteSpace = "nowrap";
Echo.Sync.Alignment.render(this._parent.component.render("tabAlignment",
Extras.Sync.TabPane._defaultTabAlignment), labelDiv, true, this._parent.component);
labelDiv.appendChild(document.createTextNode(title));
}
if (this._parent.component.render("tabHeight")) {
Echo.Sync.Extent.render(this._parent.component.render("tabHeight"), labelDiv, "height", false, false);
}
tabTr.appendChild(centerTd);
this._centerTd = centerTd;
// Render TD element to contain right border image (if required).
if (this._getRightImage(true) != null || this._getRightImage(false) != null) {
this._rightTd = document.createElement("td");
this._rightTd.appendChild(document.createTextNode("\u00a0"));
tabTr.appendChild(this._rightTd);
}
tabTbody.appendChild(tabTr);
tabTable.appendChild(tabTbody);
headerTd.appendChild(tabTable);
return headerTd;
},
/**
* Renders the icon of a tab.
*/
_renderIcon: function(icon) {
var td = document.createElement("td");
Echo.Sync.Alignment.render(this._parent.component.render("tabAlignment",
Extras.Sync.TabPane._defaultTabAlignment), td, true, this._parent.component);
var img = document.createElement("img");
img.src = Echo.Sync.ImageReference.getUrl(icon);
img.style.marginRight = this._parent.component.render("tabIconTextMargin",
Extras.Sync.TabPane._defaultTabIconTextMargin + "px");
td.appendChild(img);
return td;
}
});
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?