mixElements.append("tab");
"tab,heading,content".split(",").each(function (v){
document.createElement(v);
});
mix.tab = function (elements){
var tab;
if (type(elements) == "undefined"){
tab = $(document.createElement("tab"));
}else{
tab = $(elements).filter(function (){
var el = this.parentNode;
while (el.nodeType == 1 && el.nodeName.toLowerCase() != "html" && el.nodeName.toLowerCase() != "template")
el = el.parentNode;
return (("" + this.nodeName).toLowerCase() == "tab"
&& this._mixInit !== true
&& el.nodeName.toLowerCase() != "template");
//node name is tab and has not been initialized
//and it is not in template
});
}
tab.bind("attrChange", function (){
mix.tab.redraw(this);
}).each(function (){
this._mixInit = true;
}).childrenTag("heading").bind("click", function (e){
$(this.parentNode).attr("selected", $(this).parent().find("heading").index(this));
}).end().redraw();
$(window).resize(function (){
tab.redraw();
});
return tab;
};
mix.tab.redraw = function (el){
var selectedIdx = $(el).attr("selected");
if (type(selectedIdx) != "string" && type(selectedIdx) != "number")
selectedIdx = 0;
else
selectedIdx = selectedIdx.toInteger();
$(el).childrenTag("content").hide().filter(function (idx){
return idx == selectedIdx;
}).show().end().end().childrenTag("heading").removeClass("selected").filter(function (idx){
return idx == selectedIdx;
}).addClass("selected");
};
mix.tab.attr = function (el, name, value){
if (type(value) == "undefined"){ //getter
switch (name){
case "selected":
return el.getAttribute(name);
break;
}
return;
}
switch (name){
case "selected":
el.setAttribute(name, value);
$(el).trigger("attrChange", [name, value]);
break;
}
return value;
};
mix.tab.customAttrList = "selected".split(","); |