var tabNameArray = ["tab 1", "tab 2", "tab 3", "tab 4"];
createTabs("whatever", tabNameArray);
function createTabs(id, tabNameArray) {
var tabContent = new AW.HTML.SPAN;
var obj = new AW.UI.Tabs;
obj.setId(id);
obj.setItemText(tabNameArray);
obj.setItemCount(tabNameArray.length);
obj.setSelectedItems([0]);
obj._tabEnabled = new Array();
for (var i = 0; i < tabNameArray.length; i++)
obj._tabEnabled[i] = true;
// redraw tab content when tab is clicked
obj.onCurrentItemChanged = function(i) {
if (tabContent.element() && obj._tabEnabled[i]) {
tabContent.element().innerHTML = getTabContent(i); //draw current tab
}
};
// prevent tab headers from updating
obj.calculateItemState = function(i) {
if (obj._tabEnabled[i]) {
var state = "";
if (this.getCurrentItem() == i) {state = "current"}
if (this.getItemSelected(i)) {state = "selected"}
if (this.getItemState(i) != state) {
this.setItemState(state, i);
}
}
};
}
function disableTab(tabsId, tabIndex) {
setTabEnabled(tabsId, tabIndex, false);
}
function enableTab(tabsId, tabIndex) {
setTabEnabled(tabsId, tabIndex, true);
}
function setTabEnabled(tabsId, tabIndex, enabled) {
var tabs = AW.object(tabsId);
if (tabs) tabs._tabEnabled[tabIndex] = enabled;
}
// cancel event
obj.onItemClicked = function(event, index){
if (index == 1) {
return true;
}
}
style
----------
.aw-extension-tabs-enabled {color:black;}
.aw-extension-tabs-disabled {color:gray; background-position: 100% 0px!important;}
.aw-extension-tabs-disabled .aw-item-box {color:gray; background-position: 0px -50px!important;}
javascript
----------
function createTabs(id, tabNameArray) {
var tabContainer = new AW.HTML.SPAN;
var obj = new AW.UI.Tabs;
obj.setId(id);
obj.setItemText(tabNameArray);
obj.setItemCount(tabNameArray.length);
obj.setSelectedItems([0]);
obj._tabEnabled = new Array();
for (var i = 0; i < tabNameArray.length; i++)
obj._tabEnabled[i] = true;
// redraw tab container when tab is clicked
obj.onCurrentItemChanged = function(i) {
if (tabContainer.element() && obj._tabEnabled[i]) {
tabContainer.element().innerHTML = getTabContent(i); //draw current tab
}
};
obj.onItemClicked = function(event, index) {
return !(index != obj.getCurrentItem() && obj._tabEnabled[index]);
};
document.write(obj);
document.write(tabContainer);
}
function disableTab(tabsId, tabIndex) {
setTabEnabled(tabsId, tabIndex, false);
}
function enableTab(tabsId, tabIndex) {
setTabEnabled(tabsId, tabIndex, true);
}
//private
function setTabEnabled(tabsId, tabIndex, enabled) {
var tabs = AW.object(tabsId);
if (tabs) {
var tab = tabs.getItemTemplate(tabIndex);
if (tab) {
tabs._tabEnabled[tabIndex] = enabled;
tab.setClass("extension", (enabled ? "tabs-enabled" : "tabs-disabled"));
tab.refresh();
}
}
}
<s t y l e>
.aw-extension-tabs-enabled {color:black;}
.aw-extension-tabs-disabled {color:gray; background-position: 100% 0px!important;}
.aw-extension-tabs-disabled .aw-item-box {color:gray; background-position: 0px -50px!important;}
</ s t y l e>
AW.UI.TabsEnhanced = AW.UI.Tabs.subclass();
AW.UI.TabsEnhanced.create = function()
{
var obj = this.prototype;
obj.isEnabled = function(col)
{
if (typeof this.getItemTemplate(col).getAttribute('isEnabled') == 'undefined')
return true
else
return (this.getItemTemplate(col).getAttribute('isEnabled'))
}
obj.setTabEnabled = function(tabIndex, enabled)
{
if (enabled == true)
{
this.getItemTemplate(tabIndex).setAttribute('isEnabled', true);
this.getItemTemplate(tabIndex).setClass("extension", "tabs-enabled")
}
else
{
this.getItemTemplate(tabIndex).setAttribute('isEnabled', false);
this.getItemTemplate(tabIndex).setClass("extension", "tabs-disabled")
}
}
obj.onItemClicked = function(event, index)
{
if (this.isEnabled(index) == false)
return true;
}
}
a = new AW.UI.TabsEnhanced;
a.setItemText(["one","two","three"]);
a.setItemCount(3);
a.setTabEnabled(1, false);
document.write(a);
a.isEnabled(columnNumber);
This topic is archived.