
Otóż. Mam zakładki zrobione przy użyciu jQuery. Dołączany jest plik z klasą JS reprezentująca zakładkę do której przekazuję link i kontener który ma zostać uaktywniony. Klient zażyczył sobie jednak żebym dodał jeszcze jedną zakładkę na której będą wykonywane specyficzne operacje które wymagają dodatkowej porcji kodu JS. No i teraz tak się zastanawiam czy jest jakaś możliwość rozszerzenia klasy bazowej żeby dodać tą funkcjonalność lub jak byście ten mini problem rozwiązali.
Kod
<script>
function Fold_Collection()
{
this.folds = new Array();
var ths = this;
this.append = function($fold)
{
this.folds[this.folds.length] = $fold;
}
this.init = function($default)
{
var $links = $("ul#menu li.link_inactive");
var $panels = $("div#panels div.item_inactive");
$links.each(function($i)
{
$fold = new Fold($($links.get($i)), $($panels.get($i)), ths);
$fold.setEvtClick();
ths.append($fold);
});
this.deactivate();
this.folds[$default].activate();
}
this.deactivate = function()
{
for(var $i = 0; $i < this.folds.length; $i++)
{
this.folds[$i].deactivate();
}
}
}
function Fold($anch, $fold, $parent)
{
this.anch_ = $anch;
this.fold_ = $fold;
this.temp_ = '';
this.parent_ = $parent;
var ths = this;
this.setEvtClick = function()
{
this.anch_.click(
function()
{
ths.parent_.deactivate();
ths.activate();
});
}
this.activate = function()
{
this.anch_.attr("class", "link_active");
this.fold_.attr("class", "item_active");
}
this.deactivate = function()
{
this.anch_.attr("class", "link_inactive");
this.fold_.attr("class", "item_inactive");
}
}</script>
function Fold_Collection()
{
this.folds = new Array();
var ths = this;
this.append = function($fold)
{
this.folds[this.folds.length] = $fold;
}
this.init = function($default)
{
var $links = $("ul#menu li.link_inactive");
var $panels = $("div#panels div.item_inactive");
$links.each(function($i)
{
$fold = new Fold($($links.get($i)), $($panels.get($i)), ths);
$fold.setEvtClick();
ths.append($fold);
});
this.deactivate();
this.folds[$default].activate();
}
this.deactivate = function()
{
for(var $i = 0; $i < this.folds.length; $i++)
{
this.folds[$i].deactivate();
}
}
}
function Fold($anch, $fold, $parent)
{
this.anch_ = $anch;
this.fold_ = $fold;
this.temp_ = '';
this.parent_ = $parent;
var ths = this;
this.setEvtClick = function()
{
this.anch_.click(
function()
{
ths.parent_.deactivate();
ths.activate();
});
}
this.activate = function()
{
this.anch_.attr("class", "link_active");
this.fold_.attr("class", "item_active");
}
this.deactivate = function()
{
this.anch_.attr("class", "link_inactive");
this.fold_.attr("class", "item_inactive");
}
}</script>